4 * Citadel setup utility
14 #include <sys/types.h>
16 #include <sys/utsname.h>
24 #include <libcitadel.h>
29 #include "citadel_dirs.h"
35 #define MAXSETUP 11 /* 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 */
41 #define SERVICE_NAME "citadel"
42 #define PROTO_NAME "tcp"
43 #define NSSCONF "/etc/nsswitch.conf"
46 char setup_directory[PATH_MAX];
47 int using_web_installer = 0;
52 char *setup_titles[] =
54 "Citadel Home Directory",
55 "System Administrator",
56 "Administrator Password",
60 "Authentication mode",
69 * \brief print the actual stack frame.
71 void cit_backtrace(void)
74 void *stack_frames[50];
79 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
80 strings = backtrace_symbols(stack_frames, size);
81 for (i = 0; i < size; i++) {
83 fprintf(stderr, "%s\n", strings[i]);
85 fprintf(stderr, "%p\n", stack_frames[i]);
93 /* calculate all our path on a central place */
94 /* where to keep our config */
97 char *setup_text[] = {
99 "Enter the full pathname of the directory in which the Citadel\n"
100 "installation you are creating or updating resides. If you\n"
101 "specify a directory other than the default, you will need to\n"
102 "specify the -h flag to the server when you start it up.\n",
104 "Enter the subdirectory name for an alternate installation of "
105 "Citadel. To do a default installation just leave it blank."
106 "If you specify a directory other than the default, you will need to\n"
107 "specify the -h flag to the server when you start it up.\n"
108 "note that it may not have a leading /",
111 "Enter the name of the system administrator (which is probably\n"
112 "you). When an account is created with this name, it will\n"
113 "automatically be given administrator-level access.\n",
115 "Enter a password for the system administrator. When setup\n"
116 "completes it will attempt to create the administrator user\n"
117 "and set the password specified here.\n",
119 "Citadel needs to run under its own user ID. This would\n"
120 "typically be called \"citadel\", but if you are running Citadel\n"
121 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
122 "The server will run under this user ID. Please specify that\n"
123 "user ID here. You may specify either a user name or a numeric\n"
126 "Specify the IP address on which your server will run. If you\n"
127 "leave this blank, or if you specify 0.0.0.0, Citadel will listen\n"
128 "on all addresses. You can usually skip this unless you are\n"
129 "running multiple instances of Citadel on the same computer.\n",
131 "Specify the TCP port number on which your server will run.\n"
132 "Normally, this will be port 504, which is the official port\n"
133 "assigned by the IANA for Citadel servers. You will only need\n"
134 "to specify a different port number if you run multiple instances\n"
135 "of Citadel on the same computer and there is something else\n"
136 "already using port 504.\n",
140 "How would you like to authenticate users on your Citadel system?\n"
142 " 0. Self contained authentication - Citadel maintains its own user database\n"
143 " (This mode is *strongly* recommended)\n"
145 " 1. Authenticate users against the host system (unix or linux accounts)\n"
147 " 2. Authenticate users against an external LDAP directory (RFC 2307 compliant)\n"
149 " 3. Authenticate users against nonstandard MS Active Directory LDAP\n"
151 "WARNING: do *not* change this setting once your system is installed.\n"
153 "(Answer \"0\" unless you completely understand this option)\n"
154 "Which authentication mode do you want to use?\n",
156 "Please enter the host name or IP address of your LDAP server.\n",
158 "Please enter the port number of the LDAP service (usually 389).\n",
160 "Please enter the Base DN to search for authentication\n"
161 "(for example: dc=example,dc=com)\n",
163 "Please enter the DN of an account to use for binding to the LDAP server\n"
164 "for performing queries. The account does not require any other\n"
165 "privileges. If your LDAP server allows anonymous queries, you can.\n"
166 "leave this blank.\n",
168 "If you entered a Bind DN in the previous question, you must now enter\n"
169 "the password associated with that account. Otherwise, you can leave this\n"
174 struct config config;
178 void cleanup(int exitcode)
180 // printf("Exitcode: %d\n", exitcode);
187 void title(char *text)
189 if (setup_type == UI_TEXT) {
190 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
196 int yesno(char *question, int default_value)
202 switch (setup_type) {
206 printf("%s\nYes/No [%s] --> ",
208 ( default_value ? "Yes" : "No" )
210 fgets(buf, sizeof buf, stdin);
211 answer = tolower(buf[0]);
212 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
213 answer = default_value;
214 else if (answer == 'y')
216 else if (answer == 'n')
218 } while ((answer < 0) || (answer > 1));
222 sprintf(buf, "exec %s %s --yesno '%s' 15 75",
223 getenv("CTDL_DIALOG"),
224 ( default_value ? "" : "--defaultno" ),
242 void important_message(char *title, char *msgtext)
246 switch (setup_type) {
249 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");
250 printf(" %s \n\n%s\n\n", title, msgtext);
251 printf("Press return to continue...");
252 fgets(buf, sizeof buf, stdin);
256 sprintf(buf, "exec %s --msgbox '%s' 19 72",
257 getenv("CTDL_DIALOG"),
262 fprintf(stderr, "%s\n", msgtext);
267 void important_msgnum(int msgnum)
269 important_message("Important Message", setup_text[msgnum]);
272 void display_error(char *error_message)
274 important_message("Error", error_message);
277 void progress(char *text, long int curr, long int cmax)
279 static long dots_printed = 0L;
281 static FILE *fp = NULL;
284 switch (setup_type) {
288 printf("%s\n", text);
289 printf("..........................");
290 printf("..........................");
291 printf("..........................\r");
294 } else if (curr == cmax) {
295 printf("\r%79s\n", "");
297 a = (curr * 100) / cmax;
300 while (dots_printed < a) {
310 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
311 getenv("CTDL_DIALOG"),
313 fp = popen(buf, "w");
319 else if (curr == cmax) {
321 fprintf(fp, "100\n");
327 a = (curr * 100) / cmax;
329 fprintf(fp, "%ld\n", a);
343 * check_services_entry() -- Make sure "citadel" is in /etc/services
346 void check_services_entry(void)
352 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
353 for (i=0; i<=2; ++i) {
354 progress("Adding service entry...", i, 2);
356 sfp = fopen("/etc/services", "a");
358 sprintf(errmsg, "Cannot open /etc/services: %s", strerror(errno));
359 display_error(errmsg);
361 fprintf(sfp, "%s 504/tcp\n", SERVICE_NAME);
373 * delete_inittab_entry() -- Remove obsolete /etc/inittab entry for Citadel
376 void delete_inittab_entry(void)
380 char looking_for[256];
382 char outfilename[32];
383 int changes_made = 0;
385 /* Determine the fully qualified path name of citserver */
386 snprintf(looking_for,
392 /* Now tweak /etc/inittab */
393 infp = fopen("/etc/inittab", "r");
396 /* If /etc/inittab does not exist, return quietly.
397 * Not all host platforms have it.
399 if (errno == ENOENT) {
403 /* Other errors might mean something really did go wrong.
405 sprintf(buf, "Cannot open /etc/inittab: %s", strerror(errno));
410 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
411 outfp = fdopen(mkstemp(outfilename), "w+");
413 sprintf(buf, "Cannot open %s: %s", outfilename, strerror(errno));
419 while (fgets(buf, sizeof buf, infp) != NULL) {
420 if (strstr(buf, looking_for) != NULL) {
421 fwrite("#", 1, 1, outfp);
424 fwrite(buf, strlen(buf), 1, outfp);
431 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
433 system("/sbin/init q 2>/dev/null");
442 * install_init_scripts() -- Try to configure to start Citadel at boot
445 void install_init_scripts(void)
447 struct stat etcinitd;
449 char *initfile = "/etc/init.d/citadel";
452 if ((stat("/etc/init.d/", &etcinitd) == -1) &&
455 if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
457 initfile = CTDLDIR"/citadel.init";
459 initfile = "/etc/rc.d/init.d/citadel";
462 fp = fopen(initfile, "r");
464 if (yesno("Citadel already appears to be configured to start at boot.\n"
465 "Would you like to keep your boot configuration as is?\n", 1) == 1) {
472 if (yesno("Would you like to automatically start Citadel at boot?\n", 1) == 0) {
476 fp = fopen(initfile, "w");
478 display_error("Cannot create /etc/init.d/citadel");
482 fprintf(fp, "#!/bin/sh\n"
484 "# Init file for Citadel\n"
486 "# chkconfig: - 79 30\n"
487 "# description: Citadel service\n"
488 "# processname: citserver\n"
489 "# pidfile: %s/citadel.pid\n"
497 "test -d /var/run || exit 0\n"
501 "start) echo -n \"Starting Citadel... \"\n"
502 " if $CITADEL_DIR/citserver -d -h$CITADEL_DIR\n"
509 "stop) echo -n \"Stopping Citadel... \"\n"
510 " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
515 " rm -f %s/citadel.pid 2>/dev/null\n"
520 "restart) if $CITADEL_DIR/sendcommand DOWN 1 >/dev/null 2>&1 ; then\n"
526 "*) echo \"Usage: $0 {start|stop|restart}\"\n"
533 chmod(initfile, 0755);
535 /* Set up the run levels. */
536 system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
537 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);
539 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);
550 * On systems which use xinetd, see if we can offer to install Citadel as
551 * the default telnet target.
553 void check_xinetd_entry(void) {
554 char *filename = "/etc/xinetd.d/telnet";
557 int already_citadel = 0;
559 fp = fopen(filename, "r+");
560 if (fp == NULL) return; /* Not there. Oh well... */
562 while (fgets(buf, sizeof buf, fp) != NULL) {
563 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
566 if (already_citadel) return; /* Already set up this way. */
568 /* Otherwise, prompt the user to create an entry. */
569 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
570 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
575 snprintf(buf, sizeof buf,
576 "Setup can configure the \"xinetd\" service to automatically\n"
577 "connect incoming telnet sessions to Citadel, bypassing the\n"
578 "host system login: prompt. Would you like to do this?\n"
580 if (yesno(buf, 1) == 0) {
585 fp = fopen(filename, "w");
587 "# description: telnet service for Citadel users\n"
592 " socket_type = stream\n"
595 " server = /usr/sbin/in.telnetd\n"
596 " server_args = -h -L %s/citadel\n"
597 " log_on_failure += USERID\n"
602 /* Now try to restart the service */
603 system("/etc/init.d/xinetd restart >/dev/null 2>&1");
609 * Offer to disable other MTA's
611 void disable_other_mta(char *mta) {
616 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
617 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
619 fp = popen(buf, "r");
620 if (fp == NULL) return;
622 while (fgets(buf, sizeof buf, fp) != NULL) {
626 if (lines == 0) return; /* Nothing to do. */
629 /* Offer to replace other MTA with the vastly superior Citadel :) */
631 snprintf(buf, sizeof buf,
632 "You appear to have the \"%s\" email program\n"
633 "running on your system. If you want Citadel mail\n"
634 "connected with %s, you will have to manually integrate\n"
635 "them. It is preferable to disable %s, and use Citadel's\n"
636 "SMTP, POP3, and IMAP services.\n\n"
637 "May we disable %s so that Citadel has access to ports\n"
638 "25, 110, and 143?\n",
641 if (yesno(buf, 1) == 0) {
646 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);
648 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
656 * Check to see if our server really works. Returns 0 on success.
658 int test_server(char *setup_directory, char *relhomestr, int relhome) {
665 /* Generate a silly little cookie. We're going to write it out
666 * to the server and try to get it back. The cookie does not
667 * have to be secret ... just unique.
669 sprintf(cookie, "--test--%d--", getpid());
672 sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
677 sprintf(cmd, "%s/sendcommand ECHO %s 2>&1",
681 fp = popen(cmd, "r");
682 if (fp == NULL) return(errno);
684 while (fgets(buf, sizeof buf, fp) != NULL) {
686 && (strstr(buf, cookie) != NULL) ) {
698 void strprompt(char *prompt_title, char *prompt_text, char *str)
702 char dialog_result[PATH_MAX];
705 strcpy(setupmsg, "");
707 switch (setup_type) {
710 printf("\n%s\n", prompt_text);
711 printf("This is currently set to:\n%s\n", str);
712 printf("Enter new value or press return to leave unchanged:\n");
713 fgets(buf, sizeof buf, stdin);
714 buf[strlen(buf) - 1] = 0;
715 if (!IsEmptyStr(buf))
720 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
721 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
722 getenv("CTDL_DIALOG"),
727 fp = fopen(dialog_result, "r");
729 fgets(str, sizeof buf, fp);
730 if (str[strlen(str)-1] == 10) {
731 str[strlen(str)-1] = 0;
734 unlink(dialog_result);
742 void set_bool_val(int msgpos, int *ip) {
743 title(setup_titles[msgpos]);
744 *ip = yesno(setup_text[msgpos], *ip);
747 void set_str_val(int msgpos, char *str) {
748 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
751 void set_int_val(int msgpos, int *ip)
754 snprintf(buf, sizeof buf, "%d", (int) *ip);
755 set_str_val(msgpos, buf);
760 void set_char_val(int msgpos, char *ip)
763 snprintf(buf, sizeof buf, "%d", (int) *ip);
764 set_str_val(msgpos, buf);
765 *ip = (char) atoi(buf);
769 void set_long_val(int msgpos, long int *ip)
772 snprintf(buf, sizeof buf, "%ld", *ip);
773 set_str_val(msgpos, buf);
778 void edit_value(int curr)
782 char ctdluidname[256];
787 if (setup_type == UI_SILENT)
789 if (getenv("SYSADMIN_NAME")) {
790 strcpy(config.c_sysadm, getenv("SYSADMIN_NAME"));
794 set_str_val(curr, config.c_sysadm);
799 if (setup_type == UI_SILENT)
801 if (getenv("SYSADMIN_PW")) {
802 strcpy(admin_pass, getenv("SYSADMIN_PW"));
806 set_str_val(curr, admin_pass);
811 if (setup_type == UI_SILENT)
813 if (getenv("CITADEL_UID")) {
814 config.c_ctdluid = atoi(getenv("CITADEL_UID"));
820 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
822 i = config.c_ctdluid;
825 set_int_val(curr, &i);
826 config.c_ctdluid = i;
829 strcpy(ctdluidname, pw->pw_name);
830 set_str_val(curr, ctdluidname);
831 pw = getpwnam(ctdluidname);
833 config.c_ctdluid = pw->pw_uid;
835 else if (atoi(ctdluidname) > 0) {
836 config.c_ctdluid = atoi(ctdluidname);
844 if (setup_type == UI_SILENT)
846 if (getenv("IP_ADDR")) {
847 strcpy(config.c_ip_addr, getenv("IP_ADDR"));
851 set_str_val(curr, config.c_ip_addr);
856 if (setup_type == UI_SILENT)
858 if (getenv("CITADEL_PORT")) {
859 config.c_port_number = atoi(getenv("CITADEL_PORT"));
864 set_int_val(curr, &config.c_port_number);
869 if (setup_type == UI_SILENT)
871 if (getenv("ENABLE_UNIX_AUTH")) {
872 if (!strcasecmp(getenv("ENABLE_UNIX_AUTH"), "yes")) {
873 config.c_auth_mode = AUTHMODE_HOST;
876 config.c_auth_mode = AUTHMODE_NATIVE;
881 set_int_val(curr, &config.c_auth_mode);
886 if (setup_type == UI_SILENT)
888 if (getenv("LDAP_HOST")) {
889 strcpy(config.c_ldap_host, getenv("LDAP_HOST"));
894 set_str_val(curr, config.c_ldap_host);
899 if (setup_type == UI_SILENT)
901 if (getenv("LDAP_PORT")) {
902 config.c_ldap_port = atoi(getenv("LDAP_PORT"));
907 set_int_val(curr, &config.c_ldap_port);
912 if (setup_type == UI_SILENT)
914 if (getenv("LDAP_BASE_DN")) {
915 strcpy(config.c_ldap_base_dn, getenv("LDAP_BASE_DN"));
920 set_str_val(curr, config.c_ldap_base_dn);
925 if (setup_type == UI_SILENT)
927 if (getenv("LDAP_BIND_DN")) {
928 strcpy(config.c_ldap_bind_dn, getenv("LDAP_BIND_DN"));
933 set_str_val(curr, config.c_ldap_bind_dn);
938 if (setup_type == UI_SILENT)
940 if (getenv("LDAP_BIND_PW")) {
941 strcpy(config.c_ldap_bind_pw, getenv("LDAP_BIND_PW"));
946 set_str_val(curr, config.c_ldap_bind_pw);
955 * (re-)write the config data to disk
957 void write_config_to_disk(void)
962 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
963 display_error("setup: cannot open citadel.config");
966 fp = fdopen(fd, "wb");
968 display_error("setup: cannot open citadel.config");
971 fwrite((char *) &config, sizeof(struct config), 1, fp);
979 * Figure out what type of user interface we're going to use
981 int discover_ui(void)
984 /* Use "dialog" if we have it */
985 if (getenv("CTDL_DIALOG") != NULL) {
997 * Strip "db" entries out of /etc/nsswitch.conf
1007 int file_changed = 0;
1008 char new_filename[64];
1010 fp_read = fopen(NSSCONF, "r");
1011 if (fp_read == NULL) {
1015 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
1016 fd_write = mkstemp(new_filename);
1022 while (fgets(buf, sizeof buf, fp_read) != NULL) {
1024 strcpy(buf_nc, buf);
1025 for (i=0; i<strlen(buf_nc); ++i) {
1026 if (buf_nc[i] == '#') {
1030 for (i=0; i<strlen(buf_nc); ++i) {
1031 if (!strncasecmp(&buf_nc[i], "db", 2)) {
1033 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
1036 strcpy(&buf_nc[i], &buf_nc[i+2]);
1037 strcpy(&buf[i], &buf[i+2]);
1039 strcpy(&buf_nc[i], &buf_nc[i+1]);
1040 strcpy(&buf[i], &buf[i+1]);
1046 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
1049 unlink(new_filename);
1056 if (!file_changed) {
1057 unlink(new_filename);
1061 snprintf(question, sizeof question,
1063 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
1064 "one or more services. This is not necessary on most systems,\n"
1065 "and it is known to crash the Citadel server when delivering\n"
1066 "mail to the Internet.\n"
1068 "Do you want this module to be automatically disabled?\n"
1072 if (yesno(question, 1)) {
1073 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
1075 chmod(NSSCONF, 0644);
1077 unlink(new_filename);
1087 int main(int argc, char *argv[])
1093 int old_setup_level = 0;
1095 struct utsname my_utsname;
1101 char relhome[PATH_MAX]="";
1102 char ctdldir[PATH_MAX]=CTDLDIR;
1104 /* set an invalid setup type */
1107 /* Check to see if we're running the web installer */
1108 if (getenv("CITADEL_INSTALLER") != NULL) {
1109 using_web_installer = 1;
1112 /* parse command line args */
1113 for (a = 0; a < argc; ++a) {
1114 if (!strncmp(argv[a], "-u", 2)) {
1115 strcpy(aaa, argv[a]);
1116 strcpy(aaa, &aaa[2]);
1117 setup_type = atoi(aaa);
1119 else if (!strcmp(argv[a], "-i")) {
1122 else if (!strcmp(argv[a], "-q")) {
1123 setup_type = UI_SILENT;
1125 else if (!strncmp(argv[a], "-h", 2)) {
1126 relh=argv[a][2]!='/';
1127 if (!relh) safestrncpy(ctdl_home_directory, &argv[a][2],
1128 sizeof ctdl_home_directory);
1130 safestrncpy(relhome, &argv[a][2],
1137 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1139 /* If a setup type was not specified, try to determine automatically
1140 * the best one to use out of all available types.
1142 if (setup_type < 0) {
1143 setup_type = discover_ui();
1145 if (info_only == 1) {
1146 important_message("Citadel Setup", CITADEL);
1150 /* Get started in a valid setup directory. */
1151 strcpy(setup_directory, ctdl_run_dir);
1152 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
1153 strcpy(setup_directory, getenv("CITADEL"));
1156 set_str_val(0, setup_directory);
1159 enable_home = ( relh | home );
1161 if (chdir(setup_directory) != 0) {
1163 sprintf(errmsg, "The directory you specified does not exist: [%s]\n", setup_directory);
1165 important_message("Citadel Setup", errmsg);
1169 /* Determine our host name, in case we need to use it as a default */
1172 /* Try to stop Citadel if we can */
1173 if (!access("/etc/init.d/citadel", X_OK)) {
1174 system("/etc/init.d/citadel stop");
1177 /* Make sure Citadel is not running. */
1178 if (test_server(setup_directory, relhome, enable_home) == 0) {
1179 important_message("Citadel Setup",
1180 "The Citadel service is still running.\n"
1181 "Please stop the service manually and run "
1187 switch (setup_type) {
1191 " *** Citadel setup program ***\n\n");
1197 * What we're going to try to do here is append a whole bunch of
1198 * nulls to the citadel.config file, so we can keep the old config
1199 * values if they exist, but if the file is missing or from an
1200 * earlier version with a shorter config structure, when setup tries
1201 * to read the old config parameters, they'll all come up zero.
1202 * The length of the config file will be set to what it's supposed
1203 * to be when we rewrite it, because we replace the old file with a
1204 * completely new copy.
1206 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1207 S_IRUSR | S_IWUSR)) == -1) {
1208 display_error("setup: cannot append citadel.config");
1211 fp = fdopen(a, "ab");
1213 display_error("setup: cannot append citadel.config");
1216 for (a = 0; a < sizeof(struct config); ++a)
1220 /* now we re-open it, and read the old or blank configuration */
1221 fp = fopen(file_citadel_config, "rb");
1223 display_error("setup: cannot open citadel.config");
1226 fread((char *) &config, sizeof(struct config), 1, fp);
1229 /* set some sample/default values in place of blanks... */
1230 if (IsEmptyStr(config.c_nodename))
1231 safestrncpy(config.c_nodename, my_utsname.nodename,
1232 sizeof config.c_nodename);
1233 strtok(config.c_nodename, ".");
1234 if (IsEmptyStr(config.c_fqdn) ) {
1235 if ((he = gethostbyname(my_utsname.nodename)) != NULL)
1236 safestrncpy(config.c_fqdn, he->h_name,
1237 sizeof config.c_fqdn);
1239 safestrncpy(config.c_fqdn, my_utsname.nodename,
1240 sizeof config.c_fqdn);
1242 if (IsEmptyStr(config.c_humannode))
1243 strcpy(config.c_humannode, "My System");
1244 if (IsEmptyStr(config.c_phonenum))
1245 strcpy(config.c_phonenum, "US 800 555 1212");
1246 if (config.c_initax == 0) {
1247 config.c_initax = 4;
1249 if (IsEmptyStr(config.c_moreprompt))
1250 strcpy(config.c_moreprompt, "<more>");
1251 if (IsEmptyStr(config.c_twitroom))
1252 strcpy(config.c_twitroom, "Trashcan");
1253 if (IsEmptyStr(config.c_baseroom))
1254 strcpy(config.c_baseroom, BASEROOM);
1255 if (IsEmptyStr(config.c_aideroom))
1256 strcpy(config.c_aideroom, "Aide");
1257 if (config.c_port_number == 0) {
1258 config.c_port_number = 504;
1260 if (config.c_sleeping == 0) {
1261 config.c_sleeping = 900;
1263 if (config.c_ctdluid == 0) {
1264 pw = getpwnam("citadel");
1266 config.c_ctdluid = pw->pw_uid;
1268 if (config.c_ctdluid == 0) {
1269 pw = getpwnam("bbs");
1271 config.c_ctdluid = pw->pw_uid;
1273 if (config.c_ctdluid == 0) {
1274 pw = getpwnam("guest");
1276 config.c_ctdluid = pw->pw_uid;
1278 if (config.c_createax == 0) {
1279 config.c_createax = 3;
1282 * Negative values for maxsessions are not allowed.
1284 if (config.c_maxsessions < 0) {
1285 config.c_maxsessions = 0;
1287 /* We need a system default message expiry policy, because this is
1288 * the top level and there's no 'higher' policy to fall back on.
1289 * By default, do not expire messages at all.
1291 if (config.c_ep.expire_mode == 0) {
1292 config.c_ep.expire_mode = EXPIRE_MANUAL;
1293 config.c_ep.expire_value = 0;
1297 * Default port numbers for various services
1299 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1300 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1301 if (config.c_imap_port == 0) config.c_imap_port = 143;
1302 if (config.c_msa_port == 0) config.c_msa_port = 587;
1303 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1304 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1305 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1306 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1307 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1308 if (config.c_xmpp_c2s_port == 0) config.c_xmpp_c2s_port = 5222;
1309 if (config.c_xmpp_s2s_port == 0) config.c_xmpp_s2s_port = 5269;
1311 /* Go through a series of dialogs prompting for config info */
1312 for (curr = 1; curr <= MAXSETUP; ++curr) {
1314 if ((curr == 6) && (config.c_auth_mode != AUTHMODE_LDAP) && (config.c_auth_mode != AUTHMODE_LDAP_AD)) {
1315 curr += 5; /* skip LDAP questions if we're not authenticating against LDAP */
1319 /***** begin version update section ***** */
1320 /* take care of any updating that is necessary */
1322 old_setup_level = config.c_setup_level;
1324 if (old_setup_level == 0) {
1328 if (old_setup_level < 555) {
1329 important_message("Citadel Setup",
1330 "This Citadel installation is too old "
1334 write_config_to_disk();
1336 old_setup_level = config.c_setup_level;
1338 /* end of version update section */
1341 config.c_setup_level = REV_LEVEL;
1343 /******************************************/
1345 write_config_to_disk();
1347 mkdir(ctdl_info_dir, 0700);
1348 chmod(ctdl_info_dir, 0700);
1349 chown(ctdl_info_dir, config.c_ctdluid, -1);
1351 mkdir(ctdl_bio_dir, 0700);
1352 chmod(ctdl_bio_dir, 0700);
1353 chown(ctdl_bio_dir, config.c_ctdluid, -1);
1355 mkdir(ctdl_usrpic_dir, 0700);
1356 chmod(ctdl_usrpic_dir, 0700);
1357 chown(ctdl_usrpic_dir, config.c_ctdluid, -1);
1359 mkdir(ctdl_message_dir, 0700);
1360 chmod(ctdl_message_dir, 0700);
1361 chown(ctdl_message_dir, config.c_ctdluid, -1);
1363 mkdir(ctdl_hlp_dir, 0700);
1364 chmod(ctdl_hlp_dir, 0700);
1365 chown(ctdl_hlp_dir, config.c_ctdluid, -1);
1367 mkdir(ctdl_image_dir, 0700);
1368 chmod(ctdl_image_dir, 0700);
1369 chown(ctdl_image_dir, config.c_ctdluid, -1);
1371 mkdir(ctdl_bb_dir, 0700);
1372 chmod(ctdl_bb_dir, 0700);
1373 chown(ctdl_bb_dir, config.c_ctdluid, -1);
1375 mkdir(ctdl_file_dir, 0700);
1376 chmod(ctdl_file_dir, 0700);
1377 chown(ctdl_file_dir, config.c_ctdluid, -1);
1379 mkdir(ctdl_netcfg_dir, 0700);
1380 chmod(ctdl_netcfg_dir, 0700);
1381 chown(ctdl_netcfg_dir, config.c_ctdluid, -1);
1383 /* Delete files and directories used by older Citadel versions */
1384 system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1385 unlink("citadel.log");
1388 if (((setup_type == UI_SILENT) && (getenv("ALTER_ETC_SERVICES")!=NULL)) ||
1389 (setup_type != UI_SILENT))
1390 check_services_entry(); /* Check /etc/services */
1392 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1393 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1395 if ((getenv("ACT_AS_MTA") == NULL) ||
1396 (getenv("ACT_AS_MTA") &&
1397 strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
1398 /* Offer to disable other MTA's on the system. */
1399 disable_other_mta("courier-authdaemon");
1400 disable_other_mta("courier-imap");
1401 disable_other_mta("courier-imap-ssl");
1402 disable_other_mta("courier-pop");
1403 disable_other_mta("courier-pop3");
1404 disable_other_mta("courier-pop3d");
1405 disable_other_mta("cyrmaster");
1406 disable_other_mta("cyrus");
1407 disable_other_mta("dovecot");
1408 disable_other_mta("exim");
1409 disable_other_mta("exim4");
1410 disable_other_mta("imapd");
1411 disable_other_mta("mta");
1412 disable_other_mta("pop3d");
1413 disable_other_mta("popd");
1414 disable_other_mta("postfix");
1415 disable_other_mta("qmail");
1416 disable_other_mta("saslauthd");
1417 disable_other_mta("sendmail");
1418 disable_other_mta("vmailmgrd");
1422 /* Check for the 'db' nss and offer to disable it */
1425 if ((pw = getpwuid(config.c_ctdluid)) == NULL)
1430 progress("Setting file permissions", 0, 3);
1431 chown(ctdl_run_dir, config.c_ctdluid, gid);
1432 progress("Setting file permissions", 1, 3);
1433 chown(file_citadel_config, config.c_ctdluid, gid);
1434 progress("Setting file permissions", 2, 3);
1435 chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1436 progress("Setting file permissions", 3, 3);
1439 * If we're running on SysV, install init scripts.
1441 if (!access("/var/run", W_OK)) {
1443 if (getenv("NO_INIT_SCRIPTS") == NULL) {
1444 install_init_scripts();
1447 if (!access("/etc/init.d/citadel", X_OK)) {
1448 system("/etc/init.d/citadel start");
1452 if (test_server(setup_directory, relhome, enable_home) == 0) {
1456 snprintf (admin_cmd, sizeof(admin_cmd), "%s/sendcommand \"CREU %s|%s\" 2>&1",
1457 ctdl_sbin_dir, config.c_sysadm, admin_pass);
1458 fp = popen(admin_cmd, "r");
1460 while (fgets(buf, sizeof buf, fp) != NULL)
1462 if ((atol(buf) == 574) || (atol(buf) == 200))
1469 important_message("Error","Setup failed to create your admin user");
1471 if (setup_type != UI_SILENT)
1472 important_message("Setup finished",
1473 "Setup of the Citadel server is complete.\n"
1474 "If you will be using WebCit, please run its\n"
1475 "setup program now; otherwise, run './citadel'\n"
1479 important_message("Setup failed",
1480 "Setup is finished, but the Citadel server failed to start.\n"
1481 "Go back and check your configuration.\n"
1488 important_message("Setup finished",
1489 "Setup is finished. You may now start the server.");