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",
66 "Enter the full pathname of the directory in which the Citadel installation\n"
67 "you are creating or updating resides. If you specify a directory other\n"
68 "than the default, you will need to specify the -h flag to the server when\n"
71 "Enter the name of the system administrator (which is probably you).\n"
72 "When an account is created with this name, it will automatically be\n"
73 "assigned the highest access level.\n",
75 "Citadel needs to run under its own user ID. This would typically be\n"
76 "called \"citadel\", but if you are running Citadel as a public BBS, you\n"
77 "might also call it \"bbs\" or \"guest\". The server will run under this\n"
78 "user ID. Please specify that user ID here. You may specify either a\n"
79 "user name or a numeric UID.\n",
81 "Specify the IP address on which your server will run. If you leave this\n"
82 "blank, or if you specify 0.0.0.0, Citadel will listen on all addresses.\n"
83 "You can usually skip this unless you are running multiple instances of\n"
84 "Citadel on the same computer.\n",
86 "Specify the TCP port number on which your server will run. Normally, this\n"
87 "will be port 504, which is the official port assigned by the IANA for\n"
88 "Citadel servers. You will only need to specify a different port number if\n"
89 "you run multiple instances of Citadel on the same computer and there is\n"
90 "something else already using port 504.\n",
98 * Set an entry in inittab to the desired state
100 void set_init_entry(char *which_entry, char *new_state) {
101 char *inittab = NULL;
109 if (which_entry == NULL) return;
110 if (strlen(which_entry) == 0) return;
112 inittab = strdup("");
113 if (inittab == NULL) return;
115 fp = fopen("/etc/inittab", "r");
116 if (fp == NULL) return;
118 while(fgets(buf, sizeof buf, fp) != NULL) {
120 if (num_tokens(buf, ':') == 4) {
121 extract_token(entry, buf, 0, ':');
122 extract_token(levels, buf, 1, ':');
123 extract_token(state, buf, 2, ':');
124 extract_token(prog, buf, 3, ':'); /* includes 0x0a LF */
126 if (!strcmp(entry, which_entry)) {
127 strcpy(state, new_state);
128 sprintf(buf, "%s:%s:%s:%s",
129 entry, levels, state, prog);
133 inittab = realloc(inittab, strlen(inittab) + strlen(buf) + 2);
134 if (inittab == NULL) {
139 strcat(inittab, buf);
142 fp = fopen("/etc/inittab", "w");
144 fwrite(inittab, strlen(inittab), 1, fp);
146 kill(1, SIGHUP); /* Tell init to re-read /etc/inittab */
153 * Locate the name of an inittab entry for a specific program
155 void locate_init_entry(char *init_entry, char *program) {
160 char looking_for[SIZ];
164 strcpy(init_entry, "");
166 /* Pound through /etc/inittab line by line. Set have_entry to 1 if
167 * an entry is found which we believe starts the specified program.
169 infp = fopen("/etc/inittab", "r");
173 while (fgets(buf, sizeof buf, infp) != NULL) {
174 buf[strlen(buf) - 1] = 0;
175 extract_token(entry, buf, 0, ':');
176 extract_token(prog, buf, 3, ':');
177 if (!strncasecmp(prog, looking_for,
178 strlen(looking_for))) {
180 strcpy(init_entry, entry);
190 * Shut down the Citadel service if necessary, during setup.
192 void shutdown_citserver(void) {
193 char looking_for[SIZ];
195 snprintf(looking_for, sizeof looking_for, "%s/citserver", BBSDIR);
196 locate_init_entry(citserver_init_entry, looking_for);
197 if (strlen(citserver_init_entry) > 0) {
198 set_init_entry(citserver_init_entry, "off");
204 * Start the Citadel service.
206 void start_citserver(void) {
207 if (strlen(citserver_init_entry) > 0) {
208 set_init_entry(citserver_init_entry, "respawn");
214 void cleanup(int exitcode)
226 void title(char *text)
228 if (setup_type == UI_TEXT) {
229 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
235 int yesno(char *question)
238 newtComponent form = NULL;
239 newtComponent yesbutton = NULL;
240 newtComponent nobutton = NULL;
242 int prompt_window_height = 0;
247 switch (setup_type) {
251 printf("%s\nYes/No --> ", question);
252 fgets(buf, sizeof buf, stdin);
253 answer = tolower(buf[0]);
256 else if (answer == 'n')
258 } while ((answer < 0) || (answer > 1));
262 sprintf(buf, "%s --yesno '%s' 0 0",
263 getenv("CTDL_DIALOG"),
274 prompt_window_height = num_tokens(question, '\n') + 5;
275 newtCenteredWindow(76, prompt_window_height, "Question");
276 form = newtForm(NULL, NULL, 0);
277 for (i=0; i<num_tokens(question, '\n'); ++i) {
278 extract_token(buf, question, i, '\n');
279 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
281 yesbutton = newtButton(10, (prompt_window_height - 4), "Yes");
282 nobutton = newtButton(60, (prompt_window_height - 4), "No");
283 newtFormAddComponent(form, yesbutton);
284 newtFormAddComponent(form, nobutton);
285 if (newtRunForm(form) == yesbutton) {
292 newtFormDestroy(form);
302 void important_message(char *title, char *msgtext)
305 newtComponent form = NULL;
310 switch (setup_type) {
313 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");
314 printf(" %s \n\n%s\n\n", title, msgtext);
315 printf("Press return to continue...");
316 fgets(buf, sizeof buf, stdin);
320 sprintf(buf, "%s --backtitle '%s' --msgbox '%s' 0 0",
321 getenv("CTDL_DIALOG"),
329 newtCenteredWindow(76, 10, title);
330 form = newtForm(NULL, NULL, 0);
331 for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
332 extract_token(buf, msgtext, i, '\n');
333 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
335 newtFormAddComponent(form, newtButton(35, 5, "OK"));
338 newtFormDestroy(form);
345 void important_msgnum(int msgnum)
347 important_message("Important Message", setup_text[msgnum]);
350 void display_error(char *error_message)
352 important_message("Error", error_message);
355 void progress(char *text, long int curr, long int cmax)
359 /* These variables are static because progress() gets called
360 * multiple times during the course of whatever operation is
361 * being performed. This makes setup non-threadsafe, but who
364 static newtComponent form = NULL;
365 static newtComponent scale = NULL;
367 static long dots_printed = 0L;
369 static FILE *fp = NULL;
372 switch (setup_type) {
376 printf("%s\n", text);
377 printf("..........................");
378 printf("..........................");
379 printf("..........................\r");
382 } else if (curr == cmax) {
383 printf("\r%79s\n", "");
385 a = (curr * 100) / cmax;
388 while (dots_printed < a) {
398 sprintf(buf, "%s --gauge '%s' 10 72",
399 getenv("CTDL_DIALOG"),
401 fp = popen(buf, "w");
406 else if (curr == cmax) {
408 fprintf(fp, "100\n");
414 a = (curr * 100) / cmax;
416 fprintf(fp, "%ld\n", a);
425 newtCenteredWindow(76, 8, text);
426 form = newtForm(NULL, NULL, 0);
427 scale = newtScale(1, 3, 74, cmax);
428 newtFormAddComponent(form, scale);
432 if ((curr > 0) && (curr <= cmax)) {
433 newtScaleSet(scale, curr);
437 newtFormDestroy(form);
450 * check_services_entry() -- Make sure "citadel" is in /etc/services
453 void check_services_entry(void)
458 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
459 for (i=0; i<3; ++i) {
460 progress("Adding service entry...", i, 3);
462 sfp = fopen("/etc/services", "a");
464 display_error(strerror(errno));
466 fprintf(sfp, "%s 504/tcp\n",
478 * Generate a unique entry name for a new inittab entry
480 void generate_entry_name(char *entryname) {
483 snprintf(entryname, sizeof entryname, "c0");
486 if (entryname[1] > '9') {
489 if (entryname[0] > 'z') {
491 "Can't generate a unique entry name");
495 snprintf(buf, sizeof buf,
496 "grep %s: /etc/inittab >/dev/null 2>&1", entryname);
497 } while (system(buf) == 0);
503 * check_inittab_entry() -- Make sure "citadel" is in /etc/inittab
506 void check_inittab_entry(void)
509 char looking_for[SIZ];
513 /* Determine the fully qualified path name of citserver */
514 snprintf(looking_for, sizeof looking_for, "%s/citserver", BBSDIR);
515 locate_init_entry(citserver_init_entry, looking_for);
517 /* If there's already an entry, then we have nothing left to do. */
518 if (strlen(citserver_init_entry) > 0) {
522 /* Otherwise, prompt the user to create an entry. */
523 snprintf(question, sizeof question,
524 "Do you want this computer configured to start the Citadel\n"
525 "service automatically? (If you answer yes, an entry in\n"
526 "/etc/inittab pointing to %s will be added.)\n",
528 if (yesno(question) == 0)
531 /* Generate a unique entry name for /etc/inittab */
532 generate_entry_name(entryname);
534 /* Now write it out to /etc/inittab */
535 infp = fopen("/etc/inittab", "a");
537 display_error(strerror(errno));
539 fprintf(infp, "# Start the Citadel server...\n");
540 fprintf(infp, "%s:2345:respawn:%s -h%s -x3 -llocal4\n",
541 entryname, looking_for, setup_directory);
543 strcpy(citserver_init_entry, entryname);
549 * On systems which use xinetd, see if we can offer to install Citadel as
550 * the default telnet target.
552 void check_xinetd_entry(void) {
553 char *filename = "/etc/xinetd.d/telnet";
556 int already_citadel = 0;
558 fp = fopen(filename, "r+");
559 if (fp == NULL) return; /* Not there. Oh well... */
561 while (fgets(buf, sizeof buf, fp) != NULL) {
562 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
565 if (already_citadel) return; /* Already set up this way. */
567 /* Otherwise, prompt the user to create an entry. */
568 snprintf(buf, sizeof buf,
569 "Setup can configure the \"xinetd\" service to automatically\n"
570 "connect incoming telnet sessions to Citadel, bypassing the\n"
571 "host system login: prompt. Would you like to do this?\n"
576 fp = fopen(filename, "w");
578 "# description: telnet service for Citadel users\n"
583 " socket_type = stream\n"
586 " server = /usr/sbin/in.telnetd\n"
587 " server_args = -h -L %s/citadel\n"
588 " log_on_failure += USERID\n"
594 /* Now try to restart the service */
595 system("/etc/init.d/xinetd restart >/dev/null 2>&1");
601 * Offer to disable other MTA's
603 void disable_other_mta(char *mta) {
608 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null", mta);
609 fp = popen(buf, "r");
610 if (fp == NULL) return;
612 while (fgets(buf, sizeof buf, fp) != NULL) {
616 if (lines == 0) return; /* Nothing to do. */
618 /* Offer to replace other MTA with the vastly superior Citadel :) */
619 snprintf(buf, sizeof buf,
620 "You appear to have the \"%s\" email program\n"
621 "running on your system. Would you like to disable it,\n"
622 "allowing Citadel to handle your Internet mail instead?\n",
628 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);
630 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
638 * Check to see if our server really works. Returns 0 on success.
640 int test_server(void) {
647 /* Generate a silly little cookie. We're going to write it out
648 * to the server and try to get it back. The cookie does not
649 * have to be secret ... just unique.
651 sprintf(cookie, "%ld.%d", time(NULL), getpid());
653 sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
658 fp = popen(cmd, "r");
659 if (fp == NULL) return(errno);
661 while (fgets(buf, sizeof buf, fp) != NULL) {
663 && (strstr(buf, cookie) != NULL) ) {
675 void strprompt(char *prompt_title, char *prompt_text, char *str)
681 int prompt_window_height = 0;
688 strcpy(setupmsg, "");
690 switch (setup_type) {
693 printf("\n%s\n", prompt_text);
694 printf("This is currently set to:\n%s\n", str);
695 printf("Enter new value or press return to leave unchanged:\n");
696 fgets(buf, sizeof buf, stdin);
697 buf[strlen(buf) - 1] = 0;
698 if (strlen(buf) != 0)
703 dialog_result = tmpnam(NULL);
704 sprintf(buf, "%s --backtitle '%s' --inputbox '%s' 0 0 '%s' 2>%s",
705 getenv("CTDL_DIALOG"),
711 fp = fopen(dialog_result, "r");
713 fgets(str, sizeof buf, fp);
714 if (str[strlen(str)-1] == 10) {
715 str[strlen(str)-1] = 0;
718 unlink(dialog_result);
725 prompt_window_height = num_tokens(prompt_text, '\n') + 5 ;
726 newtCenteredWindow(76,
727 prompt_window_height,
729 form = newtForm(NULL, NULL, 0);
730 for (i=0; i<num_tokens(prompt_text, '\n'); ++i) {
731 extract_token(buf, prompt_text, i, '\n');
732 newtFormAddComponent(form, newtLabel(1, 1+i, buf));
734 newtFormAddComponent(form,
736 (prompt_window_height - 2),
740 NEWT_FLAG_RETURNEXIT)
746 newtFormDestroy(form);
752 void set_str_val(int msgpos, char *str) {
753 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
758 void set_int_val(int msgpos, int *ip)
761 snprintf(buf, sizeof buf, "%d", (int) *ip);
762 set_str_val(msgpos, buf);
767 void set_char_val(int msgpos, char *ip)
770 snprintf(buf, sizeof buf, "%d", (int) *ip);
771 set_str_val(msgpos, buf);
772 *ip = (char) atoi(buf);
776 void set_long_val(int msgpos, long int *ip)
779 snprintf(buf, sizeof buf, "%ld", *ip);
780 set_str_val(msgpos, buf);
785 void edit_value(int curr)
789 char bbsuidname[SIZ];
794 set_str_val(curr, config.c_sysadm);
799 config.c_bbsuid = 0; /* XXX Windows hack, prob. insecure */
804 set_int_val(curr, &i);
808 strcpy(bbsuidname, pw->pw_name);
809 set_str_val(curr, bbsuidname);
810 pw = getpwnam(bbsuidname);
812 config.c_bbsuid = pw->pw_uid;
814 else if (atoi(bbsuidname) > 0) {
815 config.c_bbsuid = atoi(bbsuidname);
822 set_str_val(curr, config.c_ip_addr);
826 set_int_val(curr, &config.c_port_number);
834 * (re-)write the config data to disk
836 void write_config_to_disk(void)
841 if ((fd = creat("citadel.config", S_IRUSR | S_IWUSR)) == -1) {
842 display_error("setup: cannot open citadel.config");
845 fp = fdopen(fd, "wb");
847 display_error("setup: cannot open citadel.config");
850 fwrite((char *) &config, sizeof(struct config), 1, fp);
858 * Figure out what type of user interface we're going to use
860 int discover_ui(void)
863 /* Use "dialog" if we have it */
864 if (getenv("CTDL_DIALOG") != NULL) {
872 newtDrawRootText(0, 0, "Citadel Setup");
882 int main(int argc, char *argv[])
888 int old_setup_level = 0;
890 struct utsname my_utsname;
895 /* set an invalid setup type */
898 /* Check to see if we're running the web installer */
899 if (getenv("CITADEL_INSTALLER") != NULL) {
900 using_web_installer = 1;
903 /* parse command line args */
904 for (a = 0; a < argc; ++a) {
905 if (!strncmp(argv[a], "-u", 2)) {
906 strcpy(aaa, argv[a]);
907 strcpy(aaa, &aaa[2]);
908 setup_type = atoi(aaa);
910 if (!strcmp(argv[a], "-i")) {
913 if (!strcmp(argv[a], "-q")) {
914 setup_type = UI_SILENT;
919 /* If a setup type was not specified, try to determine automatically
920 * the best one to use out of all available types.
922 if (setup_type < 0) {
923 setup_type = discover_ui();
925 if (info_only == 1) {
926 important_message("Citadel Setup", CITADEL);
930 /* Get started in a valid setup directory. */
931 strcpy(setup_directory, BBSDIR);
932 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
933 strcpy(setup_directory, getenv("CITADEL"));
936 set_str_val(0, setup_directory);
939 if (chdir(setup_directory) != 0) {
940 important_message("Citadel Setup",
941 "The directory you specified does not exist.");
945 /* Determine our host name, in case we need to use it as a default */
948 /* See if we need to shut down the Citadel service. */
949 for (a=0; a<=3; ++a) {
950 progress("Shutting down the Citadel service...", a, 3);
951 if (a == 0) shutdown_citserver();
955 /* Make sure it's stopped. */
956 if (test_server() == 0) {
957 important_message("Citadel Setup",
958 "The Citadel service is still running.\n"
959 "Please stop the service manually and run "
965 switch (setup_type) {
969 " *** Citadel setup program ***\n\n");
975 * What we're going to try to do here is append a whole bunch of
976 * nulls to the citadel.config file, so we can keep the old config
977 * values if they exist, but if the file is missing or from an
978 * earlier version with a shorter config structure, when setup tries
979 * to read the old config parameters, they'll all come up zero.
980 * The length of the config file will be set to what it's supposed
981 * to be when we rewrite it, because we replace the old file with a
982 * completely new copy.
985 if ((a = open("citadel.config", O_WRONLY | O_CREAT | O_APPEND,
986 S_IRUSR | S_IWUSR)) == -1) {
987 display_error("setup: cannot append citadel.config");
990 fp = fdopen(a, "ab");
992 display_error("setup: cannot append citadel.config");
995 for (a = 0; a < sizeof(struct config); ++a)
999 /* now we re-open it, and read the old or blank configuration */
1000 fp = fopen("citadel.config", "rb");
1002 display_error("setup: cannot open citadel.config");
1005 fread((char *) &config, sizeof(struct config), 1, fp);
1008 /* set some sample/default values in place of blanks... */
1009 if (strlen(config.c_nodename) == 0)
1010 safestrncpy(config.c_nodename, my_utsname.nodename,
1011 sizeof config.c_nodename);
1012 strtok(config.c_nodename, ".");
1013 if (strlen(config.c_fqdn) == 0) {
1014 if ((he = gethostbyname(my_utsname.nodename)) != NULL)
1015 safestrncpy(config.c_fqdn, he->h_name,
1016 sizeof config.c_fqdn);
1018 safestrncpy(config.c_fqdn, my_utsname.nodename,
1019 sizeof config.c_fqdn);
1021 if (strlen(config.c_humannode) == 0)
1022 strcpy(config.c_humannode, "My System");
1023 if (strlen(config.c_phonenum) == 0)
1024 strcpy(config.c_phonenum, "US 800 555 1212");
1025 if (config.c_initax == 0) {
1026 config.c_initax = 4;
1028 if (strlen(config.c_moreprompt) == 0)
1029 strcpy(config.c_moreprompt, "<more>");
1030 if (strlen(config.c_twitroom) == 0)
1031 strcpy(config.c_twitroom, "Trashcan");
1032 if (strlen(config.c_baseroom) == 0)
1033 strcpy(config.c_baseroom, "Lobby");
1034 if (strlen(config.c_aideroom) == 0)
1035 strcpy(config.c_aideroom, "Aide");
1036 if (config.c_port_number == 0) {
1037 config.c_port_number = 504;
1039 if (config.c_sleeping == 0) {
1040 config.c_sleeping = 900;
1042 if (config.c_bbsuid == 0) {
1043 pw = getpwnam("citadel");
1045 config.c_bbsuid = pw->pw_uid;
1047 if (config.c_bbsuid == 0) {
1048 pw = getpwnam("bbs");
1050 config.c_bbsuid = pw->pw_uid;
1052 if (config.c_bbsuid == 0) {
1053 pw = getpwnam("guest");
1055 config.c_bbsuid = pw->pw_uid;
1057 if (config.c_createax == 0) {
1058 config.c_createax = 3;
1061 * Negative values for maxsessions are not allowed.
1063 if (config.c_maxsessions < 0) {
1064 config.c_maxsessions = 0;
1066 /* We need a system default message expiry policy, because this is
1067 * the top level and there's no 'higher' policy to fall back on.
1069 if (config.c_ep.expire_mode == 0) {
1070 config.c_ep.expire_mode = EXPIRE_NUMMSGS;
1071 config.c_ep.expire_value = 150;
1075 * Default port numbers for various services
1077 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1078 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1079 if (config.c_imap_port == 0) config.c_imap_port = 143;
1081 /* Go through a series of dialogs prompting for config info */
1082 if (setup_type != UI_SILENT) {
1083 for (curr = 1; curr <= MAXSETUP; ++curr) {
1089 if (setuid(config.c_bbsuid) != 0) {
1090 important_message("Citadel Setup",
1091 "Failed to change the user ID to your Citadel user.");
1096 /***** begin version update section ***** */
1097 /* take care of any updating that is necessary */
1099 old_setup_level = config.c_setup_level;
1101 if (old_setup_level == 0) {
1105 if (old_setup_level < 555) {
1106 important_message("Citadel Setup",
1107 "This Citadel installation is too old "
1111 write_config_to_disk();
1113 old_setup_level = config.c_setup_level;
1115 /* end of version update section */
1118 config.c_setup_level = REV_LEVEL;
1120 /******************************************/
1122 write_config_to_disk();
1124 mkdir("info", 0700);
1125 chmod("info", 0700);
1128 mkdir("userpics", 0700);
1129 chmod("userpics", 0700);
1130 mkdir("messages", 0700);
1131 chmod("messages", 0700);
1132 mkdir("help", 0700);
1133 chmod("help", 0700);
1134 mkdir("images", 0700);
1135 chmod("images", 0700);
1136 mkdir("netconfigs", 0700);
1137 chmod("netconfigs", 0700);
1139 /* Delete files and directories used by older Citadel versions */
1140 system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1141 unlink("citadel.log");
1144 check_services_entry(); /* Check /etc/services */
1146 check_inittab_entry(); /* Check /etc/inittab */
1147 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1149 /* Offer to disable other MTA's on the system. */
1150 disable_other_mta("sendmail");
1151 disable_other_mta("postfix");
1152 disable_other_mta("qmail");
1153 disable_other_mta("cyrus");
1154 disable_other_mta("cyrmaster");
1155 disable_other_mta("saslauthd");
1156 disable_other_mta("mta");
1157 disable_other_mta("courier-imap");
1158 disable_other_mta("courier-imap-ssl");
1159 disable_other_mta("courier-authdaemon");
1160 disable_other_mta("courier-pop3");
1161 disable_other_mta("courier-pop3d");
1162 disable_other_mta("courier-pop");
1163 disable_other_mta("vmailmgrd");
1164 disable_other_mta("imapd");
1165 disable_other_mta("popd");
1166 disable_other_mta("pop3d");
1167 disable_other_mta("exim");
1170 if ((pw = getpwuid(config.c_bbsuid)) == NULL)
1175 progress("Setting file permissions", 0, 4);
1176 chown(".", config.c_bbsuid, gid);
1177 progress("Setting file permissions", 1, 4);
1178 chown("citadel.config", config.c_bbsuid, gid);
1179 progress("Setting file permissions", 2, 4);
1180 snprintf(aaa, sizeof aaa,
1181 "find . | grep -v chkpwd | xargs chown %ld:%ld 2>/dev/null",
1182 (long)config.c_bbsuid, (long)gid);
1184 progress("Setting file permissions", 3, 4);
1185 chmod("citadel.config", S_IRUSR | S_IWUSR);
1186 progress("Setting file permissions", 4, 4);
1189 /* Contemplate the possibility of auto-configuring OpenLDAP */
1193 /* See if we can start the Citadel service. */
1194 if (strlen(citserver_init_entry) > 0) {
1195 for (a=0; a<=3; ++a) {
1196 progress("Starting the Citadel service...", a, 3);
1197 if (a == 0) start_citserver();
1200 if (test_server() == 0) {
1201 important_message("Setup finished",
1202 "Setup is finished. You may now log in.");
1205 important_message("Setup finished",
1206 "Setup is finished, but the Citadel service "
1207 "failed to start.\n"
1208 "Go back and check your configuration.");
1212 important_message("Setup finished",
1213 "Setup is finished. You may now start the server.");
1223 * If we're in the middle of an Easy Install, we might just be able to
1224 * auto-configure a standalone OpenLDAP server.
1226 void contemplate_ldap(void) {
1228 char slapd_init_entry[SIZ];
1231 /* If conditions are not ideal, give up on this idea. */
1232 if (using_web_installer == 0) return;
1233 if (getenv("LDAP_CONFIG") == NULL) return;
1234 if (getenv("SUPPORT") == NULL) return;
1235 if (getenv("SLAPD_BINARY") == NULL) return;
1236 if (getenv("CITADEL") == NULL) return;
1238 /* Otherwise, prompt the user to create an entry. */
1239 snprintf(question, sizeof question,
1241 "Do you want this computer configured to start a standalone\n"
1242 "LDAP service automatically? (If you answer yes, a custom\n"
1243 "slapd.conf will be written, and an /etc/inittab entry\n"
1244 "pointing to %s will be added.)\n"
1246 getenv("SLAPD_BINARY")
1248 if (yesno(question) == 0)
1251 strcpy(config.c_ldap_base_dn, "dc=example,dc=com");
1252 strprompt("Base DN",
1254 "Please enter the Base DN for your directory. This will\n"
1255 "generally be something based on the primary DNS domain in\n"
1256 "which you receive mail, but it does not have to be. Your\n"
1257 "LDAP tree will be built using this Distinguished Name.\n"
1259 config.c_ldap_base_dn
1262 strcpy(config.c_ldap_host, "localhost");
1263 config.c_ldap_port = 389;
1264 sprintf(config.c_ldap_bind_dn, "cn=manager,%s", config.c_ldap_base_dn);
1266 /* FIXME ... make the generated password harder to guess */
1267 sprintf(config.c_ldap_bind_pw, "%d%ld", getpid(), time(NULL));
1269 write_config_to_disk();
1271 fp = fopen(getenv("LDAP_CONFIG"), "w");
1273 sprintf(question, "\nCannot create %s:\n%s\n\n"
1274 "Citadel will still function, but you will "
1275 "not have an LDAP service.\n\n",
1276 getenv("LDAP_CONFIG"),
1279 important_message("Error", question);
1283 fprintf(fp, "include %s/citadel-openldap.schema\n",
1285 fprintf(fp, "pidfile %s/openldap-data/slapd.pid\n",
1287 fprintf(fp, "argsfile %s/openldap-data/slapd.args\n",
1289 fprintf(fp, "allow bind_v2\n"
1293 fprintf(fp, "suffix \"%s\"\n", config.c_ldap_base_dn);
1294 fprintf(fp, "rootdn \"%s\"\n", config.c_ldap_bind_dn);
1295 fprintf(fp, "rootpw %s\n", config.c_ldap_bind_pw);
1296 fprintf(fp, "directory %s/openldap-data\n",
1298 fprintf(fp, "index objectClass eq\n");
1302 /* This is where our OpenLDAP server will keep its data. */
1303 mkdir("openldap-data", 0700);
1305 /* If inittab is already starting slapd, disable the old entry. */
1306 locate_init_entry(slapd_init_entry, getenv("SLAPD_BINARY"));
1307 if (strlen(slapd_init_entry) > 0) {
1308 set_init_entry(slapd_init_entry, "off");
1311 /* Generate a unique entry name for slapd */
1312 generate_entry_name(slapd_init_entry);
1314 /* Now write it out to /etc/inittab.
1315 * FIXME make it run as some non-root user.
1316 * The "-d 0" seems superfluous, but it's actually a way to make
1317 * slapd run in the foreground without spewing messages to the console.
1319 fp = fopen("/etc/inittab", "a");
1321 display_error(strerror(errno));
1323 fprintf(fp, "# Start the OpenLDAP server for Citadel...\n");
1324 fprintf(fp, "%s:2345:respawn:%s -d 0 -f %s\n",
1326 getenv("SLAPD_BINARY"),
1327 getenv("LDAP_CONFIG")
1333 #endif /* HAVE_LDAP */