2 * Citadel setup utility
4 * Copyright (c) 1987-2016 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #define SHOW_ME_VAPPEND_PRINTF
22 #include <sys/types.h>
31 #include <sys/socket.h>
34 #include <libcitadel.h>
38 #include "citadel_dirs.h"
49 #define _(string) gettext(string)
51 #define _(string) (string)
54 #define UI_TEXT 0 /* Default setup type -- text only */
55 #define UI_DIALOG 2 /* Use the 'whiptail' or 'dialog' program */
56 #define UI_SILENT 3 /* Silent running, for use in scripts */
58 #define SERVICE_NAME "citadel"
59 #define PROTO_NAME "tcp"
60 #define NSSCONF "/etc/nsswitch.conf"
62 typedef enum _SetupStep {
78 ///"CREATE_XINETD_ENTRY";
79 /* Environment variables, don't translate! */
80 const char *EnvNames [eMaxQuestions] = {
95 int setup_type = (-1);
100 int serv_sock = (-1) ;
102 const char *setup_titles[eMaxQuestions];
103 const char *setup_text[eMaxQuestions];
117 setlocale(LC_MESSAGES, getenv("LANG"));
119 bindtextdomain("citadel-setup", LOCALEDIR"/locale");
120 textdomain("citadel-setup");
121 bind_textdomain_codeset("citadel-setup","UTF8");
124 setup_titles[eCitadelHomeDir] = _("Citadel Home Directory");
126 setup_text[eCitadelHomeDir] = _(
127 "Enter the full pathname of the directory in which the Citadel\n"
128 "installation you are creating or updating resides. If you\n"
129 "specify a directory other than the default, you will need to\n"
130 "specify the -h flag to the server when you start it up.\n");
132 setup_text[eCitadelHomeDir] = _(
133 "Enter the subdirectory name for an alternate installation of "
134 "Citadel. To do a default installation just leave it blank."
135 "If you specify a directory other than the default, you will need to\n"
136 "specify the -h flag to the server when you start it up.\n"
137 "note that it may not have a leading /");
140 setup_titles[eSysAdminName] = _("Citadel administrator username:");
141 setup_text[eSysAdminName] = _(
142 "Please enter the name of the Citadel user account that should be granted "
143 "administrative privileges once created. If using internal authentication "
144 "this user account will be created if it does not exist. For external "
145 "authentication this user account has to exist.");
148 setup_titles[eSysAdminPW] = _("Administrator password:");
149 setup_text[eSysAdminPW] = _(
150 "Enter a password for the system administrator. When setup\n"
151 "completes it will attempt to create the administrator user\n"
152 "and set the password specified here.\n");
154 setup_titles[eUID] = _("Citadel User ID:");
155 setup_text[eUID] = _(
156 "Citadel needs to run under its own user ID. This would\n"
157 "typically be called \"citadel\", but if you are running Citadel\n"
158 "as a public site, you might also call it \"bbs\" or \"guest\".\n"
159 "The server will run under this user ID. Please specify that\n"
160 "user ID here. You may specify either a user name or a numeric\n"
163 setup_titles[eIP_ADDR] = _("Listening address for the Citadel server:");
164 setup_text[eIP_ADDR] = _(
165 "Please specify the IP address which the server should be listening to. "
166 "You can name a specific IPv4 or IPv6 address, or you can specify\n"
167 "\"*\" for \"any address\", \"::\" for \"any IPv6 address\", or \"0.0.0.0\"\n"
168 "for \"any IPv4 address\". If you leave this blank, Citadel will\n"
169 "listen on all addresses. "
170 "This can usually be left to the default unless multiple instances of Citadel "
171 "are running on the same computer.");
173 setup_titles[eCTDL_Port] = _("Server port number:");
174 setup_text[eCTDL_Port] = _(
175 "Specify the TCP port number on which your server will run.\n"
176 "Normally, this will be port 504, which is the official port\n"
177 "assigned by the IANA for Citadel servers. You will only need\n"
178 "to specify a different port number if you run multiple instances\n"
179 "of Citadel on the same computer and there is something else\n"
180 "already using port 504.\n");
182 setup_titles[eAuthType] = _("Authentication method to use:");
183 setup_text[eAuthType] = _(
184 "Please choose the user authentication mode. By default Citadel will use its "
185 "own internal user accounts database. If you choose Host, Citadel users will "
186 "have accounts on the host system, authenticated via /etc/passwd or a PAM "
187 "source. LDAP chooses an RFC 2307 compliant directory server, the last option "
188 "chooses the nonstandard MS Active Directory LDAP scheme."
190 "Do not change this option unless you are sure it is required, since changing "
191 "back requires a full reinstall of Citadel."
193 " 0. Self contained authentication\n"
194 " 1. Host system integrated authentication\n"
195 " 2. External LDAP - RFC 2307 compliant directory\n"
196 " 3. External LDAP - nonstandard MS Active Directory\n"
198 "For help: http://www.citadel.org/doku.php/faq:installation:authmodes\n"
200 "ANSWER \"0\" UNLESS YOU COMPLETELY UNDERSTAND THIS OPTION.\n");
202 setup_titles[eLDAP_Host] = _("LDAP host:");
203 setup_text[eLDAP_Host] = _(
204 "Please enter the host name or IP address of your LDAP server.\n");
206 setup_titles[eLDAP_Port] = _("LDAP port number:");
207 setup_text[eLDAP_Port] = _(
208 "Please enter the port number of the LDAP service (usually 389).\n");
210 setup_titles[eLDAP_Base_DN] = _("LDAP base DN:");
211 setup_text[eLDAP_Base_DN] = _(
212 "Please enter the Base DN to search for authentication\n"
213 "(for example: dc=example,dc=com)\n");
215 setup_titles[eLDAP_Bind_DN] = _("LDAP bind DN:");
216 setup_text[eLDAP_Bind_DN] = _(
217 "Please enter the DN of an account to use for binding to the LDAP server for "
218 "performing queries. The account does not require any other privileges. If "
219 "your LDAP server allows anonymous queries, you can leave this blank.\n");
221 setup_titles[eLDAP_Bind_PW] = _("LDAP bind password:");
222 setup_text[eLDAP_Bind_PW] = _(
223 "If you entered a Bind DN in the previous question, you must now enter\n"
224 "the password associated with that account. Otherwise, you can leave this\n"
228 // Debug loading of locales... Strace does a better job though.
229 printf("Message catalog directory: %s\n", bindtextdomain("citadel-setup", LOCALEDIR"/locale"));
230 printf("Text domain: %s\n", textdomain("citadel-setup"));
231 printf("Text domain Charset: %s\n", bind_textdomain_codeset("citadel-setup","UTF8"));
234 for (i = 0; i < eMaxQuestions; i++)
235 printf("%s - %s\n", setup_titles[i], _(setup_titles[i]));
243 void title(const char *text)
245 if (setup_type == UI_TEXT) {
246 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
252 int yesno(const char *question, int default_value)
258 switch (setup_type) {
262 printf("%s\n%s [%s] --> ",
265 ( default_value ? _("Yes") : _("No") )
267 if (fgets(buf, sizeof buf, stdin))
269 answer = tolower(buf[0]);
270 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10)) {
271 answer = default_value;
273 else if (answer == 'y') {
276 else if (answer == 'n') {
280 } while ((answer < 0) || (answer > 1));
284 snprintf(buf, sizeof buf, "exec %s --backtitle '%s' %s --yesno '%s' 15 75",
285 getenv("CTDL_DIALOG"),
287 ( default_value ? "" : "--defaultno" ),
304 void important_message(const char *title, const char *msgtext)
308 switch (setup_type) {
311 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
312 printf(" %s \n\n%s\n\n", title, msgtext);
313 printf("%s", _("Press return to continue..."));
314 if (fgets(buf, sizeof buf, stdin))
319 snprintf(buf, sizeof buf, "exec %s --backtitle '%s' --msgbox '%s' 19 72",
320 getenv("CTDL_DIALOG"),
323 int rv = system(buf);
325 fprintf(stderr, _("failed to run the dialog command\n"));
329 fprintf(stderr, "%s\n", msgtext);
334 void important_msgnum(int msgnum)
336 important_message(_("Important Message"), setup_text[msgnum]);
339 void display_error(char *error_message_format, ...)
345 va_start(arg_ptr, error_message_format);
346 StrBufVAppendPrintf(Msg, error_message_format, arg_ptr);
349 important_message(_("Error"), ChrPtr(Msg));
353 void progress(char *text, long int curr, long int cmax)
355 static long dots_printed = 0L;
357 static FILE *fp = NULL;
360 switch (setup_type) {
364 printf("%s\n", text);
365 printf("....................................................");
366 printf("..........................\r");
368 } else if (curr == cmax) {
369 printf("\r%79s\n", "");
371 a = (curr * 100) / cmax;
374 while (dots_printed < a) {
384 snprintf(buf, sizeof buf, "exec %s --backtitle '%s' --gauge '%s' 7 72 0",
385 getenv("CTDL_DIALOG"),
388 fp = popen(buf, "w");
394 else if (curr == cmax) {
396 fprintf(fp, "100\n");
402 a = (curr * 100) / cmax;
404 fprintf(fp, "%ld\n", a);
413 assert(1==0); /* If we got here then the developer is a moron */
419 int uds_connectsock(char *sockpath)
422 struct sockaddr_un addr;
424 memset(&addr, 0, sizeof(addr));
425 addr.sun_family = AF_UNIX;
426 strncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
428 s = socket(AF_UNIX, SOCK_STREAM, 0);
433 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
443 * input binary data from socket
445 void serv_read(char *buf, int bytes)
450 while (len < bytes) {
451 rlen = read(serv_sock, &buf[len], bytes - len);
461 * send binary to server
463 void serv_write(char *buf, int nbytes)
465 int bytes_written = 0;
467 while (bytes_written < nbytes) {
468 retval = write(serv_sock, &buf[bytes_written], nbytes - bytes_written);
472 bytes_written = bytes_written + retval;
479 * input string from socket - implemented in terms of serv_read()
481 void serv_gets(char *buf)
485 /* Read one character at a time.
488 serv_read(&buf[i], 1);
489 if (buf[i] == '\n' || i == (SIZ-1))
493 /* If we got a long line, discard characters until the newline.
496 while (buf[i] != '\n') {
497 serv_read(&buf[i], 1);
501 /* Strip all trailing nonprintables (crlf)
508 * send line to server - implemented in terms of serv_write()
510 void serv_puts(char *buf)
512 serv_write(buf, strlen(buf));
518 * Convenience functions to get/set system configuration entries
520 void getconf_str(char *buf, char *key)
525 sprintf(cmd, "CONF GETVAL|%s", key);
529 extract_token(buf, &ret[4], 0, '|', SIZ);
536 int getconf_int(char *key)
539 getconf_str(buf, key);
543 void setconf_str(char *key, char *val)
547 sprintf(buf, "CONF PUTVAL|%s|%s", key, val);
553 void setconf_int(char *key, int val)
557 sprintf(buf, "CONF PUTVAL|%s|%d", key, val);
567 * On systems which use xinetd, see if we can offer to install Citadel as
568 * the default telnet target.
570 void check_xinetd_entry(void)
572 char *filename = "/etc/xinetd.d/telnet";
575 int already_citadel = 0;
578 fp = fopen(filename, "r+");
579 if (fp == NULL) return; /* Not there. Oh well... */
581 while (fgets(buf, sizeof buf, fp) != NULL) {
582 if (strstr(buf, "/citadel") != NULL) {
587 if (already_citadel) return; /* Already set up this way. */
589 /* Otherwise, prompt the user to create an entry. */
590 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
591 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
596 snprintf(buf, sizeof buf,
597 _("Setup can configure the \"xinetd\" service to automatically\n"
598 "connect incoming telnet sessions to Citadel, bypassing the\n"
599 "host system login: prompt. Would you like to do this?\n"
602 if (yesno(buf, 1) == 0) {
607 fp = fopen(filename, "w");
609 "# description: telnet service for Citadel users\n"
614 " socket_type = stream\n"
617 " server = /usr/sbin/in.telnetd\n"
618 " server_args = -h -L %s/citadel\n"
619 " log_on_failure += USERID\n"
624 /* Now try to restart the service */
625 rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
627 display_error(_("failed to restart xinetd.\n"));
634 * Offer to disable other MTA's
636 void disable_other_mta(const char *mta) {
642 snprintf(buf, sizeof buf,
643 "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
644 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
647 fp = popen(buf, "r");
648 if (fp == NULL) return;
650 while (fgets(buf, sizeof buf, fp) != NULL) {
654 if (lines == 0) return; /* Nothing to do. */
656 /* Offer to replace other MTA with the vastly superior Citadel :) */
658 snprintf(buf, sizeof buf,
659 "%s \"%s\" %s%s%s%s%s%s%s",
660 _("You appear to have the "),
663 "running on your system. If you want Citadel mail\n"
666 _(" you will have to manually integrate\n"
667 "them. It is preferable to disable "),
669 _(", and use Citadel's\n"
670 "SMTP, POP3, and IMAP services.\n\n"
673 _("so that Citadel has access to ports\n"
674 "25, 110, and 143?\n")
676 if (yesno(buf, 1) == 0) {
681 snprintf(buf, sizeof buf, "for x in /etc/rc*.d/S*%s; do mv $x `echo $x |sed s/S/K/g`; done >/dev/null 2>&1", mta);
684 display_error("%s %s.\n", _("failed to disable other mta"), mta);
686 snprintf(buf, sizeof buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
689 display_error(" %s.\n", _("failed to disable other mta"), mta);
692 const char *other_mtas[] = {
693 "courier-authdaemon",
716 void disable_other_mtas(void)
719 if ((getenv("ACT_AS_MTA") == NULL) ||
720 (getenv("ACT_AS_MTA") &&
721 strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
722 /* Offer to disable other MTA's on the system. */
723 while (!IsEmptyStr(other_mtas[i]))
725 disable_other_mta(other_mtas[i]);
731 void strprompt(const char *prompt_title, const char *prompt_text, char *Target, char *DefValue)
735 char dialog_result[PATH_MAX];
739 strcpy(setupmsg, "");
741 switch (setup_type) {
744 printf("\n%s\n", prompt_text);
745 printf("%s\n%s\n", _("This is currently set to:"), Target);
746 printf("%s\n", _("Enter new value or press return to leave unchanged:"));
747 if (fgets(buf, sizeof buf, stdin)) {
748 buf[strlen(buf) - 1] = 0;
750 if (!IsEmptyStr(buf))
755 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
756 snprintf(buf, sizeof buf, "exec %s --backtitle '%s' --nocancel --inputbox '%s' 19 72 '%s' 2>%s",
757 getenv("CTDL_DIALOG"),
764 fprintf(stderr, "failed to run whiptail or dialog\n");
767 fp = fopen(dialog_result, "r");
769 if (fgets(Target, sizeof buf, fp)) {
770 if (Target[strlen(Target)-1] == 10) {
771 Target[strlen(Target)-1] = 0;
775 unlink(dialog_result);
779 if (*DefValue != '\0')
780 strcpy(Target, DefValue);
785 void set_bool_val(int msgpos, int *ip, char *DefValue)
787 title(setup_titles[msgpos]);
788 *ip = yesno(setup_text[msgpos], *ip);
791 void set_str_val(int msgpos, char *Target, char *DefValue)
793 strprompt(setup_titles[msgpos],
800 /* like set_str_val() but for numeric values */
801 void set_int_val(int msgpos, int *target, char *default_value)
804 sprintf(buf, "%d", *target);
806 set_str_val(msgpos, buf, default_value);
807 } while ( (strcmp(buf, "0")) && (atoi(buf) == 0) );
812 void edit_value(int curr)
814 struct passwd *pw = NULL;
815 char ctdluidname[256];
817 char *default_value = NULL;
823 if (setup_type == UI_SILENT)
825 default_value = getenv(EnvNames[curr]);
827 if (default_value == NULL) {
834 getconf_str(admin_name, "c_sysadm");
835 set_str_val(curr, admin_name, default_value);
836 setconf_str("c_sysadm", admin_name);
840 set_str_val(curr, admin_pass, default_value);
845 if (setup_type == UI_SILENT)
848 ctdluid = atoi(default_value);
854 ctdluid = 0; /* work-around for Windows */
856 pw = getpwuid(ctdluid);
858 set_int_val(curr, &ctdluid, default_value);
861 strcpy(ctdluidname, pw->pw_name);
862 set_str_val(curr, ctdluidname, default_value);
863 pw = getpwnam(ctdluidname);
865 ctdluid = pw->pw_uid;
867 else if (atoi(ctdluidname) > 0) {
868 ctdluid = atoi(ctdluidname);
873 setconf_int("c_ctdluid", ctdluid);
877 getconf_str(buf, "c_ip_addr");
878 set_str_val(curr, buf, default_value);
879 setconf_str("c_ip_addr", buf);
883 portnum = getconf_int("c_port_number");
884 set_int_val(curr, &portnum, default_value);
885 setconf_int("c_port_number", portnum);
889 auth = getconf_int("c_auth_mode");
890 if (setup_type == UI_SILENT)
892 if ( (default_value) && (!strcasecmp(default_value, "yes")) ) auth = AUTHMODE_HOST;
893 if ( (default_value) && (!strcasecmp(default_value, "host")) ) auth = AUTHMODE_HOST;
894 if ( (default_value) && (!strcasecmp(default_value, "ldap")) ) auth = AUTHMODE_LDAP;
895 if ( (default_value) && (!strcasecmp(default_value, "ldap_ad")) ) auth = AUTHMODE_LDAP_AD;
896 if ( (default_value) && (!strcasecmp(default_value, "active directory")) ) auth = AUTHMODE_LDAP_AD;
899 set_int_val(curr, &auth, default_value);
901 setconf_int("c_auth_mode", auth);
905 getconf_str(buf, "c_ldap_host");
906 if (IsEmptyStr(buf)) {
907 strcpy(buf, "localhost");
909 set_str_val(curr, buf, default_value);
910 setconf_str("c_ldap_host", buf);
914 lportnum = getconf_int("c_ldap_port");
918 set_int_val(curr, &lportnum, default_value);
919 setconf_int("c_ldap_port", lportnum);
923 getconf_str(buf, "c_ldap_base_dn");
924 set_str_val(curr, buf, default_value);
925 setconf_str("c_ldap_base_dn", buf);
929 getconf_str(buf, "c_ldap_bind_dn");
930 set_str_val(curr, buf, default_value);
931 setconf_str("c_ldap_bind_dn", buf);
935 getconf_str(buf, "c_ldap_bind_pw");
936 set_str_val(curr, buf, default_value);
937 setconf_str("c_ldap_bind_pw", buf);
945 * Figure out what type of user interface we're going to use
947 int discover_ui(void)
950 /* Use "whiptail" or "dialog" if we have it */
951 if (getenv("CTDL_DIALOG") != NULL) {
961 * Strip "db" entries out of /etc/nsswitch.conf
970 int file_changed = 0;
971 char new_filename[64];
974 fp_read = fopen(NSSCONF, "r");
975 if (fp_read == NULL) {
979 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
980 fd_write = mkstemp(new_filename);
986 while (fgets(buf, sizeof buf, fp_read) != NULL) {
988 for (i=0; buf_nc[i]; ++i) {
989 if (buf_nc[i] == '#') {
994 for (i=0; i<strlen(buf_nc); ++i) {
995 if (!strncasecmp(&buf_nc[i], "db", 2)) {
997 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
999 strcpy(&buf_nc[i], &buf_nc[i+2]);
1000 strcpy(&buf[i], &buf[i+2]);
1002 strcpy(&buf_nc[i], &buf_nc[i+1]);
1003 strcpy(&buf[i], &buf[i+1]);
1009 long buflen = strlen(buf);
1010 if (write(fd_write, buf, buflen) != buflen) {
1013 unlink(new_filename);
1020 if (!file_changed) {
1021 unlink(new_filename);
1025 snprintf(question, sizeof question,
1028 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
1029 "one or more services. This is not necessary on most systems,\n"
1030 "and it is known to crash the Citadel server when delivering\n"
1031 "mail to the Internet.\n"
1033 "Do you want this module to be automatically disabled?\n"
1038 if (yesno(question, 1)) {
1039 snprintf(buf, sizeof buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
1042 fprintf(stderr, "failed to edit %s.\n", NSSCONF);
1044 chmod(NSSCONF, 0644);
1046 unlink(new_filename);
1051 * Messages that are no longer in use.
1052 * We keep them here so we don't lose the translations if we need them later.
1055 important_message(_("Setup finished"),
1056 _("Setup of the Citadel server is complete.\n"
1057 "If you will be using WebCit, please run its\n"
1058 "setup program now; otherwise, run './citadel'\n"
1060 important_message(_("Setup failed"),
1061 _("Setup is finished, but the Citadel server failed to start.\n"
1062 "Go back and check your configuration.\n")
1063 important_message(_("Setup finished"),
1064 _("Setup is finished. You may now start the server."));
1070 int main(int argc, char *argv[])
1078 char relhome[PATH_MAX]="";
1079 char ctdldir[PATH_MAX]=CTDLDIR;
1082 char *activity = NULL;
1084 /* Keep a mild groove on */
1085 program_title = _("Citadel setup program");
1087 /* set an invalid setup type */
1090 /* parse command line args */
1091 for (a = 0; a < argc; ++a) {
1092 if (!strncmp(argv[a], "-u", 2)) {
1093 strcpy(aaa, argv[a]);
1094 strcpy(aaa, &aaa[2]);
1095 setup_type = atoi(aaa);
1097 else if (!strcmp(argv[a], "-q")) {
1098 setup_type = UI_SILENT;
1100 else if (!strncmp(argv[a], "-h", 2)) {
1101 relh=argv[a][2]!='/';
1103 safestrncpy(ctdl_home_directory, &argv[a][2], sizeof ctdl_home_directory);
1105 safestrncpy(relhome, &argv[a][2], sizeof relhome);
1112 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1115 /* If a setup type was not specified, try to determine automatically
1116 * the best one to use out of all available types.
1118 if (setup_type < 0) {
1119 setup_type = discover_ui();
1122 enable_home = ( relh | home );
1124 if (chdir(ctdl_run_dir) != 0) {
1125 display_error("%s: [%s]\n", _("The directory you specified does not exist"), ctdl_run_dir);
1131 * Connect to the running Citadel server.
1133 char *connectingmsg = _("Connecting to Citadel server");
1134 for (i=0; ((i<30) && (serv_sock < 0)) ; ++i) { /* wait for server to start up */
1135 progress(connectingmsg, i, 30);
1136 serv_sock = uds_connectsock(file_citadel_admin_socket);
1139 progress(connectingmsg, 30, 30);
1141 if (serv_sock < 0) {
1144 _("Setup could not connect to a running Citadel server."),
1145 strerror(errno), file_citadel_admin_socket
1151 * read the server greeting
1154 if (buf[0] != '2') {
1155 display_error("%s\n", buf);
1160 * Are we connected to the correct Citadel server?
1164 if (buf[0] != '1') {
1165 display_error("%s\n", buf);
1169 while (serv_gets(buf), strcmp(buf, "000")) {
1171 if (atoi(buf) != REV_LEVEL) {
1172 display_error("%s\n",
1173 _("Your setup program and Citadel server are from different versions.")
1186 if (setup_type == UI_TEXT) {
1187 printf("\n\n\n *** %s ***\n\n", program_title);
1190 if (setup_type == UI_DIALOG) {
1191 system("clear 2>/dev/null");
1194 /* Go through a series of dialogs prompting for config info */
1195 for (curr = 1; curr < eMaxQuestions; ++curr) {
1198 if ( (curr == eAuthType)
1199 && (getconf_int("c_auth_mode") != AUTHMODE_LDAP)
1200 && (getconf_int("c_auth_mode") != AUTHMODE_LDAP_AD)
1202 curr += 5; /* skip LDAP questions if we're not authenticating against LDAP */
1205 if (curr == eSysAdminName) {
1206 if (getconf_int("c_auth_mode") == AUTHMODE_NATIVE) {
1207 /* for native auth mode, fetch the admin's existing pw */
1208 snprintf(buf, sizeof buf, "AGUP %s", admin_name);
1211 if (buf[0] == '2') {
1212 extract_token(admin_pass, &buf[4], 1, '|', sizeof admin_pass);
1216 ++curr; /* skip the password question for non-native auth modes */
1221 if ((pw = getpwuid( getconf_int("c_ctdluid") )) == NULL) {
1227 if (create_run_directories(getconf_int("c_ctdluid"), gid) != 0) {
1228 display_error("%s\n", _("failed to create directories"));
1231 activity = _("Reconfiguring Citadel server");
1232 progress(activity, 0, 5);
1233 sleep(1); /* Let the message appear briefly */
1236 * Create the administrator account. It's ok if the command fails if this user already exists.
1238 progress(activity, 1, 5);
1239 snprintf(buf, sizeof buf, "CREU %s|%s", admin_name, admin_pass);
1241 progress(activity, 2, 5);
1243 progress(activity, 3, 5);
1246 * Assign the desired password and access level to the administrator account.
1248 snprintf(buf, sizeof buf, "AGUP %s", admin_name);
1250 progress(activity, 4, 5);
1252 if (buf[0] == '2') {
1253 int admin_flags = extract_int(&buf[4], 2);
1254 int admin_times_called = extract_int(&buf[4], 3);
1255 int admin_msgs_posted = extract_int(&buf[4], 4);
1256 snprintf(buf, sizeof buf, "ASUP %s|%s|%d|%d|%d|6",
1257 admin_name, admin_pass, admin_flags, admin_times_called, admin_msgs_posted
1262 progress(activity, 5, 5);
1265 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1266 disable_other_mtas(); /* Offer to disable other MTAs */
1267 fixnss(); /* Check for the 'db' nss and offer to disable it */
1273 activity = _("Restarting Citadel server to apply changes");
1274 progress(activity, 0, 41);
1278 long original_start_time = extract_long(&buf[4], 3);
1280 progress(activity, 1, 41);
1281 serv_puts("DOWN 1");
1282 progress(activity, 2, 41);
1284 if (buf[0] != '2') {
1285 display_error("%s\n", buf);
1292 for (i=3; i<=6; ++i) { /* wait for server to shut down */
1293 progress(activity, i, 41);
1297 for (i=7; ((i<=38) && (serv_sock < 0)) ; ++i) { /* wait for server to start up */
1298 progress(activity, i, 41);
1299 serv_sock = uds_connectsock(file_citadel_admin_socket);
1303 progress(activity, 39, 41);
1306 progress(activity, 40, 41);
1309 long new_start_time = extract_long(&buf[4], 3);
1312 progress(activity, 41, 41);
1314 if ( (original_start_time == new_start_time)
1315 || (new_start_time <= 0)
1317 display_error("%s\n", _("Setup failed to restart Citadel server. Please restart it manually."));