4 * Citadel setup utility
8 #define SHOW_ME_VAPPEND_PRINTF
10 #include "ctdl_module.h"
19 #include <sys/types.h>
21 #include <sys/utsname.h>
29 #include <libcitadel.h>
34 #include "citadel_dirs.h"
45 #define _(string) gettext(string)
47 #define _(string) (string)
51 #define MAXSETUP 11 /* How many setup questions to ask */
53 #define UI_TEXT 0 /* Default setup type -- text only */
54 #define UI_DIALOG 2 /* Use the 'dialog' program */
55 #define UI_SILENT 3 /* Silent running, for use in scripts */
57 #define SERVICE_NAME "citadel"
58 #define PROTO_NAME "tcp"
59 #define NSSCONF "/etc/nsswitch.conf"
62 typedef enum _SetupStep {
78 ///"CREATE_XINETD_ENTRY";
79 const char *EnvNames [eMaxQuestions] = {
95 int using_web_installer = 0;
100 const char *setup_titles[eMaxQuestions];
104 setup_titles[eCitadelHomeDir] = _("Citadel Home Directory");
105 setup_titles[eSysAdminName] = _("Citadel administrator username:");////
106 setup_titles[eSysAdminPW] = _("Administrator password:");//
107 setup_titles[eUID] = _("Citadel User ID:");
108 setup_titles[eIP_ADDR] = _("Listening address for the Citadel server:");///
109 setup_titles[eCTDL_Port] = _("Server port number:");
110 setup_titles[eAuthType] = _("Authentication method to use:");////
111 setup_titles[eLDAP_Host] = _("LDAP host:");///
112 setup_titles[eLDAP_Port] = _("LDAP port number:");////
113 setup_titles[eLDAP_Base_DN] = _("LDAP base DN:");///
114 setup_titles[eLDAP_Bind_DN] = _("LDAP bind DN:");//
115 setup_titles[eLDAP_Bind_PW] = _("LDAP bind password:");//
119 * \brief print the actual stack frame.
121 void cit_backtrace(void)
123 #ifdef HAVE_BACKTRACE
124 void *stack_frames[50];
129 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
130 strings = backtrace_symbols(stack_frames, size);
131 for (i = 0; i < size; i++) {
133 fprintf(stderr, "%s\n", strings[i]);
135 fprintf(stderr, "%p\n", stack_frames[i]);
141 struct config config;
143 /* calculate all our path on a central place */
144 /* where to keep our config */
147 char *setup_text[] = {
149 "Enter the full pathname of the directory in which the Citadel\n"
150 "installation you are creating or updating resides. If you\n"
151 "specify a directory other than the default, you will need to\n"
152 "specify the -h flag to the server when you start it up.\n",
154 "Enter the subdirectory name for an alternate installation of "
155 "Citadel. To do a default installation just leave it blank."
156 "If you specify a directory other than the default, you will need to\n"
157 "specify the -h flag to the server when you start it up.\n"
158 "note that it may not have a leading /",
161 "Enter the name of the system administrator (which is probably\n"
162 "you). When an account is created with this name, it will\n"
163 "automatically be given administrator-level access.\n",
165 "Enter a password for the system administrator. When setup\n"
166 "completes it will attempt to create the administrator user\n"
167 "and set the password specified here.\n",
169 "Citadel needs to run under its own user ID. This would\n"
170 "typically be called \"citadel\", but if you are running Citadel\n"
171 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
172 "The server will run under this user ID. Please specify that\n"
173 "user ID here. You may specify either a user name or a numeric\n"
176 "Specify the IP address on which your server will run. If you\n"
177 "leave this blank, or if you specify 0.0.0.0, Citadel will listen\n"
178 "on all addresses. You can usually skip this unless you are\n"
179 "running multiple instances of Citadel on the same computer.\n",
181 "Specify the TCP port number on which your server will run.\n"
182 "Normally, this will be port 504, which is the official port\n"
183 "assigned by the IANA for Citadel servers. You will only need\n"
184 "to specify a different port number if you run multiple instances\n"
185 "of Citadel on the same computer and there is something else\n"
186 "already using port 504.\n",
190 "Specify which authentication mode you wish to use.\n"
192 " 0. Self contained authentication\n"
193 " 1. Host system integrated authentication\n"
194 " 2. External LDAP - RFC 2307 compliant directory\n"
195 " 3. External LDAP - nonstandard MS Active Directory\n"
197 "For help: http://www.citadel.org/doku.php/faq:installation:authmodes\n"
199 "ANSWER \"0\" UNLESS YOU COMPLETELY UNDERSTAND THIS OPTION.\n",
201 "Please enter the host name or IP address of your LDAP server.\n",
203 "Please enter the port number of the LDAP service (usually 389).\n",
205 "Please enter the Base DN to search for authentication\n"
206 "(for example: dc=example,dc=com)\n",
208 "Please enter the DN of an account to use for binding to the LDAP server\n"
209 "for performing queries. The account does not require any other\n"
210 "privileges. If your LDAP server allows anonymous queries, you can.\n"
211 "leave this blank.\n",
213 "If you entered a Bind DN in the previous question, you must now enter\n"
214 "the password associated with that account. Otherwise, you can leave this\n"
219 struct config config;
223 void cleanup(int exitcode)
225 // printf("Exitcode: %d\n", exitcode);
232 void title(const char *text)
234 if (setup_type == UI_TEXT) {
235 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
241 int yesno(char *question, int default_value)
247 switch (setup_type) {
251 printf("%s\nYes/No [%s] --> ",
253 ( default_value ? "Yes" : "No" )
255 if (fgets(buf, sizeof buf, stdin))
257 answer = tolower(buf[0]);
258 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
259 answer = default_value;
260 else if (answer == 'y')
262 else if (answer == 'n')
265 } while ((answer < 0) || (answer > 1));
269 sprintf(buf, "exec %s %s --yesno '%s' 15 75",
270 getenv("CTDL_DIALOG"),
271 ( default_value ? "" : "--defaultno" ),
289 void important_message(char *title, char *msgtext)
294 switch (setup_type) {
297 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");
298 printf(" %s \n\n%s\n\n", title, msgtext);
299 printf("Press return to continue...");
300 if (fgets(buf, sizeof buf, stdin));
304 sprintf(buf, "exec %s --msgbox '%s' 19 72",
305 getenv("CTDL_DIALOG"),
310 fprintf(stderr, "%s\n", msgtext);
315 void important_msgnum(int msgnum)
317 important_message("Important Message", setup_text[msgnum]);
320 void display_error(char *error_message)
322 important_message("Error", error_message);
325 void progress(char *text, long int curr, long int cmax)
327 static long dots_printed = 0L;
329 static FILE *fp = NULL;
332 switch (setup_type) {
336 printf("%s\n", text);
337 printf("..........................");
338 printf("..........................");
339 printf("..........................\r");
342 } else if (curr == cmax) {
343 printf("\r%79s\n", "");
345 a = (curr * 100) / cmax;
348 while (dots_printed < a) {
358 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
359 getenv("CTDL_DIALOG"),
361 fp = popen(buf, "w");
367 else if (curr == cmax) {
369 fprintf(fp, "100\n");
375 a = (curr * 100) / cmax;
377 fprintf(fp, "%ld\n", a);
391 * check_services_entry() -- Make sure "citadel" is in /etc/services
394 void check_services_entry(void)
400 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
401 for (i=0; i<=2; ++i) {
402 progress("Adding service entry...", i, 2);
404 sfp = fopen("/etc/services", "a");
406 sprintf(errmsg, "Cannot open /etc/services: %s", strerror(errno));
407 display_error(errmsg);
409 fprintf(sfp, "%s 504/tcp\n", SERVICE_NAME);
421 * delete_inittab_entry() -- Remove obsolete /etc/inittab entry for Citadel
424 void delete_inittab_entry(void)
428 char looking_for[256];
430 char outfilename[32];
431 int changes_made = 0;
434 /* Determine the fully qualified path name of citserver */
435 snprintf(looking_for,
441 /* Now tweak /etc/inittab */
442 infp = fopen("/etc/inittab", "r");
445 /* If /etc/inittab does not exist, return quietly.
446 * Not all host platforms have it.
448 if (errno == ENOENT) {
452 /* Other errors might mean something really did go wrong.
454 sprintf(buf, "Cannot open /etc/inittab: %s", strerror(errno));
459 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
460 outfp = fdopen(mkstemp(outfilename), "w+");
462 sprintf(buf, "Cannot open %s: %s", outfilename, strerror(errno));
468 while (fgets(buf, sizeof buf, infp) != NULL) {
469 if (strstr(buf, looking_for) != NULL) {
470 rv = fwrite("#", 1, 1, outfp);
473 rv = fwrite(buf, strlen(buf), 1, outfp);
480 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
482 rv = system("/sbin/init q 2>/dev/null");
491 * install_init_scripts() -- Try to configure to start Citadel at boot
494 void install_init_scripts(void)
496 struct stat etcinitd;
498 char *initfile = "/etc/init.d/citadel";
502 if ((stat("/etc/init.d/", &etcinitd) == -1) &&
505 if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
507 initfile = CTDLDIR"/citadel.init";
509 initfile = "/etc/rc.d/init.d/citadel";
512 fp = fopen(initfile, "r");
514 if (yesno("Citadel already appears to be configured to start at boot.\n"
515 "Would you like to keep your boot configuration as is?\n", 1) == 1) {
522 if (yesno("Would you like to automatically start Citadel at boot?\n", 1) == 0) {
526 fp = fopen(initfile, "w");
528 display_error("Cannot create /etc/init.d/citadel");
532 fprintf(fp, "#!/bin/sh\n"
534 "# Init file for Citadel\n"
536 "# chkconfig: - 79 30\n"
537 "# description: Citadel service\n"
538 "# processname: citserver\n"
539 "# pidfile: %s/citadel.pid\n\n"
540 "# uncomment this to create coredumps as described in\n"
541 "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
542 "# ulimit -c unlimited\n"
550 "test -d /var/run || exit 0\n"
554 "start) echo -n \"Starting Citadel... \"\n"
555 " if $CITADEL_DIR/citserver -lmail -d\n"
562 "stop) echo -n \"Stopping Citadel... \"\n"
563 " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
568 " rm -f %s/citadel.pid 2>/dev/null\n"
573 "restart) if $CITADEL_DIR/sendcommand DOWN 1 >/dev/null 2>&1 ; then\n"
579 "*) echo \"Usage: $0 {start|stop|restart}\"\n"
586 chmod(initfile, 0755);
588 /* Set up the run levels. */
589 rv = system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
590 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);
591 rv = system(command);
592 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);
593 rv = system(command);
603 * On systems which use xinetd, see if we can offer to install Citadel as
604 * the default telnet target.
606 void check_xinetd_entry(void) {
607 char *filename = "/etc/xinetd.d/telnet";
610 int already_citadel = 0;
613 fp = fopen(filename, "r+");
614 if (fp == NULL) return; /* Not there. Oh well... */
616 while (fgets(buf, sizeof buf, fp) != NULL) {
617 if (strstr(buf, "/citadel") != NULL) already_citadel = 1;
620 if (already_citadel) return; /* Already set up this way. */
622 /* Otherwise, prompt the user to create an entry. */
623 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
624 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
629 snprintf(buf, sizeof buf,
630 "Setup can configure the \"xinetd\" service to automatically\n"
631 "connect incoming telnet sessions to Citadel, bypassing the\n"
632 "host system login: prompt. Would you like to do this?\n"
634 if (yesno(buf, 1) == 0) {
639 fp = fopen(filename, "w");
641 "# description: telnet service for Citadel users\n"
646 " socket_type = stream\n"
649 " server = /usr/sbin/in.telnetd\n"
650 " server_args = -h -L %s/citadel\n"
651 " log_on_failure += USERID\n"
656 /* Now try to restart the service */
657 rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
663 * Offer to disable other MTA's
665 void disable_other_mta(const char *mta) {
671 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
672 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
674 fp = popen(buf, "r");
675 if (fp == NULL) return;
677 while (fgets(buf, sizeof buf, fp) != NULL) {
681 if (lines == 0) return; /* Nothing to do. */
684 /* Offer to replace other MTA with the vastly superior Citadel :) */
686 snprintf(buf, sizeof buf,
687 "You appear to have the \"%s\" email program\n"
688 "running on your system. If you want Citadel mail\n"
689 "connected with %s, you will have to manually integrate\n"
690 "them. It is preferable to disable %s, and use Citadel's\n"
691 "SMTP, POP3, and IMAP services.\n\n"
692 "May we disable %s so that Citadel has access to ports\n"
693 "25, 110, and 143?\n",
696 if (yesno(buf, 1) == 0) {
701 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);
703 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
707 const char *other_mtas[] = {
708 "courier-authdaemon",
731 void disable_other_mtas(void)
734 if ((getenv("ACT_AS_MTA") == NULL) ||
735 (getenv("ACT_AS_MTA") &&
736 strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
737 /* Offer to disable other MTA's on the system. */
738 while (!IsEmptyStr(other_mtas[i]))
740 disable_other_mta(other_mtas[i]);
747 * Check to see if our server really works. Returns 0 on success.
749 int test_server(char *relhomestr, int relhome) {
756 /* Generate a silly little cookie. We're going to write it out
757 * to the server and try to get it back. The cookie does not
758 * have to be secret ... just unique.
760 sprintf(cookie, "--test--%d--", getpid());
763 sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
768 sprintf(cmd, "%s/sendcommand ECHO %s 2>&1",
772 fp = popen(cmd, "r");
773 if (fp == NULL) return(errno);
775 while (fgets(buf, sizeof buf, fp) != NULL) {
777 && (strstr(buf, cookie) != NULL) ) {
789 void strprompt(const char *prompt_title, char *prompt_text, char *Target, char *DefValue)
793 char dialog_result[PATH_MAX];
797 strcpy(setupmsg, "");
799 switch (setup_type) {
802 printf("\n%s\n", prompt_text);
803 printf("This is currently set to:\n%s\n", Target);
804 printf("Enter new value or press return to leave unchanged:\n");
805 if (fgets(buf, sizeof buf, stdin)){
806 buf[strlen(buf) - 1] = 0;
808 if (!IsEmptyStr(buf))
813 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
814 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
815 getenv("CTDL_DIALOG"),
820 fp = fopen(dialog_result, "r");
822 if (fgets(Target, sizeof buf, fp)) {
823 if (Target[strlen(Target)-1] == 10) {
824 Target[strlen(Target)-1] = 0;
828 unlink(dialog_result);
832 strcpy(Target, DefValue);
837 void set_bool_val(int msgpos, int *ip, char *DefValue)
839 title(setup_titles[msgpos]);
840 *ip = yesno(setup_text[msgpos], *ip);
843 void set_str_val(int msgpos, char *Target, char *DefValue)
845 if (DefValue != NULL)
847 strprompt(setup_titles[msgpos],
854 void set_int_val(int msgpos, int *ip, char *DefValue)
857 snprintf(buf, sizeof buf, "%d", (int) *ip);
858 set_str_val(msgpos, buf, DefValue);
863 void set_char_val(int msgpos, char *ip, char *DefValue)
866 snprintf(buf, sizeof buf, "%d", (int) *ip);
867 set_str_val(msgpos, buf, DefValue);
868 *ip = (char) atoi(buf);
872 void set_long_val(int msgpos, long int *ip, char *DefValue)
875 snprintf(buf, sizeof buf, "%ld", *ip);
876 set_str_val(msgpos, buf, DefValue);
881 void edit_value(int curr)
885 char ctdluidname[256];
888 if (setup_type == UI_SILENT)
890 Value = getenv(EnvNames[curr]);
897 set_str_val(curr, config.c_sysadm, Value);
901 set_str_val(curr, admin_pass, Value);
905 if (setup_type == UI_SILENT)
908 config.c_ctdluid = atoi(Value);
914 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
916 i = config.c_ctdluid;
919 set_int_val(curr, &i, Value);
920 config.c_ctdluid = i;
923 strcpy(ctdluidname, pw->pw_name);
924 set_str_val(curr, ctdluidname, Value);
925 pw = getpwnam(ctdluidname);
927 config.c_ctdluid = pw->pw_uid;
929 else if (atoi(ctdluidname) > 0) {
930 config.c_ctdluid = atoi(ctdluidname);
938 set_str_val(curr, config.c_ip_addr, Value);
942 set_int_val(curr, &config.c_port_number, Value);
946 if (setup_type == UI_SILENT)
949 config.c_auth_mode = AUTHMODE_NATIVE;
953 if ((strcasecmp(auth, "yes") == 0) ||
954 (strcasecmp(auth, "host") == 0))
956 config.c_auth_mode = AUTHMODE_HOST;
958 else if (strcasecmp(auth, "ldap") == 0){
959 config.c_auth_mode = AUTHMODE_LDAP;
961 else if ((strcasecmp(auth, "ldap_ad") == 0) ||
962 (strcasecmp(auth, "active directory") == 0)){
963 config.c_auth_mode = AUTHMODE_LDAP_AD;
968 set_int_val(curr, &config.c_auth_mode, Value);
973 set_str_val(curr, config.c_ldap_host, Value);
977 if (config.c_ldap_port == 0) {
978 config.c_ldap_port = 389;
980 set_int_val(curr, &config.c_ldap_port, Value);
984 set_str_val(curr, config.c_ldap_base_dn, Value);
988 set_str_val(curr, config.c_ldap_bind_dn, Value);
992 set_str_val(curr, config.c_ldap_bind_pw, Value);
999 * (re-)write the config data to disk
1001 void write_config_to_disk(void)
1007 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
1008 display_error("setup: cannot open citadel.config");
1011 fp = fdopen(fd, "wb");
1013 display_error("setup: cannot open citadel.config");
1016 rv = fwrite((char *) &config, sizeof(struct config), 1, fp);
1024 * Figure out what type of user interface we're going to use
1026 int discover_ui(void)
1029 /* Use "dialog" if we have it */
1030 if (getenv("CTDL_DIALOG") != NULL) {
1039 void migrate_old_installs(void)
1042 rv = system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1043 unlink("citadel.log");
1049 * Strip "db" entries out of /etc/nsswitch.conf
1059 int file_changed = 0;
1060 char new_filename[64];
1063 fp_read = fopen(NSSCONF, "r");
1064 if (fp_read == NULL) {
1068 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
1069 fd_write = mkstemp(new_filename);
1075 while (fgets(buf, sizeof buf, fp_read) != NULL) {
1077 strcpy(buf_nc, buf);
1078 for (i=0; i<strlen(buf_nc); ++i) {
1079 if (buf_nc[i] == '#') {
1083 for (i=0; i<strlen(buf_nc); ++i) {
1084 if (!strncasecmp(&buf_nc[i], "db", 2)) {
1086 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
1089 strcpy(&buf_nc[i], &buf_nc[i+2]);
1090 strcpy(&buf[i], &buf[i+2]);
1092 strcpy(&buf_nc[i], &buf_nc[i+1]);
1093 strcpy(&buf[i], &buf[i+1]);
1099 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
1102 unlink(new_filename);
1109 if (!file_changed) {
1110 unlink(new_filename);
1114 snprintf(question, sizeof question,
1116 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
1117 "one or more services. This is not necessary on most systems,\n"
1118 "and it is known to crash the Citadel server when delivering\n"
1119 "mail to the Internet.\n"
1121 "Do you want this module to be automatically disabled?\n"
1125 if (yesno(question, 1)) {
1126 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
1128 chmod(NSSCONF, 0644);
1130 unlink(new_filename);
1133 void check_init_script (char *relhome)
1139 * If we're running on SysV, install init scripts.
1141 if (!access("/var/run", W_OK)) {
1143 if (getenv("NO_INIT_SCRIPTS") == NULL) {
1144 install_init_scripts();
1147 if (!access("/etc/init.d/citadel", X_OK)) {
1148 rv = system("/etc/init.d/citadel start");
1152 if (test_server(relhome, enable_home) == 0) {
1156 if (config.c_auth_mode == AUTHMODE_NATIVE) {
1157 snprintf (admin_cmd, sizeof(admin_cmd), "%s/sendcommand \"CREU %s|%s\" 2>&1",
1158 ctdl_sbin_dir, config.c_sysadm, admin_pass);
1159 fp = popen(admin_cmd, "r");
1161 while (fgets(buf, sizeof buf, fp) != NULL)
1163 if ((atol(buf) == 574) || (atol(buf) == 200))
1169 if (found_it == 0) {
1170 important_message("Error","Setup failed to create your admin user");
1174 if (setup_type != UI_SILENT)
1175 important_message("Setup finished",
1176 "Setup of the Citadel server is complete.\n"
1177 "If you will be using WebCit, please run its\n"
1178 "setup program now; otherwise, run './citadel'\n"
1182 important_message("Setup failed",
1183 "Setup is finished, but the Citadel server failed to start.\n"
1184 "Go back and check your configuration.\n"
1191 important_message("Setup finished",
1192 "Setup is finished. You may now start the server.");
1196 void set_default_values(void)
1199 struct utsname my_utsname;
1202 /* Determine our host name, in case we need to use it as a default */
1205 /* set some sample/default values in place of blanks... */
1206 if (IsEmptyStr(config.c_nodename))
1207 safestrncpy(config.c_nodename, my_utsname.nodename,
1208 sizeof config.c_nodename);
1209 strtok(config.c_nodename, ".");
1210 if (IsEmptyStr(config.c_fqdn) ) {
1211 if ((he = gethostbyname(my_utsname.nodename)) != NULL) {
1212 safestrncpy(config.c_fqdn, he->h_name, sizeof config.c_fqdn);
1214 safestrncpy(config.c_fqdn, my_utsname.nodename, sizeof config.c_fqdn);
1217 if (IsEmptyStr(config.c_humannode)) {
1218 strcpy(config.c_humannode, "My System");
1220 if (IsEmptyStr(config.c_phonenum)) {
1221 strcpy(config.c_phonenum, "US 800 555 1212");
1223 if (config.c_initax == 0) {
1224 config.c_initax = 4;
1226 if (IsEmptyStr(config.c_moreprompt)) strcpy(config.c_moreprompt, "<more>");
1227 if (IsEmptyStr(config.c_twitroom)) strcpy(config.c_twitroom, "Trashcan");
1228 if (IsEmptyStr(config.c_baseroom)) strcpy(config.c_baseroom, BASEROOM);
1229 if (IsEmptyStr(config.c_aideroom)) strcpy(config.c_aideroom, "Aide");
1230 if (config.c_port_number == 0) {
1231 config.c_port_number = 504;
1233 if (config.c_sleeping == 0) {
1234 config.c_sleeping = 900;
1236 if (config.c_ctdluid == 0) {
1237 pw = getpwnam("citadel");
1239 config.c_ctdluid = pw->pw_uid;
1242 if (config.c_ctdluid == 0) {
1243 pw = getpwnam("bbs");
1245 config.c_ctdluid = pw->pw_uid;
1248 if (config.c_ctdluid == 0) {
1249 pw = getpwnam("guest");
1251 config.c_ctdluid = pw->pw_uid;
1254 if (config.c_createax == 0) {
1255 config.c_createax = 3;
1258 * Negative values for maxsessions are not allowed.
1260 if (config.c_maxsessions < 0) {
1261 config.c_maxsessions = 0;
1263 /* We need a system default message expiry policy, because this is
1264 * the top level and there's no 'higher' policy to fall back on.
1265 * By default, do not expire messages at all.
1267 if (config.c_ep.expire_mode == 0) {
1268 config.c_ep.expire_mode = EXPIRE_MANUAL;
1269 config.c_ep.expire_value = 0;
1273 * Default port numbers for various services
1275 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1276 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1277 if (config.c_imap_port == 0) config.c_imap_port = 143;
1278 if (config.c_msa_port == 0) config.c_msa_port = 587;
1279 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1280 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1281 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1282 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1283 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1284 if (config.c_xmpp_c2s_port == 0) config.c_xmpp_c2s_port = 5222;
1285 if (config.c_xmpp_s2s_port == 0) config.c_xmpp_s2s_port = 5269;
1289 void get_config (void)
1296 * What we're going to try to do here is append a whole bunch of
1297 * nulls to the citadel.config file, so we can keep the old config
1298 * values if they exist, but if the file is missing or from an
1299 * earlier version with a shorter config structure, when setup tries
1300 * to read the old config parameters, they'll all come up zero.
1301 * The length of the config file will be set to what it's supposed
1302 * to be when we rewrite it, because we replace the old file with a
1303 * completely new copy.
1305 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1306 S_IRUSR | S_IWUSR)) == -1) {
1307 display_error("setup: cannot append citadel.config");
1310 fp = fdopen(a, "ab");
1312 display_error("setup: cannot append citadel.config");
1315 for (a = 0; a < sizeof(struct config); ++a) {
1320 /* now we re-open it, and read the old or blank configuration */
1321 fp = fopen(file_citadel_config, "rb");
1323 display_error("setup: cannot open citadel.config");
1326 rv = fread((char *) &config, sizeof(struct config), 1, fp);
1331 int main(int argc, char *argv[])
1336 int old_setup_level = 0;
1340 char relhome[PATH_MAX]="";
1341 char ctdldir[PATH_MAX]=CTDLDIR;
1346 /* set an invalid setup type */
1349 /* Check to see if we're running the web installer */
1350 if (getenv("CITADEL_INSTALLER") != NULL) {
1351 using_web_installer = 1;
1354 /* parse command line args */
1355 for (a = 0; a < argc; ++a) {
1356 if (!strncmp(argv[a], "-u", 2)) {
1357 strcpy(aaa, argv[a]);
1358 strcpy(aaa, &aaa[2]);
1359 setup_type = atoi(aaa);
1361 else if (!strcmp(argv[a], "-i")) {
1364 else if (!strcmp(argv[a], "-q")) {
1365 setup_type = UI_SILENT;
1367 else if (!strncmp(argv[a], "-h", 2)) {
1368 relh=argv[a][2]!='/';
1370 safestrncpy(ctdl_home_directory, &argv[a][2], sizeof ctdl_home_directory);
1372 safestrncpy(relhome, &argv[a][2], sizeof relhome);
1379 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1382 /* If a setup type was not specified, try to determine automatically
1383 * the best one to use out of all available types.
1385 if (setup_type < 0) {
1386 setup_type = discover_ui();
1388 if (info_only == 1) {
1389 important_message("Citadel Setup", CITADEL);
1393 enable_home = ( relh | home );
1395 if (chdir(ctdl_run_dir) != 0) {
1397 sprintf(errmsg, "The directory you specified does not exist: [%s]\n", ctdl_run_dir);
1399 important_message("Citadel Setup", errmsg);
1404 /* Try to stop Citadel if we can */
1405 if (!access("/etc/init.d/citadel", X_OK)) {
1406 rv = system("/etc/init.d/citadel stop");
1409 /* Make sure Citadel is not running. */
1410 if (test_server(relhome, enable_home) == 0) {
1411 important_message("Citadel Setup",
1412 "The Citadel service is still running.\n"
1413 "Please stop the service manually and run "
1419 switch (setup_type) {
1423 " *** Citadel setup program ***\n\n");
1430 set_default_values();
1432 /* Go through a series of dialogs prompting for config info */
1433 for (curr = 1; curr <= MAXSETUP; ++curr) {
1435 if ((curr == 6) && (config.c_auth_mode != AUTHMODE_LDAP) && (config.c_auth_mode != AUTHMODE_LDAP_AD)) {
1436 curr += 5; /* skip LDAP questions if we're not authenticating against LDAP */
1440 /***** begin version update section ***** */
1441 /* take care of any updating that is necessary */
1443 old_setup_level = config.c_setup_level;
1445 if (old_setup_level == 0) {
1449 if (old_setup_level < 555) {
1450 important_message("Citadel Setup",
1451 "This Citadel installation is too old "
1455 write_config_to_disk();
1457 old_setup_level = config.c_setup_level;
1459 /* end of version update section */
1462 config.c_setup_level = REV_LEVEL;
1464 /******************************************/
1465 if ((pw = getpwuid(config.c_ctdluid)) == NULL) {
1471 create_run_directories(config.c_ctdluid, gid);
1473 write_config_to_disk();
1475 migrate_old_installs(); /* Delete files and directories used by older Citadel versions */
1477 if (((setup_type == UI_SILENT) && (getenv("ALTER_ETC_SERVICES")!=NULL)) ||
1478 (setup_type != UI_SILENT))
1479 check_services_entry(); /* Check /etc/services */
1481 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1482 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1483 disable_other_mtas(); /* Offer to disable other MTAs */
1486 fixnss(); /* Check for the 'db' nss and offer to disable it */
1488 progress("Setting file permissions", 1, 3);
1489 rv = chown(file_citadel_config, config.c_ctdluid, gid);
1490 progress("Setting file permissions", 2, 3);
1491 rv = chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1492 progress("Setting file permissions", 3, 3);
1494 check_init_script (relhome);