4 * Citadel setup utility
8 #define SHOW_ME_VAPPEND_PRINTF
10 #include "ctdl_module.h"
19 #include <sys/types.h>
21 #include <sys/utsname.h>
29 #include <libcitadel.h>
34 #include "citadel_dirs.h"
45 #define _(string) gettext(string)
47 #define _(string) (string)
51 #define MAXSETUP 11 /* How many setup questions to ask */
53 #define UI_TEXT 0 /* Default setup type -- text only */
54 #define UI_DIALOG 2 /* Use the 'dialog' program */
55 #define UI_SILENT 3 /* Silent running, for use in scripts */
57 #define SERVICE_NAME "citadel"
58 #define PROTO_NAME "tcp"
59 #define NSSCONF "/etc/nsswitch.conf"
62 typedef enum _SetupStep {
78 ///"CREATE_XINETD_ENTRY";
79 const char *EnvNames [eMaxQuestions] = {
95 char setup_directory[PATH_MAX];
96 int using_web_installer = 0;
101 const char *setup_titles[eMaxQuestions];
105 setup_titles[eCitadelHomeDir] = _("Citadel Home Directory");
106 setup_titles[eSysAdminName] = _("Citadel administrator username:");////
107 setup_titles[eSysAdminPW] = _("Administrator password:");//
108 setup_titles[eUID] = _("Citadel User ID:");
109 setup_titles[eIP_ADDR] = _("Listening address for the Citadel server:");///
110 setup_titles[eCTDL_Port] = _("Server port number:");
111 setup_titles[eAuthType] = _("Authentication method to use:");////
112 setup_titles[eLDAP_Host] = _("LDAP host:");///
113 setup_titles[eLDAP_Port] = _("LDAP port number:");////
114 setup_titles[eLDAP_Base_DN] = _("LDAP base DN:");///
115 setup_titles[eLDAP_Bind_DN] = _("LDAP bind DN:");//
116 setup_titles[eLDAP_Bind_PW] = _("LDAP bind password:");//
120 * \brief print the actual stack frame.
122 void cit_backtrace(void)
124 #ifdef HAVE_BACKTRACE
125 void *stack_frames[50];
130 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
131 strings = backtrace_symbols(stack_frames, size);
132 for (i = 0; i < size; i++) {
134 fprintf(stderr, "%s\n", strings[i]);
136 fprintf(stderr, "%p\n", stack_frames[i]);
142 struct config config;
144 /* calculate all our path on a central place */
145 /* where to keep our config */
148 char *setup_text[] = {
150 "Enter the full pathname of the directory in which the Citadel\n"
151 "installation you are creating or updating resides. If you\n"
152 "specify a directory other than the default, you will need to\n"
153 "specify the -h flag to the server when you start it up.\n",
155 "Enter the subdirectory name for an alternate installation of "
156 "Citadel. To do a default installation just leave it blank."
157 "If you specify a directory other than the default, you will need to\n"
158 "specify the -h flag to the server when you start it up.\n"
159 "note that it may not have a leading /",
162 "Enter the name of the system administrator (which is probably\n"
163 "you). When an account is created with this name, it will\n"
164 "automatically be given administrator-level access.\n",
166 "Enter a password for the system administrator. When setup\n"
167 "completes it will attempt to create the administrator user\n"
168 "and set the password specified here.\n",
170 "Citadel needs to run under its own user ID. This would\n"
171 "typically be called \"citadel\", but if you are running Citadel\n"
172 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
173 "The server will run under this user ID. Please specify that\n"
174 "user ID here. You may specify either a user name or a numeric\n"
177 "Specify the IP address on which your server will run. If you\n"
178 "leave this blank, or if you specify 0.0.0.0, Citadel will listen\n"
179 "on all addresses. You can usually skip this unless you are\n"
180 "running multiple instances of Citadel on the same computer.\n",
182 "Specify the TCP port number on which your server will run.\n"
183 "Normally, this will be port 504, which is the official port\n"
184 "assigned by the IANA for Citadel servers. You will only need\n"
185 "to specify a different port number if you run multiple instances\n"
186 "of Citadel on the same computer and there is something else\n"
187 "already using port 504.\n",
191 "Specify which authentication mode you wish to use.\n"
193 " 0. Self contained authentication\n"
194 " 1. Host system integrated authentication\n"
195 " 2. External LDAP - RFC 2307 compliant directory\n"
196 " 3. External LDAP - nonstandard MS Active Directory\n"
198 "For help: http://www.citadel.org/doku.php/faq:installation:authmodes\n"
200 "ANSWER \"0\" UNLESS YOU COMPLETELY UNDERSTAND THIS OPTION.\n",
202 "Please enter the host name or IP address of your LDAP server.\n",
204 "Please enter the port number of the LDAP service (usually 389).\n",
206 "Please enter the Base DN to search for authentication\n"
207 "(for example: dc=example,dc=com)\n",
209 "Please enter the DN of an account to use for binding to the LDAP server\n"
210 "for performing queries. The account does not require any other\n"
211 "privileges. If your LDAP server allows anonymous queries, you can.\n"
212 "leave this blank.\n",
214 "If you entered a Bind DN in the previous question, you must now enter\n"
215 "the password associated with that account. Otherwise, you can leave this\n"
220 struct config config;
224 void cleanup(int exitcode)
226 // printf("Exitcode: %d\n", exitcode);
233 void title(const char *text)
235 if (setup_type == UI_TEXT) {
236 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
242 int yesno(char *question, int default_value)
248 switch (setup_type) {
252 printf("%s\nYes/No [%s] --> ",
254 ( default_value ? "Yes" : "No" )
256 if (fgets(buf, sizeof buf, stdin))
258 answer = tolower(buf[0]);
259 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
260 answer = default_value;
261 else if (answer == 'y')
263 else if (answer == 'n')
266 } while ((answer < 0) || (answer > 1));
270 sprintf(buf, "exec %s %s --yesno '%s' 15 75",
271 getenv("CTDL_DIALOG"),
272 ( default_value ? "" : "--defaultno" ),
290 void important_message(char *title, char *msgtext)
295 switch (setup_type) {
298 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");
299 printf(" %s \n\n%s\n\n", title, msgtext);
300 printf("Press return to continue...");
301 if (fgets(buf, sizeof buf, stdin));
305 sprintf(buf, "exec %s --msgbox '%s' 19 72",
306 getenv("CTDL_DIALOG"),
311 fprintf(stderr, "%s\n", msgtext);
316 void important_msgnum(int msgnum)
318 important_message("Important Message", setup_text[msgnum]);
321 void display_error(char *error_message)
323 important_message("Error", error_message);
326 void progress(char *text, long int curr, long int cmax)
328 static long dots_printed = 0L;
330 static FILE *fp = NULL;
333 switch (setup_type) {
337 printf("%s\n", text);
338 printf("..........................");
339 printf("..........................");
340 printf("..........................\r");
343 } else if (curr == cmax) {
344 printf("\r%79s\n", "");
346 a = (curr * 100) / cmax;
349 while (dots_printed < a) {
359 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
360 getenv("CTDL_DIALOG"),
362 fp = popen(buf, "w");
368 else if (curr == cmax) {
370 fprintf(fp, "100\n");
376 a = (curr * 100) / cmax;
378 fprintf(fp, "%ld\n", a);
392 * check_services_entry() -- Make sure "citadel" is in /etc/services
395 void check_services_entry(void)
401 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
402 for (i=0; i<=2; ++i) {
403 progress("Adding service entry...", i, 2);
405 sfp = fopen("/etc/services", "a");
407 sprintf(errmsg, "Cannot open /etc/services: %s", strerror(errno));
408 display_error(errmsg);
410 fprintf(sfp, "%s 504/tcp\n", SERVICE_NAME);
422 * delete_inittab_entry() -- Remove obsolete /etc/inittab entry for Citadel
425 void delete_inittab_entry(void)
429 char looking_for[256];
431 char outfilename[32];
432 int changes_made = 0;
435 /* Determine the fully qualified path name of citserver */
436 snprintf(looking_for,
442 /* Now tweak /etc/inittab */
443 infp = fopen("/etc/inittab", "r");
446 /* If /etc/inittab does not exist, return quietly.
447 * Not all host platforms have it.
449 if (errno == ENOENT) {
453 /* Other errors might mean something really did go wrong.
455 sprintf(buf, "Cannot open /etc/inittab: %s", strerror(errno));
460 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
461 outfp = fdopen(mkstemp(outfilename), "w+");
463 sprintf(buf, "Cannot open %s: %s", outfilename, strerror(errno));
469 while (fgets(buf, sizeof buf, infp) != NULL) {
470 if (strstr(buf, looking_for) != NULL) {
471 rv = fwrite("#", 1, 1, outfp);
474 rv = fwrite(buf, strlen(buf), 1, outfp);
481 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
483 rv = system("/sbin/init q 2>/dev/null");
492 * install_init_scripts() -- Try to configure to start Citadel at boot
495 void install_init_scripts(void)
497 struct stat etcinitd;
499 char *initfile = "/etc/init.d/citadel";
503 if ((stat("/etc/init.d/", &etcinitd) == -1) &&
506 if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
508 initfile = CTDLDIR"/citadel.init";
510 initfile = "/etc/rc.d/init.d/citadel";
513 fp = fopen(initfile, "r");
515 if (yesno("Citadel already appears to be configured to start at boot.\n"
516 "Would you like to keep your boot configuration as is?\n", 1) == 1) {
523 if (yesno("Would you like to automatically start Citadel at boot?\n", 1) == 0) {
527 fp = fopen(initfile, "w");
529 display_error("Cannot create /etc/init.d/citadel");
533 fprintf(fp, "#!/bin/sh\n"
535 "# Init file for Citadel\n"
537 "# chkconfig: - 79 30\n"
538 "# description: Citadel service\n"
539 "# processname: citserver\n"
540 "# pidfile: %s/citadel.pid\n\n"
541 "# uncomment this to create coredumps as described in\n"
542 "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
543 "# ulimit -c unlimited\n"
551 "test -d /var/run || exit 0\n"
555 "start) echo -n \"Starting Citadel... \"\n"
556 " if $CITADEL_DIR/citserver -lmail -d -h$CITADEL_DIR\n"
563 "stop) echo -n \"Stopping Citadel... \"\n"
564 " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
569 " rm -f %s/citadel.pid 2>/dev/null\n"
574 "restart) if $CITADEL_DIR/sendcommand DOWN 1 >/dev/null 2>&1 ; then\n"
580 "*) echo \"Usage: $0 {start|stop|restart}\"\n"
587 chmod(initfile, 0755);
589 /* Set up the run levels. */
590 rv = system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
591 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);
592 rv = system(command);
593 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);
594 rv = system(command);
604 * On systems which use xinetd, see if we can offer to install Citadel as
605 * the default telnet target.
607 void check_xinetd_entry(void) {
608 char *filename = "/etc/xinetd.d/telnet";
611 int already_citadel = 0;
614 fp = fopen(filename, "r+");
615 if (fp == NULL) return; /* Not there. Oh well... */
617 while (fgets(buf, sizeof buf, fp) != NULL) {
618 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
621 if (already_citadel) return; /* Already set up this way. */
623 /* Otherwise, prompt the user to create an entry. */
624 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
625 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
630 snprintf(buf, sizeof buf,
631 "Setup can configure the \"xinetd\" service to automatically\n"
632 "connect incoming telnet sessions to Citadel, bypassing the\n"
633 "host system login: prompt. Would you like to do this?\n"
635 if (yesno(buf, 1) == 0) {
640 fp = fopen(filename, "w");
642 "# description: telnet service for Citadel users\n"
647 " socket_type = stream\n"
650 " server = /usr/sbin/in.telnetd\n"
651 " server_args = -h -L %s/citadel\n"
652 " log_on_failure += USERID\n"
657 /* Now try to restart the service */
658 rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
664 * Offer to disable other MTA's
666 void disable_other_mta(const char *mta) {
672 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
673 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
675 fp = popen(buf, "r");
676 if (fp == NULL) return;
678 while (fgets(buf, sizeof buf, fp) != NULL) {
682 if (lines == 0) return; /* Nothing to do. */
685 /* Offer to replace other MTA with the vastly superior Citadel :) */
687 snprintf(buf, sizeof buf,
688 "You appear to have the \"%s\" email program\n"
689 "running on your system. If you want Citadel mail\n"
690 "connected with %s, you will have to manually integrate\n"
691 "them. It is preferable to disable %s, and use Citadel's\n"
692 "SMTP, POP3, and IMAP services.\n\n"
693 "May we disable %s so that Citadel has access to ports\n"
694 "25, 110, and 143?\n",
697 if (yesno(buf, 1) == 0) {
702 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);
704 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
708 const char *other_mtas[] = {
709 "courier-authdaemon",
732 void disable_other_mtas(void)
735 if ((getenv("ACT_AS_MTA") == NULL) ||
736 (getenv("ACT_AS_MTA") &&
737 strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
738 /* Offer to disable other MTA's on the system. */
739 while (!IsEmptyStr(other_mtas[i]))
741 disable_other_mta(other_mtas[i]);
748 * Check to see if our server really works. Returns 0 on success.
750 int test_server(char *setup_directory, char *relhomestr, int relhome) {
757 /* Generate a silly little cookie. We're going to write it out
758 * to the server and try to get it back. The cookie does not
759 * have to be secret ... just unique.
761 sprintf(cookie, "--test--%d--", getpid());
764 sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
769 sprintf(cmd, "%s/sendcommand ECHO %s 2>&1",
773 fp = popen(cmd, "r");
774 if (fp == NULL) return(errno);
776 while (fgets(buf, sizeof buf, fp) != NULL) {
778 && (strstr(buf, cookie) != NULL) ) {
790 void strprompt(const char *prompt_title, char *prompt_text, char *Target, char *DefValue)
794 char dialog_result[PATH_MAX];
798 strcpy(setupmsg, "");
800 switch (setup_type) {
803 printf("\n%s\n", prompt_text);
804 printf("This is currently set to:\n%s\n", Target);
805 printf("Enter new value or press return to leave unchanged:\n");
806 if (fgets(buf, sizeof buf, stdin)){
807 buf[strlen(buf) - 1] = 0;
809 if (!IsEmptyStr(buf))
814 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
815 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
816 getenv("CTDL_DIALOG"),
821 fp = fopen(dialog_result, "r");
823 if (fgets(Target, sizeof buf, fp)) {
824 if (Target[strlen(Target)-1] == 10) {
825 Target[strlen(Target)-1] = 0;
829 unlink(dialog_result);
833 strcpy(Target, DefValue);
838 void set_bool_val(int msgpos, int *ip, char *DefValue) {
839 title(setup_titles[msgpos]);
840 *ip = yesno(setup_text[msgpos], *ip);
843 void set_str_val(int msgpos, char *Target, char *DefValue) {
844 strprompt(setup_titles[msgpos],
850 void set_int_val(int msgpos, int *ip, char *DefValue)
853 snprintf(buf, sizeof buf, "%d", (int) *ip);
854 set_str_val(msgpos, buf, DefValue);
859 void set_char_val(int msgpos, char *ip, char *DefValue)
862 snprintf(buf, sizeof buf, "%d", (int) *ip);
863 set_str_val(msgpos, buf, DefValue);
864 *ip = (char) atoi(buf);
868 void set_long_val(int msgpos, long int *ip, char *DefValue)
871 snprintf(buf, sizeof buf, "%ld", *ip);
872 set_str_val(msgpos, buf, DefValue);
877 void edit_value(int curr)
881 char ctdluidname[256];
884 if (setup_type == UI_SILENT)
886 Value = getenv(EnvNames[curr]);
893 set_str_val(curr, config.c_sysadm, Value);
897 set_str_val(curr, admin_pass, Value);
901 if (setup_type == UI_SILENT)
904 config.c_ctdluid = atoi(Value);
910 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
912 i = config.c_ctdluid;
915 set_int_val(curr, &i, Value);
916 config.c_ctdluid = i;
919 strcpy(ctdluidname, pw->pw_name);
920 set_str_val(curr, ctdluidname, Value);
921 pw = getpwnam(ctdluidname);
923 config.c_ctdluid = pw->pw_uid;
925 else if (atoi(ctdluidname) > 0) {
926 config.c_ctdluid = atoi(ctdluidname);
934 set_str_val(curr, config.c_ip_addr, Value);
938 set_int_val(curr, &config.c_port_number, Value);
942 if (setup_type == UI_SILENT)
945 config.c_auth_mode = AUTHMODE_NATIVE;
949 if ((strcasecmp(auth, "yes") == 0) ||
950 (strcasecmp(auth, "host") == 0))
952 config.c_auth_mode = AUTHMODE_HOST;
954 else if (strcasecmp(auth, "ldap") == 0){
955 config.c_auth_mode = AUTHMODE_LDAP;
957 else if ((strcasecmp(auth, "ldap_ad") == 0) ||
958 (strcasecmp(auth, "active directory") == 0)){
959 config.c_auth_mode = AUTHMODE_LDAP_AD;
964 set_int_val(curr, &config.c_auth_mode, Value);
969 set_str_val(curr, config.c_ldap_host, Value);
973 if (config.c_ldap_port == 0) {
974 config.c_ldap_port = 389;
976 set_int_val(curr, &config.c_ldap_port, Value);
980 set_str_val(curr, config.c_ldap_base_dn, Value);
984 set_str_val(curr, config.c_ldap_bind_dn, Value);
988 set_str_val(curr, config.c_ldap_bind_pw, Value);
995 * (re-)write the config data to disk
997 void write_config_to_disk(void)
1003 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
1004 display_error("setup: cannot open citadel.config");
1007 fp = fdopen(fd, "wb");
1009 display_error("setup: cannot open citadel.config");
1012 rv = fwrite((char *) &config, sizeof(struct config), 1, fp);
1020 * Figure out what type of user interface we're going to use
1022 int discover_ui(void)
1025 /* Use "dialog" if we have it */
1026 if (getenv("CTDL_DIALOG") != NULL) {
1035 void migrate_old_installs(void)
1038 rv = system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1039 unlink("citadel.log");
1045 * Strip "db" entries out of /etc/nsswitch.conf
1055 int file_changed = 0;
1056 char new_filename[64];
1059 fp_read = fopen(NSSCONF, "r");
1060 if (fp_read == NULL) {
1064 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
1065 fd_write = mkstemp(new_filename);
1071 while (fgets(buf, sizeof buf, fp_read) != NULL) {
1073 strcpy(buf_nc, buf);
1074 for (i=0; i<strlen(buf_nc); ++i) {
1075 if (buf_nc[i] == '#') {
1079 for (i=0; i<strlen(buf_nc); ++i) {
1080 if (!strncasecmp(&buf_nc[i], "db", 2)) {
1082 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
1085 strcpy(&buf_nc[i], &buf_nc[i+2]);
1086 strcpy(&buf[i], &buf[i+2]);
1088 strcpy(&buf_nc[i], &buf_nc[i+1]);
1089 strcpy(&buf[i], &buf[i+1]);
1095 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
1098 unlink(new_filename);
1105 if (!file_changed) {
1106 unlink(new_filename);
1110 snprintf(question, sizeof question,
1112 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
1113 "one or more services. This is not necessary on most systems,\n"
1114 "and it is known to crash the Citadel server when delivering\n"
1115 "mail to the Internet.\n"
1117 "Do you want this module to be automatically disabled?\n"
1121 if (yesno(question, 1)) {
1122 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
1124 chmod(NSSCONF, 0644);
1126 unlink(new_filename);
1129 void check_init_script (char *relhome)
1135 * If we're running on SysV, install init scripts.
1137 if (!access("/var/run", W_OK)) {
1139 if (getenv("NO_INIT_SCRIPTS") == NULL) {
1140 install_init_scripts();
1143 if (!access("/etc/init.d/citadel", X_OK)) {
1144 rv = system("/etc/init.d/citadel start");
1148 if (test_server(setup_directory, relhome, enable_home) == 0) {
1152 if (config.c_auth_mode == AUTHMODE_NATIVE) {
1153 snprintf (admin_cmd, sizeof(admin_cmd), "%s/sendcommand \"CREU %s|%s\" 2>&1",
1154 ctdl_sbin_dir, config.c_sysadm, admin_pass);
1155 fp = popen(admin_cmd, "r");
1157 while (fgets(buf, sizeof buf, fp) != NULL)
1159 if ((atol(buf) == 574) || (atol(buf) == 200))
1165 if (found_it == 0) {
1166 important_message("Error","Setup failed to create your admin user");
1170 if (setup_type != UI_SILENT)
1171 important_message("Setup finished",
1172 "Setup of the Citadel server is complete.\n"
1173 "If you will be using WebCit, please run its\n"
1174 "setup program now; otherwise, run './citadel'\n"
1178 important_message("Setup failed",
1179 "Setup is finished, but the Citadel server failed to start.\n"
1180 "Go back and check your configuration.\n"
1187 important_message("Setup finished",
1188 "Setup is finished. You may now start the server.");
1192 void set_default_values(void)
1195 struct utsname my_utsname;
1198 /* Determine our host name, in case we need to use it as a default */
1201 /* set some sample/default values in place of blanks... */
1202 if (IsEmptyStr(config.c_nodename))
1203 safestrncpy(config.c_nodename, my_utsname.nodename,
1204 sizeof config.c_nodename);
1205 strtok(config.c_nodename, ".");
1206 if (IsEmptyStr(config.c_fqdn) ) {
1207 if ((he = gethostbyname(my_utsname.nodename)) != NULL) {
1208 safestrncpy(config.c_fqdn, he->h_name, sizeof config.c_fqdn);
1210 safestrncpy(config.c_fqdn, my_utsname.nodename, sizeof config.c_fqdn);
1213 if (IsEmptyStr(config.c_humannode)) {
1214 strcpy(config.c_humannode, "My System");
1216 if (IsEmptyStr(config.c_phonenum)) {
1217 strcpy(config.c_phonenum, "US 800 555 1212");
1219 if (config.c_initax == 0) {
1220 config.c_initax = 4;
1222 if (IsEmptyStr(config.c_moreprompt)) strcpy(config.c_moreprompt, "<more>");
1223 if (IsEmptyStr(config.c_twitroom)) strcpy(config.c_twitroom, "Trashcan");
1224 if (IsEmptyStr(config.c_baseroom)) strcpy(config.c_baseroom, BASEROOM);
1225 if (IsEmptyStr(config.c_aideroom)) strcpy(config.c_aideroom, "Aide");
1226 if (config.c_port_number == 0) {
1227 config.c_port_number = 504;
1229 if (config.c_sleeping == 0) {
1230 config.c_sleeping = 900;
1232 if (config.c_ctdluid == 0) {
1233 pw = getpwnam("citadel");
1235 config.c_ctdluid = pw->pw_uid;
1238 if (config.c_ctdluid == 0) {
1239 pw = getpwnam("bbs");
1241 config.c_ctdluid = pw->pw_uid;
1244 if (config.c_ctdluid == 0) {
1245 pw = getpwnam("guest");
1247 config.c_ctdluid = pw->pw_uid;
1250 if (config.c_createax == 0) {
1251 config.c_createax = 3;
1254 * Negative values for maxsessions are not allowed.
1256 if (config.c_maxsessions < 0) {
1257 config.c_maxsessions = 0;
1259 /* We need a system default message expiry policy, because this is
1260 * the top level and there's no 'higher' policy to fall back on.
1261 * By default, do not expire messages at all.
1263 if (config.c_ep.expire_mode == 0) {
1264 config.c_ep.expire_mode = EXPIRE_MANUAL;
1265 config.c_ep.expire_value = 0;
1269 * Default port numbers for various services
1271 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1272 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1273 if (config.c_imap_port == 0) config.c_imap_port = 143;
1274 if (config.c_msa_port == 0) config.c_msa_port = 587;
1275 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1276 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1277 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1278 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1279 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1280 if (config.c_xmpp_c2s_port == 0) config.c_xmpp_c2s_port = 5222;
1281 if (config.c_xmpp_s2s_port == 0) config.c_xmpp_s2s_port = 5269;
1285 void get_config (void)
1292 * What we're going to try to do here is append a whole bunch of
1293 * nulls to the citadel.config file, so we can keep the old config
1294 * values if they exist, but if the file is missing or from an
1295 * earlier version with a shorter config structure, when setup tries
1296 * to read the old config parameters, they'll all come up zero.
1297 * The length of the config file will be set to what it's supposed
1298 * to be when we rewrite it, because we replace the old file with a
1299 * completely new copy.
1301 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1302 S_IRUSR | S_IWUSR)) == -1) {
1303 display_error("setup: cannot append citadel.config");
1306 fp = fdopen(a, "ab");
1308 display_error("setup: cannot append citadel.config");
1311 for (a = 0; a < sizeof(struct config); ++a) {
1316 /* now we re-open it, and read the old or blank configuration */
1317 fp = fopen(file_citadel_config, "rb");
1319 display_error("setup: cannot open citadel.config");
1322 rv = fread((char *) &config, sizeof(struct config), 1, fp);
1327 int main(int argc, char *argv[])
1332 int old_setup_level = 0;
1336 char relhome[PATH_MAX]="";
1337 char ctdldir[PATH_MAX]=CTDLDIR;
1338 char DefValue[PATH_MAX];
1343 /* set an invalid setup type */
1346 /* Check to see if we're running the web installer */
1347 if (getenv("CITADEL_INSTALLER") != NULL) {
1348 using_web_installer = 1;
1351 /* parse command line args */
1352 for (a = 0; a < argc; ++a) {
1353 if (!strncmp(argv[a], "-u", 2)) {
1354 strcpy(aaa, argv[a]);
1355 strcpy(aaa, &aaa[2]);
1356 setup_type = atoi(aaa);
1358 else if (!strcmp(argv[a], "-i")) {
1361 else if (!strcmp(argv[a], "-q")) {
1362 setup_type = UI_SILENT;
1364 else if (!strncmp(argv[a], "-h", 2)) {
1365 relh=argv[a][2]!='/';
1367 safestrncpy(ctdl_home_directory, &argv[a][2], sizeof ctdl_home_directory);
1369 safestrncpy(relhome, &argv[a][2], sizeof relhome);
1376 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1378 /* If a setup type was not specified, try to determine automatically
1379 * the best one to use out of all available types.
1381 if (setup_type < 0) {
1382 setup_type = discover_ui();
1384 if (info_only == 1) {
1385 important_message("Citadel Setup", CITADEL);
1389 /* Get started in a valid setup directory. */
1390 strcpy(setup_directory, ctdl_run_dir);
1391 strcpy(DefValue, ctdl_run_dir);
1392 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
1393 strcpy(setup_directory, getenv("CITADEL"));
1396 set_str_val(0, setup_directory, DefValue);
1399 enable_home = ( relh | home );
1401 if (chdir(setup_directory) != 0) {
1403 sprintf(errmsg, "The directory you specified does not exist: [%s]\n", setup_directory);
1405 important_message("Citadel Setup", errmsg);
1410 /* Try to stop Citadel if we can */
1411 if (!access("/etc/init.d/citadel", X_OK)) {
1412 rv = system("/etc/init.d/citadel stop");
1415 /* Make sure Citadel is not running. */
1416 if (test_server(setup_directory, relhome, enable_home) == 0) {
1417 important_message("Citadel Setup",
1418 "The Citadel service is still running.\n"
1419 "Please stop the service manually and run "
1425 switch (setup_type) {
1429 " *** Citadel setup program ***\n\n");
1436 set_default_values();
1438 /* Go through a series of dialogs prompting for config info */
1439 for (curr = 1; curr <= MAXSETUP; ++curr) {
1441 if ((curr == 6) && (config.c_auth_mode != AUTHMODE_LDAP) && (config.c_auth_mode != AUTHMODE_LDAP_AD)) {
1442 curr += 5; /* skip LDAP questions if we're not authenticating against LDAP */
1446 /***** begin version update section ***** */
1447 /* take care of any updating that is necessary */
1449 old_setup_level = config.c_setup_level;
1451 if (old_setup_level == 0) {
1455 if (old_setup_level < 555) {
1456 important_message("Citadel Setup",
1457 "This Citadel installation is too old "
1461 write_config_to_disk();
1463 old_setup_level = config.c_setup_level;
1465 /* end of version update section */
1468 config.c_setup_level = REV_LEVEL;
1470 /******************************************/
1471 if ((pw = getpwuid(config.c_ctdluid)) == NULL) {
1477 create_run_directories(config.c_ctdluid, gid);
1479 write_config_to_disk();
1481 migrate_old_installs(); /* Delete files and directories used by older Citadel versions */
1483 if (((setup_type == UI_SILENT) && (getenv("ALTER_ETC_SERVICES")!=NULL)) ||
1484 (setup_type != UI_SILENT))
1485 check_services_entry(); /* Check /etc/services */
1487 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1488 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1489 disable_other_mtas(); /* Offer to disable other MTAs */
1492 fixnss(); /* Check for the 'db' nss and offer to disable it */
1494 progress("Setting file permissions", 1, 3);
1495 rv = chown(file_citadel_config, config.c_ctdluid, gid);
1496 progress("Setting file permissions", 2, 3);
1497 rv = chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1498 progress("Setting file permissions", 3, 3);
1500 check_init_script (relhome);