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 "Specify which authentication mode you wish to use.\n"
142 " 0. Self contained authentication\n"
143 " 1. Host system integrated authentication\n"
144 " 2. External LDAP - RFC 2307 compliant directory\n"
145 " 3. External LDAP - nonstandard MS Active Directory\n"
147 "For help: http://www.citadel.org/doku.php/faq:installation:authmodes\n"
149 "ANSWER \"0\" UNLESS YOU COMPLETELY UNDERSTAND THIS OPTION.\n",
151 "Please enter the host name or IP address of your LDAP server.\n",
153 "Please enter the port number of the LDAP service (usually 389).\n",
155 "Please enter the Base DN to search for authentication\n"
156 "(for example: dc=example,dc=com)\n",
158 "Please enter the DN of an account to use for binding to the LDAP server\n"
159 "for performing queries. The account does not require any other\n"
160 "privileges. If your LDAP server allows anonymous queries, you can.\n"
161 "leave this blank.\n",
163 "If you entered a Bind DN in the previous question, you must now enter\n"
164 "the password associated with that account. Otherwise, you can leave this\n"
169 struct config config;
173 void cleanup(int exitcode)
175 // printf("Exitcode: %d\n", exitcode);
182 void title(char *text)
184 if (setup_type == UI_TEXT) {
185 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
191 int yesno(char *question, int default_value)
197 switch (setup_type) {
201 printf("%s\nYes/No [%s] --> ",
203 ( default_value ? "Yes" : "No" )
205 if (fgets(buf, sizeof buf, stdin))
207 answer = tolower(buf[0]);
208 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
209 answer = default_value;
210 else if (answer == 'y')
212 else if (answer == 'n')
215 } while ((answer < 0) || (answer > 1));
219 sprintf(buf, "exec %s %s --yesno '%s' 15 75",
220 getenv("CTDL_DIALOG"),
221 ( default_value ? "" : "--defaultno" ),
239 void important_message(char *title, char *msgtext)
243 switch (setup_type) {
246 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");
247 printf(" %s \n\n%s\n\n", title, msgtext);
248 printf("Press return to continue...");
249 if (fgets(buf, sizeof buf, stdin));
253 sprintf(buf, "exec %s --msgbox '%s' 19 72",
254 getenv("CTDL_DIALOG"),
259 fprintf(stderr, "%s\n", msgtext);
264 void important_msgnum(int msgnum)
266 important_message("Important Message", setup_text[msgnum]);
269 void display_error(char *error_message)
271 important_message("Error", error_message);
274 void progress(char *text, long int curr, long int cmax)
276 static long dots_printed = 0L;
278 static FILE *fp = NULL;
281 switch (setup_type) {
285 printf("%s\n", text);
286 printf("..........................");
287 printf("..........................");
288 printf("..........................\r");
291 } else if (curr == cmax) {
292 printf("\r%79s\n", "");
294 a = (curr * 100) / cmax;
297 while (dots_printed < a) {
307 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
308 getenv("CTDL_DIALOG"),
310 fp = popen(buf, "w");
316 else if (curr == cmax) {
318 fprintf(fp, "100\n");
324 a = (curr * 100) / cmax;
326 fprintf(fp, "%ld\n", a);
340 * check_services_entry() -- Make sure "citadel" is in /etc/services
343 void check_services_entry(void)
349 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
350 for (i=0; i<=2; ++i) {
351 progress("Adding service entry...", i, 2);
353 sfp = fopen("/etc/services", "a");
355 sprintf(errmsg, "Cannot open /etc/services: %s", strerror(errno));
356 display_error(errmsg);
358 fprintf(sfp, "%s 504/tcp\n", SERVICE_NAME);
370 * delete_inittab_entry() -- Remove obsolete /etc/inittab entry for Citadel
373 void delete_inittab_entry(void)
377 char looking_for[256];
379 char outfilename[32];
380 int changes_made = 0;
382 /* Determine the fully qualified path name of citserver */
383 snprintf(looking_for,
389 /* Now tweak /etc/inittab */
390 infp = fopen("/etc/inittab", "r");
393 /* If /etc/inittab does not exist, return quietly.
394 * Not all host platforms have it.
396 if (errno == ENOENT) {
400 /* Other errors might mean something really did go wrong.
402 sprintf(buf, "Cannot open /etc/inittab: %s", strerror(errno));
407 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
408 outfp = fdopen(mkstemp(outfilename), "w+");
410 sprintf(buf, "Cannot open %s: %s", outfilename, strerror(errno));
416 while (fgets(buf, sizeof buf, infp) != NULL) {
417 if (strstr(buf, looking_for) != NULL) {
418 fwrite("#", 1, 1, outfp);
421 fwrite(buf, strlen(buf), 1, outfp);
428 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
430 system("/sbin/init q 2>/dev/null");
439 * install_init_scripts() -- Try to configure to start Citadel at boot
442 void install_init_scripts(void)
444 struct stat etcinitd;
446 char *initfile = "/etc/init.d/citadel";
449 if ((stat("/etc/init.d/", &etcinitd) == -1) &&
452 if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
454 initfile = CTDLDIR"/citadel.init";
456 initfile = "/etc/rc.d/init.d/citadel";
459 fp = fopen(initfile, "r");
461 if (yesno("Citadel already appears to be configured to start at boot.\n"
462 "Would you like to keep your boot configuration as is?\n", 1) == 1) {
469 if (yesno("Would you like to automatically start Citadel at boot?\n", 1) == 0) {
473 fp = fopen(initfile, "w");
475 display_error("Cannot create /etc/init.d/citadel");
479 fprintf(fp, "#!/bin/sh\n"
481 "# Init file for Citadel\n"
483 "# chkconfig: - 79 30\n"
484 "# description: Citadel service\n"
485 "# processname: citserver\n"
486 "# pidfile: %s/citadel.pid\n\n"
487 "# uncomment this to create coredumps as described in\n"
488 "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
489 "# ulimit -c unlimited\n"
497 "test -d /var/run || exit 0\n"
501 "start) echo -n \"Starting Citadel... \"\n"
502 " if $CITADEL_DIR/citserver -lmail -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 if (fgets(buf, sizeof buf, stdin)){
714 buf[strlen(buf) - 1] = 0;
716 if (!IsEmptyStr(buf))
721 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
722 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
723 getenv("CTDL_DIALOG"),
728 fp = fopen(dialog_result, "r");
730 if (fgets(str, sizeof buf, fp)) {
731 if (str[strlen(str)-1] == 10) {
732 str[strlen(str)-1] = 0;
736 unlink(dialog_result);
744 void set_bool_val(int msgpos, int *ip) {
745 title(setup_titles[msgpos]);
746 *ip = yesno(setup_text[msgpos], *ip);
749 void set_str_val(int msgpos, char *str) {
750 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
753 void set_int_val(int msgpos, int *ip)
756 snprintf(buf, sizeof buf, "%d", (int) *ip);
757 set_str_val(msgpos, buf);
762 void set_char_val(int msgpos, char *ip)
765 snprintf(buf, sizeof buf, "%d", (int) *ip);
766 set_str_val(msgpos, buf);
767 *ip = (char) atoi(buf);
771 void set_long_val(int msgpos, long int *ip)
774 snprintf(buf, sizeof buf, "%ld", *ip);
775 set_str_val(msgpos, buf);
780 void edit_value(int curr)
784 char ctdluidname[256];
789 if (setup_type == UI_SILENT)
791 if (getenv("SYSADMIN_NAME")) {
792 strcpy(config.c_sysadm, getenv("SYSADMIN_NAME"));
796 set_str_val(curr, config.c_sysadm);
801 if (setup_type == UI_SILENT)
803 if (getenv("SYSADMIN_PW")) {
804 strcpy(admin_pass, getenv("SYSADMIN_PW"));
808 set_str_val(curr, admin_pass);
813 if (setup_type == UI_SILENT)
815 if (getenv("CITADEL_UID")) {
816 config.c_ctdluid = atoi(getenv("CITADEL_UID"));
822 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
824 i = config.c_ctdluid;
827 set_int_val(curr, &i);
828 config.c_ctdluid = i;
831 strcpy(ctdluidname, pw->pw_name);
832 set_str_val(curr, ctdluidname);
833 pw = getpwnam(ctdluidname);
835 config.c_ctdluid = pw->pw_uid;
837 else if (atoi(ctdluidname) > 0) {
838 config.c_ctdluid = atoi(ctdluidname);
846 if (setup_type == UI_SILENT)
848 if (getenv("IP_ADDR")) {
849 strcpy(config.c_ip_addr, getenv("IP_ADDR"));
853 set_str_val(curr, config.c_ip_addr);
858 if (setup_type == UI_SILENT)
860 if (getenv("CITADEL_PORT")) {
861 config.c_port_number = atoi(getenv("CITADEL_PORT"));
866 set_int_val(curr, &config.c_port_number);
871 if (setup_type == UI_SILENT)
873 if (getenv("ENABLE_UNIX_AUTH")) {
874 if (!strcasecmp(getenv("ENABLE_UNIX_AUTH"), "yes")) {
875 config.c_auth_mode = AUTHMODE_HOST;
878 config.c_auth_mode = AUTHMODE_NATIVE;
883 set_int_val(curr, &config.c_auth_mode);
888 if (setup_type == UI_SILENT)
890 if (getenv("LDAP_HOST")) {
891 strcpy(config.c_ldap_host, getenv("LDAP_HOST"));
896 set_str_val(curr, config.c_ldap_host);
901 if (setup_type == UI_SILENT)
903 if (getenv("LDAP_PORT")) {
904 config.c_ldap_port = atoi(getenv("LDAP_PORT"));
909 set_int_val(curr, &config.c_ldap_port);
914 if (setup_type == UI_SILENT)
916 if (getenv("LDAP_BASE_DN")) {
917 strcpy(config.c_ldap_base_dn, getenv("LDAP_BASE_DN"));
922 set_str_val(curr, config.c_ldap_base_dn);
927 if (setup_type == UI_SILENT)
929 if (getenv("LDAP_BIND_DN")) {
930 strcpy(config.c_ldap_bind_dn, getenv("LDAP_BIND_DN"));
935 set_str_val(curr, config.c_ldap_bind_dn);
940 if (setup_type == UI_SILENT)
942 if (getenv("LDAP_BIND_PW")) {
943 strcpy(config.c_ldap_bind_pw, getenv("LDAP_BIND_PW"));
948 set_str_val(curr, config.c_ldap_bind_pw);
957 * (re-)write the config data to disk
959 void write_config_to_disk(void)
964 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
965 display_error("setup: cannot open citadel.config");
968 fp = fdopen(fd, "wb");
970 display_error("setup: cannot open citadel.config");
973 fwrite((char *) &config, sizeof(struct config), 1, fp);
981 * Figure out what type of user interface we're going to use
983 int discover_ui(void)
986 /* Use "dialog" if we have it */
987 if (getenv("CTDL_DIALOG") != NULL) {
999 * Strip "db" entries out of /etc/nsswitch.conf
1009 int file_changed = 0;
1010 char new_filename[64];
1012 fp_read = fopen(NSSCONF, "r");
1013 if (fp_read == NULL) {
1017 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
1018 fd_write = mkstemp(new_filename);
1024 while (fgets(buf, sizeof buf, fp_read) != NULL) {
1026 strcpy(buf_nc, buf);
1027 for (i=0; i<strlen(buf_nc); ++i) {
1028 if (buf_nc[i] == '#') {
1032 for (i=0; i<strlen(buf_nc); ++i) {
1033 if (!strncasecmp(&buf_nc[i], "db", 2)) {
1035 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
1038 strcpy(&buf_nc[i], &buf_nc[i+2]);
1039 strcpy(&buf[i], &buf[i+2]);
1041 strcpy(&buf_nc[i], &buf_nc[i+1]);
1042 strcpy(&buf[i], &buf[i+1]);
1048 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
1051 unlink(new_filename);
1058 if (!file_changed) {
1059 unlink(new_filename);
1063 snprintf(question, sizeof question,
1065 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
1066 "one or more services. This is not necessary on most systems,\n"
1067 "and it is known to crash the Citadel server when delivering\n"
1068 "mail to the Internet.\n"
1070 "Do you want this module to be automatically disabled?\n"
1074 if (yesno(question, 1)) {
1075 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
1077 chmod(NSSCONF, 0644);
1079 unlink(new_filename);
1089 int main(int argc, char *argv[])
1095 int old_setup_level = 0;
1097 struct utsname my_utsname;
1103 char relhome[PATH_MAX]="";
1104 char ctdldir[PATH_MAX]=CTDLDIR;
1106 /* set an invalid setup type */
1109 /* Check to see if we're running the web installer */
1110 if (getenv("CITADEL_INSTALLER") != NULL) {
1111 using_web_installer = 1;
1114 /* parse command line args */
1115 for (a = 0; a < argc; ++a) {
1116 if (!strncmp(argv[a], "-u", 2)) {
1117 strcpy(aaa, argv[a]);
1118 strcpy(aaa, &aaa[2]);
1119 setup_type = atoi(aaa);
1121 else if (!strcmp(argv[a], "-i")) {
1124 else if (!strcmp(argv[a], "-q")) {
1125 setup_type = UI_SILENT;
1127 else if (!strncmp(argv[a], "-h", 2)) {
1128 relh=argv[a][2]!='/';
1129 if (!relh) safestrncpy(ctdl_home_directory, &argv[a][2],
1130 sizeof ctdl_home_directory);
1132 safestrncpy(relhome, &argv[a][2],
1139 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1141 /* If a setup type was not specified, try to determine automatically
1142 * the best one to use out of all available types.
1144 if (setup_type < 0) {
1145 setup_type = discover_ui();
1147 if (info_only == 1) {
1148 important_message("Citadel Setup", CITADEL);
1152 /* Get started in a valid setup directory. */
1153 strcpy(setup_directory, ctdl_run_dir);
1154 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
1155 strcpy(setup_directory, getenv("CITADEL"));
1158 set_str_val(0, setup_directory);
1161 enable_home = ( relh | home );
1163 if (chdir(setup_directory) != 0) {
1165 sprintf(errmsg, "The directory you specified does not exist: [%s]\n", setup_directory);
1167 important_message("Citadel Setup", errmsg);
1171 /* Determine our host name, in case we need to use it as a default */
1174 /* Try to stop Citadel if we can */
1175 if (!access("/etc/init.d/citadel", X_OK)) {
1176 system("/etc/init.d/citadel stop");
1179 /* Make sure Citadel is not running. */
1180 if (test_server(setup_directory, relhome, enable_home) == 0) {
1181 important_message("Citadel Setup",
1182 "The Citadel service is still running.\n"
1183 "Please stop the service manually and run "
1189 switch (setup_type) {
1193 " *** Citadel setup program ***\n\n");
1199 * What we're going to try to do here is append a whole bunch of
1200 * nulls to the citadel.config file, so we can keep the old config
1201 * values if they exist, but if the file is missing or from an
1202 * earlier version with a shorter config structure, when setup tries
1203 * to read the old config parameters, they'll all come up zero.
1204 * The length of the config file will be set to what it's supposed
1205 * to be when we rewrite it, because we replace the old file with a
1206 * completely new copy.
1208 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1209 S_IRUSR | S_IWUSR)) == -1) {
1210 display_error("setup: cannot append citadel.config");
1213 fp = fdopen(a, "ab");
1215 display_error("setup: cannot append citadel.config");
1218 for (a = 0; a < sizeof(struct config); ++a)
1222 /* now we re-open it, and read the old or blank configuration */
1223 fp = fopen(file_citadel_config, "rb");
1225 display_error("setup: cannot open citadel.config");
1228 fread((char *) &config, sizeof(struct config), 1, fp);
1231 /* set some sample/default values in place of blanks... */
1232 if (IsEmptyStr(config.c_nodename))
1233 safestrncpy(config.c_nodename, my_utsname.nodename,
1234 sizeof config.c_nodename);
1235 strtok(config.c_nodename, ".");
1236 if (IsEmptyStr(config.c_fqdn) ) {
1237 if ((he = gethostbyname(my_utsname.nodename)) != NULL)
1238 safestrncpy(config.c_fqdn, he->h_name,
1239 sizeof config.c_fqdn);
1241 safestrncpy(config.c_fqdn, my_utsname.nodename,
1242 sizeof config.c_fqdn);
1244 if (IsEmptyStr(config.c_humannode))
1245 strcpy(config.c_humannode, "My System");
1246 if (IsEmptyStr(config.c_phonenum))
1247 strcpy(config.c_phonenum, "US 800 555 1212");
1248 if (config.c_initax == 0) {
1249 config.c_initax = 4;
1251 if (IsEmptyStr(config.c_moreprompt))
1252 strcpy(config.c_moreprompt, "<more>");
1253 if (IsEmptyStr(config.c_twitroom))
1254 strcpy(config.c_twitroom, "Trashcan");
1255 if (IsEmptyStr(config.c_baseroom))
1256 strcpy(config.c_baseroom, BASEROOM);
1257 if (IsEmptyStr(config.c_aideroom))
1258 strcpy(config.c_aideroom, "Aide");
1259 if (config.c_port_number == 0) {
1260 config.c_port_number = 504;
1262 if (config.c_sleeping == 0) {
1263 config.c_sleeping = 900;
1265 if (config.c_ctdluid == 0) {
1266 pw = getpwnam("citadel");
1268 config.c_ctdluid = pw->pw_uid;
1270 if (config.c_ctdluid == 0) {
1271 pw = getpwnam("bbs");
1273 config.c_ctdluid = pw->pw_uid;
1275 if (config.c_ctdluid == 0) {
1276 pw = getpwnam("guest");
1278 config.c_ctdluid = pw->pw_uid;
1280 if (config.c_createax == 0) {
1281 config.c_createax = 3;
1284 * Negative values for maxsessions are not allowed.
1286 if (config.c_maxsessions < 0) {
1287 config.c_maxsessions = 0;
1289 /* We need a system default message expiry policy, because this is
1290 * the top level and there's no 'higher' policy to fall back on.
1291 * By default, do not expire messages at all.
1293 if (config.c_ep.expire_mode == 0) {
1294 config.c_ep.expire_mode = EXPIRE_MANUAL;
1295 config.c_ep.expire_value = 0;
1299 * Default port numbers for various services
1301 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1302 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1303 if (config.c_imap_port == 0) config.c_imap_port = 143;
1304 if (config.c_msa_port == 0) config.c_msa_port = 587;
1305 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1306 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1307 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1308 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1309 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1310 if (config.c_xmpp_c2s_port == 0) config.c_xmpp_c2s_port = 5222;
1311 if (config.c_xmpp_s2s_port == 0) config.c_xmpp_s2s_port = 5269;
1313 /* Go through a series of dialogs prompting for config info */
1314 for (curr = 1; curr <= MAXSETUP; ++curr) {
1316 if ((curr == 6) && (config.c_auth_mode != AUTHMODE_LDAP) && (config.c_auth_mode != AUTHMODE_LDAP_AD)) {
1317 curr += 5; /* skip LDAP questions if we're not authenticating against LDAP */
1321 /***** begin version update section ***** */
1322 /* take care of any updating that is necessary */
1324 old_setup_level = config.c_setup_level;
1326 if (old_setup_level == 0) {
1330 if (old_setup_level < 555) {
1331 important_message("Citadel Setup",
1332 "This Citadel installation is too old "
1336 write_config_to_disk();
1338 old_setup_level = config.c_setup_level;
1340 /* end of version update section */
1343 config.c_setup_level = REV_LEVEL;
1345 /******************************************/
1347 write_config_to_disk();
1349 mkdir(ctdl_info_dir, 0700);
1350 chmod(ctdl_info_dir, 0700);
1351 chown(ctdl_info_dir, config.c_ctdluid, -1);
1353 mkdir(ctdl_bio_dir, 0700);
1354 chmod(ctdl_bio_dir, 0700);
1355 chown(ctdl_bio_dir, config.c_ctdluid, -1);
1357 mkdir(ctdl_usrpic_dir, 0700);
1358 chmod(ctdl_usrpic_dir, 0700);
1359 chown(ctdl_usrpic_dir, config.c_ctdluid, -1);
1361 mkdir(ctdl_message_dir, 0700);
1362 chmod(ctdl_message_dir, 0700);
1363 chown(ctdl_message_dir, config.c_ctdluid, -1);
1365 mkdir(ctdl_hlp_dir, 0700);
1366 chmod(ctdl_hlp_dir, 0700);
1367 chown(ctdl_hlp_dir, config.c_ctdluid, -1);
1369 mkdir(ctdl_image_dir, 0700);
1370 chmod(ctdl_image_dir, 0700);
1371 chown(ctdl_image_dir, config.c_ctdluid, -1);
1373 mkdir(ctdl_bb_dir, 0700);
1374 chmod(ctdl_bb_dir, 0700);
1375 chown(ctdl_bb_dir, config.c_ctdluid, -1);
1377 mkdir(ctdl_file_dir, 0700);
1378 chmod(ctdl_file_dir, 0700);
1379 chown(ctdl_file_dir, config.c_ctdluid, -1);
1381 mkdir(ctdl_netcfg_dir, 0700);
1382 chmod(ctdl_netcfg_dir, 0700);
1383 chown(ctdl_netcfg_dir, config.c_ctdluid, -1);
1385 /* Delete files and directories used by older Citadel versions */
1386 system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1387 unlink("citadel.log");
1390 if (((setup_type == UI_SILENT) && (getenv("ALTER_ETC_SERVICES")!=NULL)) ||
1391 (setup_type != UI_SILENT))
1392 check_services_entry(); /* Check /etc/services */
1394 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1395 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1397 if ((getenv("ACT_AS_MTA") == NULL) ||
1398 (getenv("ACT_AS_MTA") &&
1399 strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
1400 /* Offer to disable other MTA's on the system. */
1401 disable_other_mta("courier-authdaemon");
1402 disable_other_mta("courier-imap");
1403 disable_other_mta("courier-imap-ssl");
1404 disable_other_mta("courier-pop");
1405 disable_other_mta("courier-pop3");
1406 disable_other_mta("courier-pop3d");
1407 disable_other_mta("cyrmaster");
1408 disable_other_mta("cyrus");
1409 disable_other_mta("dovecot");
1410 disable_other_mta("exim");
1411 disable_other_mta("exim4");
1412 disable_other_mta("imapd");
1413 disable_other_mta("mta");
1414 disable_other_mta("pop3d");
1415 disable_other_mta("popd");
1416 disable_other_mta("postfix");
1417 disable_other_mta("qmail");
1418 disable_other_mta("saslauthd");
1419 disable_other_mta("sendmail");
1420 disable_other_mta("vmailmgrd");
1424 /* Check for the 'db' nss and offer to disable it */
1427 if ((pw = getpwuid(config.c_ctdluid)) == NULL)
1432 progress("Setting file permissions", 0, 3);
1433 chown(ctdl_run_dir, config.c_ctdluid, gid);
1434 progress("Setting file permissions", 1, 3);
1435 chown(file_citadel_config, config.c_ctdluid, gid);
1436 progress("Setting file permissions", 2, 3);
1437 chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1438 progress("Setting file permissions", 3, 3);
1441 * If we're running on SysV, install init scripts.
1443 if (!access("/var/run", W_OK)) {
1445 if (getenv("NO_INIT_SCRIPTS") == NULL) {
1446 install_init_scripts();
1449 if (!access("/etc/init.d/citadel", X_OK)) {
1450 system("/etc/init.d/citadel start");
1454 if (test_server(setup_directory, relhome, enable_home) == 0) {
1458 snprintf (admin_cmd, sizeof(admin_cmd), "%s/sendcommand \"CREU %s|%s\" 2>&1",
1459 ctdl_sbin_dir, config.c_sysadm, admin_pass);
1460 fp = popen(admin_cmd, "r");
1462 while (fgets(buf, sizeof buf, fp) != NULL)
1464 if ((atol(buf) == 574) || (atol(buf) == 200))
1471 important_message("Error","Setup failed to create your admin user");
1473 if (setup_type != UI_SILENT)
1474 important_message("Setup finished",
1475 "Setup of the Citadel server is complete.\n"
1476 "If you will be using WebCit, please run its\n"
1477 "setup program now; otherwise, run './citadel'\n"
1481 important_message("Setup failed",
1482 "Setup is finished, but the Citadel server failed to start.\n"
1483 "Go back and check your configuration.\n"
1490 important_message("Setup finished",
1491 "Setup is finished. You may now start the server.");