4 * Citadel setup utility
14 #include <sys/types.h>
16 #include <sys/utsname.h>
30 #include "citadel_dirs.h"
37 #define MAXSETUP 5 /* 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",
66 /* calculate all our path on a central place */
67 /* where to keep our config */
70 char *setup_text[] = {
72 "Enter the full pathname of the directory in which the Citadel\n"
73 "installation you are creating or updating resides. If you\n"
74 "specify a directory other than the default, you will need to\n"
75 "specify the -h flag to the server when you start it up.\n",
77 "Enter the subdirectory name for an alternate installation of "
78 "Citadel. To do a default installation just leave it blank."
79 "If you specify a directory other than the default, you will need to\n"
80 "specify the -h flag to the server when you start it up.\n"
81 "note that it may not have a leading /",
84 "Enter the name of the system administrator (which is probably\n"
85 "you). When an account is created with this name, it will\n"
86 "automatically be given administrator-level access.\n",
88 "Citadel needs to run under its own user ID. This would\n"
89 "typically be called \"citadel\", but if you are running Citadel\n"
90 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
91 "The server will run under this user ID. Please specify that\n"
92 "user ID here. You may specify either a user name or a numeric\n"
95 "Specify the IP address on which your server will run. If you\n"
96 "leave this blank, or if you specify 0.0.0.0, Citadel will listen\n"
97 "on all addresses. You can usually skip this unless you are\n"
98 "running multiple instances of Citadel on the same computer.\n",
100 "Specify the TCP port number on which your server will run.\n"
101 "Normally, this will be port 504, which is the official port\n"
102 "assigned by the IANA for Citadel servers. You will only need\n"
103 "to specify a different port number if you run multiple instances\n"
104 "of Citadel on the same computer and there is something else\n"
105 "already using port 504.\n",
107 "Normally, a Citadel system uses a 'black box' authentication mode.\n"
108 "This means that users do not have accounts or home directories on\n"
109 "the underlying host system -- Citadel manages its own user database.\n"
110 "However, if you wish to override this behavior, you can enable the\n"
111 "host based authentication mode which is traditional for Unix systems.\n"
112 "Do you want to do this? Enter 0 for black box authentication mode,\n"
113 "or 1 for host authentication mode. FIXME this is badly worded,\n"
114 "rewrite it and offer a better dialog mode.\n"
118 struct config config;
122 void cleanup(int exitcode)
134 void title(char *text)
136 if (setup_type == UI_TEXT) {
137 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
143 int yesno(char *question)
146 newtComponent form = NULL;
147 newtComponent yesbutton = NULL;
148 newtComponent nobutton = NULL;
149 int prompt_window_height = 0;
155 switch (setup_type) {
159 printf("%s\nYes/No --> ", question);
160 fgets(buf, sizeof buf, stdin);
161 answer = tolower(buf[0]);
164 else if (answer == 'n')
166 } while ((answer < 0) || (answer > 1));
170 sprintf(buf, "exec %s --yesno '%s' 10 72",
171 getenv("CTDL_DIALOG"),
184 prompt_window_height = num_tokens(question, '\n') + 5;
185 newtCenteredWindow(76, prompt_window_height, "Question");
186 form = newtForm(NULL, NULL, 0);
187 for (i=0; i<num_tokens(question, '\n'); ++i) {
188 extract_token(buf, question, i, '\n', sizeof buf);
189 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
191 yesbutton = newtButton(10, (prompt_window_height - 4), "Yes");
192 nobutton = newtButton(60, (prompt_window_height - 4), "No");
193 newtFormAddComponent(form, yesbutton);
194 newtFormAddComponent(form, nobutton);
195 if (newtRunForm(form) == yesbutton) {
202 newtFormDestroy(form);
212 void important_message(char *title, char *msgtext)
215 newtComponent form = NULL;
220 switch (setup_type) {
223 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");
224 printf(" %s \n\n%s\n\n", title, msgtext);
225 printf("Press return to continue...");
226 fgets(buf, sizeof buf, stdin);
230 sprintf(buf, "exec %s --msgbox '%s' 19 72",
231 getenv("CTDL_DIALOG"),
238 newtCenteredWindow(76, 10, title);
239 form = newtForm(NULL, NULL, 0);
240 for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
241 extract_token(buf, msgtext, i, '\n', sizeof buf);
242 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
244 newtFormAddComponent(form, newtButton(35, 5, "OK"));
247 newtFormDestroy(form);
254 void important_msgnum(int msgnum)
256 important_message("Important Message", setup_text[msgnum]);
259 void display_error(char *error_message)
261 important_message("Error", error_message);
264 void progress(char *text, long int curr, long int cmax)
268 /* These variables are static because progress() gets called
269 * multiple times during the course of whatever operation is
270 * being performed. This makes setup non-threadsafe, but who
273 static newtComponent form = NULL;
274 static newtComponent scale = NULL;
276 static long dots_printed = 0L;
278 static FILE *fp = NULL;
281 switch (setup_type) {
285 printf("%s\n", text);
286 printf("..........................");
287 printf("..........................");
288 printf("..........................\r");
291 } else if (curr == cmax) {
292 printf("\r%79s\n", "");
294 a = (curr * 100) / cmax;
297 while (dots_printed < a) {
307 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
308 getenv("CTDL_DIALOG"),
310 fp = popen(buf, "w");
316 else if (curr == cmax) {
318 fprintf(fp, "100\n");
324 a = (curr * 100) / cmax;
326 fprintf(fp, "%ld\n", a);
335 newtCenteredWindow(76, 8, text);
336 form = newtForm(NULL, NULL, 0);
337 scale = newtScale(1, 3, 74, cmax);
338 newtFormAddComponent(form, scale);
342 if ((curr > 0) && (curr <= cmax)) {
343 newtScaleSet(scale, curr);
347 newtFormDestroy(form);
360 * check_services_entry() -- Make sure "citadel" is in /etc/services
363 void check_services_entry(void)
369 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
370 for (i=0; i<=2; ++i) {
371 progress("Adding service entry...", i, 2);
373 sfp = fopen("/etc/services", "a");
375 sprintf(errmsg, "Cannot open /etc/services: %s", strerror(errno));
376 display_error(errmsg);
378 fprintf(sfp, "%s 504/tcp\n", SERVICE_NAME);
391 * delete_inittab_entry() -- Remove obsolete /etc/inittab entry for Citadel
394 void delete_inittab_entry(void)
398 char looking_for[256];
400 char outfilename[32];
401 int changes_made = 0;
403 /* Determine the fully qualified path name of citserver */
404 snprintf(looking_for,
414 /* Now tweak /etc/inittab */
415 infp = fopen("/etc/inittab", "r");
418 /* If /etc/inittab does not exist, return quietly.
419 * Not all host platforms have it.
421 if (errno == ENOENT) {
425 /* Other errors might mean something really did go wrong.
427 sprintf(buf, "Cannot open /etc/inittab: %s", strerror(errno));
432 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
433 outfp = fdopen(mkstemp(outfilename), "w+");
435 sprintf(buf, "Cannot open %s: %s", outfilename, strerror(errno));
441 while (fgets(buf, sizeof buf, infp) != NULL) {
442 if (strstr(buf, looking_for) != NULL) {
443 fwrite("#", 1, 1, outfp);
446 fwrite(buf, strlen(buf), 1, outfp);
453 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
455 system("/sbin/init q 2>/dev/null");
464 * install_init_scripts() -- Try to configure to start Citadel at boot
467 void install_init_scripts(void)
471 if (yesno("Would you like to automatically start Citadel at boot?\n") == 0) {
475 fp = fopen("/etc/init.d/citadel", "w");
477 display_error("Cannot create /etc/init.d/citadel");
481 fprintf(fp, "#!/bin/sh\n"
483 "CITADEL_DIR=%s\n", setup_directory);
485 "test -x $CITADEL_DIR/ctdlsvc || exit 0\n"
486 "test -d /var/run || exit 0\n"
490 "start) echo -n \"Starting Citadel... \"\n"
491 " if $CITADEL_DIR/ctdlsvc /var/run/citadel.pid "
492 "$CITADEL_DIR/citserver "
500 "stop) echo -n \"Stopping Citadel... \"\n"
501 " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
506 " rm -f /var/run/citadel.pid 2>/dev/null\n");
511 "*) echo \"Usage: $0 {start|stop|restart}\"\n"
518 chmod("/etc/init.d/citadel", 0755);
520 /* Set up the run levels. */
521 system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
522 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");
523 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");
533 * On systems which use xinetd, see if we can offer to install Citadel as
534 * the default telnet target.
536 void check_xinetd_entry(void) {
537 char *filename = "/etc/xinetd.d/telnet";
540 int already_citadel = 0;
542 fp = fopen(filename, "r+");
543 if (fp == NULL) return; /* Not there. Oh well... */
545 while (fgets(buf, sizeof buf, fp) != NULL) {
546 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
549 if (already_citadel) return; /* Already set up this way. */
551 /* Otherwise, prompt the user to create an entry. */
552 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
553 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
558 snprintf(buf, sizeof buf,
559 "Setup can configure the \"xinetd\" service to automatically\n"
560 "connect incoming telnet sessions to Citadel, bypassing the\n"
561 "host system login: prompt. Would you like to do this?\n"
563 if (yesno(buf) == 0) {
568 fp = fopen(filename, "w");
570 "# description: telnet service for Citadel users\n"
575 " socket_type = stream\n"
578 " server = /usr/sbin/in.telnetd\n"
579 " server_args = -h -L %s/citadel\n"
580 " log_on_failure += USERID\n"
590 /* Now try to restart the service */
591 system("/etc/init.d/xinetd restart >/dev/null 2>&1");
597 * Offer to disable other MTA's
599 void disable_other_mta(char *mta) {
604 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
605 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
607 fp = popen(buf, "r");
608 if (fp == NULL) return;
610 while (fgets(buf, sizeof buf, fp) != NULL) {
614 if (lines == 0) return; /* Nothing to do. */
617 /* Offer to replace other MTA with the vastly superior Citadel :) */
619 if (getenv("ACT_AS_MTA")) {
620 if (strcasecmp(getenv("ACT_AS_MTA"), "yes")) {
625 snprintf(buf, sizeof buf,
626 "You appear to have the \"%s\" email program\n"
627 "running on your system. If you want Citadel mail\n"
628 "connected with %s, you will have to manually integrate\n"
629 "them. It is preferable to disable %s, and use Citadel's\n"
630 "SMTP, POP3, and IMAP services.\n\n"
631 "May we disable %s so that Citadel has access to ports\n"
632 "25, 110, and 143?\n",
635 if (yesno(buf) == 0) {
640 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);
642 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
650 * Check to see if our server really works. Returns 0 on success.
652 int test_server(void) {
659 /* Generate a silly little cookie. We're going to write it out
660 * to the server and try to get it back. The cookie does not
661 * have to be secret ... just unique.
663 sprintf(cookie, "--test--%d--", getpid());
665 sprintf(cmd, "%s/sendcommand %s%s ECHO %s 2>&1",
671 (enable_home)?"-h":"",
672 (enable_home)?setup_directory:"",
675 fp = popen(cmd, "r");
676 if (fp == NULL) return(errno);
678 while (fgets(buf, sizeof buf, fp) != NULL) {
680 && (strstr(buf, cookie) != NULL) ) {
692 void strprompt(char *prompt_title, char *prompt_text, char *str)
698 int prompt_window_height = 0;
702 char dialog_result[PATH_MAX];
705 strcpy(setupmsg, "");
707 switch (setup_type) {
710 printf("\n%s\n", prompt_text);
711 printf("This is currently set to:\n%s\n", str);
712 printf("Enter new value or press return to leave unchanged:\n");
713 fgets(buf, sizeof buf, stdin);
714 buf[strlen(buf) - 1] = 0;
715 if (strlen(buf) != 0)
720 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
721 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
722 getenv("CTDL_DIALOG"),
727 fp = fopen(dialog_result, "r");
729 fgets(str, sizeof buf, fp);
730 if (str[strlen(str)-1] == 10) {
731 str[strlen(str)-1] = 0;
734 unlink(dialog_result);
741 prompt_window_height = num_tokens(prompt_text, '\n') + 5 ;
742 newtCenteredWindow(76,
743 prompt_window_height,
745 form = newtForm(NULL, NULL, 0);
746 for (i=0; i<num_tokens(prompt_text, '\n'); ++i) {
747 extract_token(buf, prompt_text, i, '\n', sizeof buf);
748 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
750 newtFormAddComponent(form,
752 (prompt_window_height - 2),
755 (const char **) &result,
756 NEWT_FLAG_RETURNEXIT)
762 newtFormDestroy(form);
768 void set_str_val(int msgpos, char *str) {
769 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
774 void set_int_val(int msgpos, int *ip)
777 snprintf(buf, sizeof buf, "%d", (int) *ip);
778 set_str_val(msgpos, buf);
783 void set_char_val(int msgpos, char *ip)
786 snprintf(buf, sizeof buf, "%d", (int) *ip);
787 set_str_val(msgpos, buf);
788 *ip = (char) atoi(buf);
792 void set_long_val(int msgpos, long int *ip)
795 snprintf(buf, sizeof buf, "%ld", *ip);
796 set_str_val(msgpos, buf);
801 void edit_value(int curr)
805 char ctdluidname[SIZ];
810 if (getenv("SYSADMIN_NAME")) {
811 strcpy(config.c_sysadm, getenv("SYSADMIN_NAME"));
814 set_str_val(curr, config.c_sysadm);
820 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
822 i = config.c_ctdluid;
825 set_int_val(curr, &i);
826 config.c_ctdluid = i;
829 strcpy(ctdluidname, pw->pw_name);
830 set_str_val(curr, ctdluidname);
831 pw = getpwnam(ctdluidname);
833 config.c_ctdluid = pw->pw_uid;
835 else if (atoi(ctdluidname) > 0) {
836 config.c_ctdluid = atoi(ctdluidname);
843 set_str_val(curr, config.c_ip_addr);
847 set_int_val(curr, &config.c_port_number);
850 /* FIXME we need a set_bool_val() function */
852 set_int_val(curr, &config.c_auth_mode);
859 * (re-)write the config data to disk
861 void write_config_to_disk(void)
866 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
867 display_error("setup: cannot open citadel.config");
870 fp = fdopen(fd, "wb");
872 display_error("setup: cannot open citadel.config");
875 fwrite((char *) &config, sizeof(struct config), 1, fp);
883 * Figure out what type of user interface we're going to use
885 int discover_ui(void)
888 /* Use "dialog" if we have it */
889 if (getenv("CTDL_DIALOG") != NULL) {
897 newtDrawRootText(0, 0, "Citadel Setup");
908 * Strip "db" entries out of /etc/nsswitch.conf
918 int file_changed = 0;
919 char new_filename[64];
921 fp_read = fopen(NSSCONF, "r");
922 if (fp_read == NULL) {
926 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
927 fd_write = mkstemp(new_filename);
933 while (fgets(buf, sizeof buf, fp_read) != NULL) {
936 for (i=0; i<strlen(buf_nc); ++i) {
937 if (buf_nc[i] == '#') {
941 for (i=0; i<strlen(buf_nc); ++i) {
942 if (!strncasecmp(&buf_nc[i], "db", 2)) {
944 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
947 strcpy(&buf_nc[i], &buf_nc[i+2]);
948 strcpy(&buf[i], &buf[i+2]);
950 strcpy(&buf_nc[i], &buf_nc[i+1]);
951 strcpy(&buf[i], &buf[i+1]);
957 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
960 unlink(new_filename);
968 unlink(new_filename);
972 snprintf(question, sizeof question,
974 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
975 "one or more services. This is not necessary on most systems,\n"
976 "and it is known to crash the Citadel server when delivering\n"
977 "mail to the Internet.\n"
979 "Do you want this module to be automatically disabled?\n"
983 if (yesno(question)) {
984 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
987 unlink(new_filename);
997 int main(int argc, char *argv[])
1003 int old_setup_level = 0;
1005 struct utsname my_utsname;
1011 char relhome[PATH_MAX]="";
1012 char ctdldir[PATH_MAX]=CTDLDIR;
1014 /* set an invalid setup type */
1017 /* Check to see if we're running the web installer */
1018 if (getenv("CITADEL_INSTALLER") != NULL) {
1019 using_web_installer = 1;
1022 /* parse command line args */
1023 for (a = 0; a < argc; ++a) {
1024 if (!strncmp(argv[a], "-u", 2)) {
1025 strcpy(aaa, argv[a]);
1026 strcpy(aaa, &aaa[2]);
1027 setup_type = atoi(aaa);
1029 if (!strcmp(argv[a], "-i")) {
1032 if (!strcmp(argv[a], "-q")) {
1033 setup_type = UI_SILENT;
1038 /* If a setup type was not specified, try to determine automatically
1039 * the best one to use out of all available types.
1041 if (setup_type < 0) {
1042 setup_type = discover_ui();
1044 if (info_only == 1) {
1045 important_message("Citadel Setup", CITADEL);
1049 /* Get started in a valid setup directory. */
1050 strcpy(setup_directory,
1057 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
1058 strcpy(setup_directory, getenv("CITADEL"));
1061 set_str_val(0, setup_directory);
1064 home=(setup_directory[1]!='\0');
1065 relh=home&(setup_directory[1]!='/');
1067 safestrncpy(ctdl_home_directory, setup_directory, sizeof ctdl_home_directory);
1070 safestrncpy(relhome, ctdl_home_directory, sizeof relhome);
1073 calc_dirs_n_files(relh, home, relhome, ctdldir);
1075 enable_home=(relh|home);
1078 if (chdir(setup_directory) == 0) {
1079 strcpy(file_citadel_config, "./citadel.config");
1082 important_message("Citadel Setup",
1083 "The directory you specified does not exist.");
1088 /* Determine our host name, in case we need to use it as a default */
1091 /* Try to stop Citadel if we can */
1092 if (!access("/etc/init.d/citadel", X_OK)) {
1093 system("/etc/init.d/citadel stop");
1096 /* Make sure Citadel is not running. */
1097 if (test_server() == 0) {
1098 important_message("Citadel Setup",
1099 "The Citadel service is still running.\n"
1100 "Please stop the service manually and run "
1106 switch (setup_type) {
1110 " *** Citadel setup program ***\n\n");
1116 * What we're going to try to do here is append a whole bunch of
1117 * nulls to the citadel.config file, so we can keep the old config
1118 * values if they exist, but if the file is missing or from an
1119 * earlier version with a shorter config structure, when setup tries
1120 * to read the old config parameters, they'll all come up zero.
1121 * The length of the config file will be set to what it's supposed
1122 * to be when we rewrite it, because we replace the old file with a
1123 * completely new copy.
1125 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1126 S_IRUSR | S_IWUSR)) == -1) {
1127 display_error("setup: cannot append citadel.config");
1130 fp = fdopen(a, "ab");
1132 display_error("setup: cannot append citadel.config");
1135 for (a = 0; a < sizeof(struct config); ++a)
1139 /* now we re-open it, and read the old or blank configuration */
1140 fp = fopen(file_citadel_config, "rb");
1142 display_error("setup: cannot open citadel.config");
1145 fread((char *) &config, sizeof(struct config), 1, fp);
1148 /* set some sample/default values in place of blanks... */
1149 if (strlen(config.c_nodename) == 0)
1150 safestrncpy(config.c_nodename, my_utsname.nodename,
1151 sizeof config.c_nodename);
1152 strtok(config.c_nodename, ".");
1153 if (strlen(config.c_fqdn) == 0) {
1154 if ((he = gethostbyname(my_utsname.nodename)) != NULL)
1155 safestrncpy(config.c_fqdn, he->h_name,
1156 sizeof config.c_fqdn);
1158 safestrncpy(config.c_fqdn, my_utsname.nodename,
1159 sizeof config.c_fqdn);
1161 if (strlen(config.c_humannode) == 0)
1162 strcpy(config.c_humannode, "My System");
1163 if (strlen(config.c_phonenum) == 0)
1164 strcpy(config.c_phonenum, "US 800 555 1212");
1165 if (config.c_initax == 0) {
1166 config.c_initax = 4;
1168 if (strlen(config.c_moreprompt) == 0)
1169 strcpy(config.c_moreprompt, "<more>");
1170 if (strlen(config.c_twitroom) == 0)
1171 strcpy(config.c_twitroom, "Trashcan");
1172 if (strlen(config.c_baseroom) == 0)
1173 strcpy(config.c_baseroom, BASEROOM);
1174 if (strlen(config.c_aideroom) == 0)
1175 strcpy(config.c_aideroom, "Aide");
1176 if (config.c_port_number == 0) {
1177 config.c_port_number = 504;
1179 if (config.c_sleeping == 0) {
1180 config.c_sleeping = 900;
1182 if (config.c_ctdluid == 0) {
1183 pw = getpwnam("citadel");
1185 config.c_ctdluid = pw->pw_uid;
1187 if (config.c_ctdluid == 0) {
1188 pw = getpwnam("bbs");
1190 config.c_ctdluid = pw->pw_uid;
1192 if (config.c_ctdluid == 0) {
1193 pw = getpwnam("guest");
1195 config.c_ctdluid = pw->pw_uid;
1197 if (config.c_createax == 0) {
1198 config.c_createax = 3;
1201 * Negative values for maxsessions are not allowed.
1203 if (config.c_maxsessions < 0) {
1204 config.c_maxsessions = 0;
1206 /* We need a system default message expiry policy, because this is
1207 * the top level and there's no 'higher' policy to fall back on.
1208 * By default, do not expire messages at all.
1210 if (config.c_ep.expire_mode == 0) {
1211 config.c_ep.expire_mode = EXPIRE_MANUAL;
1212 config.c_ep.expire_value = 0;
1216 * Default port numbers for various services
1218 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1219 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1220 if (config.c_imap_port == 0) config.c_imap_port = 143;
1221 if (config.c_msa_port == 0) config.c_msa_port = 587;
1222 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1223 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1224 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1225 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1226 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1228 /* Go through a series of dialogs prompting for config info */
1229 if (setup_type != UI_SILENT) {
1230 for (curr = 1; curr <= MAXSETUP; ++curr) {
1235 /***** begin version update section ***** */
1236 /* take care of any updating that is necessary */
1238 old_setup_level = config.c_setup_level;
1240 if (old_setup_level == 0) {
1244 if (old_setup_level < 555) {
1245 important_message("Citadel Setup",
1246 "This Citadel installation is too old "
1250 write_config_to_disk();
1252 old_setup_level = config.c_setup_level;
1254 /* end of version update section */
1257 config.c_setup_level = REV_LEVEL;
1259 /******************************************/
1261 write_config_to_disk();
1263 mkdir(ctdl_info_dir, 0700);
1264 chmod(ctdl_info_dir, 0700);
1265 chown(ctdl_info_dir, config.c_ctdluid, -1);
1267 mkdir(ctdl_bio_dir, 0700);
1268 chmod(ctdl_bio_dir, 0700);
1269 chown(ctdl_bio_dir, config.c_ctdluid, -1);
1271 mkdir(ctdl_usrpic_dir, 0700);
1272 chmod(ctdl_usrpic_dir, 0700);
1273 chown(ctdl_usrpic_dir, config.c_ctdluid, -1);
1275 mkdir(ctdl_message_dir, 0700);
1276 chmod(ctdl_message_dir, 0700);
1277 chown(ctdl_message_dir, config.c_ctdluid, -1);
1279 mkdir(ctdl_hlp_dir, 0700);
1280 chmod(ctdl_hlp_dir, 0700);
1281 chown(ctdl_hlp_dir, config.c_ctdluid, -1);
1283 mkdir(ctdl_image_dir, 0700);
1284 chmod(ctdl_image_dir, 0700);
1285 chown(ctdl_image_dir, config.c_ctdluid, -1);
1287 mkdir(ctdl_bb_dir, 0700);
1288 chmod(ctdl_bb_dir, 0700);
1289 chown(ctdl_bb_dir, config.c_ctdluid, -1);
1291 mkdir(ctdl_file_dir, 0700);
1292 chmod(ctdl_file_dir, 0700);
1293 chown(ctdl_file_dir, config.c_ctdluid, -1);
1295 mkdir(ctdl_netcfg_dir, 0700);
1296 chmod(ctdl_netcfg_dir, 0700);
1297 chown(ctdl_netcfg_dir, config.c_ctdluid, -1);
1299 /* TODO: where to put this? */
1300 mkdir("netconfigs", 0700);
1301 chmod("netconfigs", 0700);
1302 chown("netconfigs", config.c_ctdluid, -1);
1304 /* Delete files and directories used by older Citadel versions */
1305 system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1306 unlink("citadel.log");
1309 check_services_entry(); /* Check /etc/services */
1311 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1312 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1314 /* Offer to disable other MTA's on the system. */
1315 disable_other_mta("courier-authdaemon");
1316 disable_other_mta("courier-imap");
1317 disable_other_mta("courier-imap-ssl");
1318 disable_other_mta("courier-pop");
1319 disable_other_mta("courier-pop3");
1320 disable_other_mta("courier-pop3d");
1321 disable_other_mta("cyrmaster");
1322 disable_other_mta("cyrus");
1323 disable_other_mta("dovecot");
1324 disable_other_mta("exim");
1325 disable_other_mta("exim4");
1326 disable_other_mta("hula");
1327 disable_other_mta("imapd");
1328 disable_other_mta("mta");
1329 disable_other_mta("pop3d");
1330 disable_other_mta("popd");
1331 disable_other_mta("postfix");
1332 disable_other_mta("qmail");
1333 disable_other_mta("saslauthd");
1334 disable_other_mta("sendmail");
1335 disable_other_mta("vmailmgrd");
1336 disable_other_mta("zimbra");
1339 /* Check for the 'db' nss and offer to disable it */
1342 if ((pw = getpwuid(config.c_ctdluid)) == NULL)
1347 progress("Setting file permissions", 0, 4);
1348 chown(".", config.c_ctdluid, gid);
1350 progress("Setting file permissions", 1, 4);
1351 chown(file_citadel_config, config.c_ctdluid, gid);
1353 progress("Setting file permissions", 2, 4);
1355 snprintf(aaa, sizeof aaa,
1358 chown(aaa,0,0); /* config.c_ctdluid, gid); chkpwd needs to be root owned*/
1360 progress("Setting file permissions", 3, 4);
1364 progress("Setting file permissions", 3, 4);
1365 chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1367 progress("Setting file permissions", 4, 4);
1370 * If we're running on SysV, install init scripts.
1372 if (!access("/var/run", W_OK)) {
1374 if (getenv("NO_INIT_SCRIPTS") == NULL) {
1375 install_init_scripts();
1378 if (!access("/etc/init.d/citadel", X_OK)) {
1379 system("/etc/init.d/citadel start");
1383 if (test_server() == 0) {
1384 important_message("Setup finished",
1385 "Setup of the Citadel server is complete.\n"
1386 "If you will be using WebCit, please run its\n"
1387 "setup program now; otherwise, run './citadel'\n"
1391 important_message("Setup failed",
1392 "Setup is finished, but the Citadel server failed to start.\n"
1393 "Go back and check your configuration.\n"
1400 important_message("Setup finished",
1401 "Setup is finished. You may now start the server.");