+static int isarg_rights(const char *arg) {
+ return strchr(arg, ',') || !parse_rights(arg, 0, 0);
+}
+
+static void cf_adduser(char **argv) {
+ if(disorder_adduser(getclient(), argv[0], argv[1], argv[2]))
+ exit(EXIT_FAILURE);
+}
+
+static void cf_deluser(char **argv) {
+ if(disorder_deluser(getclient(), argv[0]))
+ exit(EXIT_FAILURE);
+}
+
+static void cf_edituser(char **argv) {
+ if(disorder_edituser(getclient(), argv[0], argv[1], argv[2]))
+ exit(EXIT_FAILURE);
+}
+
+static void cf_userinfo(char **argv) {
+ char *s;
+
+ if(disorder_userinfo(getclient(), argv[0], argv[1], &s))
+ exit(EXIT_FAILURE);
+ xprintf("%s\n", nullcheck(utf82mb(s)));
+}
+
+static int isarg_option(const char *arg) {
+ return arg[0] == '-';
+}
+
+static int argvlen(char **argv) {
+ char **start = argv;
+
+ while(*argv)
+ ++argv;
+ return argv - start;
+}
+
+static const struct option setup_guest_options[] = {
+ { "help", no_argument, 0, 'h' },
+ { "online-registration", no_argument, 0, 'r' },
+ { "no-online-registration", no_argument, 0, 'R' },
+ { 0, 0, 0, 0 }
+};
+
+static void help_setup_guest(void) {
+ xprintf("Usage:\n"
+ " disorder setup-guest [OPTIONS]\n"
+ "Options:\n"
+ " --help, -h Display usage message\n"
+ " --online-registration Enable online registration (default)\n"
+ " --no-online-registration Disable online registration\n");
+ xfclose(stdout);
+ exit(0);
+}
+
+static void cf_setup_guest(char **argv) {
+ int n, online_registration = 1;
+
+ while((n = getopt_long(argvlen(argv) + 1, argv - 1,
+ "hrR", setup_guest_options, 0)) >= 0) {
+ switch(n) {
+ case 'h': help_setup_guest();
+ case 'r': online_registration = 1; break;
+ case 'R': online_registration = 0; break;
+ default: fatal(0, "invalid option");
+ }
+ }
+ if(online_registration && !config->mail_sender)
+ fatal(0, "you MUST set mail_sender if you want online registration");
+ if(disorder_adduser(getclient(), "guest", "",
+ online_registration ? "read,register" : "read"))