4 * Citadel setup utility
14 #include <sys/types.h>
16 #include <sys/utsname.h>
24 #include <libcitadel.h>
29 #include "citadel_dirs.h"
31 #define MAXSETUP 5 /* How many setup questions to ask */
33 #define UI_TEXT 0 /* Default setup type -- text only */
34 #define UI_DIALOG 2 /* Use the 'dialog' program */
35 #define UI_SILENT 3 /* Silent running, for use in scripts */
37 #define SERVICE_NAME "citadel"
38 #define PROTO_NAME "tcp"
39 #define NSSCONF "/etc/nsswitch.conf"
42 char setup_directory[PATH_MAX];
43 int using_web_installer = 0;
46 char *setup_titles[] =
48 "Citadel Home Directory",
49 "System Administrator",
59 /* calculate all our path on a central place */
60 /* where to keep our config */
63 char *setup_text[] = {
65 "Enter the full pathname of the directory in which the Citadel\n"
66 "installation you are creating or updating resides. If you\n"
67 "specify a directory other than the default, you will need to\n"
68 "specify the -h flag to the server when you start it up.\n",
70 "Enter the subdirectory name for an alternate installation of "
71 "Citadel. To do a default installation just leave it blank."
72 "If you specify a directory other than the default, you will need to\n"
73 "specify the -h flag to the server when you start it up.\n"
74 "note that it may not have a leading /",
77 "Enter the name of the system administrator (which is probably\n"
78 "you). When an account is created with this name, it will\n"
79 "automatically be given administrator-level access.\n",
81 "Citadel needs to run under its own user ID. This would\n"
82 "typically be called \"citadel\", but if you are running Citadel\n"
83 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
84 "The server will run under this user ID. Please specify that\n"
85 "user ID here. You may specify either a user name or a numeric\n"
88 "Specify the IP address on which your server will run. If you\n"
89 "leave this blank, or if you specify 0.0.0.0, Citadel will listen\n"
90 "on all addresses. You can usually skip this unless you are\n"
91 "running multiple instances of Citadel on the same computer.\n",
93 "Specify the TCP port number on which your server will run.\n"
94 "Normally, this will be port 504, which is the official port\n"
95 "assigned by the IANA for Citadel servers. You will only need\n"
96 "to specify a different port number if you run multiple instances\n"
97 "of Citadel on the same computer and there is something else\n"
98 "already using port 504.\n",
100 "Normally, a Citadel system uses a \"black box\" authentication mode.\n"
101 "This means that users do not have accounts or home directories on\n"
102 "the underlying host system -- Citadel manages its own user database.\n"
103 "However, if you wish to override this behavior, you can enable the\n"
104 "host based authentication mode which is traditional for Unix systems.\n"
105 "WARNING: do *not* change this setting once your system is installed.\n"
107 "(Answer \"no\" unless you completely understand this option)\n"
108 "Do you want to enable host based authentication mode?\n"
112 struct config config;
116 void cleanup(int exitcode)
123 void title(char *text)
125 if (setup_type == UI_TEXT) {
126 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
132 int yesno(char *question, int default_value)
138 switch (setup_type) {
142 printf("%s\nYes/No [%s] --> ",
144 ( default_value ? "Yes" : "No" )
146 fgets(buf, sizeof buf, stdin);
147 answer = tolower(buf[0]);
148 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
149 answer = default_value;
150 else if (answer == 'y')
152 else if (answer == 'n')
154 } while ((answer < 0) || (answer > 1));
158 sprintf(buf, "exec %s %s --yesno '%s' 15 75",
159 getenv("CTDL_DIALOG"),
160 ( default_value ? "" : "--defaultno" ),
176 void important_message(char *title, char *msgtext)
180 switch (setup_type) {
183 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");
184 printf(" %s \n\n%s\n\n", title, msgtext);
185 printf("Press return to continue...");
186 fgets(buf, sizeof buf, stdin);
190 sprintf(buf, "exec %s --msgbox '%s' 19 72",
191 getenv("CTDL_DIALOG"),
198 void important_msgnum(int msgnum)
200 important_message("Important Message", setup_text[msgnum]);
203 void display_error(char *error_message)
205 important_message("Error", error_message);
208 void progress(char *text, long int curr, long int cmax)
210 static long dots_printed = 0L;
212 static FILE *fp = NULL;
215 switch (setup_type) {
219 printf("%s\n", text);
220 printf("..........................");
221 printf("..........................");
222 printf("..........................\r");
225 } else if (curr == cmax) {
226 printf("\r%79s\n", "");
228 a = (curr * 100) / cmax;
231 while (dots_printed < a) {
241 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
242 getenv("CTDL_DIALOG"),
244 fp = popen(buf, "w");
250 else if (curr == cmax) {
252 fprintf(fp, "100\n");
258 a = (curr * 100) / cmax;
260 fprintf(fp, "%ld\n", a);
272 * check_services_entry() -- Make sure "citadel" is in /etc/services
275 void check_services_entry(void)
281 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
282 for (i=0; i<=2; ++i) {
283 progress("Adding service entry...", i, 2);
285 sfp = fopen("/etc/services", "a");
287 sprintf(errmsg, "Cannot open /etc/services: %s", strerror(errno));
288 display_error(errmsg);
290 fprintf(sfp, "%s 504/tcp\n", SERVICE_NAME);
302 * delete_inittab_entry() -- Remove obsolete /etc/inittab entry for Citadel
305 void delete_inittab_entry(void)
309 char looking_for[256];
311 char outfilename[32];
312 int changes_made = 0;
314 /* Determine the fully qualified path name of citserver */
315 snprintf(looking_for,
321 /* Now tweak /etc/inittab */
322 infp = fopen("/etc/inittab", "r");
325 /* If /etc/inittab does not exist, return quietly.
326 * Not all host platforms have it.
328 if (errno == ENOENT) {
332 /* Other errors might mean something really did go wrong.
334 sprintf(buf, "Cannot open /etc/inittab: %s", strerror(errno));
339 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
340 outfp = fdopen(mkstemp(outfilename), "w+");
342 sprintf(buf, "Cannot open %s: %s", outfilename, strerror(errno));
348 while (fgets(buf, sizeof buf, infp) != NULL) {
349 if (strstr(buf, looking_for) != NULL) {
350 fwrite("#", 1, 1, outfp);
353 fwrite(buf, strlen(buf), 1, outfp);
360 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
362 system("/sbin/init q 2>/dev/null");
371 * install_init_scripts() -- Try to configure to start Citadel at boot
374 void install_init_scripts(void)
376 struct stat etcinitd;
378 char *initfile = "/etc/init.d/citadel";
381 if ((stat("/etc/init.d/", &etcinitd) == -1) &&
384 if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
386 initfile = CTDLDIR"/citadel.init";
388 initfile = "/etc/rc.d/init.d/citadel";
391 fp = fopen(initfile, "r");
393 if (yesno("Citadel already appears to be configured to start at boot.\n"
394 "Would you like to keep your boot configuration as is?\n", 1) == 1) {
401 if (yesno("Would you like to automatically start Citadel at boot?\n", 1) == 0) {
405 fp = fopen(initfile, "w");
407 display_error("Cannot create /etc/init.d/citadel");
411 fprintf(fp, "#!/bin/sh\n"
413 "# Init file for Citadel\n"
415 "# chkconfig: - 79 30\n"
416 "# description: Citadel service\n"
417 "# processname: citserver\n"
418 "# pidfile: %s/citadel.pid\n"
426 "test -d /var/run || exit 0\n"
430 "start) echo -n \"Starting Citadel... \"\n"
431 " if $CITADEL_DIR/citserver -d -h$CITADEL_DIR\n"
438 "stop) echo -n \"Stopping Citadel... \"\n"
439 " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
444 " rm -f %s/citadel.pid 2>/dev/null\n"
452 "*) echo \"Usage: $0 {start|stop|restart}\"\n"
459 chmod(initfile, 0755);
461 /* Set up the run levels. */
462 system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
463 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);
465 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);
476 * On systems which use xinetd, see if we can offer to install Citadel as
477 * the default telnet target.
479 void check_xinetd_entry(void) {
480 char *filename = "/etc/xinetd.d/telnet";
483 int already_citadel = 0;
485 fp = fopen(filename, "r+");
486 if (fp == NULL) return; /* Not there. Oh well... */
488 while (fgets(buf, sizeof buf, fp) != NULL) {
489 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
492 if (already_citadel) return; /* Already set up this way. */
494 /* Otherwise, prompt the user to create an entry. */
495 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
496 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
501 snprintf(buf, sizeof buf,
502 "Setup can configure the \"xinetd\" service to automatically\n"
503 "connect incoming telnet sessions to Citadel, bypassing the\n"
504 "host system login: prompt. Would you like to do this?\n"
506 if (yesno(buf, 1) == 0) {
511 fp = fopen(filename, "w");
513 "# description: telnet service for Citadel users\n"
518 " socket_type = stream\n"
521 " server = /usr/sbin/in.telnetd\n"
522 " server_args = -h -L %s/citadel\n"
523 " log_on_failure += USERID\n"
528 /* Now try to restart the service */
529 system("/etc/init.d/xinetd restart >/dev/null 2>&1");
535 * Offer to disable other MTA's
537 void disable_other_mta(char *mta) {
542 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
543 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
545 fp = popen(buf, "r");
546 if (fp == NULL) return;
548 while (fgets(buf, sizeof buf, fp) != NULL) {
552 if (lines == 0) return; /* Nothing to do. */
555 /* Offer to replace other MTA with the vastly superior Citadel :) */
557 if (getenv("ACT_AS_MTA")) {
558 if (strcasecmp(getenv("ACT_AS_MTA"), "yes")) {
563 snprintf(buf, sizeof buf,
564 "You appear to have the \"%s\" email program\n"
565 "running on your system. If you want Citadel mail\n"
566 "connected with %s, you will have to manually integrate\n"
567 "them. It is preferable to disable %s, and use Citadel's\n"
568 "SMTP, POP3, and IMAP services.\n\n"
569 "May we disable %s so that Citadel has access to ports\n"
570 "25, 110, and 143?\n",
573 if (yesno(buf, 1) == 0) {
578 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);
580 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
588 * Check to see if our server really works. Returns 0 on success.
590 int test_server(void) {
597 /* Generate a silly little cookie. We're going to write it out
598 * to the server and try to get it back. The cookie does not
599 * have to be secret ... just unique.
601 sprintf(cookie, "--test--%d--", getpid());
603 sprintf(cmd, "%s/sendcommand %s%s ECHO %s 2>&1",
605 (enable_home)?"-h":"",
606 (enable_home)?ctdl_run_dir:"",
609 fp = popen(cmd, "r");
610 if (fp == NULL) return(errno);
612 while (fgets(buf, sizeof buf, fp) != NULL) {
614 && (strstr(buf, cookie) != NULL) ) {
626 void strprompt(char *prompt_title, char *prompt_text, char *str)
630 char dialog_result[PATH_MAX];
633 strcpy(setupmsg, "");
635 switch (setup_type) {
638 printf("\n%s\n", prompt_text);
639 printf("This is currently set to:\n%s\n", str);
640 printf("Enter new value or press return to leave unchanged:\n");
641 fgets(buf, sizeof buf, stdin);
642 buf[strlen(buf) - 1] = 0;
643 if (!IsEmptyStr(buf))
648 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
649 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
650 getenv("CTDL_DIALOG"),
655 fp = fopen(dialog_result, "r");
657 fgets(str, sizeof buf, fp);
658 if (str[strlen(str)-1] == 10) {
659 str[strlen(str)-1] = 0;
662 unlink(dialog_result);
669 void set_bool_val(int msgpos, int *ip) {
670 title(setup_titles[msgpos]);
671 *ip = yesno(setup_text[msgpos], *ip);
674 void set_str_val(int msgpos, char *str) {
675 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
678 void set_int_val(int msgpos, int *ip)
681 snprintf(buf, sizeof buf, "%d", (int) *ip);
682 set_str_val(msgpos, buf);
687 void set_char_val(int msgpos, char *ip)
690 snprintf(buf, sizeof buf, "%d", (int) *ip);
691 set_str_val(msgpos, buf);
692 *ip = (char) atoi(buf);
696 void set_long_val(int msgpos, long int *ip)
699 snprintf(buf, sizeof buf, "%ld", *ip);
700 set_str_val(msgpos, buf);
705 void edit_value(int curr)
709 char ctdluidname[256];
714 if (setup_type == UI_SILENT)
716 if (getenv("SYSADMIN_NAME")) {
717 strcpy(config.c_sysadm, getenv("SYSADMIN_NAME"));
721 set_str_val(curr, config.c_sysadm);
726 if (setup_type == UI_SILENT)
728 if (getenv("CITADEL_UID")) {
729 config.c_ctdluid = atoi(getenv("CITADEL_UID"));
735 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
737 i = config.c_ctdluid;
740 set_int_val(curr, &i);
741 config.c_ctdluid = i;
744 strcpy(ctdluidname, pw->pw_name);
745 set_str_val(curr, ctdluidname);
746 pw = getpwnam(ctdluidname);
748 config.c_ctdluid = pw->pw_uid;
750 else if (atoi(ctdluidname) > 0) {
751 config.c_ctdluid = atoi(ctdluidname);
759 if (setup_type == UI_SILENT)
761 if (getenv("IP_ADDR")) {
762 strcpy(config.c_ip_addr, getenv("IP_ADDR"));
766 set_str_val(curr, config.c_ip_addr);
771 if (setup_type == UI_SILENT)
773 if (getenv("CITADEL_PORT")) {
774 config.c_port_number = atoi(getenv("CITADEL_PORT"));
779 set_int_val(curr, &config.c_port_number);
784 if (setup_type == UI_SILENT)
786 if (getenv("ENABLE_UNIX_AUTH")) {
787 if (!strcasecmp(getenv("ENABLE_UNIX_AUTH"), "yes")) {
788 config.c_auth_mode = AUTHMODE_HOST;
791 config.c_auth_mode = AUTHMODE_NATIVE;
796 set_bool_val(curr, &config.c_auth_mode);
804 * (re-)write the config data to disk
806 void write_config_to_disk(void)
811 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
812 display_error("setup: cannot open citadel.config");
815 fp = fdopen(fd, "wb");
817 display_error("setup: cannot open citadel.config");
820 fwrite((char *) &config, sizeof(struct config), 1, fp);
828 * Figure out what type of user interface we're going to use
830 int discover_ui(void)
833 /* Use "dialog" if we have it */
834 if (getenv("CTDL_DIALOG") != NULL) {
846 * Strip "db" entries out of /etc/nsswitch.conf
856 int file_changed = 0;
857 char new_filename[64];
859 fp_read = fopen(NSSCONF, "r");
860 if (fp_read == NULL) {
864 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
865 fd_write = mkstemp(new_filename);
871 while (fgets(buf, sizeof buf, fp_read) != NULL) {
874 for (i=0; i<strlen(buf_nc); ++i) {
875 if (buf_nc[i] == '#') {
879 for (i=0; i<strlen(buf_nc); ++i) {
880 if (!strncasecmp(&buf_nc[i], "db", 2)) {
882 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
885 strcpy(&buf_nc[i], &buf_nc[i+2]);
886 strcpy(&buf[i], &buf[i+2]);
888 strcpy(&buf_nc[i], &buf_nc[i+1]);
889 strcpy(&buf[i], &buf[i+1]);
895 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
898 unlink(new_filename);
906 unlink(new_filename);
910 snprintf(question, sizeof question,
912 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
913 "one or more services. This is not necessary on most systems,\n"
914 "and it is known to crash the Citadel server when delivering\n"
915 "mail to the Internet.\n"
917 "Do you want this module to be automatically disabled?\n"
921 if (yesno(question, 1)) {
922 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
925 unlink(new_filename);
935 int main(int argc, char *argv[])
941 int old_setup_level = 0;
943 struct utsname my_utsname;
949 char relhome[PATH_MAX]="";
950 char ctdldir[PATH_MAX]=CTDLDIR;
952 /* set an invalid setup type */
955 /* Check to see if we're running the web installer */
956 if (getenv("CITADEL_INSTALLER") != NULL) {
957 using_web_installer = 1;
960 /* parse command line args */
961 for (a = 0; a < argc; ++a) {
962 if (!strncmp(argv[a], "-u", 2)) {
963 strcpy(aaa, argv[a]);
964 strcpy(aaa, &aaa[2]);
965 setup_type = atoi(aaa);
967 if (!strcmp(argv[a], "-i")) {
970 if (!strcmp(argv[a], "-q")) {
971 setup_type = UI_SILENT;
976 /* If a setup type was not specified, try to determine automatically
977 * the best one to use out of all available types.
979 if (setup_type < 0) {
980 setup_type = discover_ui();
982 if (info_only == 1) {
983 important_message("Citadel Setup", CITADEL);
987 /* Get started in a valid setup directory. */
988 strcpy(setup_directory, ctdl_run_dir);
989 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
990 strcpy(setup_directory, getenv("CITADEL"));
993 set_str_val(0, setup_directory);
996 home=(setup_directory[1]!='\0');
997 relh=home&(setup_directory[1]!='/');
999 safestrncpy(ctdl_home_directory, setup_directory, sizeof ctdl_home_directory);
1002 safestrncpy(relhome, ctdl_home_directory, sizeof relhome);
1005 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1007 enable_home=(relh|home);
1010 if (chdir(setup_directory) == 0) {
1011 strcpy(file_citadel_config, "./citadel.config");
1014 important_message("Citadel Setup",
1015 "The directory you specified does not exist.");
1020 /* Determine our host name, in case we need to use it as a default */
1023 /* Try to stop Citadel if we can */
1024 if (!access("/etc/init.d/citadel", X_OK)) {
1025 system("/etc/init.d/citadel stop");
1028 /* Make sure Citadel is not running. */
1029 if (test_server() == 0) {
1030 important_message("Citadel Setup",
1031 "The Citadel service is still running.\n"
1032 "Please stop the service manually and run "
1038 switch (setup_type) {
1042 " *** Citadel setup program ***\n\n");
1048 * What we're going to try to do here is append a whole bunch of
1049 * nulls to the citadel.config file, so we can keep the old config
1050 * values if they exist, but if the file is missing or from an
1051 * earlier version with a shorter config structure, when setup tries
1052 * to read the old config parameters, they'll all come up zero.
1053 * The length of the config file will be set to what it's supposed
1054 * to be when we rewrite it, because we replace the old file with a
1055 * completely new copy.
1057 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1058 S_IRUSR | S_IWUSR)) == -1) {
1059 display_error("setup: cannot append citadel.config");
1062 fp = fdopen(a, "ab");
1064 display_error("setup: cannot append citadel.config");
1067 for (a = 0; a < sizeof(struct config); ++a)
1071 /* now we re-open it, and read the old or blank configuration */
1072 fp = fopen(file_citadel_config, "rb");
1074 display_error("setup: cannot open citadel.config");
1077 fread((char *) &config, sizeof(struct config), 1, fp);
1080 /* set some sample/default values in place of blanks... */
1081 if (IsEmptyStr(config.c_nodename))
1082 safestrncpy(config.c_nodename, my_utsname.nodename,
1083 sizeof config.c_nodename);
1084 strtok(config.c_nodename, ".");
1085 if (IsEmptyStr(config.c_fqdn) ) {
1086 if ((he = gethostbyname(my_utsname.nodename)) != NULL)
1087 safestrncpy(config.c_fqdn, he->h_name,
1088 sizeof config.c_fqdn);
1090 safestrncpy(config.c_fqdn, my_utsname.nodename,
1091 sizeof config.c_fqdn);
1093 if (IsEmptyStr(config.c_humannode))
1094 strcpy(config.c_humannode, "My System");
1095 if (IsEmptyStr(config.c_phonenum))
1096 strcpy(config.c_phonenum, "US 800 555 1212");
1097 if (config.c_initax == 0) {
1098 config.c_initax = 4;
1100 if (IsEmptyStr(config.c_moreprompt))
1101 strcpy(config.c_moreprompt, "<more>");
1102 if (IsEmptyStr(config.c_twitroom))
1103 strcpy(config.c_twitroom, "Trashcan");
1104 if (IsEmptyStr(config.c_baseroom))
1105 strcpy(config.c_baseroom, BASEROOM);
1106 if (IsEmptyStr(config.c_aideroom))
1107 strcpy(config.c_aideroom, "Aide");
1108 if (config.c_port_number == 0) {
1109 config.c_port_number = 504;
1111 if (config.c_sleeping == 0) {
1112 config.c_sleeping = 900;
1114 if (config.c_ctdluid == 0) {
1115 pw = getpwnam("citadel");
1117 config.c_ctdluid = pw->pw_uid;
1119 if (config.c_ctdluid == 0) {
1120 pw = getpwnam("bbs");
1122 config.c_ctdluid = pw->pw_uid;
1124 if (config.c_ctdluid == 0) {
1125 pw = getpwnam("guest");
1127 config.c_ctdluid = pw->pw_uid;
1129 if (config.c_createax == 0) {
1130 config.c_createax = 3;
1133 * Negative values for maxsessions are not allowed.
1135 if (config.c_maxsessions < 0) {
1136 config.c_maxsessions = 0;
1138 /* We need a system default message expiry policy, because this is
1139 * the top level and there's no 'higher' policy to fall back on.
1140 * By default, do not expire messages at all.
1142 if (config.c_ep.expire_mode == 0) {
1143 config.c_ep.expire_mode = EXPIRE_MANUAL;
1144 config.c_ep.expire_value = 0;
1148 * Default port numbers for various services
1150 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1151 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1152 if (config.c_imap_port == 0) config.c_imap_port = 143;
1153 if (config.c_msa_port == 0) config.c_msa_port = 587;
1154 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1155 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1156 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1157 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1158 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1159 if (config.c_xmpp_c2s_port == 0) config.c_xmpp_c2s_port = 5222;
1160 if (config.c_xmpp_s2s_port == 0) config.c_xmpp_s2s_port = 5269;
1162 /* Go through a series of dialogs prompting for config info */
1163 for (curr = 1; curr <= MAXSETUP; ++curr) {
1167 /***** begin version update section ***** */
1168 /* take care of any updating that is necessary */
1170 old_setup_level = config.c_setup_level;
1172 if (old_setup_level == 0) {
1176 if (old_setup_level < 555) {
1177 important_message("Citadel Setup",
1178 "This Citadel installation is too old "
1182 write_config_to_disk();
1184 old_setup_level = config.c_setup_level;
1186 /* end of version update section */
1189 config.c_setup_level = REV_LEVEL;
1191 /******************************************/
1193 write_config_to_disk();
1195 mkdir(ctdl_info_dir, 0700);
1196 chmod(ctdl_info_dir, 0700);
1197 chown(ctdl_info_dir, config.c_ctdluid, -1);
1199 mkdir(ctdl_bio_dir, 0700);
1200 chmod(ctdl_bio_dir, 0700);
1201 chown(ctdl_bio_dir, config.c_ctdluid, -1);
1203 mkdir(ctdl_usrpic_dir, 0700);
1204 chmod(ctdl_usrpic_dir, 0700);
1205 chown(ctdl_usrpic_dir, config.c_ctdluid, -1);
1207 mkdir(ctdl_message_dir, 0700);
1208 chmod(ctdl_message_dir, 0700);
1209 chown(ctdl_message_dir, config.c_ctdluid, -1);
1211 mkdir(ctdl_hlp_dir, 0700);
1212 chmod(ctdl_hlp_dir, 0700);
1213 chown(ctdl_hlp_dir, config.c_ctdluid, -1);
1215 mkdir(ctdl_image_dir, 0700);
1216 chmod(ctdl_image_dir, 0700);
1217 chown(ctdl_image_dir, config.c_ctdluid, -1);
1219 mkdir(ctdl_bb_dir, 0700);
1220 chmod(ctdl_bb_dir, 0700);
1221 chown(ctdl_bb_dir, config.c_ctdluid, -1);
1223 mkdir(ctdl_file_dir, 0700);
1224 chmod(ctdl_file_dir, 0700);
1225 chown(ctdl_file_dir, config.c_ctdluid, -1);
1227 mkdir(ctdl_netcfg_dir, 0700);
1228 chmod(ctdl_netcfg_dir, 0700);
1229 chown(ctdl_netcfg_dir, config.c_ctdluid, -1);
1231 /* Delete files and directories used by older Citadel versions */
1232 system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1233 unlink("citadel.log");
1236 check_services_entry(); /* Check /etc/services */
1238 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1239 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1241 /* Offer to disable other MTA's on the system. */
1242 disable_other_mta("courier-authdaemon");
1243 disable_other_mta("courier-imap");
1244 disable_other_mta("courier-imap-ssl");
1245 disable_other_mta("courier-pop");
1246 disable_other_mta("courier-pop3");
1247 disable_other_mta("courier-pop3d");
1248 disable_other_mta("cyrmaster");
1249 disable_other_mta("cyrus");
1250 disable_other_mta("dovecot");
1251 disable_other_mta("exim");
1252 disable_other_mta("exim4");
1253 disable_other_mta("imapd");
1254 disable_other_mta("mta");
1255 disable_other_mta("pop3d");
1256 disable_other_mta("popd");
1257 disable_other_mta("postfix");
1258 disable_other_mta("qmail");
1259 disable_other_mta("saslauthd");
1260 disable_other_mta("sendmail");
1261 disable_other_mta("vmailmgrd");
1264 /* Check for the 'db' nss and offer to disable it */
1267 if ((pw = getpwuid(config.c_ctdluid)) == NULL)
1272 progress("Setting file permissions", 0, 3);
1273 chown(ctdl_run_dir, config.c_ctdluid, gid);
1274 progress("Setting file permissions", 1, 3);
1275 chown(file_citadel_config, config.c_ctdluid, gid);
1276 progress("Setting file permissions", 2, 3);
1277 chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1278 progress("Setting file permissions", 3, 3);
1281 * If we're running on SysV, install init scripts.
1283 if (!access("/var/run", W_OK)) {
1285 if (getenv("NO_INIT_SCRIPTS") == NULL) {
1286 install_init_scripts();
1289 if (!access("/etc/init.d/citadel", X_OK)) {
1290 system("/etc/init.d/citadel start");
1294 if (test_server() == 0) {
1295 important_message("Setup finished",
1296 "Setup of the Citadel server is complete.\n"
1297 "If you will be using WebCit, please run its\n"
1298 "setup program now; otherwise, run './citadel'\n"
1302 important_message("Setup failed",
1303 "Setup is finished, but the Citadel server failed to start.\n"
1304 "Go back and check your configuration.\n"
1311 important_message("Setup finished",
1312 "Setup is finished. You may now start the server.");