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;
55 * We will set have_sysv_init to nonzero if the host operating system
56 * has a System V style init driven by /etc/inittab. This will cause
57 * setup to offer to automatically start and stop the Citadel service.
59 int have_sysv_init = 0;
62 void contemplate_ldap(void);
65 char *setup_titles[] =
67 "Citadel Home Directory",
68 "System Administrator",
77 /* calculate all our path on a central place */
78 /* where to keep our config */
81 char *setup_text[] = {
83 "Enter the full pathname of the directory in which the Citadel\n"
84 "installation you are creating or updating resides. If you\n"
85 "specify a directory other than the default, you will need to\n"
86 "specify the -h flag to the server when you start it up.\n",
88 "Enter the subdirectory name for an alternate installation of "
89 "Citadel. To do a default installation just leave it blank."
90 "If you specify a directory other than the default, you will need to\n"
91 "specify the -h flag to the server when you start it up.\n"
92 "note that it may not have a leading /",
95 "Enter the name of the system administrator (which is probably\n"
96 "you). When an account is created with this name, it will\n"
97 "automatically be given administrator-level access.\n",
99 "Citadel needs to run under its own user ID. This would\n"
100 "typically be called \"citadel\", but if you are running Citadel\n"
101 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
102 "The server will run under this user ID. Please specify that\n"
103 "user ID here. You may specify either a user name or a numeric\n"
106 "Specify the IP address on which your server will run. If you\n"
107 "leave this blank, or if you specify 0.0.0.0, Citadel will listen\n"
108 "on all addresses. You can usually skip this unless you are\n"
109 "running multiple instances of Citadel on the same computer.\n",
111 "Specify the TCP port number on which your server will run.\n"
112 "Normally, this will be port 504, which is the official port\n"
113 "assigned by the IANA for Citadel servers. You will only need\n"
114 "to specify a different port number if you run multiple instances\n"
115 "of Citadel on the same computer and there is something else\n"
116 "already using port 504.\n",
120 struct config config;
124 * Set an entry in inittab to the desired state
126 void set_init_entry(char *which_entry, char *new_state) {
127 char *inittab = NULL;
135 if (which_entry == NULL) return;
136 if (strlen(which_entry) == 0) return;
138 inittab = strdup("");
139 if (inittab == NULL) return;
141 fp = fopen("/etc/inittab", "r");
142 if (fp == NULL) return;
144 while(fgets(buf, sizeof buf, fp) != NULL) {
146 if (num_tokens(buf, ':') == 4) {
147 extract_token(entry, buf, 0, ':', sizeof entry);
148 extract_token(levels, buf, 1, ':', sizeof levels);
149 extract_token(state, buf, 2, ':', sizeof state);
150 extract_token(prog, buf, 3, ':', sizeof prog); /* includes 0x0a LF */
152 if (!strcmp(entry, which_entry)) {
153 strcpy(state, new_state);
154 sprintf(buf, "%s:%s:%s:%s",
155 entry, levels, state, prog);
159 inittab = realloc(inittab, strlen(inittab) + strlen(buf) + 2);
160 if (inittab == NULL) {
165 strcat(inittab, buf);
168 fp = fopen("/etc/inittab", "w");
170 fwrite(inittab, strlen(inittab), 1, fp);
172 kill(1, SIGHUP); /* Tell init to re-read /etc/inittab */
179 * Locate the name of an inittab entry for a specific program
181 void locate_init_entry(char *init_entry, char *looking_for) {
189 strcpy(init_entry, "");
191 /* Pound through /etc/inittab line by line. Set have_entry to 1 if
192 * an entry is found which we believe starts the specified program.
194 infp = fopen("/etc/inittab", "r");
198 while (fgets(buf, sizeof buf, infp) != NULL) {
199 buf[strlen(buf) - 1] = 0;
200 extract_token(entry, buf, 0, ':', sizeof entry);
201 extract_token(prog, buf, 3, ':', sizeof prog);
202 if (!strncasecmp(prog, looking_for,
203 strlen(looking_for))) {
205 strcpy(init_entry, entry);
215 * Shut down the Citadel service if necessary, during setup.
217 void shutdown_citserver(void) {
218 char looking_for[SIZ];
220 snprintf(looking_for,
229 locate_init_entry(citserver_init_entry, looking_for);
230 if (strlen(citserver_init_entry) > 0) {
231 set_init_entry(citserver_init_entry, "off");
237 * Start the Citadel service.
239 void start_citserver(void) {
240 if (strlen(citserver_init_entry) > 0) {
241 set_init_entry(citserver_init_entry, "respawn");
247 void cleanup(int exitcode)
259 void title(char *text)
261 if (setup_type == UI_TEXT) {
262 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
268 int yesno(char *question)
271 newtComponent form = NULL;
272 newtComponent yesbutton = NULL;
273 newtComponent nobutton = NULL;
274 int prompt_window_height = 0;
280 switch (setup_type) {
284 printf("%s\nYes/No --> ", question);
285 fgets(buf, sizeof buf, stdin);
286 answer = tolower(buf[0]);
289 else if (answer == 'n')
291 } while ((answer < 0) || (answer > 1));
295 sprintf(buf, "exec %s --yesno '%s' 10 72",
296 getenv("CTDL_DIALOG"),
309 prompt_window_height = num_tokens(question, '\n') + 5;
310 newtCenteredWindow(76, prompt_window_height, "Question");
311 form = newtForm(NULL, NULL, 0);
312 for (i=0; i<num_tokens(question, '\n'); ++i) {
313 extract_token(buf, question, i, '\n', sizeof buf);
314 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
316 yesbutton = newtButton(10, (prompt_window_height - 4), "Yes");
317 nobutton = newtButton(60, (prompt_window_height - 4), "No");
318 newtFormAddComponent(form, yesbutton);
319 newtFormAddComponent(form, nobutton);
320 if (newtRunForm(form) == yesbutton) {
327 newtFormDestroy(form);
337 void important_message(char *title, char *msgtext)
340 newtComponent form = NULL;
345 switch (setup_type) {
348 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");
349 printf(" %s \n\n%s\n\n", title, msgtext);
350 printf("Press return to continue...");
351 fgets(buf, sizeof buf, stdin);
355 sprintf(buf, "exec %s --msgbox '%s' 19 72",
356 getenv("CTDL_DIALOG"),
363 newtCenteredWindow(76, 10, title);
364 form = newtForm(NULL, NULL, 0);
365 for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
366 extract_token(buf, msgtext, i, '\n', sizeof buf);
367 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
369 newtFormAddComponent(form, newtButton(35, 5, "OK"));
372 newtFormDestroy(form);
379 void important_msgnum(int msgnum)
381 important_message("Important Message", setup_text[msgnum]);
384 void display_error(char *error_message)
386 important_message("Error", error_message);
389 void progress(char *text, long int curr, long int cmax)
393 /* These variables are static because progress() gets called
394 * multiple times during the course of whatever operation is
395 * being performed. This makes setup non-threadsafe, but who
398 static newtComponent form = NULL;
399 static newtComponent scale = NULL;
401 static long dots_printed = 0L;
403 static FILE *fp = NULL;
406 switch (setup_type) {
410 printf("%s\n", text);
411 printf("..........................");
412 printf("..........................");
413 printf("..........................\r");
416 } else if (curr == cmax) {
417 printf("\r%79s\n", "");
419 a = (curr * 100) / cmax;
422 while (dots_printed < a) {
432 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
433 getenv("CTDL_DIALOG"),
435 fp = popen(buf, "w");
441 else if (curr == cmax) {
443 fprintf(fp, "100\n");
449 a = (curr * 100) / cmax;
451 fprintf(fp, "%ld\n", a);
460 newtCenteredWindow(76, 8, text);
461 form = newtForm(NULL, NULL, 0);
462 scale = newtScale(1, 3, 74, cmax);
463 newtFormAddComponent(form, scale);
467 if ((curr > 0) && (curr <= cmax)) {
468 newtScaleSet(scale, curr);
472 newtFormDestroy(form);
485 * check_services_entry() -- Make sure "citadel" is in /etc/services
488 void check_services_entry(void)
493 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
494 for (i=0; i<=3; ++i) {
495 progress("Adding service entry...", i, 3);
497 sfp = fopen("/etc/services", "a");
499 display_error(strerror(errno));
501 fprintf(sfp, "%s 504/tcp\n",
513 * Generate a unique entry name for a new inittab entry
515 void generate_entry_name(char *entryname) {
518 snprintf(entryname, sizeof entryname, "c0");
521 if (entryname[1] > '9') {
524 if (entryname[0] > 'z') {
526 "Can't generate a unique entry name");
530 snprintf(buf, sizeof buf,
531 "grep %s: /etc/inittab >/dev/null 2>&1", entryname);
532 } while (system(buf) == 0);
538 * check_inittab_entry() -- Make sure "citadel" is in /etc/inittab
541 void check_inittab_entry(void)
544 char looking_for[SIZ];
548 /* Determine the fully qualified path name of citserver */
549 snprintf(looking_for,
558 locate_init_entry(citserver_init_entry, looking_for);
560 /* If there's already an entry, then we have nothing left to do. */
561 if (strlen(citserver_init_entry) > 0) {
565 /* Otherwise, prompt the user to create an entry. */
566 if (getenv("CREATE_INITTAB_ENTRY") != NULL) {
567 if (strcasecmp(getenv("CREATE_INITTAB_ENTRY"), "yes")) {
572 snprintf(question, sizeof question,
573 "Do you want this computer configured to start the Citadel\n"
574 "service automatically? (If you answer yes, an entry in\n"
575 "/etc/inittab pointing to %s will be added.)\n",
577 if (yesno(question) == 0) {
582 /* Generate a unique entry name for /etc/inittab */
583 generate_entry_name(entryname);
585 /* Now write it out to /etc/inittab */
586 infp = fopen("/etc/inittab", "a");
588 display_error(strerror(errno));
590 fprintf(infp, "# Start the Citadel server...\n");
591 fprintf(infp, "%s:2345:respawn:%s %s%s -llocal4\n",
594 (enable_home)?"-h":"",
595 (enable_home)?setup_directory:"");
597 strcpy(citserver_init_entry, entryname);
603 * On systems which use xinetd, see if we can offer to install Citadel as
604 * the default telnet target.
606 void check_xinetd_entry(void) {
607 char *filename = "/etc/xinetd.d/telnet";
610 int already_citadel = 0;
612 fp = fopen(filename, "r+");
613 if (fp == NULL) return; /* Not there. Oh well... */
615 while (fgets(buf, sizeof buf, fp) != NULL) {
616 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
619 if (already_citadel) return; /* Already set up this way. */
621 /* Otherwise, prompt the user to create an entry. */
622 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
623 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
628 snprintf(buf, sizeof buf,
629 "Setup can configure the \"xinetd\" service to automatically\n"
630 "connect incoming telnet sessions to Citadel, bypassing the\n"
631 "host system login: prompt. Would you like to do this?\n"
633 if (yesno(buf) == 0) {
638 fp = fopen(filename, "w");
640 "# description: telnet service for Citadel users\n"
645 " socket_type = stream\n"
648 " server = /usr/sbin/in.telnetd\n"
649 " server_args = -h -L %s/citadel\n"
650 " log_on_failure += USERID\n"
660 /* Now try to restart the service */
661 system("/etc/init.d/xinetd restart >/dev/null 2>&1");
667 * Offer to disable other MTA's
669 void disable_other_mta(char *mta) {
674 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
675 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
677 fp = popen(buf, "r");
678 if (fp == NULL) return;
680 while (fgets(buf, sizeof buf, fp) != NULL) {
684 if (lines == 0) return; /* Nothing to do. */
687 /* Offer to replace other MTA with the vastly superior Citadel :) */
689 if (getenv("ACT_AS_MTA")) {
690 if (strcasecmp(getenv("ACT_AS_MTA"), "yes")) {
695 snprintf(buf, sizeof buf,
696 "You appear to have the \"%s\" email program\n"
697 "running on your system. If you want Citadel mail\n"
698 "connected with %s, you will have to manually integrate\n"
699 "them. It is preferable to disable %s, and use Citadel's\n"
700 "SMTP, POP3, and IMAP services.\n\n"
701 "May we disable %s so that Citadel has access to ports\n"
702 "25, 110, and 143?\n",
705 if (yesno(buf) == 0) {
710 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);
712 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
720 * Check to see if our server really works. Returns 0 on success.
722 int test_server(void) {
729 /* Generate a silly little cookie. We're going to write it out
730 * to the server and try to get it back. The cookie does not
731 * have to be secret ... just unique.
733 sprintf(cookie, "--test--%d--", getpid());
735 sprintf(cmd, "%s/sendcommand %s%s ECHO %s 2>&1",
741 (enable_home)?"-h":"",
742 (enable_home)?setup_directory:"",
745 fp = popen(cmd, "r");
746 if (fp == NULL) return(errno);
748 while (fgets(buf, sizeof buf, fp) != NULL) {
750 && (strstr(buf, cookie) != NULL) ) {
762 void strprompt(char *prompt_title, char *prompt_text, char *str)
768 int prompt_window_height = 0;
772 char dialog_result[PATH_MAX];
775 strcpy(setupmsg, "");
777 switch (setup_type) {
780 printf("\n%s\n", prompt_text);
781 printf("This is currently set to:\n%s\n", str);
782 printf("Enter new value or press return to leave unchanged:\n");
783 fgets(buf, sizeof buf, stdin);
784 buf[strlen(buf) - 1] = 0;
785 if (strlen(buf) != 0)
790 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
791 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
792 getenv("CTDL_DIALOG"),
797 fp = fopen(dialog_result, "r");
799 fgets(str, sizeof buf, fp);
800 if (str[strlen(str)-1] == 10) {
801 str[strlen(str)-1] = 0;
804 unlink(dialog_result);
811 prompt_window_height = num_tokens(prompt_text, '\n') + 5 ;
812 newtCenteredWindow(76,
813 prompt_window_height,
815 form = newtForm(NULL, NULL, 0);
816 for (i=0; i<num_tokens(prompt_text, '\n'); ++i) {
817 extract_token(buf, prompt_text, i, '\n', sizeof buf);
818 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
820 newtFormAddComponent(form,
822 (prompt_window_height - 2),
825 (const char **) &result,
826 NEWT_FLAG_RETURNEXIT)
832 newtFormDestroy(form);
838 void set_str_val(int msgpos, char *str) {
839 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
844 void set_int_val(int msgpos, int *ip)
847 snprintf(buf, sizeof buf, "%d", (int) *ip);
848 set_str_val(msgpos, buf);
853 void set_char_val(int msgpos, char *ip)
856 snprintf(buf, sizeof buf, "%d", (int) *ip);
857 set_str_val(msgpos, buf);
858 *ip = (char) atoi(buf);
862 void set_long_val(int msgpos, long int *ip)
865 snprintf(buf, sizeof buf, "%ld", *ip);
866 set_str_val(msgpos, buf);
871 void edit_value(int curr)
875 char ctdluidname[SIZ];
880 if (getenv("SYSADMIN_NAME")) {
881 strcpy(config.c_sysadm, getenv("SYSADMIN_NAME"));
884 set_str_val(curr, config.c_sysadm);
890 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
892 i = config.c_ctdluid;
895 set_int_val(curr, &i);
896 config.c_ctdluid = i;
899 strcpy(ctdluidname, pw->pw_name);
900 set_str_val(curr, ctdluidname);
901 pw = getpwnam(ctdluidname);
903 config.c_ctdluid = pw->pw_uid;
905 else if (atoi(ctdluidname) > 0) {
906 config.c_ctdluid = atoi(ctdluidname);
913 set_str_val(curr, config.c_ip_addr);
917 set_int_val(curr, &config.c_port_number);
925 * (re-)write the config data to disk
927 void write_config_to_disk(void)
932 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
933 display_error("setup: cannot open citadel.config");
936 fp = fdopen(fd, "wb");
938 display_error("setup: cannot open citadel.config");
941 fwrite((char *) &config, sizeof(struct config), 1, fp);
949 * Figure out what type of user interface we're going to use
951 int discover_ui(void)
954 /* Use "dialog" if we have it */
955 if (getenv("CTDL_DIALOG") != NULL) {
963 newtDrawRootText(0, 0, "Citadel Setup");
974 * Strip "db" entries out of /etc/nsswitch.conf
984 int file_changed = 0;
985 char new_filename[64];
987 fp_read = fopen(NSSCONF, "r");
988 if (fp_read == NULL) {
992 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
993 fd_write = mkstemp(new_filename);
999 while (fgets(buf, sizeof buf, fp_read) != NULL) {
1001 strcpy(buf_nc, buf);
1002 for (i=0; i<strlen(buf_nc); ++i) {
1003 if (buf_nc[i] == '#') {
1007 for (i=0; i<strlen(buf_nc); ++i) {
1008 if (!strncasecmp(&buf_nc[i], "db", 2)) {
1010 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
1013 strcpy(&buf_nc[i], &buf_nc[i+2]);
1014 strcpy(&buf[i], &buf[i+2]);
1016 strcpy(&buf_nc[i], &buf_nc[i+1]);
1017 strcpy(&buf[i], &buf[i+1]);
1023 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
1026 unlink(new_filename);
1033 if (!file_changed) {
1034 unlink(new_filename);
1038 snprintf(question, sizeof question,
1040 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
1041 "one or more services. This is not necessary on most systems,\n"
1042 "and it is known to crash the Citadel server when delivering\n"
1043 "mail to the Internet.\n"
1045 "Do you want this module to be automatically disabled?\n"
1049 if (yesno(question)) {
1050 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
1053 unlink(new_filename);
1063 int main(int argc, char *argv[])
1069 int old_setup_level = 0;
1071 struct utsname my_utsname;
1077 char relhome[PATH_MAX]="";
1078 char ctdldir[PATH_MAX]=CTDLDIR;
1080 /* set an invalid setup type */
1083 /* Learn whether to skip the auto-service-start questions */
1084 fp = fopen("/etc/inittab", "r");
1090 /* Check to see if we're running the web installer */
1091 if (getenv("CITADEL_INSTALLER") != NULL) {
1092 using_web_installer = 1;
1095 /* parse command line args */
1096 for (a = 0; a < argc; ++a) {
1097 if (!strncmp(argv[a], "-u", 2)) {
1098 strcpy(aaa, argv[a]);
1099 strcpy(aaa, &aaa[2]);
1100 setup_type = atoi(aaa);
1102 if (!strcmp(argv[a], "-i")) {
1105 if (!strcmp(argv[a], "-q")) {
1106 setup_type = UI_SILENT;
1111 /* If a setup type was not specified, try to determine automatically
1112 * the best one to use out of all available types.
1114 if (setup_type < 0) {
1115 setup_type = discover_ui();
1117 if (info_only == 1) {
1118 important_message("Citadel Setup", CITADEL);
1122 /* Get started in a valid setup directory. */
1123 strcpy(setup_directory,
1130 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
1131 strcpy(setup_directory, getenv("CITADEL"));
1134 set_str_val(0, setup_directory);
1137 home=(setup_directory[1]!='\0');
1138 relh=home&(setup_directory[1]!='/');
1140 safestrncpy(ctdl_home_directory, setup_directory, sizeof ctdl_home_directory);
1143 safestrncpy(relhome, ctdl_home_directory, sizeof relhome);
1146 calc_dirs_n_files(relh, home, relhome, ctdldir);
1148 enable_home=(relh|home);
1151 if (chdir(setup_directory) == 0) {
1152 strcpy(file_citadel_config, "./citadel.config");
1155 important_message("Citadel Setup",
1156 "The directory you specified does not exist.");
1161 /* Determine our host name, in case we need to use it as a default */
1164 if (have_sysv_init) {
1165 /* See if we need to shut down the Citadel service. */
1166 for (a=0; a<=3; ++a) {
1167 progress("Shutting down the Citadel service...", a, 3);
1168 if (a == 0) shutdown_citserver();
1172 /* Make sure it's stopped. */
1173 if (test_server() == 0) {
1174 important_message("Citadel Setup",
1175 "The Citadel service is still running.\n"
1176 "Please stop the service manually and run "
1183 switch (setup_type) {
1187 " *** Citadel setup program ***\n\n");
1193 * What we're going to try to do here is append a whole bunch of
1194 * nulls to the citadel.config file, so we can keep the old config
1195 * values if they exist, but if the file is missing or from an
1196 * earlier version with a shorter config structure, when setup tries
1197 * to read the old config parameters, they'll all come up zero.
1198 * The length of the config file will be set to what it's supposed
1199 * to be when we rewrite it, because we replace the old file with a
1200 * completely new copy.
1202 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1203 S_IRUSR | S_IWUSR)) == -1) {
1204 display_error("setup: cannot append citadel.config");
1207 fp = fdopen(a, "ab");
1209 display_error("setup: cannot append citadel.config");
1212 for (a = 0; a < sizeof(struct config); ++a)
1216 /* now we re-open it, and read the old or blank configuration */
1217 fp = fopen(file_citadel_config, "rb");
1219 display_error("setup: cannot open citadel.config");
1222 fread((char *) &config, sizeof(struct config), 1, fp);
1225 /* set some sample/default values in place of blanks... */
1226 if (strlen(config.c_nodename) == 0)
1227 safestrncpy(config.c_nodename, my_utsname.nodename,
1228 sizeof config.c_nodename);
1229 strtok(config.c_nodename, ".");
1230 if (strlen(config.c_fqdn) == 0) {
1231 if ((he = gethostbyname(my_utsname.nodename)) != NULL)
1232 safestrncpy(config.c_fqdn, he->h_name,
1233 sizeof config.c_fqdn);
1235 safestrncpy(config.c_fqdn, my_utsname.nodename,
1236 sizeof config.c_fqdn);
1238 if (strlen(config.c_humannode) == 0)
1239 strcpy(config.c_humannode, "My System");
1240 if (strlen(config.c_phonenum) == 0)
1241 strcpy(config.c_phonenum, "US 800 555 1212");
1242 if (config.c_initax == 0) {
1243 config.c_initax = 4;
1245 if (strlen(config.c_moreprompt) == 0)
1246 strcpy(config.c_moreprompt, "<more>");
1247 if (strlen(config.c_twitroom) == 0)
1248 strcpy(config.c_twitroom, "Trashcan");
1249 if (strlen(config.c_baseroom) == 0)
1250 strcpy(config.c_baseroom, BASEROOM);
1251 if (strlen(config.c_aideroom) == 0)
1252 strcpy(config.c_aideroom, "Aide");
1253 if (config.c_port_number == 0) {
1254 config.c_port_number = 504;
1256 if (config.c_sleeping == 0) {
1257 config.c_sleeping = 900;
1259 if (config.c_ctdluid == 0) {
1260 pw = getpwnam("citadel");
1262 config.c_ctdluid = pw->pw_uid;
1264 if (config.c_ctdluid == 0) {
1265 pw = getpwnam("bbs");
1267 config.c_ctdluid = pw->pw_uid;
1269 if (config.c_ctdluid == 0) {
1270 pw = getpwnam("guest");
1272 config.c_ctdluid = pw->pw_uid;
1274 if (config.c_createax == 0) {
1275 config.c_createax = 3;
1278 * Negative values for maxsessions are not allowed.
1280 if (config.c_maxsessions < 0) {
1281 config.c_maxsessions = 0;
1283 /* We need a system default message expiry policy, because this is
1284 * the top level and there's no 'higher' policy to fall back on.
1285 * By default, do not expire messages at all.
1287 if (config.c_ep.expire_mode == 0) {
1288 config.c_ep.expire_mode = EXPIRE_MANUAL;
1289 config.c_ep.expire_value = 0;
1293 * Default port numbers for various services
1295 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1296 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1297 if (config.c_imap_port == 0) config.c_imap_port = 143;
1298 if (config.c_msa_port == 0) config.c_msa_port = 587;
1299 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1300 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1301 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1303 /* Go through a series of dialogs prompting for config info */
1304 if (setup_type != UI_SILENT) {
1305 for (curr = 1; curr <= MAXSETUP; ++curr) {
1310 /***** begin version update section ***** */
1311 /* take care of any updating that is necessary */
1313 old_setup_level = config.c_setup_level;
1315 if (old_setup_level == 0) {
1319 if (old_setup_level < 555) {
1320 important_message("Citadel Setup",
1321 "This Citadel installation is too old "
1325 write_config_to_disk();
1327 old_setup_level = config.c_setup_level;
1329 /* end of version update section */
1332 config.c_setup_level = REV_LEVEL;
1334 /******************************************/
1336 write_config_to_disk();
1338 mkdir(ctdl_info_dir, 0700);
1339 chmod(ctdl_info_dir, 0700);
1340 chown(ctdl_info_dir, config.c_ctdluid, -1);
1342 mkdir(ctdl_bio_dir, 0700);
1343 chmod(ctdl_bio_dir, 0700);
1344 chown(ctdl_bio_dir, config.c_ctdluid, -1);
1346 mkdir(ctdl_usrpic_dir, 0700);
1347 chmod(ctdl_usrpic_dir, 0700);
1348 chown(ctdl_usrpic_dir, config.c_ctdluid, -1);
1350 mkdir(ctdl_message_dir, 0700);
1351 chmod(ctdl_message_dir, 0700);
1352 chown(ctdl_message_dir, config.c_ctdluid, -1);
1354 mkdir(ctdl_hlp_dir, 0700);
1355 chmod(ctdl_hlp_dir, 0700);
1356 chown(ctdl_hlp_dir, config.c_ctdluid, -1);
1358 mkdir(ctdl_image_dir, 0700);
1359 chmod(ctdl_image_dir, 0700);
1360 chown(ctdl_image_dir, config.c_ctdluid, -1);
1362 mkdir(ctdl_bb_dir, 0700);
1363 chmod(ctdl_bb_dir, 0700);
1364 chown(ctdl_bb_dir, config.c_ctdluid, -1);
1366 mkdir(ctdl_file_dir, 0700);
1367 chmod(ctdl_file_dir, 0700);
1368 chown(ctdl_file_dir, config.c_ctdluid, -1);
1370 mkdir(ctdl_netcfg_dir, 0700);
1371 chmod(ctdl_netcfg_dir, 0700);
1372 chown(ctdl_netcfg_dir, config.c_ctdluid, -1);
1374 /* TODO: where to put this? */
1375 mkdir("netconfigs", 0700);
1376 chmod("netconfigs", 0700);
1377 chown("netconfigs", config.c_ctdluid, -1);
1379 /* Delete files and directories used by older Citadel versions */
1380 system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1381 unlink("citadel.log");
1384 check_services_entry(); /* Check /etc/services */
1386 if (have_sysv_init) {
1387 check_inittab_entry(); /* Check /etc/inittab */
1389 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1391 /* Offer to disable other MTA's on the system. */
1392 disable_other_mta("courier-authdaemon");
1393 disable_other_mta("courier-imap");
1394 disable_other_mta("courier-imap-ssl");
1395 disable_other_mta("courier-pop");
1396 disable_other_mta("courier-pop3");
1397 disable_other_mta("courier-pop3d");
1398 disable_other_mta("cyrmaster");
1399 disable_other_mta("cyrus");
1400 disable_other_mta("dovecot");
1401 disable_other_mta("exim");
1402 disable_other_mta("exim4");
1403 disable_other_mta("hula");
1404 disable_other_mta("imapd");
1405 disable_other_mta("mta");
1406 disable_other_mta("pop3d");
1407 disable_other_mta("popd");
1408 disable_other_mta("postfix");
1409 disable_other_mta("qmail");
1410 disable_other_mta("saslauthd");
1411 disable_other_mta("sendmail");
1412 disable_other_mta("vmailmgrd");
1413 disable_other_mta("zimbra");
1416 /* Check for the 'db' nss and offer to disable it */
1419 if ((pw = getpwuid(config.c_ctdluid)) == NULL)
1424 progress("Setting file permissions", 0, 4);
1425 chown(".", config.c_ctdluid, gid);
1427 progress("Setting file permissions", 1, 4);
1428 chown(file_citadel_config, config.c_ctdluid, gid);
1430 progress("Setting file permissions", 2, 4);
1432 snprintf(aaa, sizeof aaa,
1435 chown(aaa,0,0); /* config.c_ctdluid, gid); chkpwd needs to be root owned*/
1437 progress("Setting file permissions", 3, 4);
1441 progress("Setting file permissions", 3, 4);
1442 chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1444 progress("Setting file permissions", 4, 4);
1447 /* Contemplate the possibility of auto-configuring OpenLDAP */
1451 /* See if we can start the Citadel service. */
1452 if ( (have_sysv_init) && (strlen(citserver_init_entry) > 0) ) {
1453 for (a=0; a<=3; ++a) {
1454 progress("Starting the Citadel service...", a, 3);
1455 if (a == 0) start_citserver();
1458 if (test_server() == 0) {
1459 important_message("Setup finished",
1460 "Setup of the Citadel server is complete.\n"
1461 "If you will be using WebCit, please run its\n"
1462 "setup program now; otherwise, run './citadel'\n"
1466 important_message("Setup finished",
1467 "Setup is finished, but the Citadel service "
1468 "failed to start.\n"
1469 "Go back and check your configuration.");
1473 important_message("Setup finished",
1474 "Setup is finished. You may now start the server.");
1484 * If we're in the middle of an Easy Install, we might just be able to
1485 * auto-configure a standalone OpenLDAP server.
1487 void contemplate_ldap(void) {
1489 char slapd_init_entry[SIZ];
1492 /* If conditions are not ideal, give up on this idea... */
1493 if (!have_sysv_init) return;
1494 if (using_web_installer == 0) return;
1495 if (getenv("LDAP_CONFIG") == NULL) return;
1496 if (getenv("SUPPORT") == NULL) return;
1497 if (getenv("SLAPD_BINARY") == NULL) return;
1498 if (getenv("CITADEL") == NULL) return;
1500 /* And if inittab is already starting slapd, bail out... */
1501 locate_init_entry(slapd_init_entry, getenv("SLAPD_BINARY"));
1502 if (strlen(slapd_init_entry) > 0) {
1503 important_message("Citadel Setup",
1504 "You appear to already have a standalone LDAP "
1505 "service\nconfigured for use with Citadel. No "
1506 "changes will be made.\n");
1507 /* set_init_entry(slapd_init_entry, "off"); */
1511 /* Generate a unique entry name for slapd if we don't have one. */
1513 generate_entry_name(slapd_init_entry);
1516 /* Ask the user if it's ok to set up slapd automatically. */
1517 snprintf(question, sizeof question,
1519 "Do you want this computer configured to start a standalone\n"
1520 "LDAP service automatically? (If you answer yes, a new\n"
1521 "slapd.conf will be written, and an /etc/inittab entry\n"
1522 "pointing to %s will be added.)\n"
1524 getenv("SLAPD_BINARY")
1526 if (yesno(question) == 0)
1529 strcpy(config.c_ldap_base_dn, "dc=example,dc=com");
1530 strprompt("Base DN",
1532 "Please enter the Base DN for your directory. This will\n"
1533 "generally be something based on the primary DNS domain in\n"
1534 "which you receive mail, but it does not have to be. Your\n"
1535 "LDAP tree will be built using this Distinguished Name.\n"
1537 config.c_ldap_base_dn
1540 strcpy(config.c_ldap_host, "localhost");
1541 config.c_ldap_port = 389;
1542 sprintf(config.c_ldap_bind_dn, "cn=manager,%s", config.c_ldap_base_dn);
1545 * Generate a bind password. If you're some grey hat hacker who
1546 * is just dying to get some street cred on Bugtraq, and you think
1547 * this password generation scheme is too weak, please submit a patch
1548 * instead of just whining about it, ok?
1550 sprintf(config.c_ldap_bind_pw, "%d%ld", getpid(), (long)time(NULL));
1552 write_config_to_disk();
1554 fp = fopen(getenv("LDAP_CONFIG"), "w");
1556 sprintf(question, "\nCannot create %s:\n%s\n\n"
1557 "Citadel will still function, but you will "
1558 "not have an LDAP service.\n\n",
1559 getenv("LDAP_CONFIG"),
1562 important_message("Error", question);
1566 fprintf(fp, "include %s/citadel-openldap.schema\n",
1568 fprintf(fp, "pidfile %s/openldap-data/slapd.pid\n",
1570 fprintf(fp, "argsfile %s/openldap-data/slapd.args\n",
1572 fprintf(fp, "allow bind_v2\n"
1576 fprintf(fp, "suffix \"%s\"\n", config.c_ldap_base_dn);
1577 fprintf(fp, "rootdn \"%s\"\n", config.c_ldap_bind_dn);
1578 fprintf(fp, "rootpw %s\n", config.c_ldap_bind_pw);
1579 fprintf(fp, "directory %s/openldap-data\n",
1581 fprintf(fp, "index objectClass eq\n");
1585 /* This is where our OpenLDAP server will keep its data. */
1586 mkdir("openldap-data", 0700);
1588 /* Now write it out to /etc/inittab.
1589 * FIXME make it run as some non-root user.
1590 * The "-d 0" seems superfluous, but it's actually a way to make
1591 * slapd run in the foreground without spewing messages to the console.
1593 fp = fopen("/etc/inittab", "a");
1595 display_error(strerror(errno));
1597 fprintf(fp, "# Start the OpenLDAP server for Citadel...\n");
1598 fprintf(fp, "%s:2345:respawn:%s -d 0 -f %s\n",
1600 getenv("SLAPD_BINARY"),
1601 getenv("LDAP_CONFIG")
1607 #endif /* HAVE_LDAP */