4 * Citadel setup utility
14 #include <sys/types.h>
16 #include <sys/utsname.h>
30 #include "citadel_dirs.h"
37 #define MAXSETUP 4 /* How many setup questions to ask */
39 #define UI_TEXT 0 /* Default setup type -- text only */
40 #define UI_DIALOG 2 /* Use the 'dialog' program */
41 #define UI_SILENT 3 /* Silent running, for use in scripts */
42 #define UI_NEWT 4 /* Use the "newt" window library */
44 #define SERVICE_NAME "citadel"
45 #define PROTO_NAME "tcp"
46 #define NSSCONF "/etc/nsswitch.conf"
49 char setup_directory[PATH_MAX];
50 int using_web_installer = 0;
53 char *setup_titles[] =
55 "Citadel Home Directory",
56 "System Administrator",
65 /* calculate all our path on a central place */
66 /* where to keep our config */
69 char *setup_text[] = {
71 "Enter the full pathname of the directory in which the Citadel\n"
72 "installation you are creating or updating resides. If you\n"
73 "specify a directory other than the default, you will need to\n"
74 "specify the -h flag to the server when you start it up.\n",
76 "Enter the subdirectory name for an alternate installation of "
77 "Citadel. To do a default installation just leave it blank."
78 "If you specify a directory other than the default, you will need to\n"
79 "specify the -h flag to the server when you start it up.\n"
80 "note that it may not have a leading /",
83 "Enter the name of the system administrator (which is probably\n"
84 "you). When an account is created with this name, it will\n"
85 "automatically be given administrator-level access.\n",
87 "Citadel needs to run under its own user ID. This would\n"
88 "typically be called \"citadel\", but if you are running Citadel\n"
89 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
90 "The server will run under this user ID. Please specify that\n"
91 "user ID here. You may specify either a user name or a numeric\n"
94 "Specify the IP address on which your server will run. If you\n"
95 "leave this blank, or if you specify 0.0.0.0, Citadel will listen\n"
96 "on all addresses. You can usually skip this unless you are\n"
97 "running multiple instances of Citadel on the same computer.\n",
99 "Specify the TCP port number on which your server will run.\n"
100 "Normally, this will be port 504, which is the official port\n"
101 "assigned by the IANA for Citadel servers. You will only need\n"
102 "to specify a different port number if you run multiple instances\n"
103 "of Citadel on the same computer and there is something else\n"
104 "already using port 504.\n",
108 struct config config;
112 void cleanup(int exitcode)
124 void title(char *text)
126 if (setup_type == UI_TEXT) {
127 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
133 int yesno(char *question)
136 newtComponent form = NULL;
137 newtComponent yesbutton = NULL;
138 newtComponent nobutton = NULL;
139 int prompt_window_height = 0;
145 switch (setup_type) {
149 printf("%s\nYes/No --> ", question);
150 fgets(buf, sizeof buf, stdin);
151 answer = tolower(buf[0]);
154 else if (answer == 'n')
156 } while ((answer < 0) || (answer > 1));
160 sprintf(buf, "exec %s --yesno '%s' 10 72",
161 getenv("CTDL_DIALOG"),
174 prompt_window_height = num_tokens(question, '\n') + 5;
175 newtCenteredWindow(76, prompt_window_height, "Question");
176 form = newtForm(NULL, NULL, 0);
177 for (i=0; i<num_tokens(question, '\n'); ++i) {
178 extract_token(buf, question, i, '\n', sizeof buf);
179 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
181 yesbutton = newtButton(10, (prompt_window_height - 4), "Yes");
182 nobutton = newtButton(60, (prompt_window_height - 4), "No");
183 newtFormAddComponent(form, yesbutton);
184 newtFormAddComponent(form, nobutton);
185 if (newtRunForm(form) == yesbutton) {
192 newtFormDestroy(form);
202 void important_message(char *title, char *msgtext)
205 newtComponent form = NULL;
210 switch (setup_type) {
213 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");
214 printf(" %s \n\n%s\n\n", title, msgtext);
215 printf("Press return to continue...");
216 fgets(buf, sizeof buf, stdin);
220 sprintf(buf, "exec %s --msgbox '%s' 19 72",
221 getenv("CTDL_DIALOG"),
228 newtCenteredWindow(76, 10, title);
229 form = newtForm(NULL, NULL, 0);
230 for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
231 extract_token(buf, msgtext, i, '\n', sizeof buf);
232 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
234 newtFormAddComponent(form, newtButton(35, 5, "OK"));
237 newtFormDestroy(form);
244 void important_msgnum(int msgnum)
246 important_message("Important Message", setup_text[msgnum]);
249 void display_error(char *error_message)
251 important_message("Error", error_message);
254 void progress(char *text, long int curr, long int cmax)
258 /* These variables are static because progress() gets called
259 * multiple times during the course of whatever operation is
260 * being performed. This makes setup non-threadsafe, but who
263 static newtComponent form = NULL;
264 static newtComponent scale = NULL;
266 static long dots_printed = 0L;
268 static FILE *fp = NULL;
271 switch (setup_type) {
275 printf("%s\n", text);
276 printf("..........................");
277 printf("..........................");
278 printf("..........................\r");
281 } else if (curr == cmax) {
282 printf("\r%79s\n", "");
284 a = (curr * 100) / cmax;
287 while (dots_printed < a) {
297 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
298 getenv("CTDL_DIALOG"),
300 fp = popen(buf, "w");
306 else if (curr == cmax) {
308 fprintf(fp, "100\n");
314 a = (curr * 100) / cmax;
316 fprintf(fp, "%ld\n", a);
325 newtCenteredWindow(76, 8, text);
326 form = newtForm(NULL, NULL, 0);
327 scale = newtScale(1, 3, 74, cmax);
328 newtFormAddComponent(form, scale);
332 if ((curr > 0) && (curr <= cmax)) {
333 newtScaleSet(scale, curr);
337 newtFormDestroy(form);
350 * check_services_entry() -- Make sure "citadel" is in /etc/services
353 void check_services_entry(void)
359 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
360 for (i=0; i<=2; ++i) {
361 progress("Adding service entry...", i, 2);
363 sfp = fopen("/etc/services", "a");
365 sprintf(errmsg, "Cannot open /etc/services: %s", strerror(errno));
366 display_error(errmsg);
368 fprintf(sfp, "%s 504/tcp\n", SERVICE_NAME);
381 * delete_inittab_entry() -- Remove obsolete /etc/inittab entry for Citadel
384 void delete_inittab_entry(void)
388 char looking_for[256];
390 char outfilename[32];
391 int changes_made = 0;
393 /* Determine the fully qualified path name of citserver */
394 snprintf(looking_for,
404 /* Now tweak /etc/inittab */
405 infp = fopen("/etc/inittab", "r");
407 sprintf(buf, "Cannot open /etc/inittab: %s", strerror(errno));
412 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
413 outfp = fdopen(mkstemp(outfilename), "w+");
415 sprintf(buf, "Cannot open %s: %s", outfilename, strerror(errno));
421 while (fgets(buf, sizeof buf, infp) != NULL) {
422 if (strstr(buf, looking_for) == NULL) {
423 fwrite(buf, strlen(buf), 1, outfp);
434 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
436 system("/sbin/init q 2>/dev/null");
445 * install_init_scripts() -- Try to configure to start Citadel at boot
448 void install_init_scripts(void)
452 if (yesno("Would you like to automatically start Citadel at boot?\n") == 0) {
456 fp = fopen("/etc/init.d/citadel", "w");
458 display_error("Cannot create /etc/init.d/citadel");
462 fprintf(fp, "#!/bin/sh\n"
464 "CITADEL_DIR=%s\n", setup_directory);
466 "test -x $CITADEL_DIR/ctdlsvc || exit 0\n"
467 "test -d /var/run || exit 0\n"
471 "start) echo -n \"Starting Citadel... \"\n"
472 " if $CITADEL_DIR/ctdlsvc /var/run/citadel.pid "
473 "$CITADEL_DIR/citserver "
481 "stop) echo -n \"Stopping Citadel... \"\n"
482 " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
487 " rm -f /var/run/citadel.pid 2>/dev/null\n");
492 "*) echo \"Usage: $0 {start|stop|restart}\"\n"
499 chmod("/etc/init.d/citadel", 0755);
501 /* Set up the run levels. */
502 system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
503 system("for x in 2 3 4 5 ; do [ -d /etc/rc$x.d ] && ln -s /etc/init.d/citadel /etc/rc$x.d/S79citadel ; done 2>/dev/null");
504 system("for x in 0 6 S; do [ -d /etc/rc$x.d ] && ln -s /etc/init.d/citadel /etc/rc$x.d/K30citadel ; done 2>/dev/null");
514 * On systems which use xinetd, see if we can offer to install Citadel as
515 * the default telnet target.
517 void check_xinetd_entry(void) {
518 char *filename = "/etc/xinetd.d/telnet";
521 int already_citadel = 0;
523 fp = fopen(filename, "r+");
524 if (fp == NULL) return; /* Not there. Oh well... */
526 while (fgets(buf, sizeof buf, fp) != NULL) {
527 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
530 if (already_citadel) return; /* Already set up this way. */
532 /* Otherwise, prompt the user to create an entry. */
533 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
534 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
539 snprintf(buf, sizeof buf,
540 "Setup can configure the \"xinetd\" service to automatically\n"
541 "connect incoming telnet sessions to Citadel, bypassing the\n"
542 "host system login: prompt. Would you like to do this?\n"
544 if (yesno(buf) == 0) {
549 fp = fopen(filename, "w");
551 "# description: telnet service for Citadel users\n"
556 " socket_type = stream\n"
559 " server = /usr/sbin/in.telnetd\n"
560 " server_args = -h -L %s/citadel\n"
561 " log_on_failure += USERID\n"
571 /* Now try to restart the service */
572 system("/etc/init.d/xinetd restart >/dev/null 2>&1");
578 * Offer to disable other MTA's
580 void disable_other_mta(char *mta) {
585 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
586 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
588 fp = popen(buf, "r");
589 if (fp == NULL) return;
591 while (fgets(buf, sizeof buf, fp) != NULL) {
595 if (lines == 0) return; /* Nothing to do. */
598 /* Offer to replace other MTA with the vastly superior Citadel :) */
600 if (getenv("ACT_AS_MTA")) {
601 if (strcasecmp(getenv("ACT_AS_MTA"), "yes")) {
606 snprintf(buf, sizeof buf,
607 "You appear to have the \"%s\" email program\n"
608 "running on your system. If you want Citadel mail\n"
609 "connected with %s, you will have to manually integrate\n"
610 "them. It is preferable to disable %s, and use Citadel's\n"
611 "SMTP, POP3, and IMAP services.\n\n"
612 "May we disable %s so that Citadel has access to ports\n"
613 "25, 110, and 143?\n",
616 if (yesno(buf) == 0) {
621 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);
623 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
631 * Check to see if our server really works. Returns 0 on success.
633 int test_server(void) {
640 /* Generate a silly little cookie. We're going to write it out
641 * to the server and try to get it back. The cookie does not
642 * have to be secret ... just unique.
644 sprintf(cookie, "--test--%d--", getpid());
646 sprintf(cmd, "%s/sendcommand %s%s ECHO %s 2>&1",
652 (enable_home)?"-h":"",
653 (enable_home)?setup_directory:"",
656 fp = popen(cmd, "r");
657 if (fp == NULL) return(errno);
659 while (fgets(buf, sizeof buf, fp) != NULL) {
661 && (strstr(buf, cookie) != NULL) ) {
673 void strprompt(char *prompt_title, char *prompt_text, char *str)
679 int prompt_window_height = 0;
683 char dialog_result[PATH_MAX];
686 strcpy(setupmsg, "");
688 switch (setup_type) {
691 printf("\n%s\n", prompt_text);
692 printf("This is currently set to:\n%s\n", str);
693 printf("Enter new value or press return to leave unchanged:\n");
694 fgets(buf, sizeof buf, stdin);
695 buf[strlen(buf) - 1] = 0;
696 if (strlen(buf) != 0)
701 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
702 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
703 getenv("CTDL_DIALOG"),
708 fp = fopen(dialog_result, "r");
710 fgets(str, sizeof buf, fp);
711 if (str[strlen(str)-1] == 10) {
712 str[strlen(str)-1] = 0;
715 unlink(dialog_result);
722 prompt_window_height = num_tokens(prompt_text, '\n') + 5 ;
723 newtCenteredWindow(76,
724 prompt_window_height,
726 form = newtForm(NULL, NULL, 0);
727 for (i=0; i<num_tokens(prompt_text, '\n'); ++i) {
728 extract_token(buf, prompt_text, i, '\n', sizeof buf);
729 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
731 newtFormAddComponent(form,
733 (prompt_window_height - 2),
736 (const char **) &result,
737 NEWT_FLAG_RETURNEXIT)
743 newtFormDestroy(form);
749 void set_str_val(int msgpos, char *str) {
750 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
755 void set_int_val(int msgpos, int *ip)
758 snprintf(buf, sizeof buf, "%d", (int) *ip);
759 set_str_val(msgpos, buf);
764 void set_char_val(int msgpos, char *ip)
767 snprintf(buf, sizeof buf, "%d", (int) *ip);
768 set_str_val(msgpos, buf);
769 *ip = (char) atoi(buf);
773 void set_long_val(int msgpos, long int *ip)
776 snprintf(buf, sizeof buf, "%ld", *ip);
777 set_str_val(msgpos, buf);
782 void edit_value(int curr)
786 char ctdluidname[SIZ];
791 if (getenv("SYSADMIN_NAME")) {
792 strcpy(config.c_sysadm, getenv("SYSADMIN_NAME"));
795 set_str_val(curr, config.c_sysadm);
801 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
803 i = config.c_ctdluid;
806 set_int_val(curr, &i);
807 config.c_ctdluid = i;
810 strcpy(ctdluidname, pw->pw_name);
811 set_str_val(curr, ctdluidname);
812 pw = getpwnam(ctdluidname);
814 config.c_ctdluid = pw->pw_uid;
816 else if (atoi(ctdluidname) > 0) {
817 config.c_ctdluid = atoi(ctdluidname);
824 set_str_val(curr, config.c_ip_addr);
828 set_int_val(curr, &config.c_port_number);
836 * (re-)write the config data to disk
838 void write_config_to_disk(void)
843 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
844 display_error("setup: cannot open citadel.config");
847 fp = fdopen(fd, "wb");
849 display_error("setup: cannot open citadel.config");
852 fwrite((char *) &config, sizeof(struct config), 1, fp);
860 * Figure out what type of user interface we're going to use
862 int discover_ui(void)
865 /* Use "dialog" if we have it */
866 if (getenv("CTDL_DIALOG") != NULL) {
874 newtDrawRootText(0, 0, "Citadel Setup");
885 * Strip "db" entries out of /etc/nsswitch.conf
895 int file_changed = 0;
896 char new_filename[64];
898 fp_read = fopen(NSSCONF, "r");
899 if (fp_read == NULL) {
903 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
904 fd_write = mkstemp(new_filename);
910 while (fgets(buf, sizeof buf, fp_read) != NULL) {
913 for (i=0; i<strlen(buf_nc); ++i) {
914 if (buf_nc[i] == '#') {
918 for (i=0; i<strlen(buf_nc); ++i) {
919 if (!strncasecmp(&buf_nc[i], "db", 2)) {
921 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
924 strcpy(&buf_nc[i], &buf_nc[i+2]);
925 strcpy(&buf[i], &buf[i+2]);
927 strcpy(&buf_nc[i], &buf_nc[i+1]);
928 strcpy(&buf[i], &buf[i+1]);
934 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
937 unlink(new_filename);
945 unlink(new_filename);
949 snprintf(question, sizeof question,
951 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
952 "one or more services. This is not necessary on most systems,\n"
953 "and it is known to crash the Citadel server when delivering\n"
954 "mail to the Internet.\n"
956 "Do you want this module to be automatically disabled?\n"
960 if (yesno(question)) {
961 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
964 unlink(new_filename);
974 int main(int argc, char *argv[])
980 int old_setup_level = 0;
982 struct utsname my_utsname;
988 char relhome[PATH_MAX]="";
989 char ctdldir[PATH_MAX]=CTDLDIR;
991 /* set an invalid setup type */
994 /* Check to see if we're running the web installer */
995 if (getenv("CITADEL_INSTALLER") != NULL) {
996 using_web_installer = 1;
999 /* parse command line args */
1000 for (a = 0; a < argc; ++a) {
1001 if (!strncmp(argv[a], "-u", 2)) {
1002 strcpy(aaa, argv[a]);
1003 strcpy(aaa, &aaa[2]);
1004 setup_type = atoi(aaa);
1006 if (!strcmp(argv[a], "-i")) {
1009 if (!strcmp(argv[a], "-q")) {
1010 setup_type = UI_SILENT;
1015 /* If a setup type was not specified, try to determine automatically
1016 * the best one to use out of all available types.
1018 if (setup_type < 0) {
1019 setup_type = discover_ui();
1021 if (info_only == 1) {
1022 important_message("Citadel Setup", CITADEL);
1026 /* Get started in a valid setup directory. */
1027 strcpy(setup_directory,
1034 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
1035 strcpy(setup_directory, getenv("CITADEL"));
1038 set_str_val(0, setup_directory);
1041 home=(setup_directory[1]!='\0');
1042 relh=home&(setup_directory[1]!='/');
1044 safestrncpy(ctdl_home_directory, setup_directory, sizeof ctdl_home_directory);
1047 safestrncpy(relhome, ctdl_home_directory, sizeof relhome);
1050 calc_dirs_n_files(relh, home, relhome, ctdldir);
1052 enable_home=(relh|home);
1055 if (chdir(setup_directory) == 0) {
1056 strcpy(file_citadel_config, "./citadel.config");
1059 important_message("Citadel Setup",
1060 "The directory you specified does not exist.");
1065 /* Determine our host name, in case we need to use it as a default */
1068 /* Try to stop Citadel if we can */
1069 if (!access("/etc/init.d/citadel", X_OK)) {
1070 for (a=0; a<=2; ++a) {
1071 progress("Stopping the Citadel service...", a, 2);
1072 if (a == 0) system("/etc/init.d/citadel stop >/dev/null 2>&1");
1077 /* Make sure Citadel is not running. */
1078 if (test_server() == 0) {
1079 important_message("Citadel Setup",
1080 "The Citadel service is still running.\n"
1081 "Please stop the service manually and run "
1087 switch (setup_type) {
1091 " *** Citadel setup program ***\n\n");
1097 * What we're going to try to do here is append a whole bunch of
1098 * nulls to the citadel.config file, so we can keep the old config
1099 * values if they exist, but if the file is missing or from an
1100 * earlier version with a shorter config structure, when setup tries
1101 * to read the old config parameters, they'll all come up zero.
1102 * The length of the config file will be set to what it's supposed
1103 * to be when we rewrite it, because we replace the old file with a
1104 * completely new copy.
1106 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1107 S_IRUSR | S_IWUSR)) == -1) {
1108 display_error("setup: cannot append citadel.config");
1111 fp = fdopen(a, "ab");
1113 display_error("setup: cannot append citadel.config");
1116 for (a = 0; a < sizeof(struct config); ++a)
1120 /* now we re-open it, and read the old or blank configuration */
1121 fp = fopen(file_citadel_config, "rb");
1123 display_error("setup: cannot open citadel.config");
1126 fread((char *) &config, sizeof(struct config), 1, fp);
1129 /* set some sample/default values in place of blanks... */
1130 if (strlen(config.c_nodename) == 0)
1131 safestrncpy(config.c_nodename, my_utsname.nodename,
1132 sizeof config.c_nodename);
1133 strtok(config.c_nodename, ".");
1134 if (strlen(config.c_fqdn) == 0) {
1135 if ((he = gethostbyname(my_utsname.nodename)) != NULL)
1136 safestrncpy(config.c_fqdn, he->h_name,
1137 sizeof config.c_fqdn);
1139 safestrncpy(config.c_fqdn, my_utsname.nodename,
1140 sizeof config.c_fqdn);
1142 if (strlen(config.c_humannode) == 0)
1143 strcpy(config.c_humannode, "My System");
1144 if (strlen(config.c_phonenum) == 0)
1145 strcpy(config.c_phonenum, "US 800 555 1212");
1146 if (config.c_initax == 0) {
1147 config.c_initax = 4;
1149 if (strlen(config.c_moreprompt) == 0)
1150 strcpy(config.c_moreprompt, "<more>");
1151 if (strlen(config.c_twitroom) == 0)
1152 strcpy(config.c_twitroom, "Trashcan");
1153 if (strlen(config.c_baseroom) == 0)
1154 strcpy(config.c_baseroom, BASEROOM);
1155 if (strlen(config.c_aideroom) == 0)
1156 strcpy(config.c_aideroom, "Aide");
1157 if (config.c_port_number == 0) {
1158 config.c_port_number = 504;
1160 if (config.c_sleeping == 0) {
1161 config.c_sleeping = 900;
1163 if (config.c_ctdluid == 0) {
1164 pw = getpwnam("citadel");
1166 config.c_ctdluid = pw->pw_uid;
1168 if (config.c_ctdluid == 0) {
1169 pw = getpwnam("bbs");
1171 config.c_ctdluid = pw->pw_uid;
1173 if (config.c_ctdluid == 0) {
1174 pw = getpwnam("guest");
1176 config.c_ctdluid = pw->pw_uid;
1178 if (config.c_createax == 0) {
1179 config.c_createax = 3;
1182 * Negative values for maxsessions are not allowed.
1184 if (config.c_maxsessions < 0) {
1185 config.c_maxsessions = 0;
1187 /* We need a system default message expiry policy, because this is
1188 * the top level and there's no 'higher' policy to fall back on.
1189 * By default, do not expire messages at all.
1191 if (config.c_ep.expire_mode == 0) {
1192 config.c_ep.expire_mode = EXPIRE_MANUAL;
1193 config.c_ep.expire_value = 0;
1197 * Default port numbers for various services
1199 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1200 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1201 if (config.c_imap_port == 0) config.c_imap_port = 143;
1202 if (config.c_msa_port == 0) config.c_msa_port = 587;
1203 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1204 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1205 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1206 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1207 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1209 /* Go through a series of dialogs prompting for config info */
1210 if (setup_type != UI_SILENT) {
1211 for (curr = 1; curr <= MAXSETUP; ++curr) {
1216 /***** begin version update section ***** */
1217 /* take care of any updating that is necessary */
1219 old_setup_level = config.c_setup_level;
1221 if (old_setup_level == 0) {
1225 if (old_setup_level < 555) {
1226 important_message("Citadel Setup",
1227 "This Citadel installation is too old "
1231 write_config_to_disk();
1233 old_setup_level = config.c_setup_level;
1235 /* end of version update section */
1238 config.c_setup_level = REV_LEVEL;
1240 /******************************************/
1242 write_config_to_disk();
1244 mkdir(ctdl_info_dir, 0700);
1245 chmod(ctdl_info_dir, 0700);
1246 chown(ctdl_info_dir, config.c_ctdluid, -1);
1248 mkdir(ctdl_bio_dir, 0700);
1249 chmod(ctdl_bio_dir, 0700);
1250 chown(ctdl_bio_dir, config.c_ctdluid, -1);
1252 mkdir(ctdl_usrpic_dir, 0700);
1253 chmod(ctdl_usrpic_dir, 0700);
1254 chown(ctdl_usrpic_dir, config.c_ctdluid, -1);
1256 mkdir(ctdl_message_dir, 0700);
1257 chmod(ctdl_message_dir, 0700);
1258 chown(ctdl_message_dir, config.c_ctdluid, -1);
1260 mkdir(ctdl_hlp_dir, 0700);
1261 chmod(ctdl_hlp_dir, 0700);
1262 chown(ctdl_hlp_dir, config.c_ctdluid, -1);
1264 mkdir(ctdl_image_dir, 0700);
1265 chmod(ctdl_image_dir, 0700);
1266 chown(ctdl_image_dir, config.c_ctdluid, -1);
1268 mkdir(ctdl_bb_dir, 0700);
1269 chmod(ctdl_bb_dir, 0700);
1270 chown(ctdl_bb_dir, config.c_ctdluid, -1);
1272 mkdir(ctdl_file_dir, 0700);
1273 chmod(ctdl_file_dir, 0700);
1274 chown(ctdl_file_dir, config.c_ctdluid, -1);
1276 mkdir(ctdl_netcfg_dir, 0700);
1277 chmod(ctdl_netcfg_dir, 0700);
1278 chown(ctdl_netcfg_dir, config.c_ctdluid, -1);
1280 /* TODO: where to put this? */
1281 mkdir("netconfigs", 0700);
1282 chmod("netconfigs", 0700);
1283 chown("netconfigs", config.c_ctdluid, -1);
1285 /* Delete files and directories used by older Citadel versions */
1286 system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1287 unlink("citadel.log");
1290 check_services_entry(); /* Check /etc/services */
1292 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1293 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1295 /* Offer to disable other MTA's on the system. */
1296 disable_other_mta("courier-authdaemon");
1297 disable_other_mta("courier-imap");
1298 disable_other_mta("courier-imap-ssl");
1299 disable_other_mta("courier-pop");
1300 disable_other_mta("courier-pop3");
1301 disable_other_mta("courier-pop3d");
1302 disable_other_mta("cyrmaster");
1303 disable_other_mta("cyrus");
1304 disable_other_mta("dovecot");
1305 disable_other_mta("exim");
1306 disable_other_mta("exim4");
1307 disable_other_mta("hula");
1308 disable_other_mta("imapd");
1309 disable_other_mta("mta");
1310 disable_other_mta("pop3d");
1311 disable_other_mta("popd");
1312 disable_other_mta("postfix");
1313 disable_other_mta("qmail");
1314 disable_other_mta("saslauthd");
1315 disable_other_mta("sendmail");
1316 disable_other_mta("vmailmgrd");
1317 disable_other_mta("zimbra");
1320 /* Check for the 'db' nss and offer to disable it */
1323 if ((pw = getpwuid(config.c_ctdluid)) == NULL)
1328 progress("Setting file permissions", 0, 4);
1329 chown(".", config.c_ctdluid, gid);
1331 progress("Setting file permissions", 1, 4);
1332 chown(file_citadel_config, config.c_ctdluid, gid);
1334 progress("Setting file permissions", 2, 4);
1336 snprintf(aaa, sizeof aaa,
1339 chown(aaa,0,0); /* config.c_ctdluid, gid); chkpwd needs to be root owned*/
1341 progress("Setting file permissions", 3, 4);
1345 progress("Setting file permissions", 3, 4);
1346 chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1348 progress("Setting file permissions", 4, 4);
1351 * If we're running on SysV, install init scripts.
1353 if (!access("/var/run", W_OK)) {
1355 if (getenv("NO_INIT_SCRIPTS") == NULL) {
1356 install_init_scripts();
1359 if (!access("/etc/init.d/citadel", X_OK)) {
1360 for (a=0; a<=2; ++a) {
1361 progress("Starting the Citadel service...", a, 2);
1362 if (a == 0) system("/etc/init.d/citadel start >/dev/null 2>&1");
1367 if (test_server() == 0) {
1368 important_message("Setup finished",
1369 "Setup of the Citadel server is complete.\n"
1370 "If you will be using WebCit, please run its\n"
1371 "setup program now; otherwise, run './citadel'\n"
1375 important_message("Setup failed",
1376 "Setup is finished, but the Citadel server failed to start.\n"
1377 "Go back and check your configuration.\n"
1384 important_message("Setup finished",
1385 "Setup is finished. You may now start the server.");