4 * Citadel setup utility
14 #include <sys/types.h>
16 #include <sys/utsname.h>
35 #define MAXSETUP 4 /* How many setup questions to ask */
37 #define UI_TEXT 0 /* Default setup type -- text only */
38 #define UI_DIALOG 2 /* Use the 'dialog' program */
39 #define UI_SILENT 3 /* Silent running, for use in scripts */
40 #define UI_NEWT 4 /* Use the "newt" window library */
42 #define SERVICE_NAME "citadel"
43 #define PROTO_NAME "tcp"
46 char setup_directory[SIZ];
47 char citserver_init_entry[SIZ];
48 int using_web_installer = 0;
51 void contemplate_ldap(void);
54 char *setup_titles[] =
56 "Citadel Home Directory",
57 "System Administrator",
64 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 name of the system administrator (which is probably\n"
71 "you). When an account is created with this name, it will\n"
72 "automatically be assigned the highest access level.\n",
74 "Citadel needs to run under its own user ID. This would\n"
75 "typically be called \"citadel\", but if you are running Citadel\n"
76 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
77 "The server will run under this user ID. Please specify that\n"
78 "user ID here. You may specify either a user name or a numeric\n"
81 "Specify the IP address on which your server will run. If you\n"
82 "leave this blank, or if you specify 0.0.0.0, Citadel will listen\n"
83 "on all addresses. You can usually skip this unless you are\n"
84 "running multiple instances of Citadel on the same computer.\n",
86 "Specify the TCP port number on which your server will run.\n"
87 "Normally, this will be port 504, which is the official port\n"
88 "assigned by the IANA for Citadel servers. You will only need\n"
89 "to specify a different port number if you run multiple instances\n"
90 "of Citadel on the same computer and there is something else\n"
91 "already using port 504.\n",
99 * Set an entry in inittab to the desired state
101 void set_init_entry(char *which_entry, char *new_state) {
102 char *inittab = NULL;
110 if (which_entry == NULL) return;
111 if (strlen(which_entry) == 0) return;
113 inittab = strdup("");
114 if (inittab == NULL) return;
116 fp = fopen("/etc/inittab", "r");
117 if (fp == NULL) return;
119 while(fgets(buf, sizeof buf, fp) != NULL) {
121 if (num_tokens(buf, ':') == 4) {
122 extract_token(entry, buf, 0, ':');
123 extract_token(levels, buf, 1, ':');
124 extract_token(state, buf, 2, ':');
125 extract_token(prog, buf, 3, ':'); /* includes 0x0a LF */
127 if (!strcmp(entry, which_entry)) {
128 strcpy(state, new_state);
129 sprintf(buf, "%s:%s:%s:%s",
130 entry, levels, state, prog);
134 inittab = realloc(inittab, strlen(inittab) + strlen(buf) + 2);
135 if (inittab == NULL) {
140 strcat(inittab, buf);
143 fp = fopen("/etc/inittab", "w");
145 fwrite(inittab, strlen(inittab), 1, fp);
147 kill(1, SIGHUP); /* Tell init to re-read /etc/inittab */
154 * Locate the name of an inittab entry for a specific program
156 void locate_init_entry(char *init_entry, char *program) {
161 char looking_for[SIZ];
165 strcpy(init_entry, "");
167 /* Pound through /etc/inittab line by line. Set have_entry to 1 if
168 * an entry is found which we believe starts the specified program.
170 infp = fopen("/etc/inittab", "r");
174 while (fgets(buf, sizeof buf, infp) != NULL) {
175 buf[strlen(buf) - 1] = 0;
176 extract_token(entry, buf, 0, ':');
177 extract_token(prog, buf, 3, ':');
178 if (!strncasecmp(prog, looking_for,
179 strlen(looking_for))) {
181 strcpy(init_entry, entry);
191 * Shut down the Citadel service if necessary, during setup.
193 void shutdown_citserver(void) {
194 char looking_for[SIZ];
196 snprintf(looking_for, sizeof looking_for, "%s/citserver", BBSDIR);
197 locate_init_entry(citserver_init_entry, looking_for);
198 if (strlen(citserver_init_entry) > 0) {
199 set_init_entry(citserver_init_entry, "off");
205 * Start the Citadel service.
207 void start_citserver(void) {
208 if (strlen(citserver_init_entry) > 0) {
209 set_init_entry(citserver_init_entry, "respawn");
215 void cleanup(int exitcode)
227 void title(char *text)
229 if (setup_type == UI_TEXT) {
230 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
236 int yesno(char *question)
239 newtComponent form = NULL;
240 newtComponent yesbutton = NULL;
241 newtComponent nobutton = NULL;
242 int prompt_window_height = 0;
248 switch (setup_type) {
252 printf("%s\nYes/No --> ", question);
253 fgets(buf, sizeof buf, stdin);
254 answer = tolower(buf[0]);
257 else if (answer == 'n')
259 } while ((answer < 0) || (answer > 1));
263 sprintf(buf, "exec %s --yesno '%s' 10 72",
264 getenv("CTDL_DIALOG"),
277 prompt_window_height = num_tokens(question, '\n') + 5;
278 newtCenteredWindow(76, prompt_window_height, "Question");
279 form = newtForm(NULL, NULL, 0);
280 for (i=0; i<num_tokens(question, '\n'); ++i) {
281 extract_token(buf, question, i, '\n');
282 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
284 yesbutton = newtButton(10, (prompt_window_height - 4), "Yes");
285 nobutton = newtButton(60, (prompt_window_height - 4), "No");
286 newtFormAddComponent(form, yesbutton);
287 newtFormAddComponent(form, nobutton);
288 if (newtRunForm(form) == yesbutton) {
295 newtFormDestroy(form);
305 void important_message(char *title, char *msgtext)
308 newtComponent form = NULL;
313 switch (setup_type) {
316 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");
317 printf(" %s \n\n%s\n\n", title, msgtext);
318 printf("Press return to continue...");
319 fgets(buf, sizeof buf, stdin);
323 sprintf(buf, "exec %s --backtitle '%s' --msgbox '%s' 19 72",
324 getenv("CTDL_DIALOG"),
332 newtCenteredWindow(76, 10, title);
333 form = newtForm(NULL, NULL, 0);
334 for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
335 extract_token(buf, msgtext, i, '\n');
336 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
338 newtFormAddComponent(form, newtButton(35, 5, "OK"));
341 newtFormDestroy(form);
348 void important_msgnum(int msgnum)
350 important_message("Important Message", setup_text[msgnum]);
353 void display_error(char *error_message)
355 important_message("Error", error_message);
358 void progress(char *text, long int curr, long int cmax)
362 /* These variables are static because progress() gets called
363 * multiple times during the course of whatever operation is
364 * being performed. This makes setup non-threadsafe, but who
367 static newtComponent form = NULL;
368 static newtComponent scale = NULL;
370 static long dots_printed = 0L;
372 static FILE *fp = NULL;
375 switch (setup_type) {
379 printf("%s\n", text);
380 printf("..........................");
381 printf("..........................");
382 printf("..........................\r");
385 } else if (curr == cmax) {
386 printf("\r%79s\n", "");
388 a = (curr * 100) / cmax;
391 while (dots_printed < a) {
401 sprintf(buf, "exec %s --gauge '%s' 7 72",
402 getenv("CTDL_DIALOG"),
404 fp = popen(buf, "w");
410 else if (curr == cmax) {
412 fprintf(fp, "100\n");
418 a = (curr * 100) / cmax;
420 fprintf(fp, "%ld\n", a);
429 newtCenteredWindow(76, 8, text);
430 form = newtForm(NULL, NULL, 0);
431 scale = newtScale(1, 3, 74, cmax);
432 newtFormAddComponent(form, scale);
436 if ((curr > 0) && (curr <= cmax)) {
437 newtScaleSet(scale, curr);
441 newtFormDestroy(form);
454 * check_services_entry() -- Make sure "citadel" is in /etc/services
457 void check_services_entry(void)
462 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
463 for (i=0; i<=3; ++i) {
464 progress("Adding service entry...", i, 3);
466 sfp = fopen("/etc/services", "a");
468 display_error(strerror(errno));
470 fprintf(sfp, "%s 504/tcp\n",
482 * Generate a unique entry name for a new inittab entry
484 void generate_entry_name(char *entryname) {
487 snprintf(entryname, sizeof entryname, "c0");
490 if (entryname[1] > '9') {
493 if (entryname[0] > 'z') {
495 "Can't generate a unique entry name");
499 snprintf(buf, sizeof buf,
500 "grep %s: /etc/inittab >/dev/null 2>&1", entryname);
501 } while (system(buf) == 0);
507 * check_inittab_entry() -- Make sure "citadel" is in /etc/inittab
510 void check_inittab_entry(void)
513 char looking_for[SIZ];
517 /* Determine the fully qualified path name of citserver */
518 snprintf(looking_for, sizeof looking_for, "%s/citserver", BBSDIR);
519 locate_init_entry(citserver_init_entry, looking_for);
521 /* If there's already an entry, then we have nothing left to do. */
522 if (strlen(citserver_init_entry) > 0) {
526 /* Otherwise, prompt the user to create an entry. */
527 snprintf(question, sizeof question,
528 "Do you want this computer configured to start the Citadel\n"
529 "service automatically? (If you answer yes, an entry in\n"
530 "/etc/inittab pointing to %s will be added.)\n",
532 if (yesno(question) == 0)
535 /* Generate a unique entry name for /etc/inittab */
536 generate_entry_name(entryname);
538 /* Now write it out to /etc/inittab */
539 infp = fopen("/etc/inittab", "a");
541 display_error(strerror(errno));
543 fprintf(infp, "# Start the Citadel server...\n");
544 fprintf(infp, "%s:2345:respawn:%s -h%s -x3 -llocal4\n",
545 entryname, looking_for, setup_directory);
547 strcpy(citserver_init_entry, entryname);
553 * On systems which use xinetd, see if we can offer to install Citadel as
554 * the default telnet target.
556 void check_xinetd_entry(void) {
557 char *filename = "/etc/xinetd.d/telnet";
560 int already_citadel = 0;
562 fp = fopen(filename, "r+");
563 if (fp == NULL) return; /* Not there. Oh well... */
565 while (fgets(buf, sizeof buf, fp) != NULL) {
566 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
569 if (already_citadel) return; /* Already set up this way. */
571 /* Otherwise, prompt the user to create an entry. */
572 snprintf(buf, sizeof buf,
573 "Setup can configure the \"xinetd\" service to automatically\n"
574 "connect incoming telnet sessions to Citadel, bypassing the\n"
575 "host system login: prompt. Would you like to do this?\n"
580 fp = fopen(filename, "w");
582 "# description: telnet service for Citadel users\n"
587 " socket_type = stream\n"
590 " server = /usr/sbin/in.telnetd\n"
591 " server_args = -h -L %s/citadel\n"
592 " log_on_failure += USERID\n"
598 /* Now try to restart the service */
599 system("/etc/init.d/xinetd restart >/dev/null 2>&1");
605 * Offer to disable other MTA's
607 void disable_other_mta(char *mta) {
612 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null", mta);
613 fp = popen(buf, "r");
614 if (fp == NULL) return;
616 while (fgets(buf, sizeof buf, fp) != NULL) {
620 if (lines == 0) return; /* Nothing to do. */
622 /* Offer to replace other MTA with the vastly superior Citadel :) */
623 snprintf(buf, sizeof buf,
624 "You appear to have the \"%s\" email program\n"
625 "running on your system. Would you like to disable it,\n"
626 "allowing Citadel to handle your Internet mail instead?\n",
632 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);
634 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
642 * Check to see if our server really works. Returns 0 on success.
644 int test_server(void) {
651 /* Generate a silly little cookie. We're going to write it out
652 * to the server and try to get it back. The cookie does not
653 * have to be secret ... just unique.
655 sprintf(cookie, "%ld.%d", time(NULL), getpid());
657 sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
662 fp = popen(cmd, "r");
663 if (fp == NULL) return(errno);
665 while (fgets(buf, sizeof buf, fp) != NULL) {
667 && (strstr(buf, cookie) != NULL) ) {
679 void strprompt(char *prompt_title, char *prompt_text, char *str)
685 int prompt_window_height = 0;
692 strcpy(setupmsg, "");
694 switch (setup_type) {
697 printf("\n%s\n", prompt_text);
698 printf("This is currently set to:\n%s\n", str);
699 printf("Enter new value or press return to leave unchanged:\n");
700 fgets(buf, sizeof buf, stdin);
701 buf[strlen(buf) - 1] = 0;
702 if (strlen(buf) != 0)
707 dialog_result = tmpnam(NULL);
708 sprintf(buf, "exec %s --backtitle '%s' --inputbox '%s' 19 72 '%s' 2>%s",
709 getenv("CTDL_DIALOG"),
715 fp = fopen(dialog_result, "r");
717 fgets(str, sizeof buf, fp);
718 if (str[strlen(str)-1] == 10) {
719 str[strlen(str)-1] = 0;
722 unlink(dialog_result);
729 prompt_window_height = num_tokens(prompt_text, '\n') + 5 ;
730 newtCenteredWindow(76,
731 prompt_window_height,
733 form = newtForm(NULL, NULL, 0);
734 for (i=0; i<num_tokens(prompt_text, '\n'); ++i) {
735 extract_token(buf, prompt_text, i, '\n');
736 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
738 newtFormAddComponent(form,
740 (prompt_window_height - 2),
744 NEWT_FLAG_RETURNEXIT)
750 newtFormDestroy(form);
756 void set_str_val(int msgpos, char *str) {
757 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
762 void set_int_val(int msgpos, int *ip)
765 snprintf(buf, sizeof buf, "%d", (int) *ip);
766 set_str_val(msgpos, buf);
771 void set_char_val(int msgpos, char *ip)
774 snprintf(buf, sizeof buf, "%d", (int) *ip);
775 set_str_val(msgpos, buf);
776 *ip = (char) atoi(buf);
780 void set_long_val(int msgpos, long int *ip)
783 snprintf(buf, sizeof buf, "%ld", *ip);
784 set_str_val(msgpos, buf);
789 void edit_value(int curr)
793 char bbsuidname[SIZ];
798 set_str_val(curr, config.c_sysadm);
803 config.c_bbsuid = 0; /* XXX Windows hack, prob. insecure */
808 set_int_val(curr, &i);
812 strcpy(bbsuidname, pw->pw_name);
813 set_str_val(curr, bbsuidname);
814 pw = getpwnam(bbsuidname);
816 config.c_bbsuid = pw->pw_uid;
818 else if (atoi(bbsuidname) > 0) {
819 config.c_bbsuid = atoi(bbsuidname);
826 set_str_val(curr, config.c_ip_addr);
830 set_int_val(curr, &config.c_port_number);
838 * (re-)write the config data to disk
840 void write_config_to_disk(void)
845 if ((fd = creat("citadel.config", S_IRUSR | S_IWUSR)) == -1) {
846 display_error("setup: cannot open citadel.config");
849 fp = fdopen(fd, "wb");
851 display_error("setup: cannot open citadel.config");
854 fwrite((char *) &config, sizeof(struct config), 1, fp);
862 * Figure out what type of user interface we're going to use
864 int discover_ui(void)
867 /* Use "dialog" if we have it */
868 if (getenv("CTDL_DIALOG") != NULL) {
876 newtDrawRootText(0, 0, "Citadel Setup");
886 int main(int argc, char *argv[])
892 int old_setup_level = 0;
894 struct utsname my_utsname;
899 /* set an invalid setup type */
902 /* Check to see if we're running the web installer */
903 if (getenv("CITADEL_INSTALLER") != NULL) {
904 using_web_installer = 1;
907 /* parse command line args */
908 for (a = 0; a < argc; ++a) {
909 if (!strncmp(argv[a], "-u", 2)) {
910 strcpy(aaa, argv[a]);
911 strcpy(aaa, &aaa[2]);
912 setup_type = atoi(aaa);
914 if (!strcmp(argv[a], "-i")) {
917 if (!strcmp(argv[a], "-q")) {
918 setup_type = UI_SILENT;
923 /* If a setup type was not specified, try to determine automatically
924 * the best one to use out of all available types.
926 if (setup_type < 0) {
927 setup_type = discover_ui();
929 if (info_only == 1) {
930 important_message("Citadel Setup", CITADEL);
934 /* Get started in a valid setup directory. */
935 strcpy(setup_directory, BBSDIR);
936 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
937 strcpy(setup_directory, getenv("CITADEL"));
940 set_str_val(0, setup_directory);
943 if (chdir(setup_directory) != 0) {
944 important_message("Citadel Setup",
945 "The directory you specified does not exist.");
949 /* Determine our host name, in case we need to use it as a default */
952 /* See if we need to shut down the Citadel service. */
953 for (a=0; a<=3; ++a) {
954 progress("Shutting down the Citadel service...", a, 3);
955 if (a == 0) shutdown_citserver();
959 /* Make sure it's stopped. */
960 if (test_server() == 0) {
961 important_message("Citadel Setup",
962 "The Citadel service is still running.\n"
963 "Please stop the service manually and run "
969 switch (setup_type) {
973 " *** Citadel setup program ***\n\n");
979 * What we're going to try to do here is append a whole bunch of
980 * nulls to the citadel.config file, so we can keep the old config
981 * values if they exist, but if the file is missing or from an
982 * earlier version with a shorter config structure, when setup tries
983 * to read the old config parameters, they'll all come up zero.
984 * The length of the config file will be set to what it's supposed
985 * to be when we rewrite it, because we replace the old file with a
986 * completely new copy.
989 if ((a = open("citadel.config", O_WRONLY | O_CREAT | O_APPEND,
990 S_IRUSR | S_IWUSR)) == -1) {
991 display_error("setup: cannot append citadel.config");
994 fp = fdopen(a, "ab");
996 display_error("setup: cannot append citadel.config");
999 for (a = 0; a < sizeof(struct config); ++a)
1003 /* now we re-open it, and read the old or blank configuration */
1004 fp = fopen("citadel.config", "rb");
1006 display_error("setup: cannot open citadel.config");
1009 fread((char *) &config, sizeof(struct config), 1, fp);
1012 /* set some sample/default values in place of blanks... */
1013 if (strlen(config.c_nodename) == 0)
1014 safestrncpy(config.c_nodename, my_utsname.nodename,
1015 sizeof config.c_nodename);
1016 strtok(config.c_nodename, ".");
1017 if (strlen(config.c_fqdn) == 0) {
1018 if ((he = gethostbyname(my_utsname.nodename)) != NULL)
1019 safestrncpy(config.c_fqdn, he->h_name,
1020 sizeof config.c_fqdn);
1022 safestrncpy(config.c_fqdn, my_utsname.nodename,
1023 sizeof config.c_fqdn);
1025 if (strlen(config.c_humannode) == 0)
1026 strcpy(config.c_humannode, "My System");
1027 if (strlen(config.c_phonenum) == 0)
1028 strcpy(config.c_phonenum, "US 800 555 1212");
1029 if (config.c_initax == 0) {
1030 config.c_initax = 4;
1032 if (strlen(config.c_moreprompt) == 0)
1033 strcpy(config.c_moreprompt, "<more>");
1034 if (strlen(config.c_twitroom) == 0)
1035 strcpy(config.c_twitroom, "Trashcan");
1036 if (strlen(config.c_baseroom) == 0)
1037 strcpy(config.c_baseroom, "Lobby");
1038 if (strlen(config.c_aideroom) == 0)
1039 strcpy(config.c_aideroom, "Aide");
1040 if (config.c_port_number == 0) {
1041 config.c_port_number = 504;
1043 if (config.c_sleeping == 0) {
1044 config.c_sleeping = 900;
1046 if (config.c_bbsuid == 0) {
1047 pw = getpwnam("citadel");
1049 config.c_bbsuid = pw->pw_uid;
1051 if (config.c_bbsuid == 0) {
1052 pw = getpwnam("bbs");
1054 config.c_bbsuid = pw->pw_uid;
1056 if (config.c_bbsuid == 0) {
1057 pw = getpwnam("guest");
1059 config.c_bbsuid = pw->pw_uid;
1061 if (config.c_createax == 0) {
1062 config.c_createax = 3;
1065 * Negative values for maxsessions are not allowed.
1067 if (config.c_maxsessions < 0) {
1068 config.c_maxsessions = 0;
1070 /* We need a system default message expiry policy, because this is
1071 * the top level and there's no 'higher' policy to fall back on.
1073 if (config.c_ep.expire_mode == 0) {
1074 config.c_ep.expire_mode = EXPIRE_NUMMSGS;
1075 config.c_ep.expire_value = 150;
1079 * Default port numbers for various services
1081 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1082 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1083 if (config.c_imap_port == 0) config.c_imap_port = 143;
1085 /* Go through a series of dialogs prompting for config info */
1086 if (setup_type != UI_SILENT) {
1087 for (curr = 1; curr <= MAXSETUP; ++curr) {
1093 if (setuid(config.c_bbsuid) != 0) {
1094 important_message("Citadel Setup",
1095 "Failed to change the user ID to your Citadel user.");
1100 /***** begin version update section ***** */
1101 /* take care of any updating that is necessary */
1103 old_setup_level = config.c_setup_level;
1105 if (old_setup_level == 0) {
1109 if (old_setup_level < 555) {
1110 important_message("Citadel Setup",
1111 "This Citadel installation is too old "
1115 write_config_to_disk();
1117 old_setup_level = config.c_setup_level;
1119 /* end of version update section */
1122 config.c_setup_level = REV_LEVEL;
1124 /******************************************/
1126 write_config_to_disk();
1128 mkdir("info", 0700);
1129 chmod("info", 0700);
1132 mkdir("userpics", 0700);
1133 chmod("userpics", 0700);
1134 mkdir("messages", 0700);
1135 chmod("messages", 0700);
1136 mkdir("help", 0700);
1137 chmod("help", 0700);
1138 mkdir("images", 0700);
1139 chmod("images", 0700);
1140 mkdir("netconfigs", 0700);
1141 chmod("netconfigs", 0700);
1143 /* Delete files and directories used by older Citadel versions */
1144 system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1145 unlink("citadel.log");
1148 check_services_entry(); /* Check /etc/services */
1150 check_inittab_entry(); /* Check /etc/inittab */
1151 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1153 /* Offer to disable other MTA's on the system. */
1154 disable_other_mta("sendmail");
1155 disable_other_mta("postfix");
1156 disable_other_mta("qmail");
1157 disable_other_mta("cyrus");
1158 disable_other_mta("cyrmaster");
1159 disable_other_mta("saslauthd");
1160 disable_other_mta("mta");
1161 disable_other_mta("courier-imap");
1162 disable_other_mta("courier-imap-ssl");
1163 disable_other_mta("courier-authdaemon");
1164 disable_other_mta("courier-pop3");
1165 disable_other_mta("courier-pop3d");
1166 disable_other_mta("courier-pop");
1167 disable_other_mta("vmailmgrd");
1168 disable_other_mta("imapd");
1169 disable_other_mta("popd");
1170 disable_other_mta("pop3d");
1171 disable_other_mta("exim");
1174 if ((pw = getpwuid(config.c_bbsuid)) == NULL)
1179 progress("Setting file permissions", 0, 4);
1180 chown(".", config.c_bbsuid, gid);
1182 progress("Setting file permissions", 1, 4);
1183 chown("citadel.config", config.c_bbsuid, gid);
1185 progress("Setting file permissions", 2, 4);
1186 snprintf(aaa, sizeof aaa,
1187 "find . | grep -v chkpwd | xargs chown %ld:%ld 2>/dev/null",
1188 (long)config.c_bbsuid, (long)gid);
1191 progress("Setting file permissions", 3, 4);
1192 chmod("citadel.config", S_IRUSR | S_IWUSR);
1194 progress("Setting file permissions", 4, 4);
1197 /* Contemplate the possibility of auto-configuring OpenLDAP */
1201 /* See if we can start the Citadel service. */
1202 if (strlen(citserver_init_entry) > 0) {
1203 for (a=0; a<=3; ++a) {
1204 progress("Starting the Citadel service...", a, 3);
1205 if (a == 0) start_citserver();
1208 if (test_server() == 0) {
1209 important_message("Setup finished",
1210 "Setup is finished. You may now log in.");
1213 important_message("Setup finished",
1214 "Setup is finished, but the Citadel service "
1215 "failed to start.\n"
1216 "Go back and check your configuration.");
1220 important_message("Setup finished",
1221 "Setup is finished. You may now start the server.");
1231 * If we're in the middle of an Easy Install, we might just be able to
1232 * auto-configure a standalone OpenLDAP server.
1234 void contemplate_ldap(void) {
1236 char slapd_init_entry[SIZ];
1239 /* If conditions are not ideal, give up on this idea. */
1240 if (using_web_installer == 0) return;
1241 if (getenv("LDAP_CONFIG") == NULL) return;
1242 if (getenv("SUPPORT") == NULL) return;
1243 if (getenv("SLAPD_BINARY") == NULL) return;
1244 if (getenv("CITADEL") == NULL) return;
1246 /* Otherwise, prompt the user to create an entry. */
1247 snprintf(question, sizeof question,
1249 "Do you want this computer configured to start a standalone\n"
1250 "LDAP service automatically? (If you answer yes, a custom\n"
1251 "slapd.conf will be written, and an /etc/inittab entry\n"
1252 "pointing to %s will be added.)\n"
1254 getenv("SLAPD_BINARY")
1256 if (yesno(question) == 0)
1259 strcpy(config.c_ldap_base_dn, "dc=example,dc=com");
1260 strprompt("Base DN",
1262 "Please enter the Base DN for your directory. This will\n"
1263 "generally be something based on the primary DNS domain in\n"
1264 "which you receive mail, but it does not have to be. Your\n"
1265 "LDAP tree will be built using this Distinguished Name.\n"
1267 config.c_ldap_base_dn
1270 strcpy(config.c_ldap_host, "localhost");
1271 config.c_ldap_port = 389;
1272 sprintf(config.c_ldap_bind_dn, "cn=manager,%s", config.c_ldap_base_dn);
1274 /* FIXME ... make the generated password harder to guess */
1275 sprintf(config.c_ldap_bind_pw, "%d%ld", getpid(), time(NULL));
1277 write_config_to_disk();
1279 fp = fopen(getenv("LDAP_CONFIG"), "w");
1281 sprintf(question, "\nCannot create %s:\n%s\n\n"
1282 "Citadel will still function, but you will "
1283 "not have an LDAP service.\n\n",
1284 getenv("LDAP_CONFIG"),
1287 important_message("Error", question);
1291 fprintf(fp, "include %s/citadel-openldap.schema\n",
1293 fprintf(fp, "pidfile %s/openldap-data/slapd.pid\n",
1295 fprintf(fp, "argsfile %s/openldap-data/slapd.args\n",
1297 fprintf(fp, "allow bind_v2\n"
1301 fprintf(fp, "suffix \"%s\"\n", config.c_ldap_base_dn);
1302 fprintf(fp, "rootdn \"%s\"\n", config.c_ldap_bind_dn);
1303 fprintf(fp, "rootpw %s\n", config.c_ldap_bind_pw);
1304 fprintf(fp, "directory %s/openldap-data\n",
1306 fprintf(fp, "index objectClass eq\n");
1310 /* This is where our OpenLDAP server will keep its data. */
1311 mkdir("openldap-data", 0700);
1313 /* If inittab is already starting slapd, disable the old entry. */
1314 locate_init_entry(slapd_init_entry, getenv("SLAPD_BINARY"));
1315 if (strlen(slapd_init_entry) > 0) {
1316 set_init_entry(slapd_init_entry, "off");
1319 /* Generate a unique entry name for slapd */
1320 generate_entry_name(slapd_init_entry);
1322 /* Now write it out to /etc/inittab.
1323 * FIXME make it run as some non-root user.
1324 * The "-d 0" seems superfluous, but it's actually a way to make
1325 * slapd run in the foreground without spewing messages to the console.
1327 fp = fopen("/etc/inittab", "a");
1329 display_error(strerror(errno));
1331 fprintf(fp, "# Start the OpenLDAP server for Citadel...\n");
1332 fprintf(fp, "%s:2345:respawn:%s -d 0 -f %s\n",
1334 getenv("SLAPD_BINARY"),
1335 getenv("LDAP_CONFIG")
1341 #endif /* HAVE_LDAP */