2 * Citadel setup utility
4 * Copyright (c) 1987-2012 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #define SHOW_ME_VAPPEND_PRINTF
22 #include <sys/types.h>
31 #include <sys/socket.h>
34 #include <libcitadel.h>
38 #include "citadel_dirs.h"
49 #define _(string) gettext(string)
51 #define _(string) (string)
54 #define UI_TEXT 0 /* Default setup type -- text only */
55 #define UI_DIALOG 2 /* Use the 'whiptail' or 'dialog' program */
56 #define UI_SILENT 3 /* Silent running, for use in scripts */
58 #define SERVICE_NAME "citadel"
59 #define PROTO_NAME "tcp"
60 #define NSSCONF "/etc/nsswitch.conf"
62 typedef enum _SetupStep {
78 ///"CREATE_XINETD_ENTRY";
79 /* Environment variables, don't translate! */
80 const char *EnvNames [eMaxQuestions] = {
95 int setup_type = (-1);
96 int using_web_installer = 0;
100 int serv_sock = (-1) ;
101 char configs[NUM_CONFIGS][1024];
103 const char *setup_titles[eMaxQuestions];
104 const char *setup_text[eMaxQuestions];
118 setlocale(LC_MESSAGES, getenv("LANG"));
120 bindtextdomain("citadel-setup", LOCALEDIR"/locale");
121 textdomain("citadel-setup");
122 bind_textdomain_codeset("citadel-setup","UTF8");
125 setup_titles[eCitadelHomeDir] = _("Citadel Home Directory");
127 setup_text[eCitadelHomeDir] = _(
128 "Enter the full pathname of the directory in which the Citadel\n"
129 "installation you are creating or updating resides. If you\n"
130 "specify a directory other than the default, you will need to\n"
131 "specify the -h flag to the server when you start it up.\n");
133 setup_text[eCitadelHomeDir] = _(
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 setup_titles[eSysAdminName] = _("Citadel administrator username:");
142 setup_text[eSysAdminName] = _(
143 "Please enter the name of the Citadel user account that should be granted "
144 "administrative privileges once created. If using internal authentication "
145 "this user account will be created if it does not exist. For external "
146 "authentication this user account has to exist.");
149 setup_titles[eSysAdminPW] = _("Administrator password:");
150 setup_text[eSysAdminPW] = _(
151 "Enter a password for the system administrator. When setup\n"
152 "completes it will attempt to create the administrator user\n"
153 "and set the password specified here.\n");
155 setup_titles[eUID] = _("Citadel User ID:");
156 setup_text[eUID] = _(
157 "Citadel needs to run under its own user ID. This would\n"
158 "typically be called \"citadel\", but if you are running Citadel\n"
159 "as a public site, you might also call it \"bbs\" or \"guest\".\n"
160 "The server will run under this user ID. Please specify that\n"
161 "user ID here. You may specify either a user name or a numeric\n"
164 setup_titles[eIP_ADDR] = _("Listening address for the Citadel server:");
165 setup_text[eIP_ADDR] = _(
166 "Please specify the IP address which the server should be listening to. "
167 "You can name a specific IPv4 or IPv6 address, or you can specify\n"
168 "\"*\" for \"any address\", \"::\" for \"any IPv6 address\", or \"0.0.0.0\"\n"
169 "for \"any IPv4 address\". If you leave this blank, Citadel will\n"
170 "listen on all addresses. "
171 "This can usually be left to the default unless multiple instances of Citadel "
172 "are running on the same computer.");
174 setup_titles[eCTDL_Port] = _("Server port number:");
175 setup_text[eCTDL_Port] = _(
176 "Specify the TCP port number on which your server will run.\n"
177 "Normally, this will be port 504, which is the official port\n"
178 "assigned by the IANA for Citadel servers. You will only need\n"
179 "to specify a different port number if you run multiple instances\n"
180 "of Citadel on the same computer and there is something else\n"
181 "already using port 504.\n");
183 setup_titles[eAuthType] = _("Authentication method to use:");
184 setup_text[eAuthType] = _(
185 "Please choose the user authentication mode. By default Citadel will use its "
186 "own internal user accounts database. If you choose Host, Citadel users will "
187 "have accounts on the host system, authenticated via /etc/passwd or a PAM "
188 "source. LDAP chooses an RFC 2307 compliant directory server, the last option "
189 "chooses the nonstandard MS Active Directory LDAP scheme."
191 "Do not change this option unless you are sure it is required, since changing "
192 "back requires a full reinstall of Citadel."
194 " 0. Self contained authentication\n"
195 " 1. Host system integrated authentication\n"
196 " 2. External LDAP - RFC 2307 compliant directory\n"
197 " 3. External LDAP - nonstandard MS Active Directory\n"
199 "For help: http://www.citadel.org/doku.php/faq:installation:authmodes\n"
201 "ANSWER \"0\" UNLESS YOU COMPLETELY UNDERSTAND THIS OPTION.\n");
203 setup_titles[eLDAP_Host] = _("LDAP host:");
204 setup_text[eLDAP_Host] = _(
205 "Please enter the host name or IP address of your LDAP server.\n");
207 setup_titles[eLDAP_Port] = _("LDAP port number:");
208 setup_text[eLDAP_Port] = _(
209 "Please enter the port number of the LDAP service (usually 389).\n");
211 setup_titles[eLDAP_Base_DN] = _("LDAP base DN:");
212 setup_text[eLDAP_Base_DN] = _(
213 "Please enter the Base DN to search for authentication\n"
214 "(for example: dc=example,dc=com)\n");
216 setup_titles[eLDAP_Bind_DN] = _("LDAP bind DN:");
217 setup_text[eLDAP_Bind_DN] = _(
218 "Please enter the DN of an account to use for binding to the LDAP server for "
219 "performing queries. The account does not require any other privileges. If "
220 "your LDAP server allows anonymous queries, you can leave this blank.\n");
222 setup_titles[eLDAP_Bind_PW] = _("LDAP bind password:");
223 setup_text[eLDAP_Bind_PW] = _(
224 "If you entered a Bind DN in the previous question, you must now enter\n"
225 "the password associated with that account. Otherwise, you can leave this\n"
229 // Debug loading of locales... Strace does a better job though.
230 printf("Message catalog directory: %s\n", bindtextdomain("citadel-setup", LOCALEDIR"/locale"));
231 printf("Text domain: %s\n", textdomain("citadel-setup"));
232 printf("Text domain Charset: %s\n", bind_textdomain_codeset("citadel-setup","UTF8"));
235 for (i = 0; i < eMaxQuestions; i++)
236 printf("%s - %s\n", setup_titles[i], _(setup_titles[i]));
243 * Print the stack frame for a backtrace
245 void cit_backtrace(void)
247 #ifdef HAVE_BACKTRACE
248 void *stack_frames[50];
252 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
253 strings = backtrace_symbols(stack_frames, size);
254 for (i = 0; i < size; i++) {
256 fprintf(stderr, "%s\n", strings[i]);
258 fprintf(stderr, "%p\n", stack_frames[i]);
266 void title(const char *text)
268 if (setup_type == UI_TEXT) {
269 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
275 int yesno(const char *question, int default_value)
281 switch (setup_type) {
285 printf("%s\n%s [%s] --> ",
288 ( default_value ? _("Yes") : _("No") )
290 if (fgets(buf, sizeof buf, stdin))
292 answer = tolower(buf[0]);
293 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10)) {
294 answer = default_value;
296 else if (answer == 'y') {
299 else if (answer == 'n') {
303 } while ((answer < 0) || (answer > 1));
307 snprintf(buf, sizeof buf, "exec %s --backtitle '%s' %s --yesno '%s' 15 75",
308 getenv("CTDL_DIALOG"),
310 ( default_value ? "" : "--defaultno" ),
327 void important_message(const char *title, const char *msgtext)
331 switch (setup_type) {
334 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");
335 printf(" %s \n\n%s\n\n", title, msgtext);
336 printf("%s", _("Press return to continue..."));
337 if (fgets(buf, sizeof buf, stdin));
341 snprintf(buf, sizeof buf, "exec %s --backtitle '%s' --msgbox '%s' 19 72",
342 getenv("CTDL_DIALOG"),
345 int rv = system(buf);
347 fprintf(stderr, _("failed to run the dialog command\n"));
351 fprintf(stderr, "%s\n", msgtext);
356 void important_msgnum(int msgnum)
358 important_message(_("Important Message"), setup_text[msgnum]);
361 void display_error(char *error_message_format, ...)
367 va_start(arg_ptr, error_message_format);
368 StrBufVAppendPrintf(Msg, error_message_format, arg_ptr);
371 important_message(_("Error"), ChrPtr(Msg));
375 void progress(char *text, long int curr, long int cmax)
377 static long dots_printed = 0L;
379 static FILE *fp = NULL;
382 switch (setup_type) {
386 printf("%s\n", text);
387 printf("....................................................");
388 printf("..........................\r");
390 } else if (curr == cmax) {
391 printf("\r%79s\n", "");
393 a = (curr * 100) / cmax;
396 while (dots_printed < a) {
406 snprintf(buf, sizeof buf, "exec %s --backtitle '%s' --gauge '%s' 7 72 0",
407 getenv("CTDL_DIALOG"),
410 fp = popen(buf, "w");
416 else if (curr == cmax) {
418 fprintf(fp, "100\n");
424 a = (curr * 100) / cmax;
426 fprintf(fp, "%ld\n", a);
435 assert(1==0); /* If we got here then the developer is a moron */
441 int uds_connectsock(char *sockpath)
444 struct sockaddr_un addr;
446 memset(&addr, 0, sizeof(addr));
447 addr.sun_family = AF_UNIX;
448 strncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
450 s = socket(AF_UNIX, SOCK_STREAM, 0);
455 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
465 * input binary data from socket
467 void serv_read(char *buf, int bytes)
472 while (len < bytes) {
473 rlen = read(serv_sock, &buf[len], bytes - len);
483 * send binary to server
485 void serv_write(char *buf, int nbytes)
487 int bytes_written = 0;
489 while (bytes_written < nbytes) {
490 retval = write(serv_sock, &buf[bytes_written], nbytes - bytes_written);
494 bytes_written = bytes_written + retval;
501 * input string from socket - implemented in terms of serv_read()
503 void serv_gets(char *buf)
507 /* Read one character at a time.
510 serv_read(&buf[i], 1);
511 if (buf[i] == '\n' || i == (SIZ-1))
515 /* If we got a long line, discard characters until the newline.
518 while (buf[i] != '\n') {
519 serv_read(&buf[i], 1);
523 /* Strip all trailing nonprintables (crlf)
530 * send line to server - implemented in terms of serv_write()
532 void serv_puts(char *buf)
534 serv_write(buf, strlen(buf));
540 * On systems which use xinetd, see if we can offer to install Citadel as
541 * the default telnet target.
543 void check_xinetd_entry(void) {
544 char *filename = "/etc/xinetd.d/telnet";
547 int already_citadel = 0;
550 fp = fopen(filename, "r+");
551 if (fp == NULL) return; /* Not there. Oh well... */
553 while (fgets(buf, sizeof buf, fp) != NULL) {
554 if (strstr(buf, "/citadel") != NULL) {
559 if (already_citadel) return; /* Already set up this way. */
561 /* Otherwise, prompt the user to create an entry. */
562 if (getenv("CREATE_XINETD_ENTRY") != NULL) {
563 if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
568 snprintf(buf, sizeof buf,
569 _("Setup can configure the \"xinetd\" service to automatically\n"
570 "connect incoming telnet sessions to Citadel, bypassing the\n"
571 "host system login: prompt. Would you like to do this?\n"
574 if (yesno(buf, 1) == 0) {
579 fp = fopen(filename, "w");
581 "# description: telnet service for Citadel users\n"
586 " socket_type = stream\n"
589 " server = /usr/sbin/in.telnetd\n"
590 " server_args = -h -L %s/citadel\n"
591 " log_on_failure += USERID\n"
596 /* Now try to restart the service */
597 rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
599 display_error(_("failed to restart xinetd.\n"));
606 * Offer to disable other MTA's
608 void disable_other_mta(const char *mta) {
614 snprintf(buf, sizeof buf,
615 "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
616 "/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. */
628 /* Offer to replace other MTA with the vastly superior Citadel :) */
630 snprintf(buf, sizeof buf,
631 "%s \"%s\" %s%s%s%s%s%s%s",
632 _("You appear to have the "),
635 "running on your system. If you want Citadel mail\n"
638 _(" you will have to manually integrate\n"
639 "them. It is preferable to disable "),
641 _(", and use Citadel's\n"
642 "SMTP, POP3, and IMAP services.\n\n"
645 _("so that Citadel has access to ports\n"
646 "25, 110, and 143?\n")
648 if (yesno(buf, 1) == 0) {
653 snprintf(buf, sizeof 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);
656 display_error("%s %s.\n", _("failed to disable other mta"), mta);
658 snprintf(buf, sizeof buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
661 display_error(" %s.\n", _("failed to disable other mta"), mta);
664 const char *other_mtas[] = {
665 "courier-authdaemon",
688 void disable_other_mtas(void)
691 if ((getenv("ACT_AS_MTA") == NULL) ||
692 (getenv("ACT_AS_MTA") &&
693 strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
694 /* Offer to disable other MTA's on the system. */
695 while (!IsEmptyStr(other_mtas[i]))
697 disable_other_mta(other_mtas[i]);
703 void strprompt(const char *prompt_title, const char *prompt_text, char *Target, char *DefValue)
707 char dialog_result[PATH_MAX];
711 strcpy(setupmsg, "");
713 switch (setup_type) {
716 printf("\n%s\n", prompt_text);
717 printf("%s\n%s\n", _("This is currently set to:"), Target);
718 printf("%s\n", _("Enter new value or press return to leave unchanged:"));
719 if (fgets(buf, sizeof buf, stdin)){
720 buf[strlen(buf) - 1] = 0;
722 if (!IsEmptyStr(buf))
727 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
728 snprintf(buf, sizeof buf, "exec %s --backtitle '%s' --nocancel --inputbox '%s' 19 72 '%s' 2>%s",
729 getenv("CTDL_DIALOG"),
736 fprintf(stderr, "failed to run whiptail or dialog\n");
739 fp = fopen(dialog_result, "r");
741 if (fgets(Target, sizeof buf, fp)) {
742 if (Target[strlen(Target)-1] == 10) {
743 Target[strlen(Target)-1] = 0;
747 unlink(dialog_result);
751 if (*DefValue != '\0')
752 strcpy(Target, DefValue);
757 void set_bool_val(int msgpos, int *ip, char *DefValue)
759 title(setup_titles[msgpos]);
760 *ip = yesno(setup_text[msgpos], *ip);
763 void set_str_val(int msgpos, char *Target, char *DefValue)
765 strprompt(setup_titles[msgpos],
772 /* like set_str_val() but make sure we ended up with a numeric value */
773 void set_int_val(int msgpos, char *target, char *DefValue)
776 set_str_val(msgpos, target, DefValue);
777 if (!strcmp(target, "0")) return;
778 if (atoi(target) != 0) return;
783 void edit_value(int curr)
787 char ctdluidname[256];
790 if (setup_type == UI_SILENT)
792 Value = getenv(EnvNames[curr]);
801 set_str_val(curr, configs[13], Value);
805 set_str_val(curr, admin_pass, Value);
809 if (setup_type == UI_SILENT)
812 sprintf(configs[69], "%d", atoi(Value));
818 strcpy(configs[69], "0"); /* work-around for Windows */
820 i = atoi(configs[69]);
823 set_int_val(curr, configs[69], Value);
824 sprintf(configs[69], "%d", i);
827 strcpy(ctdluidname, pw->pw_name);
828 set_str_val(curr, ctdluidname, Value);
829 pw = getpwnam(ctdluidname);
831 sprintf(configs[69], "%d", pw->pw_uid);
833 else if (atoi(ctdluidname) > 0) {
834 sprintf(configs[69], "%d", atoi(ctdluidname));
842 set_str_val(curr, configs[37], Value);
846 set_int_val(curr, configs[68], Value);
850 if (setup_type == UI_SILENT)
853 //config.c_auth_mode = AUTHMODE_NATIVE;
857 if ((strcasecmp(auth, "yes") == 0) ||
858 (strcasecmp(auth, "host") == 0))
860 //config.c_auth_mode = AUTHMODE_HOST;
862 else if (strcasecmp(auth, "ldap") == 0){
863 //config.c_auth_mode = AUTHMODE_LDAP;
865 else if ((strcasecmp(auth, "ldap_ad") == 0) ||
866 (strcasecmp(auth, "active directory") == 0)){
867 //config.c_auth_mode = AUTHMODE_LDAP_AD;
872 set_int_val(curr, configs[52], Value);
877 if (IsEmptyStr(configs[32])) {
878 strcpy(configs[32], "localhost");
880 set_str_val(curr, configs[32], Value);
884 if (atoi(configs[33]) == 0) {
885 strcpy(configs[33], "389");
887 set_int_val(curr, configs[33], Value);
891 set_str_val(curr, configs[34], Value);
895 set_str_val(curr, configs[35], Value);
899 set_str_val(curr, configs[36], Value);
908 * Figure out what type of user interface we're going to use
910 int discover_ui(void)
913 /* Use "whiptail" or "dialog" if we have it */
914 if (getenv("CTDL_DIALOG") != NULL) {
924 * Strip "db" entries out of /etc/nsswitch.conf
933 int file_changed = 0;
934 char new_filename[64];
937 fp_read = fopen(NSSCONF, "r");
938 if (fp_read == NULL) {
942 strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
943 fd_write = mkstemp(new_filename);
949 while (fgets(buf, sizeof buf, fp_read) != NULL) {
951 for (i=0; i<strlen(buf_nc); ++i) {
952 if (buf_nc[i] == '#') {
956 for (i=0; i<strlen(buf_nc); ++i) {
957 if (!strncasecmp(&buf_nc[i], "db", 2)) {
959 if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
961 strcpy(&buf_nc[i], &buf_nc[i+2]);
962 strcpy(&buf[i], &buf[i+2]);
964 strcpy(&buf_nc[i], &buf_nc[i+1]);
965 strcpy(&buf[i], &buf[i+1]);
971 if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
974 unlink(new_filename);
982 unlink(new_filename);
986 snprintf(question, sizeof question,
989 "/etc/nsswitch.conf is configured to use the 'db' module for\n"
990 "one or more services. This is not necessary on most systems,\n"
991 "and it is known to crash the Citadel server when delivering\n"
992 "mail to the Internet.\n"
994 "Do you want this module to be automatically disabled?\n"
999 if (yesno(question, 1)) {
1000 snprintf(buf, sizeof buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
1003 fprintf(stderr, "failed to edit %s.\n", NSSCONF);
1005 chmod(NSSCONF, 0644);
1007 unlink(new_filename);
1013 important_message(_("Setup finished"),
1014 _("Setup of the Citadel server is complete.\n"
1015 "If you will be using WebCit, please run its\n"
1016 "setup program now; otherwise, run './citadel'\n"
1018 important_message(_("Setup failed"),
1019 _("Setup is finished, but the Citadel server failed to start.\n"
1020 "Go back and check your configuration.\n")
1021 important_message(_("Setup finished"),
1022 _("Setup is finished. You may now start the server."));
1027 #define GetDefaultVALINT(CFGNAME, DEFL) GetDefaultValInt(&config.CFGNAME, "CITADEL_"#CFGNAME, DEFL)
1028 void GetDefaultValInt(int *WhereTo, const char *VarName, int DefVal)
1031 if (*WhereTo == 0) *WhereTo = DefVal;
1033 if ((setup_type == UI_SILENT) &&
1034 (ch = getenv(VarName), ch != NULL))
1036 *WhereTo = atoi(ch);
1039 #define GetDefaultVALCHAR(CFGNAME, DEFL) GetDefaultValChar(&config.CFGNAME, "CITADEL_"#CFGNAME, DEFL)
1040 void GetDefaultValChar(char *WhereTo, const char *VarName, char DefVal)
1043 if (*WhereTo == 0) *WhereTo = DefVal;
1045 if ((setup_type == UI_SILENT) &&
1046 (ch = getenv(VarName), ch != NULL))
1048 *WhereTo = atoi(ch);
1051 #define GetDefaultVALSTR(CFGNAME, DEFL) GetDefaultValStr(&config.CFGNAME[0], sizeof(config.CFGNAME), "CITADEL_"#CFGNAME, DEFL)
1052 void GetDefaultValStr(char *WhereTo, size_t nMax, const char *VarName, const char *DefVal)
1055 if (*WhereTo == '\0')
1056 safestrncpy(WhereTo, DefVal, nMax);
1058 if ((setup_type == UI_SILENT) &&
1059 (ch = getenv(VarName), ch != NULL))
1061 safestrncpy(WhereTo, ch, nMax);
1066 void set_default_values(void)
1070 struct utsname my_utsname;
1073 /* Determine our host name, in case we need to use it as a default */
1076 /* set some sample/default values in place of blanks... */
1077 GetDefaultVALSTR(c_nodename, my_utsname.nodename);
1078 strtok(config.c_nodename, ".");
1079 if (IsEmptyStr(config.c_fqdn) ) {
1080 if ((he = gethostbyname(my_utsname.nodename)) != NULL) {
1081 safestrncpy(config.c_fqdn, he->h_name, sizeof config.c_fqdn);
1083 safestrncpy(config.c_fqdn, my_utsname.nodename, sizeof config.c_fqdn);
1086 GetDefaultVALSTR(c_humannode, _("My System"));
1087 GetDefaultVALSTR(c_phonenum, _("US 800 555 1212"));
1089 GetDefaultVALCHAR(c_initax, 4);
1091 GetDefaultVALSTR(c_moreprompt, "<more>");
1092 GetDefaultVALSTR(c_twitroom, "Trashcan");
1093 GetDefaultVALSTR(c_baseroom, BASEROOM);
1094 GetDefaultVALSTR(c_aideroom, "Aide");
1095 GetDefaultVALINT(c_port_number, 504);
1097 GetDefaultVALINT(c_sleeping, 900);
1099 if (config.c_ctdluid == 0) {
1100 pw = getpwnam("citadel");
1102 config.c_ctdluid = pw->pw_uid;
1105 if (config.c_ctdluid == 0) {
1106 pw = getpwnam("bbs");
1108 config.c_ctdluid = pw->pw_uid;
1111 if (config.c_ctdluid == 0) {
1112 pw = getpwnam("guest");
1114 config.c_ctdluid = pw->pw_uid;
1117 if (config.c_createax == 0) {
1118 config.c_createax = 3;
1121 * Negative values for maxsessions are not allowed.
1123 if (config.c_maxsessions < 0) {
1124 config.c_maxsessions = 0;
1126 /* We need a system default message expiry policy, because this is
1127 * the top level and there's no 'higher' policy to fall back on.
1128 * By default, do not expire messages at all.
1130 if (config.c_ep.expire_mode == 0) {
1131 config.c_ep.expire_mode = EXPIRE_MANUAL;
1132 config.c_ep.expire_value = 0;
1136 * Default port numbers for various services
1138 GetDefaultVALINT(c_smtp_port, 25);
1139 GetDefaultVALINT(c_pop3_port, 110);
1140 GetDefaultVALINT(c_imap_port, 143);
1141 GetDefaultVALINT(c_msa_port, 587);
1142 GetDefaultVALINT(c_smtps_port, 465);
1143 GetDefaultVALINT(c_pop3s_port, 995);
1144 GetDefaultVALINT(c_imaps_port, 993);
1145 GetDefaultVALINT(c_pftcpdict_port, -1);
1146 GetDefaultVALINT(c_managesieve_port, 2020);
1147 GetDefaultVALINT(c_xmpp_c2s_port, 5222);
1148 GetDefaultVALINT(c_xmpp_s2s_port, 5269);
1154 int main(int argc, char *argv[])
1164 char relhome[PATH_MAX]="";
1165 char ctdldir[PATH_MAX]=CTDLDIR;
1168 char *activity = NULL;
1170 /* Keep a mild groove on */
1171 program_title = _("Citadel setup program");
1173 /* set an invalid setup type */
1176 /* Check to see if we're running the web installer */
1177 if (getenv("CITADEL_INSTALLER") != NULL) {
1178 using_web_installer = 1;
1181 /* parse command line args */
1182 for (a = 0; a < argc; ++a) {
1183 if (!strncmp(argv[a], "-u", 2)) {
1184 strcpy(aaa, argv[a]);
1185 strcpy(aaa, &aaa[2]);
1186 setup_type = atoi(aaa);
1188 else if (!strcmp(argv[a], "-i")) {
1191 else if (!strcmp(argv[a], "-q")) {
1192 setup_type = UI_SILENT;
1194 else if (!strncmp(argv[a], "-h", 2)) {
1195 relh=argv[a][2]!='/';
1197 safestrncpy(ctdl_home_directory, &argv[a][2], sizeof ctdl_home_directory);
1199 safestrncpy(relhome, &argv[a][2], sizeof relhome);
1206 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1209 /* If a setup type was not specified, try to determine automatically
1210 * the best one to use out of all available types.
1212 if (setup_type < 0) {
1213 setup_type = discover_ui();
1215 if (info_only == 1) {
1216 important_message(_("Citadel Setup"), CITADEL);
1220 enable_home = ( relh | home );
1222 if (chdir(ctdl_run_dir) != 0) {
1223 display_error(_("Citadel Setup"),
1225 _("The directory you specified does not exist"),
1232 * Connect to the running Citadel server.
1234 while ((serv_sock < 0) && (nRetries < 10)) {
1235 serv_sock = uds_connectsock(file_citadel_admin_socket);
1240 if (serv_sock < 0) {
1243 _("Setup could not connect to a running Citadel server."),
1244 strerror(errno), file_citadel_admin_socket
1250 * read the server greeting
1253 if (buf[0] != '2') {
1254 display_error("%s\n", buf);
1259 * Are we connected to the correct Citadel server?
1263 if (buf[0] != '1') {
1264 display_error("%s\n", buf);
1268 while (serv_gets(buf), strcmp(buf, "000")) {
1270 if (atoi(buf) != REV_LEVEL) {
1271 display_error("%s\n",
1272 _("Your setup program and Citadel server are from different versions.")
1281 * Load the server's configuration
1283 serv_puts("CONF GET");
1285 if (buf[0] != '1') {
1286 display_error("%s\n", buf);
1289 memset(configs, 0, sizeof configs);
1291 while (serv_gets(buf), strcmp(buf, "000")) {
1292 if (a < NUM_CONFIGS) {
1293 safestrncpy(configs[a], buf, sizeof(configs[a]));
1302 /* _("Citadel Setup"), */
1304 if (setup_type == UI_TEXT) {
1305 printf("\n\n\n *** %s ***\n\n", program_title);
1308 if (setup_type == UI_DIALOG) {
1309 system("clear 2>/dev/null");
1312 set_default_values();
1314 /* Go through a series of dialogs prompting for config info */
1315 for (curr = 1; curr < eMaxQuestions; ++curr) {
1319 && (atoi(configs[52]) != AUTHMODE_LDAP)
1320 && (atoi(configs[52]) != AUTHMODE_LDAP_AD)
1322 curr += 5; /* skip LDAP questions if we're not authenticating against LDAP */
1325 if (curr == eSysAdminName) {
1326 if (atoi(configs[52]) == AUTHMODE_NATIVE) {
1327 /* for native auth mode, fetch the admin's existing pw */
1328 snprintf(buf, sizeof buf, "AGUP %s", configs[13]);
1331 if (buf[0] == '2') {
1332 extract_token(admin_pass, &buf[4], 1, '|', sizeof admin_pass);
1336 ++curr; /* skip the password question for non-native auth modes */
1341 if ((pw = getpwuid(atoi(configs[69]))) == NULL) {
1347 create_run_directories(atoi(configs[69]), gid);
1349 activity = _("Reconfiguring Citadel server");
1350 progress(activity, 0, NUM_CONFIGS+3);
1351 sleep(1); /* Let the message appear briefly */
1352 serv_puts("CONF SET");
1354 if (buf[0] == '4') {
1355 for (i=0; i<NUM_CONFIGS; ++i) {
1356 progress(activity, i+1, NUM_CONFIGS+3);
1357 serv_puts(configs[i]);
1361 sleep(1); /* Let the message appear briefly */
1364 * Create the administrator account. It's ok if the command fails if this user already exists.
1366 progress(activity, NUM_CONFIGS+1, NUM_CONFIGS+3);
1367 snprintf(buf, sizeof buf, "CREU %s|%s", configs[13], admin_pass);
1369 progress(activity, NUM_CONFIGS+2, NUM_CONFIGS+3);
1371 progress(activity, NUM_CONFIGS+3, NUM_CONFIGS+3);
1374 * Assign the desired password and access level to the administrator account.
1376 snprintf(buf, sizeof buf, "AGUP %s", configs[13]);
1379 if (buf[0] == '2') {
1380 int admin_flags = extract_int(&buf[4], 2);
1381 int admin_times_called = extract_int(&buf[4], 3);
1382 int admin_msgs_posted = extract_int(&buf[4], 4);
1383 snprintf(buf, sizeof buf, "ASUP %s|%s|%d|%d|%d|6",
1384 configs[13], admin_pass, admin_flags, admin_times_called, admin_msgs_posted
1391 check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */
1392 disable_other_mtas(); /* Offer to disable other MTAs */
1393 fixnss(); /* Check for the 'db' nss and offer to disable it */
1396 activity = _("Setting file permissions");
1397 progress(activity, 0, 2);
1398 //chown(file_citadel_config, config.c_ctdluid, gid);
1399 progress(activity, 1, 2);
1400 chmod(file_citadel_config, S_IRUSR | S_IWUSR);
1401 progress(activity, 2, 2);
1406 activity = _("Restarting Citadel server to apply changes");
1407 progress(activity, 0, 41);
1411 long original_start_time = extract_long(&buf[4], 3);
1413 progress(activity, 1, 41);
1414 serv_puts("DOWN 1");
1415 progress(activity, 2, 41);
1417 if (buf[0] != '2') {
1418 display_error("%s\n", buf);
1425 for (i=3; i<=6; ++i) { /* wait for server to shut down */
1426 progress(activity, i, 41);
1430 for (i=7; ((i<=38) && (serv_sock < 0)) ; ++i) { /* wait for server to start up */
1431 progress(activity, i, 41);
1432 serv_sock = uds_connectsock(file_citadel_admin_socket);
1436 progress(activity, 39, 41);
1439 progress(activity, 40, 41);
1442 long new_start_time = extract_long(&buf[4], 3);
1445 progress(activity, 41, 41);
1447 if ( (original_start_time == new_start_time)
1448 || (new_start_time <= 0)
1450 display_error("%s\n",
1451 _("Setup failed to restart Citadel server. Please restart it manually.")