2 * Citadel setup utility
5 #define SHOW_ME_VAPPEND_PRINTF
6 #include "ctdl_module.h"
13 #include <sys/types.h>
15 #include <sys/utsname.h>
23 #include <libcitadel.h>
28 #include "citadel_dirs.h"
39 #define _(string) gettext(string)
41 #define _(string) (string)
45 #define MAXSETUP 11 /* How many setup questions to ask */
47 #define UI_TEXT 0 /* Default setup type -- text only */
48 #define UI_DIALOG 2 /* Use the 'dialog' program */
49 #define UI_SILENT 3 /* Silent running, for use in scripts */
51 #define SERVICE_NAME "citadel"
52 #define PROTO_NAME "tcp"
53 #define NSSCONF "/etc/nsswitch.conf"
56 typedef enum _SetupStep {
72 ///"CREATE_XINETD_ENTRY";
73 const char *EnvNames [eMaxQuestions] = {
89 int using_web_installer = 0;
94 const char *setup_titles[eMaxQuestions];
98 setup_titles[eCitadelHomeDir] = _("Citadel Home Directory");
99 setup_titles[eSysAdminName] = _("Citadel administrator username:");////
100 setup_titles[eSysAdminPW] = _("Administrator password:");//
101 setup_titles[eUID] = _("Citadel User ID:");
102 setup_titles[eIP_ADDR] = _("Listening address for the Citadel server:");///
103 setup_titles[eCTDL_Port] = _("Server port number:");
104 setup_titles[eAuthType] = _("Authentication method to use:");////
105 setup_titles[eLDAP_Host] = _("LDAP host:");///
106 setup_titles[eLDAP_Port] = _("LDAP port number:");////
107 setup_titles[eLDAP_Base_DN] = _("LDAP base DN:");///
108 setup_titles[eLDAP_Bind_DN] = _("LDAP bind DN:");//
109 setup_titles[eLDAP_Bind_PW] = _("LDAP bind password:");//
113 * print the actual stack frame.
115 void cit_backtrace(void)
117 #ifdef HAVE_BACKTRACE
118 void *stack_frames[50];
122 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
123 strings = backtrace_symbols(stack_frames, size);
124 for (i = 0; i < size; i++) {
126 fprintf(stderr, "%s\n", strings[i]);
128 fprintf(stderr, "%p\n", stack_frames[i]);
134 struct config config;
136 /* calculate all our path on a central place */
137 /* where to keep our config */
140 char *setup_text[] = {
142 "Enter the full pathname of the directory in which the Citadel\n"
143 "installation you are creating or updating resides. If you\n"
144 "specify a directory other than the default, you will need to\n"
145 "specify the -h flag to the server when you start it up.\n",
147 "Enter the subdirectory name for an alternate installation of "
148 "Citadel. To do a default installation just leave it blank."
149 "If you specify a directory other than the default, you will need to\n"
150 "specify the -h flag to the server when you start it up.\n"
151 "note that it may not have a leading /",
154 "Enter the name of the system administrator (which is probably\n"
155 "you). When an account is created with this name, it will\n"
156 "automatically be given administrator-level access.\n",
158 "Enter a password for the system administrator. When setup\n"
159 "completes it will attempt to create the administrator user\n"
160 "and set the password specified here.\n",
162 "Citadel needs to run under its own user ID. This would\n"
163 "typically be called \"citadel\", but if you are running Citadel\n"
164 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
165 "The server will run under this user ID. Please specify that\n"
166 "user ID here. You may specify either a user name or a numeric\n"
169 "Specify the IP address on which your server will run.\n"
170 "You can name a specific IPv4 or IPv6 address, or you can specify\n"
171 "'*' for 'any address', '::' for 'any IPv6 address', or '0.0.0.0'\n"
172 "for 'any IPv4 address'. If you leave this blank, Citadel will\n"
173 "listen on all addresses. You can usually skip this unless you are\n"
174 "running multiple instances of Citadel on the same computer.\n",
176 "Specify the TCP port number on which your server will run.\n"
177 "Normally, this will be port 504, which is the official port\n"
178 "assigned by the IANA for Citadel servers. You will only need\n"
179 "to specify a different port number if you run multiple instances\n"
180 "of Citadel on the same computer and there is something else\n"
181 "already using port 504.\n",
183 "Specify which authentication mode you wish to use.\n"
185 " 0. Self contained authentication\n"
186 " 1. Host system integrated authentication\n"
187 " 2. External LDAP - RFC 2307 compliant directory\n"
188 " 3. External LDAP - nonstandard MS Active Directory\n"
190 "For help: http://www.citadel.org/doku.php/faq:installation:authmodes\n"
192 "ANSWER \"0\" UNLESS YOU COMPLETELY UNDERSTAND THIS OPTION.\n",
194 "Please enter the host name or IP address of your LDAP server.\n",
196 "Please enter the port number of the LDAP service (usually 389).\n",
198 "Please enter the Base DN to search for authentication\n"
199 "(for example: dc=example,dc=com)\n",
201 "Please enter the DN of an account to use for binding to the LDAP server\n"
202 "for performing queries. The account does not require any other\n"
203 "privileges. If your LDAP server allows anonymous queries, you can.\n"
204 "leave this blank.\n",
206 "If you entered a Bind DN in the previous question, you must now enter\n"
207 "the password associated with that account. Otherwise, you can leave this\n"
212 struct config config;
216 void cleanup(int exitcode)
218 // printf("Exitcode: %d\n", exitcode);
225 void title(const char *text)
227 if (setup_type == UI_TEXT) {
228 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
234 int yesno(char *question, int default_value)
240 switch (setup_type) {
244 printf("%s\nYes/No [%s] --> ",
246 ( default_value ? "Yes" : "No" )
248 if (fgets(buf, sizeof buf, stdin))
250 answer = tolower(buf[0]);
251 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
252 answer = default_value;
253 else if (answer == 'y')
255 else if (answer == 'n')
258 } while ((answer < 0) || (answer > 1));
262 sprintf(buf, "exec %s %s --yesno '%s' 15 75",
263 getenv("CTDL_DIALOG"),
264 ( default_value ? "" : "--defaultno" ),
282 void important_message(char *title, char *msgtext)
287 switch (setup_type) {
290 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");
291 printf(" %s \n\n%s\n\n", title, msgtext);
292 printf("Press return to continue...");
293 if (fgets(buf, sizeof buf, stdin));
297 sprintf(buf, "exec %s --msgbox '%s' 19 72",
298 getenv("CTDL_DIALOG"),
303 fprintf(stderr, "%s\n", msgtext);
308 void important_msgnum(int msgnum)
310 important_message("Important Message", setup_text[msgnum]);
313 void display_error(char *error_message)
315 important_message("Error", error_message);
318 void progress(char *text, long int curr, long int cmax)
320 static long dots_printed = 0L;
322 static FILE *fp = NULL;
325 switch (setup_type) {
329 printf("%s\n", text);
330 printf("....................................................");
331 printf("..........................\r");
334 } else if (curr == cmax) {
335 printf("\r%79s\n", "");
337 a = (curr * 100) / cmax;
340 while (dots_printed < a) {
350 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
351 getenv("CTDL_DIALOG"),
353 fp = popen(buf, "w");
359 else if (curr == cmax) {
361 fprintf(fp, "100\n");
367 a = (curr * 100) / cmax;
369 fprintf(fp, "%ld\n", a);
383 * check_services_entry() -- Make sure "citadel" is in /etc/services
386 void check_services_entry(void)
392 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
393 for (i=0; i<=2; ++i) {
394 progress("Adding service entry...", i, 2);
396 sfp = fopen("/etc/services", "a");
398 sprintf(errmsg, "Cannot open /etc/services: %s", strerror(errno));
399 display_error(errmsg);
401 fprintf(sfp, "%s 504/tcp\n", SERVICE_NAME);
413 * delete_inittab_entry() -- Remove obsolete /etc/inittab entry for Citadel
415 void delete_inittab_entry(void)
419 char looking_for[256];
421 char outfilename[32];
422 int changes_made = 0;
425 /* Determine the fully qualified path name of citserver */
426 snprintf(looking_for,
432 /* Now tweak /etc/inittab */
433 infp = fopen("/etc/inittab", "r");
436 /* If /etc/inittab does not exist, return quietly.
437 * Not all host platforms have it.
439 if (errno == ENOENT) {
443 /* Other errors might mean something really did go wrong.
445 sprintf(buf, "Cannot open /etc/inittab: %s", strerror(errno));
450 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
451 outfp = fdopen(mkstemp(outfilename), "w+");
453 sprintf(buf, "Cannot open %s: %s", outfilename, strerror(errno));
459 while (fgets(buf, sizeof buf, infp) != NULL) {
460 if (strstr(buf, looking_for) != NULL) {
461 rv = fwrite("#", 1, 1, outfp);
464 rv = fwrite(buf, strlen(buf), 1, outfp);
471 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
473 rv = system("/sbin/init q 2>/dev/null");
482 * install_init_scripts() -- Try to configure to start Citadel at boot
484 void install_init_scripts(void)
486 struct stat etcinitd;
488 char *initfile = "/etc/init.d/citadel";
492 if ((stat("/etc/init.d/", &etcinitd) == -1) &&
495 if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
497 initfile = CTDLDIR"/citadel.init";
499 initfile = "/etc/rc.d/init.d/citadel";
502 fp = fopen(initfile, "r");
504 if (yesno("Citadel already appears to be configured to start at boot.\n"
505 "Would you like to keep your boot configuration as is?\n", 1) == 1) {
512 if (yesno("Would you like to automatically start Citadel at boot?\n", 1) == 0) {
516 fp = fopen(initfile, "w");
518 display_error("Cannot create /etc/init.d/citadel");
522 fprintf(fp, "#!/bin/sh\n"
524 "# Init file for Citadel\n"
526 "# chkconfig: - 79 30\n"
527 "# description: Citadel service\n"
528 "# processname: citserver\n"
529 "# pidfile: %s/citadel.pid\n\n"
530 "# uncomment this to create coredumps as described in\n"
531 "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
532 "# ulimit -c unlimited\n"
540 "test -d /var/run || exit 0\n"
544 "start) echo -n \"Starting Citadel... \"\n"
545 " if $CITADEL_DIR/citserver -lmail -d\n"
552 "stop) echo -n \"Stopping Citadel... \"\n"
553 " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
558 " rm -f %s/citadel.pid 2>/dev/null\n"
563 "restart) if $CITADEL_DIR/sendcommand DOWN 1 >/dev/null 2>&1 ; then\n"
569 "*) echo \"Usage: $0 {start|stop|restart}\"\n"
576 chmod(initfile, 0755);
578 /* Set up the run levels. */
579 rv = system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
580 snprintf(command, sizeof(command), "for x in 2 3 4 5 ; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/S79citadel ; done 2>/dev/null", initfile);
581 rv = system(command);
582 snprintf(command, sizeof(command),"for x in 0 6 S; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/K30citadel ; done 2>/dev/null", initfile);
583 rv = system(command);
590 * On systems which use xinetd, see if we can offer to install Citadel as
591 * the default telnet target.
593 void check_xinetd_entry(void) {
594 char *filename = "/etc/xinetd.d/telnet";
597 int already_citadel = 0;
600 fp = fopen(filename, "r+");
601 if (fp == NULL) return; /* Not there. Oh well... */
603 while (fgets(buf, sizeof buf, fp) != NULL) {
604 if (strstr(buf, "/citadel") != NULL) already_citadel = 1;
607 if (already_citadel) return; /* Already set up this way. */
609 /* Otherwise, prompt the user to create an entry. */
610 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
611 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
616 snprintf(buf, sizeof buf,
617 "Setup can configure the \"xinetd\" service to automatically\n"
618 "connect incoming telnet sessions to Citadel, bypassing the\n"
619 "host system login: prompt. Would you like to do this?\n"
621 if (yesno(buf, 1) == 0) {
626 fp = fopen(filename, "w");
628 "# description: telnet service for Citadel users\n"
633 " socket_type = stream\n"
636 " server = /usr/sbin/in.telnetd\n"
637 " server_args = -h -L %s/citadel\n"
638 " log_on_failure += USERID\n"
643 /* Now try to restart the service */
644 rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
650 * Offer to disable other MTA's
652 void disable_other_mta(const char *mta) {
658 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
659 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
661 fp = popen(buf, "r");
662 if (fp == NULL) return;
664 while (fgets(buf, sizeof buf, fp) != NULL) {
668 if (lines == 0) return; /* Nothing to do. */
671 /* Offer to replace other MTA with the vastly superior Citadel :) */
673 snprintf(buf, sizeof buf,
674 "You appear to have the \"%s\" email program\n"
675 "running on your system. If you want Citadel mail\n"
676 "connected with %s, you will have to manually integrate\n"
677 "them. It is preferable to disable %s, and use Citadel's\n"
678 "SMTP, POP3, and IMAP services.\n\n"
679 "May we disable %s so that Citadel has access to ports\n"
680 "25, 110, and 143?\n",
683 if (yesno(buf, 1) == 0) {
688 sprintf(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);
690 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
694 const char *other_mtas[] = {
695 "courier-authdaemon",
718 void disable_other_mtas(void)
721 if ((getenv("ACT_AS_MTA") == NULL) ||
722 (getenv("ACT_AS_MTA") &&
723 strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
724 /* Offer to disable other MTA's on the system. */
725 while (!IsEmptyStr(other_mtas[i]))
727 disable_other_mta(other_mtas[i]);
734 * Check to see if our server really works. Returns 0 on success.
736 int test_server(char *relhomestr, int relhome) {
743 /* Generate a silly little cookie. We're going to write it out
744 * to the server and try to get it back. The cookie does not
745 * have to be secret ... just unique.
747 sprintf(cookie, "--test--%d--", getpid());
750 sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
755 sprintf(cmd, "%s/sendcommand ECHO %s 2>&1",
759 fp = popen(cmd, "r");
760 if (fp == NULL) return(errno);
762 while (fgets(buf, sizeof buf, fp) != NULL) {
764 && (strstr(buf, cookie) != NULL) ) {
776 void strprompt(const char *prompt_title, char *prompt_text, char *Target, char *DefValue)
780 char dialog_result[PATH_MAX];
784 strcpy(setupmsg, "");
786 switch (setup_type) {
789 printf("\n%s\n", prompt_text);
790 printf("This is currently set to:\n%s\n", Target);
791 printf("Enter new value or press return to leave unchanged:\n");
792 if (fgets(buf, sizeof buf, stdin)){
793 buf[strlen(buf) - 1] = 0;
795 if (!IsEmptyStr(buf))
800 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
801 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
802 getenv("CTDL_DIALOG"),
807 fp = fopen(dialog_result, "r");
809 if (fgets(Target, sizeof buf, fp)) {
810 if (Target[strlen(Target)-1] == 10) {
811 Target[strlen(Target)-1] = 0;
815 unlink(dialog_result);
819 strcpy(Target, DefValue);
824 void set_bool_val(int msgpos, int *ip, char *DefValue)
826 title(setup_titles[msgpos]);
827 *ip = yesno(setup_text[msgpos], *ip);
830 void set_str_val(int msgpos, char *Target, char *DefValue)
832 strprompt(setup_titles[msgpos],
838 void set_int_val(int msgpos, int *ip, char *DefValue)
841 snprintf(buf, sizeof buf, "%d", (int) *ip);
842 set_str_val(msgpos, buf, DefValue);
847 void set_char_val(int msgpos, char *ip, char *DefValue)
850 snprintf(buf, sizeof buf, "%d", (int) *ip);
851 set_str_val(msgpos, buf, DefValue);
852 *ip = (char) atoi(buf);
856 void set_long_val(int msgpos, long int *ip, char *DefValue)
859 snprintf(buf, sizeof buf, "%ld", *ip);
860 set_str_val(msgpos, buf, DefValue);
865 void edit_value(int curr)
869 char ctdluidname[256];
872 if (setup_type == UI_SILENT)
874 Value = getenv(EnvNames[curr]);
883 set_str_val(curr, config.c_sysadm, Value);
887 set_str_val(curr, admin_pass, Value);
891 if (setup_type == UI_SILENT)
894 config.c_ctdluid = atoi(Value);
900 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
902 i = config.c_ctdluid;
905 set_int_val(curr, &i, Value);
906 config.c_ctdluid = i;
909 strcpy(ctdluidname, pw->pw_name);
910 set_str_val(curr, ctdluidname, Value);
911 pw = getpwnam(ctdluidname);
913 config.c_ctdluid = pw->pw_uid;
915 else if (atoi(ctdluidname) > 0) {
916 config.c_ctdluid = atoi(ctdluidname);
924 set_str_val(curr, config.c_ip_addr, Value);
928 set_int_val(curr, &config.c_port_number, Value);
932 if (setup_type == UI_SILENT)
935 config.c_auth_mode = AUTHMODE_NATIVE;
939 if ((strcasecmp(auth, "yes") == 0) ||
940 (strcasecmp(auth, "host") == 0))
942 config.c_auth_mode = AUTHMODE_HOST;
944 else if (strcasecmp(auth, "ldap") == 0){
945 config.c_auth_mode = AUTHMODE_LDAP;
947 else if ((strcasecmp(auth, "ldap_ad") == 0) ||
948 (strcasecmp(auth, "active directory") == 0)){
949 config.c_auth_mode = AUTHMODE_LDAP_AD;
954 set_int_val(curr, &config.c_auth_mode, Value);
959 set_str_val(curr, config.c_ldap_host, Value);
963 if (config.c_ldap_port == 0) {
964 config.c_ldap_port = 389;
966 set_int_val(curr, &config.c_ldap_port, Value);
970 set_str_val(curr, config.c_ldap_base_dn, Value);
974 set_str_val(curr, config.c_ldap_bind_dn, Value);
978 set_str_val(curr, config.c_ldap_bind_pw, Value);
985 * (re-)write the config data to disk
987 void write_config_to_disk(void)
993 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
994 display_error("setup: cannot open citadel.config");
997 fp = fdopen(fd, "wb");
999 display_error("setup: cannot open citadel.config");
1002 rv = fwrite((char *) &config, sizeof(struct config), 1, fp);
1010 * Figure out what type of user interface we're going to use
1012 int discover_ui(void)
1015 /* Use "dialog" if we have it */
1016 if (getenv("CTDL_DIALOG") != NULL) {
1025 void migrate_old_installs(void)
1028 rv = system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1029 unlink("citadel.log");
1035 * Strip "db" entries out of /etc/nsswitch.conf
1045 int file_changed = 0;
1046 char new_filename[64];
1049 fp_read = fopen(NSSCONF, "r");
1050 if (fp_read == NULL) {
1054 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
1055 fd_write = mkstemp(new_filename);
1061 while (fgets(buf, sizeof buf, fp_read) != NULL) {
1063 strcpy(buf_nc, buf);
1064 for (i=0; i<strlen(buf_nc); ++i) {
1065 if (buf_nc[i] == '#') {
1069 for (i=0; i<strlen(buf_nc); ++i) {
1070 if (!strncasecmp(&buf_nc[i], "db", 2)) {
1072 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
1075 strcpy(&buf_nc[i], &buf_nc[i+2]);
1076 strcpy(&buf[i], &buf[i+2]);
1078 strcpy(&buf_nc[i], &buf_nc[i+1]);
1079 strcpy(&buf[i], &buf[i+1]);
1085 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
1088 unlink(new_filename);
1095 if (!file_changed) {
1096 unlink(new_filename);
1100 snprintf(question, sizeof question,
1102 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
1103 "one or more services. This is not necessary on most systems,\n"
1104 "and it is known to crash the Citadel server when delivering\n"
1105 "mail to the Internet.\n"
1107 "Do you want this module to be automatically disabled?\n"
1111 if (yesno(question, 1)) {
1112 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
1114 chmod(NSSCONF, 0644);
1116 unlink(new_filename);
1119 void check_init_script (char *relhome)
1125 * If we're running on SysV, install init scripts.
1127 if (!access("/var/run", W_OK)) {
1129 if (getenv("NO_INIT_SCRIPTS") == NULL) {
1130 install_init_scripts();
1133 if (!access("/etc/init.d/citadel", X_OK)) {
1134 rv = system("/etc/init.d/citadel start");
1138 if (test_server(relhome, enable_home) == 0) {
1142 if (config.c_auth_mode == AUTHMODE_NATIVE) {
1143 snprintf (admin_cmd, sizeof(admin_cmd), "%s/sendcommand \"CREU %s|%s\" 2>&1",
1144 ctdl_sbin_dir, config.c_sysadm, admin_pass);
1145 fp = popen(admin_cmd, "r");
1147 while (fgets(buf, sizeof buf, fp) != NULL)
1149 if ((atol(buf) == 574) || (atol(buf) == 200))
1155 if (found_it == 0) {
1156 important_message("Error","Setup failed to create your admin user");
1160 if (setup_type != UI_SILENT)
1161 important_message("Setup finished",
1162 "Setup of the Citadel server is complete.\n"
1163 "If you will be using WebCit, please run its\n"
1164 "setup program now; otherwise, run './citadel'\n"
1168 important_message("Setup failed",
1169 "Setup is finished, but the Citadel server failed to start.\n"
1170 "Go back and check your configuration.\n"
1177 important_message("Setup finished",
1178 "Setup is finished. You may now start the server.");
1182 void set_default_values(void)
1185 struct utsname my_utsname;
1188 /* Determine our host name, in case we need to use it as a default */
1191 /* set some sample/default values in place of blanks... */
1192 if (IsEmptyStr(config.c_nodename))
1193 safestrncpy(config.c_nodename, my_utsname.nodename,
1194 sizeof config.c_nodename);
1195 strtok(config.c_nodename, ".");
1196 if (IsEmptyStr(config.c_fqdn) ) {
1197 if ((he = gethostbyname(my_utsname.nodename)) != NULL) {
1198 safestrncpy(config.c_fqdn, he->h_name, sizeof config.c_fqdn);
1200 safestrncpy(config.c_fqdn, my_utsname.nodename, sizeof config.c_fqdn);
1203 if (IsEmptyStr(config.c_humannode)) {
1204 strcpy(config.c_humannode, "My System");
1206 if (IsEmptyStr(config.c_phonenum)) {
1207 strcpy(config.c_phonenum, "US 800 555 1212");
1209 if (config.c_initax == 0) {
1210 config.c_initax = 4;
1212 if (IsEmptyStr(config.c_moreprompt)) strcpy(config.c_moreprompt, "<more>");
1213 if (IsEmptyStr(config.c_twitroom)) strcpy(config.c_twitroom, "Trashcan");
1214 if (IsEmptyStr(config.c_baseroom)) strcpy(config.c_baseroom, BASEROOM);
1215 if (IsEmptyStr(config.c_aideroom)) strcpy(config.c_aideroom, "Aide");
1216 if (config.c_port_number == 0) {
1217 config.c_port_number = 504;
1219 if (config.c_sleeping == 0) {
1220 config.c_sleeping = 900;
1222 if (config.c_ctdluid == 0) {
1223 pw = getpwnam("citadel");
1225 config.c_ctdluid = pw->pw_uid;
1228 if (config.c_ctdluid == 0) {
1229 pw = getpwnam("bbs");
1231 config.c_ctdluid = pw->pw_uid;
1234 if (config.c_ctdluid == 0) {
1235 pw = getpwnam("guest");
1237 config.c_ctdluid = pw->pw_uid;
1240 if (config.c_createax == 0) {
1241 config.c_createax = 3;
1244 * Negative values for maxsessions are not allowed.
1246 if (config.c_maxsessions < 0) {
1247 config.c_maxsessions = 0;
1249 /* We need a system default message expiry policy, because this is
1250 * the top level and there's no 'higher' policy to fall back on.
1251 * By default, do not expire messages at all.
1253 if (config.c_ep.expire_mode == 0) {
1254 config.c_ep.expire_mode = EXPIRE_MANUAL;
1255 config.c_ep.expire_value = 0;
1259 * Default port numbers for various services
1261 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1262 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1263 if (config.c_imap_port == 0) config.c_imap_port = 143;
1264 if (config.c_msa_port == 0) config.c_msa_port = 587;
1265 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1266 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1267 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1268 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1269 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1270 if (config.c_xmpp_c2s_port == 0) config.c_xmpp_c2s_port = 5222;
1271 if (config.c_xmpp_s2s_port == 0) config.c_xmpp_s2s_port = 5269;
1275 void get_config (void)
1282 * What we're going to try to do here is append a whole bunch of
1283 * nulls to the citadel.config file, so we can keep the old config
1284 * values if they exist, but if the file is missing or from an
1285 * earlier version with a shorter config structure, when setup tries
1286 * to read the old config parameters, they'll all come up zero.
1287 * The length of the config file will be set to what it's supposed
1288 * to be when we rewrite it, because we replace the old file with a
1289 * completely new copy.
1291 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1292 S_IRUSR | S_IWUSR)) == -1) {
1293 display_error("setup: cannot append citadel.config");
1296 fp = fdopen(a, "ab");
1298 display_error("setup: cannot append citadel.config");
1301 for (a = 0; a < sizeof(struct config); ++a) {
1306 /* now we re-open it, and read the old or blank configuration */
1307 fp = fopen(file_citadel_config, "rb");
1309 display_error("setup: cannot open citadel.config");
1312 rv = fread((char *) &config, sizeof(struct config), 1, fp);
1317 int main(int argc, char *argv[])
1322 int old_setup_level = 0;
1326 char relhome[PATH_MAX]="";
1327 char ctdldir[PATH_MAX]=CTDLDIR;
1332 /* set an invalid setup type */
1335 /* Check to see if we're running the web installer */
1336 if (getenv("CITADEL_INSTALLER") != NULL) {
1337 using_web_installer = 1;
1340 /* parse command line args */
1341 for (a = 0; a < argc; ++a) {
1342 if (!strncmp(argv[a], "-u", 2)) {
1343 strcpy(aaa, argv[a]);
1344 strcpy(aaa, &aaa[2]);
1345 setup_type = atoi(aaa);
1347 else if (!strcmp(argv[a], "-i")) {
1350 else if (!strcmp(argv[a], "-q")) {
1351 setup_type = UI_SILENT;
1353 else if (!strncmp(argv[a], "-h", 2)) {
1354 relh=argv[a][2]!='/';
1356 safestrncpy(ctdl_home_directory, &argv[a][2], sizeof ctdl_home_directory);
1358 safestrncpy(relhome, &argv[a][2], sizeof relhome);
1365 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1368 /* If a setup type was not specified, try to determine automatically
1369 * the best one to use out of all available types.
1371 if (setup_type < 0) {
1372 setup_type = discover_ui();
1374 if (info_only == 1) {
1375 important_message("Citadel Setup", CITADEL);
1379 enable_home = ( relh | home );
1381 if (chdir(ctdl_run_dir) != 0) {
1383 sprintf(errmsg, "The directory you specified does not exist: [%s]\n", ctdl_run_dir);
1385 important_message("Citadel Setup", errmsg);
1390 /* Try to stop Citadel if we can */
1391 if (!access("/etc/init.d/citadel", X_OK)) {
1392 rv = system("/etc/init.d/citadel stop");
1395 /* Make sure Citadel is not running. */
1396 if (test_server(relhome, enable_home) == 0) {
1397 important_message("Citadel Setup",
1398 "The Citadel service is still running.\n"
1399 "Please stop the service manually and run "
1405 switch (setup_type) {
1409 " *** Citadel setup program ***\n\n");
1416 set_default_values();
1418 /* Go through a series of dialogs prompting for config info */
1419 for (curr = 1; curr <= MAXSETUP; ++curr) {
1421 if ((curr == 6) && (config.c_auth_mode != AUTHMODE_LDAP) && (config.c_auth_mode != AUTHMODE_LDAP_AD)) {
1422 curr += 5; /* skip LDAP questions if we're not authenticating against LDAP */
1426 /***** begin version update section *****/
1428 old_setup_level = config.c_setup_level;
1430 if (old_setup_level == 0) {
1434 if (old_setup_level < 555) {
1437 "This Citadel installation is too old to be upgraded."
1441 write_config_to_disk();
1443 old_setup_level = config.c_setup_level;
1445 /***** end of version update section *****/
1448 config.c_setup_level = REV_LEVEL;
1450 if ((pw = getpwuid(config.c_ctdluid)) == NULL) {
1456 create_run_directories(config.c_ctdluid, gid);
1458 write_config_to_disk();
1460 migrate_old_installs(); /* Delete files and directories used by older Citadel versions */
1462 if ( ((setup_type == UI_SILENT)
1463 && (getenv("ALTER_ETC_SERVICES")!=NULL))
1464 || (setup_type != UI_SILENT)
1466 check_services_entry(); /* Check /etc/services */
1470 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1471 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1472 disable_other_mtas(); /* Offer to disable other MTAs */
1473 fixnss(); /* Check for the 'db' nss and offer to disable it */
1476 progress("Setting file permissions", 1, 3);
1477 rv = chown(file_citadel_config, config.c_ctdluid, gid);
1478 progress("Setting file permissions", 2, 3);
1479 rv = chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1480 progress("Setting file permissions", 3, 3);
1482 check_init_script(relhome);