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[SIZ];
50 char citserver_init_entry[SIZ];
51 int using_web_installer = 0;
54 char *setup_titles[] =
56 "Citadel Home Directory",
57 "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",
109 struct config config;
113 void cleanup(int exitcode)
125 void title(char *text)
127 if (setup_type == UI_TEXT) {
128 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
134 int yesno(char *question)
137 newtComponent form = NULL;
138 newtComponent yesbutton = NULL;
139 newtComponent nobutton = NULL;
140 int prompt_window_height = 0;
146 switch (setup_type) {
150 printf("%s\nYes/No --> ", question);
151 fgets(buf, sizeof buf, stdin);
152 answer = tolower(buf[0]);
155 else if (answer == 'n')
157 } while ((answer < 0) || (answer > 1));
161 sprintf(buf, "exec %s --yesno '%s' 10 72",
162 getenv("CTDL_DIALOG"),
175 prompt_window_height = num_tokens(question, '\n') + 5;
176 newtCenteredWindow(76, prompt_window_height, "Question");
177 form = newtForm(NULL, NULL, 0);
178 for (i=0; i<num_tokens(question, '\n'); ++i) {
179 extract_token(buf, question, i, '\n', sizeof buf);
180 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
182 yesbutton = newtButton(10, (prompt_window_height - 4), "Yes");
183 nobutton = newtButton(60, (prompt_window_height - 4), "No");
184 newtFormAddComponent(form, yesbutton);
185 newtFormAddComponent(form, nobutton);
186 if (newtRunForm(form) == yesbutton) {
193 newtFormDestroy(form);
203 void important_message(char *title, char *msgtext)
206 newtComponent form = NULL;
211 switch (setup_type) {
214 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");
215 printf(" %s \n\n%s\n\n", title, msgtext);
216 printf("Press return to continue...");
217 fgets(buf, sizeof buf, stdin);
221 sprintf(buf, "exec %s --msgbox '%s' 19 72",
222 getenv("CTDL_DIALOG"),
229 newtCenteredWindow(76, 10, title);
230 form = newtForm(NULL, NULL, 0);
231 for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
232 extract_token(buf, msgtext, i, '\n', sizeof buf);
233 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
235 newtFormAddComponent(form, newtButton(35, 5, "OK"));
238 newtFormDestroy(form);
245 void important_msgnum(int msgnum)
247 important_message("Important Message", setup_text[msgnum]);
250 void display_error(char *error_message)
252 important_message("Error", error_message);
255 void progress(char *text, long int curr, long int cmax)
259 /* These variables are static because progress() gets called
260 * multiple times during the course of whatever operation is
261 * being performed. This makes setup non-threadsafe, but who
264 static newtComponent form = NULL;
265 static newtComponent scale = NULL;
267 static long dots_printed = 0L;
269 static FILE *fp = NULL;
272 switch (setup_type) {
276 printf("%s\n", text);
277 printf("..........................");
278 printf("..........................");
279 printf("..........................\r");
282 } else if (curr == cmax) {
283 printf("\r%79s\n", "");
285 a = (curr * 100) / cmax;
288 while (dots_printed < a) {
298 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
299 getenv("CTDL_DIALOG"),
301 fp = popen(buf, "w");
307 else if (curr == cmax) {
309 fprintf(fp, "100\n");
315 a = (curr * 100) / cmax;
317 fprintf(fp, "%ld\n", a);
326 newtCenteredWindow(76, 8, text);
327 form = newtForm(NULL, NULL, 0);
328 scale = newtScale(1, 3, 74, cmax);
329 newtFormAddComponent(form, scale);
333 if ((curr > 0) && (curr <= cmax)) {
334 newtScaleSet(scale, curr);
338 newtFormDestroy(form);
351 * check_services_entry() -- Make sure "citadel" is in /etc/services
354 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 display_error(strerror(errno));
367 fprintf(sfp, "%s 504/tcp\n",
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 display_error(strerror(errno));
411 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
412 outfp = fdopen(mkstemp(outfilename), "w+");
414 display_error(strerror(errno));
419 while (fgets(buf, sizeof buf, infp) != NULL) {
420 if (strstr(buf, looking_for) == NULL) {
421 fwrite(buf, strlen(buf), 1, outfp);
432 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
434 system("/sbin/init q 2>/dev/null");
443 * install_init_scripts() -- Try to configure to start Citadel at boot
446 void install_init_scripts(void)
450 if (yesno("Would you like to automatically start Citadel at boot?\n") == 0) {
454 fp = fopen("/etc/init.d/citadel", "w");
456 display_error("Cannot create /etc/init.d/citadel");
460 fprintf(fp, "#!/bin/sh\n"
462 "CITADEL_DIR=%s\n", setup_directory);
464 "test -x $CITADEL_DIR/ctdlsvc || exit 0\n"
465 "test -d /var/run || exit 0\n"
469 "start) echo -n \"Starting Citadel... \"\n"
470 " if $CITADEL_DIR/ctdlsvc /var/run/citadel.pid "
471 "$CITADEL_DIR/citserver "
479 "stop) echo -n \"Stopping Citadel... \"\n"
480 " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
485 " rm -f /var/run/citadel.pid 2>/dev/null\n");
487 "*) echo \"Usage: $0 {start|stop}\"\n"
494 chmod("/etc/init.d/citadel", 0755);
496 /* Set up the run levels. */
497 system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
498 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");
499 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");
509 * On systems which use xinetd, see if we can offer to install Citadel as
510 * the default telnet target.
512 void check_xinetd_entry(void) {
513 char *filename = "/etc/xinetd.d/telnet";
516 int already_citadel = 0;
518 fp = fopen(filename, "r+");
519 if (fp == NULL) return; /* Not there. Oh well... */
521 while (fgets(buf, sizeof buf, fp) != NULL) {
522 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
525 if (already_citadel) return; /* Already set up this way. */
527 /* Otherwise, prompt the user to create an entry. */
528 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
529 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
534 snprintf(buf, sizeof buf,
535 "Setup can configure the \"xinetd\" service to automatically\n"
536 "connect incoming telnet sessions to Citadel, bypassing the\n"
537 "host system login: prompt. Would you like to do this?\n"
539 if (yesno(buf) == 0) {
544 fp = fopen(filename, "w");
546 "# description: telnet service for Citadel users\n"
551 " socket_type = stream\n"
554 " server = /usr/sbin/in.telnetd\n"
555 " server_args = -h -L %s/citadel\n"
556 " log_on_failure += USERID\n"
566 /* Now try to restart the service */
567 system("/etc/init.d/xinetd restart >/dev/null 2>&1");
573 * Offer to disable other MTA's
575 void disable_other_mta(char *mta) {
580 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
581 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
583 fp = popen(buf, "r");
584 if (fp == NULL) return;
586 while (fgets(buf, sizeof buf, fp) != NULL) {
590 if (lines == 0) return; /* Nothing to do. */
593 /* Offer to replace other MTA with the vastly superior Citadel :) */
595 if (getenv("ACT_AS_MTA")) {
596 if (strcasecmp(getenv("ACT_AS_MTA"), "yes")) {
601 snprintf(buf, sizeof buf,
602 "You appear to have the \"%s\" email program\n"
603 "running on your system. If you want Citadel mail\n"
604 "connected with %s, you will have to manually integrate\n"
605 "them. It is preferable to disable %s, and use Citadel's\n"
606 "SMTP, POP3, and IMAP services.\n\n"
607 "May we disable %s so that Citadel has access to ports\n"
608 "25, 110, and 143?\n",
611 if (yesno(buf) == 0) {
616 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);
618 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
626 * Check to see if our server really works. Returns 0 on success.
628 int test_server(void) {
635 /* Generate a silly little cookie. We're going to write it out
636 * to the server and try to get it back. The cookie does not
637 * have to be secret ... just unique.
639 sprintf(cookie, "--test--%d--", getpid());
641 sprintf(cmd, "%s/sendcommand %s%s ECHO %s 2>&1",
647 (enable_home)?"-h":"",
648 (enable_home)?setup_directory:"",
651 fp = popen(cmd, "r");
652 if (fp == NULL) return(errno);
654 while (fgets(buf, sizeof buf, fp) != NULL) {
656 && (strstr(buf, cookie) != NULL) ) {
668 void strprompt(char *prompt_title, char *prompt_text, char *str)
674 int prompt_window_height = 0;
678 char dialog_result[PATH_MAX];
681 strcpy(setupmsg, "");
683 switch (setup_type) {
686 printf("\n%s\n", prompt_text);
687 printf("This is currently set to:\n%s\n", str);
688 printf("Enter new value or press return to leave unchanged:\n");
689 fgets(buf, sizeof buf, stdin);
690 buf[strlen(buf) - 1] = 0;
691 if (strlen(buf) != 0)
696 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
697 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
698 getenv("CTDL_DIALOG"),
703 fp = fopen(dialog_result, "r");
705 fgets(str, sizeof buf, fp);
706 if (str[strlen(str)-1] == 10) {
707 str[strlen(str)-1] = 0;
710 unlink(dialog_result);
717 prompt_window_height = num_tokens(prompt_text, '\n') + 5 ;
718 newtCenteredWindow(76,
719 prompt_window_height,
721 form = newtForm(NULL, NULL, 0);
722 for (i=0; i<num_tokens(prompt_text, '\n'); ++i) {
723 extract_token(buf, prompt_text, i, '\n', sizeof buf);
724 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
726 newtFormAddComponent(form,
728 (prompt_window_height - 2),
731 (const char **) &result,
732 NEWT_FLAG_RETURNEXIT)
738 newtFormDestroy(form);
744 void set_str_val(int msgpos, char *str) {
745 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
750 void set_int_val(int msgpos, int *ip)
753 snprintf(buf, sizeof buf, "%d", (int) *ip);
754 set_str_val(msgpos, buf);
759 void set_char_val(int msgpos, char *ip)
762 snprintf(buf, sizeof buf, "%d", (int) *ip);
763 set_str_val(msgpos, buf);
764 *ip = (char) atoi(buf);
768 void set_long_val(int msgpos, long int *ip)
771 snprintf(buf, sizeof buf, "%ld", *ip);
772 set_str_val(msgpos, buf);
777 void edit_value(int curr)
781 char ctdluidname[SIZ];
786 if (getenv("SYSADMIN_NAME")) {
787 strcpy(config.c_sysadm, getenv("SYSADMIN_NAME"));
790 set_str_val(curr, config.c_sysadm);
796 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
798 i = config.c_ctdluid;
801 set_int_val(curr, &i);
802 config.c_ctdluid = i;
805 strcpy(ctdluidname, pw->pw_name);
806 set_str_val(curr, ctdluidname);
807 pw = getpwnam(ctdluidname);
809 config.c_ctdluid = pw->pw_uid;
811 else if (atoi(ctdluidname) > 0) {
812 config.c_ctdluid = atoi(ctdluidname);
819 set_str_val(curr, config.c_ip_addr);
823 set_int_val(curr, &config.c_port_number);
831 * (re-)write the config data to disk
833 void write_config_to_disk(void)
838 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
839 display_error("setup: cannot open citadel.config");
842 fp = fdopen(fd, "wb");
844 display_error("setup: cannot open citadel.config");
847 fwrite((char *) &config, sizeof(struct config), 1, fp);
855 * Figure out what type of user interface we're going to use
857 int discover_ui(void)
860 /* Use "dialog" if we have it */
861 if (getenv("CTDL_DIALOG") != NULL) {
869 newtDrawRootText(0, 0, "Citadel Setup");
880 * Strip "db" entries out of /etc/nsswitch.conf
890 int file_changed = 0;
891 char new_filename[64];
893 fp_read = fopen(NSSCONF, "r");
894 if (fp_read == NULL) {
898 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
899 fd_write = mkstemp(new_filename);
905 while (fgets(buf, sizeof buf, fp_read) != NULL) {
908 for (i=0; i<strlen(buf_nc); ++i) {
909 if (buf_nc[i] == '#') {
913 for (i=0; i<strlen(buf_nc); ++i) {
914 if (!strncasecmp(&buf_nc[i], "db", 2)) {
916 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
919 strcpy(&buf_nc[i], &buf_nc[i+2]);
920 strcpy(&buf[i], &buf[i+2]);
922 strcpy(&buf_nc[i], &buf_nc[i+1]);
923 strcpy(&buf[i], &buf[i+1]);
929 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
932 unlink(new_filename);
940 unlink(new_filename);
944 snprintf(question, sizeof question,
946 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
947 "one or more services. This is not necessary on most systems,\n"
948 "and it is known to crash the Citadel server when delivering\n"
949 "mail to the Internet.\n"
951 "Do you want this module to be automatically disabled?\n"
955 if (yesno(question)) {
956 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
959 unlink(new_filename);
969 int main(int argc, char *argv[])
975 int old_setup_level = 0;
977 struct utsname my_utsname;
983 char relhome[PATH_MAX]="";
984 char ctdldir[PATH_MAX]=CTDLDIR;
986 /* set an invalid setup type */
989 /* Check to see if we're running the web installer */
990 if (getenv("CITADEL_INSTALLER") != NULL) {
991 using_web_installer = 1;
994 /* parse command line args */
995 for (a = 0; a < argc; ++a) {
996 if (!strncmp(argv[a], "-u", 2)) {
997 strcpy(aaa, argv[a]);
998 strcpy(aaa, &aaa[2]);
999 setup_type = atoi(aaa);
1001 if (!strcmp(argv[a], "-i")) {
1004 if (!strcmp(argv[a], "-q")) {
1005 setup_type = UI_SILENT;
1010 /* If a setup type was not specified, try to determine automatically
1011 * the best one to use out of all available types.
1013 if (setup_type < 0) {
1014 setup_type = discover_ui();
1016 if (info_only == 1) {
1017 important_message("Citadel Setup", CITADEL);
1021 /* Get started in a valid setup directory. */
1022 strcpy(setup_directory,
1029 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
1030 strcpy(setup_directory, getenv("CITADEL"));
1033 set_str_val(0, setup_directory);
1036 home=(setup_directory[1]!='\0');
1037 relh=home&(setup_directory[1]!='/');
1039 safestrncpy(ctdl_home_directory, setup_directory, sizeof ctdl_home_directory);
1042 safestrncpy(relhome, ctdl_home_directory, sizeof relhome);
1045 calc_dirs_n_files(relh, home, relhome, ctdldir);
1047 enable_home=(relh|home);
1050 if (chdir(setup_directory) == 0) {
1051 strcpy(file_citadel_config, "./citadel.config");
1054 important_message("Citadel Setup",
1055 "The directory you specified does not exist.");
1060 /* Determine our host name, in case we need to use it as a default */
1063 /* Try to stop Citadel if we can */
1064 if (!access("/etc/init.d/citadel", X_OK)) {
1065 for (a=0; a<=2; ++a) {
1066 progress("Stopping the Citadel service...", a, 2);
1067 if (a == 0) system("/etc/init.d/citadel stop >/dev/null 2>&1");
1072 /* Make sure Citadel is not running. */
1073 if (test_server() == 0) {
1074 important_message("Citadel Setup",
1075 "The Citadel service is still running.\n"
1076 "Please stop the service manually and run "
1082 switch (setup_type) {
1086 " *** Citadel setup program ***\n\n");
1092 * What we're going to try to do here is append a whole bunch of
1093 * nulls to the citadel.config file, so we can keep the old config
1094 * values if they exist, but if the file is missing or from an
1095 * earlier version with a shorter config structure, when setup tries
1096 * to read the old config parameters, they'll all come up zero.
1097 * The length of the config file will be set to what it's supposed
1098 * to be when we rewrite it, because we replace the old file with a
1099 * completely new copy.
1101 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1102 S_IRUSR | S_IWUSR)) == -1) {
1103 display_error("setup: cannot append citadel.config");
1106 fp = fdopen(a, "ab");
1108 display_error("setup: cannot append citadel.config");
1111 for (a = 0; a < sizeof(struct config); ++a)
1115 /* now we re-open it, and read the old or blank configuration */
1116 fp = fopen(file_citadel_config, "rb");
1118 display_error("setup: cannot open citadel.config");
1121 fread((char *) &config, sizeof(struct config), 1, fp);
1124 /* set some sample/default values in place of blanks... */
1125 if (strlen(config.c_nodename) == 0)
1126 safestrncpy(config.c_nodename, my_utsname.nodename,
1127 sizeof config.c_nodename);
1128 strtok(config.c_nodename, ".");
1129 if (strlen(config.c_fqdn) == 0) {
1130 if ((he = gethostbyname(my_utsname.nodename)) != NULL)
1131 safestrncpy(config.c_fqdn, he->h_name,
1132 sizeof config.c_fqdn);
1134 safestrncpy(config.c_fqdn, my_utsname.nodename,
1135 sizeof config.c_fqdn);
1137 if (strlen(config.c_humannode) == 0)
1138 strcpy(config.c_humannode, "My System");
1139 if (strlen(config.c_phonenum) == 0)
1140 strcpy(config.c_phonenum, "US 800 555 1212");
1141 if (config.c_initax == 0) {
1142 config.c_initax = 4;
1144 if (strlen(config.c_moreprompt) == 0)
1145 strcpy(config.c_moreprompt, "<more>");
1146 if (strlen(config.c_twitroom) == 0)
1147 strcpy(config.c_twitroom, "Trashcan");
1148 if (strlen(config.c_baseroom) == 0)
1149 strcpy(config.c_baseroom, BASEROOM);
1150 if (strlen(config.c_aideroom) == 0)
1151 strcpy(config.c_aideroom, "Aide");
1152 if (config.c_port_number == 0) {
1153 config.c_port_number = 504;
1155 if (config.c_sleeping == 0) {
1156 config.c_sleeping = 900;
1158 if (config.c_ctdluid == 0) {
1159 pw = getpwnam("citadel");
1161 config.c_ctdluid = pw->pw_uid;
1163 if (config.c_ctdluid == 0) {
1164 pw = getpwnam("bbs");
1166 config.c_ctdluid = pw->pw_uid;
1168 if (config.c_ctdluid == 0) {
1169 pw = getpwnam("guest");
1171 config.c_ctdluid = pw->pw_uid;
1173 if (config.c_createax == 0) {
1174 config.c_createax = 3;
1177 * Negative values for maxsessions are not allowed.
1179 if (config.c_maxsessions < 0) {
1180 config.c_maxsessions = 0;
1182 /* We need a system default message expiry policy, because this is
1183 * the top level and there's no 'higher' policy to fall back on.
1184 * By default, do not expire messages at all.
1186 if (config.c_ep.expire_mode == 0) {
1187 config.c_ep.expire_mode = EXPIRE_MANUAL;
1188 config.c_ep.expire_value = 0;
1192 * Default port numbers for various services
1194 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1195 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1196 if (config.c_imap_port == 0) config.c_imap_port = 143;
1197 if (config.c_msa_port == 0) config.c_msa_port = 587;
1198 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1199 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1200 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1201 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1202 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1204 /* Go through a series of dialogs prompting for config info */
1205 if (setup_type != UI_SILENT) {
1206 for (curr = 1; curr <= MAXSETUP; ++curr) {
1211 /***** begin version update section ***** */
1212 /* take care of any updating that is necessary */
1214 old_setup_level = config.c_setup_level;
1216 if (old_setup_level == 0) {
1220 if (old_setup_level < 555) {
1221 important_message("Citadel Setup",
1222 "This Citadel installation is too old "
1226 write_config_to_disk();
1228 old_setup_level = config.c_setup_level;
1230 /* end of version update section */
1233 config.c_setup_level = REV_LEVEL;
1235 /******************************************/
1237 write_config_to_disk();
1239 mkdir(ctdl_info_dir, 0700);
1240 chmod(ctdl_info_dir, 0700);
1241 chown(ctdl_info_dir, config.c_ctdluid, -1);
1243 mkdir(ctdl_bio_dir, 0700);
1244 chmod(ctdl_bio_dir, 0700);
1245 chown(ctdl_bio_dir, config.c_ctdluid, -1);
1247 mkdir(ctdl_usrpic_dir, 0700);
1248 chmod(ctdl_usrpic_dir, 0700);
1249 chown(ctdl_usrpic_dir, config.c_ctdluid, -1);
1251 mkdir(ctdl_message_dir, 0700);
1252 chmod(ctdl_message_dir, 0700);
1253 chown(ctdl_message_dir, config.c_ctdluid, -1);
1255 mkdir(ctdl_hlp_dir, 0700);
1256 chmod(ctdl_hlp_dir, 0700);
1257 chown(ctdl_hlp_dir, config.c_ctdluid, -1);
1259 mkdir(ctdl_image_dir, 0700);
1260 chmod(ctdl_image_dir, 0700);
1261 chown(ctdl_image_dir, config.c_ctdluid, -1);
1263 mkdir(ctdl_bb_dir, 0700);
1264 chmod(ctdl_bb_dir, 0700);
1265 chown(ctdl_bb_dir, config.c_ctdluid, -1);
1267 mkdir(ctdl_file_dir, 0700);
1268 chmod(ctdl_file_dir, 0700);
1269 chown(ctdl_file_dir, config.c_ctdluid, -1);
1271 mkdir(ctdl_netcfg_dir, 0700);
1272 chmod(ctdl_netcfg_dir, 0700);
1273 chown(ctdl_netcfg_dir, config.c_ctdluid, -1);
1275 /* TODO: where to put this? */
1276 mkdir("netconfigs", 0700);
1277 chmod("netconfigs", 0700);
1278 chown("netconfigs", config.c_ctdluid, -1);
1280 /* Delete files and directories used by older Citadel versions */
1281 system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1282 unlink("citadel.log");
1285 check_services_entry(); /* Check /etc/services */
1287 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1288 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1290 /* Offer to disable other MTA's on the system. */
1291 disable_other_mta("courier-authdaemon");
1292 disable_other_mta("courier-imap");
1293 disable_other_mta("courier-imap-ssl");
1294 disable_other_mta("courier-pop");
1295 disable_other_mta("courier-pop3");
1296 disable_other_mta("courier-pop3d");
1297 disable_other_mta("cyrmaster");
1298 disable_other_mta("cyrus");
1299 disable_other_mta("dovecot");
1300 disable_other_mta("exim");
1301 disable_other_mta("exim4");
1302 disable_other_mta("hula");
1303 disable_other_mta("imapd");
1304 disable_other_mta("mta");
1305 disable_other_mta("pop3d");
1306 disable_other_mta("popd");
1307 disable_other_mta("postfix");
1308 disable_other_mta("qmail");
1309 disable_other_mta("saslauthd");
1310 disable_other_mta("sendmail");
1311 disable_other_mta("vmailmgrd");
1312 disable_other_mta("zimbra");
1315 /* Check for the 'db' nss and offer to disable it */
1318 if ((pw = getpwuid(config.c_ctdluid)) == NULL)
1323 progress("Setting file permissions", 0, 4);
1324 chown(".", config.c_ctdluid, gid);
1326 progress("Setting file permissions", 1, 4);
1327 chown(file_citadel_config, config.c_ctdluid, gid);
1329 progress("Setting file permissions", 2, 4);
1331 snprintf(aaa, sizeof aaa,
1334 chown(aaa,0,0); /* config.c_ctdluid, gid); chkpwd needs to be root owned*/
1336 progress("Setting file permissions", 3, 4);
1340 progress("Setting file permissions", 3, 4);
1341 chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1343 progress("Setting file permissions", 4, 4);
1346 * If we're running on SysV, install init scripts.
1348 if (!access("/var/run", W_OK)) {
1349 install_init_scripts();
1351 if (!access("/etc/init.d/citadel", X_OK)) {
1352 for (a=0; a<=2; ++a) {
1353 progress("Starting the Citadel service...", a, 2);
1354 if (a == 0) system("/etc/init.d/citadel start >/dev/null 2>&1");
1359 if (test_server() == 0) {
1360 important_message("Setup finished",
1361 "Setup of the Citadel server is complete.\n"
1362 "If you will be using WebCit, please run its\n"
1363 "setup program now; otherwise, run './citadel'\n"
1367 important_message("Setup failed",
1368 "Setup is finished, but the Citadel server failed to start.\n"
1369 "Go back and check your configuration.\n"
1376 important_message("Setup finished",
1377 "Setup is finished. You may now start the server.");