4 * Citadel setup utility
8 #include "ctdl_module.h"
17 #include <sys/types.h>
19 #include <sys/utsname.h>
27 #include <libcitadel.h>
32 #include "citadel_dirs.h"
43 #define _(string) gettext(string)
45 #define _(string) (string)
49 #define MAXSETUP 11 /* How many setup questions to ask */
51 #define UI_TEXT 0 /* Default setup type -- text only */
52 #define UI_DIALOG 2 /* Use the 'dialog' program */
53 #define UI_SILENT 3 /* Silent running, for use in scripts */
55 #define SERVICE_NAME "citadel"
56 #define PROTO_NAME "tcp"
57 #define NSSCONF "/etc/nsswitch.conf"
60 typedef enum _SetupStep {
76 char setup_directory[PATH_MAX];
77 int using_web_installer = 0;
82 char *setup_titles[] =
84 "Citadel Home Directory",
85 "System Administrator",
86 "Administrator Password",
90 "Authentication mode",
99 * \brief print the actual stack frame.
101 void cit_backtrace(void)
103 #ifdef HAVE_BACKTRACE
104 void *stack_frames[50];
109 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
110 strings = backtrace_symbols(stack_frames, size);
111 for (i = 0; i < size; i++) {
113 fprintf(stderr, "%s\n", strings[i]);
115 fprintf(stderr, "%p\n", stack_frames[i]);
121 struct config config;
123 /* calculate all our path on a central place */
124 /* where to keep our config */
127 char *setup_text[] = {
129 "Enter the full pathname of the directory in which the Citadel\n"
130 "installation you are creating or updating resides. If you\n"
131 "specify a directory other than the default, you will need to\n"
132 "specify the -h flag to the server when you start it up.\n",
134 "Enter the subdirectory name for an alternate installation of "
135 "Citadel. To do a default installation just leave it blank."
136 "If you specify a directory other than the default, you will need to\n"
137 "specify the -h flag to the server when you start it up.\n"
138 "note that it may not have a leading /",
141 "Enter the name of the system administrator (which is probably\n"
142 "you). When an account is created with this name, it will\n"
143 "automatically be given administrator-level access.\n",
145 "Enter a password for the system administrator. When setup\n"
146 "completes it will attempt to create the administrator user\n"
147 "and set the password specified here.\n",
149 "Citadel needs to run under its own user ID. This would\n"
150 "typically be called \"citadel\", but if you are running Citadel\n"
151 "as a public BBS, you might also call it \"bbs\" or \"guest\".\n"
152 "The server will run under this user ID. Please specify that\n"
153 "user ID here. You may specify either a user name or a numeric\n"
156 "Specify the IP address on which your server will run. If you\n"
157 "leave this blank, or if you specify 0.0.0.0, Citadel will listen\n"
158 "on all addresses. You can usually skip this unless you are\n"
159 "running multiple instances of Citadel on the same computer.\n",
161 "Specify the TCP port number on which your server will run.\n"
162 "Normally, this will be port 504, which is the official port\n"
163 "assigned by the IANA for Citadel servers. You will only need\n"
164 "to specify a different port number if you run multiple instances\n"
165 "of Citadel on the same computer and there is something else\n"
166 "already using port 504.\n",
170 "Specify which authentication mode you wish to use.\n"
172 " 0. Self contained authentication\n"
173 " 1. Host system integrated authentication\n"
174 " 2. External LDAP - RFC 2307 compliant directory\n"
175 " 3. External LDAP - nonstandard MS Active Directory\n"
177 "For help: http://www.citadel.org/doku.php/faq:installation:authmodes\n"
179 "ANSWER \"0\" UNLESS YOU COMPLETELY UNDERSTAND THIS OPTION.\n",
181 "Please enter the host name or IP address of your LDAP server.\n",
183 "Please enter the port number of the LDAP service (usually 389).\n",
185 "Please enter the Base DN to search for authentication\n"
186 "(for example: dc=example,dc=com)\n",
188 "Please enter the DN of an account to use for binding to the LDAP server\n"
189 "for performing queries. The account does not require any other\n"
190 "privileges. If your LDAP server allows anonymous queries, you can.\n"
191 "leave this blank.\n",
193 "If you entered a Bind DN in the previous question, you must now enter\n"
194 "the password associated with that account. Otherwise, you can leave this\n"
199 struct config config;
203 void cleanup(int exitcode)
205 // printf("Exitcode: %d\n", exitcode);
212 void title(char *text)
214 if (setup_type == UI_TEXT) {
215 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
221 int yesno(char *question, int default_value)
227 switch (setup_type) {
231 printf("%s\nYes/No [%s] --> ",
233 ( default_value ? "Yes" : "No" )
235 if (fgets(buf, sizeof buf, stdin))
237 answer = tolower(buf[0]);
238 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
239 answer = default_value;
240 else if (answer == 'y')
242 else if (answer == 'n')
245 } while ((answer < 0) || (answer > 1));
249 sprintf(buf, "exec %s %s --yesno '%s' 15 75",
250 getenv("CTDL_DIALOG"),
251 ( default_value ? "" : "--defaultno" ),
269 void important_message(char *title, char *msgtext)
274 switch (setup_type) {
277 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");
278 printf(" %s \n\n%s\n\n", title, msgtext);
279 printf("Press return to continue...");
280 if (fgets(buf, sizeof buf, stdin));
284 sprintf(buf, "exec %s --msgbox '%s' 19 72",
285 getenv("CTDL_DIALOG"),
290 fprintf(stderr, "%s\n", msgtext);
295 void important_msgnum(int msgnum)
297 important_message("Important Message", setup_text[msgnum]);
300 void display_error(char *error_message)
302 important_message("Error", error_message);
305 void progress(char *text, long int curr, long int cmax)
307 static long dots_printed = 0L;
309 static FILE *fp = NULL;
312 switch (setup_type) {
316 printf("%s\n", text);
317 printf("..........................");
318 printf("..........................");
319 printf("..........................\r");
322 } else if (curr == cmax) {
323 printf("\r%79s\n", "");
325 a = (curr * 100) / cmax;
328 while (dots_printed < a) {
338 sprintf(buf, "exec %s --gauge '%s' 7 72 0",
339 getenv("CTDL_DIALOG"),
341 fp = popen(buf, "w");
347 else if (curr == cmax) {
349 fprintf(fp, "100\n");
355 a = (curr * 100) / cmax;
357 fprintf(fp, "%ld\n", a);
371 * check_services_entry() -- Make sure "citadel" is in /etc/services
374 void check_services_entry(void)
380 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
381 for (i=0; i<=2; ++i) {
382 progress("Adding service entry...", i, 2);
384 sfp = fopen("/etc/services", "a");
386 sprintf(errmsg, "Cannot open /etc/services: %s", strerror(errno));
387 display_error(errmsg);
389 fprintf(sfp, "%s 504/tcp\n", SERVICE_NAME);
401 * delete_inittab_entry() -- Remove obsolete /etc/inittab entry for Citadel
404 void delete_inittab_entry(void)
408 char looking_for[256];
410 char outfilename[32];
411 int changes_made = 0;
414 /* Determine the fully qualified path name of citserver */
415 snprintf(looking_for,
421 /* Now tweak /etc/inittab */
422 infp = fopen("/etc/inittab", "r");
425 /* If /etc/inittab does not exist, return quietly.
426 * Not all host platforms have it.
428 if (errno == ENOENT) {
432 /* Other errors might mean something really did go wrong.
434 sprintf(buf, "Cannot open /etc/inittab: %s", strerror(errno));
439 strcpy(outfilename, "/tmp/ctdlsetup.XXXXXX");
440 outfp = fdopen(mkstemp(outfilename), "w+");
442 sprintf(buf, "Cannot open %s: %s", outfilename, strerror(errno));
448 while (fgets(buf, sizeof buf, infp) != NULL) {
449 if (strstr(buf, looking_for) != NULL) {
450 rv = fwrite("#", 1, 1, outfp);
453 rv = fwrite(buf, strlen(buf), 1, outfp);
460 sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
462 rv = system("/sbin/init q 2>/dev/null");
471 * install_init_scripts() -- Try to configure to start Citadel at boot
474 void install_init_scripts(void)
476 struct stat etcinitd;
478 char *initfile = "/etc/init.d/citadel";
482 if ((stat("/etc/init.d/", &etcinitd) == -1) &&
485 if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
487 initfile = CTDLDIR"/citadel.init";
489 initfile = "/etc/rc.d/init.d/citadel";
492 fp = fopen(initfile, "r");
494 if (yesno("Citadel already appears to be configured to start at boot.\n"
495 "Would you like to keep your boot configuration as is?\n", 1) == 1) {
502 if (yesno("Would you like to automatically start Citadel at boot?\n", 1) == 0) {
506 fp = fopen(initfile, "w");
508 display_error("Cannot create /etc/init.d/citadel");
512 fprintf(fp, "#!/bin/sh\n"
514 "# Init file for Citadel\n"
516 "# chkconfig: - 79 30\n"
517 "# description: Citadel service\n"
518 "# processname: citserver\n"
519 "# pidfile: %s/citadel.pid\n\n"
520 "# uncomment this to create coredumps as described in\n"
521 "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
522 "# ulimit -c unlimited\n"
530 "test -d /var/run || exit 0\n"
534 "start) echo -n \"Starting Citadel... \"\n"
535 " if $CITADEL_DIR/citserver -lmail -d -h$CITADEL_DIR\n"
542 "stop) echo -n \"Stopping Citadel... \"\n"
543 " if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
548 " rm -f %s/citadel.pid 2>/dev/null\n"
553 "restart) if $CITADEL_DIR/sendcommand DOWN 1 >/dev/null 2>&1 ; then\n"
559 "*) echo \"Usage: $0 {start|stop|restart}\"\n"
566 chmod(initfile, 0755);
568 /* Set up the run levels. */
569 rv = system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
570 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);
571 rv = system(command);
572 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);
573 rv = system(command);
583 * On systems which use xinetd, see if we can offer to install Citadel as
584 * the default telnet target.
586 void check_xinetd_entry(void) {
587 char *filename = "/etc/xinetd.d/telnet";
590 int already_citadel = 0;
593 fp = fopen(filename, "r+");
594 if (fp == NULL) return; /* Not there. Oh well... */
596 while (fgets(buf, sizeof buf, fp) != NULL) {
597 if (strstr(buf, setup_directory) != NULL) already_citadel = 1;
600 if (already_citadel) return; /* Already set up this way. */
602 /* Otherwise, prompt the user to create an entry. */
603 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
604 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
609 snprintf(buf, sizeof buf,
610 "Setup can configure the \"xinetd\" service to automatically\n"
611 "connect incoming telnet sessions to Citadel, bypassing the\n"
612 "host system login: prompt. Would you like to do this?\n"
614 if (yesno(buf, 1) == 0) {
619 fp = fopen(filename, "w");
621 "# description: telnet service for Citadel users\n"
626 " socket_type = stream\n"
629 " server = /usr/sbin/in.telnetd\n"
630 " server_args = -h -L %s/citadel\n"
631 " log_on_failure += USERID\n"
636 /* Now try to restart the service */
637 rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
643 * Offer to disable other MTA's
645 void disable_other_mta(char *mta) {
651 sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
652 "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
654 fp = popen(buf, "r");
655 if (fp == NULL) return;
657 while (fgets(buf, sizeof buf, fp) != NULL) {
661 if (lines == 0) return; /* Nothing to do. */
664 /* Offer to replace other MTA with the vastly superior Citadel :) */
666 snprintf(buf, sizeof buf,
667 "You appear to have the \"%s\" email program\n"
668 "running on your system. If you want Citadel mail\n"
669 "connected with %s, you will have to manually integrate\n"
670 "them. It is preferable to disable %s, and use Citadel's\n"
671 "SMTP, POP3, and IMAP services.\n\n"
672 "May we disable %s so that Citadel has access to ports\n"
673 "25, 110, and 143?\n",
676 if (yesno(buf, 1) == 0) {
681 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);
683 sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
691 * Check to see if our server really works. Returns 0 on success.
693 int test_server(char *setup_directory, char *relhomestr, int relhome) {
700 /* Generate a silly little cookie. We're going to write it out
701 * to the server and try to get it back. The cookie does not
702 * have to be secret ... just unique.
704 sprintf(cookie, "--test--%d--", getpid());
707 sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
712 sprintf(cmd, "%s/sendcommand ECHO %s 2>&1",
716 fp = popen(cmd, "r");
717 if (fp == NULL) return(errno);
719 while (fgets(buf, sizeof buf, fp) != NULL) {
721 && (strstr(buf, cookie) != NULL) ) {
733 void strprompt(char *prompt_title, char *prompt_text, char *str)
737 char dialog_result[PATH_MAX];
741 strcpy(setupmsg, "");
743 switch (setup_type) {
746 printf("\n%s\n", prompt_text);
747 printf("This is currently set to:\n%s\n", str);
748 printf("Enter new value or press return to leave unchanged:\n");
749 if (fgets(buf, sizeof buf, stdin)){
750 buf[strlen(buf) - 1] = 0;
752 if (!IsEmptyStr(buf))
757 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
758 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
759 getenv("CTDL_DIALOG"),
764 fp = fopen(dialog_result, "r");
766 if (fgets(str, sizeof buf, fp)) {
767 if (str[strlen(str)-1] == 10) {
768 str[strlen(str)-1] = 0;
772 unlink(dialog_result);
780 void set_bool_val(int msgpos, int *ip) {
781 title(setup_titles[msgpos]);
782 *ip = yesno(setup_text[msgpos], *ip);
785 void set_str_val(int msgpos, char *str) {
786 strprompt(setup_titles[msgpos], setup_text[msgpos], str);
789 void set_int_val(int msgpos, int *ip)
792 snprintf(buf, sizeof buf, "%d", (int) *ip);
793 set_str_val(msgpos, buf);
798 void set_char_val(int msgpos, char *ip)
801 snprintf(buf, sizeof buf, "%d", (int) *ip);
802 set_str_val(msgpos, buf);
803 *ip = (char) atoi(buf);
807 void set_long_val(int msgpos, long int *ip)
810 snprintf(buf, sizeof buf, "%ld", *ip);
811 set_str_val(msgpos, buf);
816 void edit_value(int curr)
820 char ctdluidname[256];
825 if (setup_type == UI_SILENT)
827 if (getenv("SYSADMIN_NAME")) {
828 strcpy(config.c_sysadm, getenv("SYSADMIN_NAME"));
832 set_str_val(curr, config.c_sysadm);
837 if (setup_type == UI_SILENT)
839 if (getenv("SYSADMIN_PW")) {
840 strcpy(admin_pass, getenv("SYSADMIN_PW"));
844 set_str_val(curr, admin_pass);
849 if (setup_type == UI_SILENT)
851 if (getenv("CITADEL_UID")) {
852 config.c_ctdluid = atoi(getenv("CITADEL_UID"));
858 config.c_ctdluid = 0; /* XXX Windows hack, prob. insecure */
860 i = config.c_ctdluid;
863 set_int_val(curr, &i);
864 config.c_ctdluid = i;
867 strcpy(ctdluidname, pw->pw_name);
868 set_str_val(curr, ctdluidname);
869 pw = getpwnam(ctdluidname);
871 config.c_ctdluid = pw->pw_uid;
873 else if (atoi(ctdluidname) > 0) {
874 config.c_ctdluid = atoi(ctdluidname);
882 if (setup_type == UI_SILENT)
884 if (getenv("IP_ADDR")) {
885 strcpy(config.c_ip_addr, getenv("IP_ADDR"));
889 set_str_val(curr, config.c_ip_addr);
894 if (setup_type == UI_SILENT)
896 if (getenv("CITADEL_PORT")) {
897 config.c_port_number = atoi(getenv("CITADEL_PORT"));
902 set_int_val(curr, &config.c_port_number);
907 if (setup_type == UI_SILENT)
910 config.c_auth_mode = AUTHMODE_NATIVE;
911 auth = getenv("ENABLE_UNIX_AUTH");
914 if ((strcasecmp(auth, "yes") == 0) ||
915 (strcasecmp(auth, "host") == 0))
917 config.c_auth_mode = AUTHMODE_HOST;
919 else if (strcasecmp(auth, "ldap") == 0){
920 config.c_auth_mode = AUTHMODE_LDAP;
922 else if ((strcasecmp(auth, "ldap_ad") == 0) ||
923 (strcasecmp(auth, "active directory") == 0)){
924 config.c_auth_mode = AUTHMODE_LDAP_AD;
929 set_int_val(curr, &config.c_auth_mode);
934 if (setup_type == UI_SILENT)
936 if (getenv("LDAP_HOST")) {
937 strcpy(config.c_ldap_host, getenv("LDAP_HOST"));
942 set_str_val(curr, config.c_ldap_host);
947 if (setup_type == UI_SILENT)
949 if (getenv("LDAP_PORT")) {
950 config.c_ldap_port = atoi(getenv("LDAP_PORT"));
955 if (config.c_ldap_port == 0) {
956 config.c_ldap_port = 389;
958 set_int_val(curr, &config.c_ldap_port);
963 if (setup_type == UI_SILENT)
965 if (getenv("LDAP_BASE_DN")) {
966 strcpy(config.c_ldap_base_dn, getenv("LDAP_BASE_DN"));
971 set_str_val(curr, config.c_ldap_base_dn);
976 if (setup_type == UI_SILENT)
978 if (getenv("LDAP_BIND_DN")) {
979 strcpy(config.c_ldap_bind_dn, getenv("LDAP_BIND_DN"));
984 set_str_val(curr, config.c_ldap_bind_dn);
989 if (setup_type == UI_SILENT)
991 if (getenv("LDAP_BIND_PW")) {
992 strcpy(config.c_ldap_bind_pw, getenv("LDAP_BIND_PW"));
997 set_str_val(curr, config.c_ldap_bind_pw);
1006 * (re-)write the config data to disk
1008 void write_config_to_disk(void)
1014 if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
1015 display_error("setup: cannot open citadel.config");
1018 fp = fdopen(fd, "wb");
1020 display_error("setup: cannot open citadel.config");
1023 rv = fwrite((char *) &config, sizeof(struct config), 1, fp);
1031 * Figure out what type of user interface we're going to use
1033 int discover_ui(void)
1036 /* Use "dialog" if we have it */
1037 if (getenv("CTDL_DIALOG") != NULL) {
1049 * Strip "db" entries out of /etc/nsswitch.conf
1059 int file_changed = 0;
1060 char new_filename[64];
1063 fp_read = fopen(NSSCONF, "r");
1064 if (fp_read == NULL) {
1068 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
1069 fd_write = mkstemp(new_filename);
1075 while (fgets(buf, sizeof buf, fp_read) != NULL) {
1077 strcpy(buf_nc, buf);
1078 for (i=0; i<strlen(buf_nc); ++i) {
1079 if (buf_nc[i] == '#') {
1083 for (i=0; i<strlen(buf_nc); ++i) {
1084 if (!strncasecmp(&buf_nc[i], "db", 2)) {
1086 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
1089 strcpy(&buf_nc[i], &buf_nc[i+2]);
1090 strcpy(&buf[i], &buf[i+2]);
1092 strcpy(&buf_nc[i], &buf_nc[i+1]);
1093 strcpy(&buf[i], &buf[i+1]);
1099 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
1102 unlink(new_filename);
1109 if (!file_changed) {
1110 unlink(new_filename);
1114 snprintf(question, sizeof question,
1116 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
1117 "one or more services. This is not necessary on most systems,\n"
1118 "and it is known to crash the Citadel server when delivering\n"
1119 "mail to the Internet.\n"
1121 "Do you want this module to be automatically disabled?\n"
1125 if (yesno(question, 1)) {
1126 sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
1128 chmod(NSSCONF, 0644);
1130 unlink(new_filename);
1140 int main(int argc, char *argv[])
1146 int old_setup_level = 0;
1148 struct utsname my_utsname;
1154 char relhome[PATH_MAX]="";
1155 char ctdldir[PATH_MAX]=CTDLDIR;
1158 /* set an invalid setup type */
1161 /* Check to see if we're running the web installer */
1162 if (getenv("CITADEL_INSTALLER") != NULL) {
1163 using_web_installer = 1;
1166 /* parse command line args */
1167 for (a = 0; a < argc; ++a) {
1168 if (!strncmp(argv[a], "-u", 2)) {
1169 strcpy(aaa, argv[a]);
1170 strcpy(aaa, &aaa[2]);
1171 setup_type = atoi(aaa);
1173 else if (!strcmp(argv[a], "-i")) {
1176 else if (!strcmp(argv[a], "-q")) {
1177 setup_type = UI_SILENT;
1179 else if (!strncmp(argv[a], "-h", 2)) {
1180 relh=argv[a][2]!='/';
1182 safestrncpy(ctdl_home_directory, &argv[a][2], sizeof ctdl_home_directory);
1184 safestrncpy(relhome, &argv[a][2], sizeof relhome);
1191 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1193 /* If a setup type was not specified, try to determine automatically
1194 * the best one to use out of all available types.
1196 if (setup_type < 0) {
1197 setup_type = discover_ui();
1199 if (info_only == 1) {
1200 important_message("Citadel Setup", CITADEL);
1204 /* Get started in a valid setup directory. */
1205 strcpy(setup_directory, ctdl_run_dir);
1206 if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
1207 strcpy(setup_directory, getenv("CITADEL"));
1210 set_str_val(0, setup_directory);
1213 enable_home = ( relh | home );
1215 if (chdir(setup_directory) != 0) {
1217 sprintf(errmsg, "The directory you specified does not exist: [%s]\n", setup_directory);
1219 important_message("Citadel Setup", errmsg);
1223 /* Determine our host name, in case we need to use it as a default */
1226 /* Try to stop Citadel if we can */
1227 if (!access("/etc/init.d/citadel", X_OK)) {
1228 rv = system("/etc/init.d/citadel stop");
1231 /* Make sure Citadel is not running. */
1232 if (test_server(setup_directory, relhome, enable_home) == 0) {
1233 important_message("Citadel Setup",
1234 "The Citadel service is still running.\n"
1235 "Please stop the service manually and run "
1241 switch (setup_type) {
1245 " *** Citadel setup program ***\n\n");
1251 * What we're going to try to do here is append a whole bunch of
1252 * nulls to the citadel.config file, so we can keep the old config
1253 * values if they exist, but if the file is missing or from an
1254 * earlier version with a shorter config structure, when setup tries
1255 * to read the old config parameters, they'll all come up zero.
1256 * The length of the config file will be set to what it's supposed
1257 * to be when we rewrite it, because we replace the old file with a
1258 * completely new copy.
1260 if ((a = open(file_citadel_config, O_WRONLY | O_CREAT | O_APPEND,
1261 S_IRUSR | S_IWUSR)) == -1) {
1262 display_error("setup: cannot append citadel.config");
1265 fp = fdopen(a, "ab");
1267 display_error("setup: cannot append citadel.config");
1270 for (a = 0; a < sizeof(struct config); ++a) {
1275 /* now we re-open it, and read the old or blank configuration */
1276 fp = fopen(file_citadel_config, "rb");
1278 display_error("setup: cannot open citadel.config");
1281 rv = fread((char *) &config, sizeof(struct config), 1, fp);
1284 /* set some sample/default values in place of blanks... */
1285 if (IsEmptyStr(config.c_nodename))
1286 safestrncpy(config.c_nodename, my_utsname.nodename,
1287 sizeof config.c_nodename);
1288 strtok(config.c_nodename, ".");
1289 if (IsEmptyStr(config.c_fqdn) ) {
1290 if ((he = gethostbyname(my_utsname.nodename)) != NULL) {
1291 safestrncpy(config.c_fqdn, he->h_name, sizeof config.c_fqdn);
1293 safestrncpy(config.c_fqdn, my_utsname.nodename, sizeof config.c_fqdn);
1296 if (IsEmptyStr(config.c_humannode)) {
1297 strcpy(config.c_humannode, "My System");
1299 if (IsEmptyStr(config.c_phonenum)) {
1300 strcpy(config.c_phonenum, "US 800 555 1212");
1302 if (config.c_initax == 0) {
1303 config.c_initax = 4;
1305 if (IsEmptyStr(config.c_moreprompt)) strcpy(config.c_moreprompt, "<more>");
1306 if (IsEmptyStr(config.c_twitroom)) strcpy(config.c_twitroom, "Trashcan");
1307 if (IsEmptyStr(config.c_baseroom)) strcpy(config.c_baseroom, BASEROOM);
1308 if (IsEmptyStr(config.c_aideroom)) strcpy(config.c_aideroom, "Aide");
1309 if (config.c_port_number == 0) {
1310 config.c_port_number = 504;
1312 if (config.c_sleeping == 0) {
1313 config.c_sleeping = 900;
1315 if (config.c_ctdluid == 0) {
1316 pw = getpwnam("citadel");
1318 config.c_ctdluid = pw->pw_uid;
1321 if (config.c_ctdluid == 0) {
1322 pw = getpwnam("bbs");
1324 config.c_ctdluid = pw->pw_uid;
1327 if (config.c_ctdluid == 0) {
1328 pw = getpwnam("guest");
1330 config.c_ctdluid = pw->pw_uid;
1333 if (config.c_createax == 0) {
1334 config.c_createax = 3;
1337 * Negative values for maxsessions are not allowed.
1339 if (config.c_maxsessions < 0) {
1340 config.c_maxsessions = 0;
1342 /* We need a system default message expiry policy, because this is
1343 * the top level and there's no 'higher' policy to fall back on.
1344 * By default, do not expire messages at all.
1346 if (config.c_ep.expire_mode == 0) {
1347 config.c_ep.expire_mode = EXPIRE_MANUAL;
1348 config.c_ep.expire_value = 0;
1352 * Default port numbers for various services
1354 if (config.c_smtp_port == 0) config.c_smtp_port = 25;
1355 if (config.c_pop3_port == 0) config.c_pop3_port = 110;
1356 if (config.c_imap_port == 0) config.c_imap_port = 143;
1357 if (config.c_msa_port == 0) config.c_msa_port = 587;
1358 if (config.c_smtps_port == 0) config.c_smtps_port = 465;
1359 if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
1360 if (config.c_imaps_port == 0) config.c_imaps_port = 993;
1361 if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
1362 if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
1363 if (config.c_xmpp_c2s_port == 0) config.c_xmpp_c2s_port = 5222;
1364 if (config.c_xmpp_s2s_port == 0) config.c_xmpp_s2s_port = 5269;
1366 /* Go through a series of dialogs prompting for config info */
1367 for (curr = 1; curr <= MAXSETUP; ++curr) {
1369 if ((curr == 6) && (config.c_auth_mode != AUTHMODE_LDAP) && (config.c_auth_mode != AUTHMODE_LDAP_AD)) {
1370 curr += 5; /* skip LDAP questions if we're not authenticating against LDAP */
1374 /***** begin version update section ***** */
1375 /* take care of any updating that is necessary */
1377 old_setup_level = config.c_setup_level;
1379 if (old_setup_level == 0) {
1383 if (old_setup_level < 555) {
1384 important_message("Citadel Setup",
1385 "This Citadel installation is too old "
1389 write_config_to_disk();
1391 old_setup_level = config.c_setup_level;
1393 /* end of version update section */
1396 config.c_setup_level = REV_LEVEL;
1398 /******************************************/
1400 write_config_to_disk();
1402 rv = mkdir(ctdl_info_dir, 0700);
1403 rv = chmod(ctdl_info_dir, 0700);
1404 rv = chown(ctdl_info_dir, config.c_ctdluid, -1);
1406 rv = mkdir(ctdl_bio_dir, 0700);
1407 rv = chmod(ctdl_bio_dir, 0700);
1408 rv = chown(ctdl_bio_dir, config.c_ctdluid, -1);
1410 rv = mkdir(ctdl_usrpic_dir, 0700);
1411 rv = chmod(ctdl_usrpic_dir, 0700);
1412 rv = chown(ctdl_usrpic_dir, config.c_ctdluid, -1);
1414 rv = mkdir(ctdl_message_dir, 0700);
1415 rv = chmod(ctdl_message_dir, 0700);
1416 rv = chown(ctdl_message_dir, config.c_ctdluid, -1);
1418 rv = mkdir(ctdl_hlp_dir, 0700);
1419 rv = chmod(ctdl_hlp_dir, 0700);
1420 rv = chown(ctdl_hlp_dir, config.c_ctdluid, -1);
1422 rv = mkdir(ctdl_image_dir, 0700);
1423 rv = chmod(ctdl_image_dir, 0700);
1424 rv = chown(ctdl_image_dir, config.c_ctdluid, -1);
1426 rv = mkdir(ctdl_bb_dir, 0700);
1427 rv = chmod(ctdl_bb_dir, 0700);
1428 rv = chown(ctdl_bb_dir, config.c_ctdluid, -1);
1430 rv = mkdir(ctdl_file_dir, 0700);
1431 rv = chmod(ctdl_file_dir, 0700);
1432 rv = chown(ctdl_file_dir, config.c_ctdluid, -1);
1434 rv = mkdir(ctdl_netcfg_dir, 0700);
1435 rv = chmod(ctdl_netcfg_dir, 0700);
1436 rv = chown(ctdl_netcfg_dir, config.c_ctdluid, -1);
1438 /* Delete files and directories used by older Citadel versions */
1439 rv = system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
1440 unlink("citadel.log");
1443 if (((setup_type == UI_SILENT) && (getenv("ALTER_ETC_SERVICES")!=NULL)) ||
1444 (setup_type != UI_SILENT))
1445 check_services_entry(); /* Check /etc/services */
1447 delete_inittab_entry(); /* Remove obsolete /etc/inittab entry */
1448 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1450 if ((getenv("ACT_AS_MTA") == NULL) ||
1451 (getenv("ACT_AS_MTA") &&
1452 strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
1453 /* Offer to disable other MTA's on the system. */
1454 disable_other_mta("courier-authdaemon");
1455 disable_other_mta("courier-imap");
1456 disable_other_mta("courier-imap-ssl");
1457 disable_other_mta("courier-pop");
1458 disable_other_mta("courier-pop3");
1459 disable_other_mta("courier-pop3d");
1460 disable_other_mta("cyrmaster");
1461 disable_other_mta("cyrus");
1462 disable_other_mta("dovecot");
1463 disable_other_mta("exim");
1464 disable_other_mta("exim4");
1465 disable_other_mta("imapd");
1466 disable_other_mta("mta");
1467 disable_other_mta("pop3d");
1468 disable_other_mta("popd");
1469 disable_other_mta("postfix");
1470 disable_other_mta("qmail");
1471 disable_other_mta("saslauthd");
1472 disable_other_mta("sendmail");
1473 disable_other_mta("vmailmgrd");
1477 /* Check for the 'db' nss and offer to disable it */
1480 if ((pw = getpwuid(config.c_ctdluid)) == NULL) {
1486 progress("Setting file permissions", 0, 3);
1487 rv = chown(ctdl_run_dir, config.c_ctdluid, gid);
1488 progress("Setting file permissions", 1, 3);
1489 rv = chown(file_citadel_config, config.c_ctdluid, gid);
1490 progress("Setting file permissions", 2, 3);
1491 rv = chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1492 progress("Setting file permissions", 3, 3);
1495 * If we're running on SysV, install init scripts.
1497 if (!access("/var/run", W_OK)) {
1499 if (getenv("NO_INIT_SCRIPTS") == NULL) {
1500 install_init_scripts();
1503 if (!access("/etc/init.d/citadel", X_OK)) {
1504 rv = system("/etc/init.d/citadel start");
1508 if (test_server(setup_directory, relhome, enable_home) == 0) {
1512 if (config.c_auth_mode == AUTHMODE_NATIVE) {
1513 snprintf (admin_cmd, sizeof(admin_cmd), "%s/sendcommand \"CREU %s|%s\" 2>&1",
1514 ctdl_sbin_dir, config.c_sysadm, admin_pass);
1515 fp = popen(admin_cmd, "r");
1517 while (fgets(buf, sizeof buf, fp) != NULL)
1519 if ((atol(buf) == 574) || (atol(buf) == 200))
1525 if (found_it == 0) {
1526 important_message("Error","Setup failed to create your admin user");
1530 if (setup_type != UI_SILENT)
1531 important_message("Setup finished",
1532 "Setup of the Citadel server is complete.\n"
1533 "If you will be using WebCit, please run its\n"
1534 "setup program now; otherwise, run './citadel'\n"
1538 important_message("Setup failed",
1539 "Setup is finished, but the Citadel server failed to start.\n"
1540 "Go back and check your configuration.\n"
1547 important_message("Setup finished",
1548 "Setup is finished. You may now start the server.");