oops
[citadel.git] / citadel / utils / setup.c
index 0d6d7c03227c027448fb3852891ac2dbb1f7d985..df16c0ea704921d18a73ab0488f66412e9e5f413 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Citadel setup utility
  *
- * Copyright (c) 1987-2015 by the citadel.org team
+ * Copyright (c) 1987-2019 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License version 3.
@@ -36,9 +36,6 @@
 #include "axdefs.h"
 #include "sysdep.h"
 #include "citadel_dirs.h"
-#if HAVE_BACKTRACE
-#include <execinfo.h>
-#endif
 
 #ifdef ENABLE_NLS
 #ifdef HAVE_XLOCALE_H
@@ -192,8 +189,8 @@ void SetTitles(void)
 "\n"
 " 0. Self contained authentication\n"
 " 1. Host system integrated authentication\n"
-" 2. External LDAP - RFC 2307 compliant directory\n"
-" 3. External LDAP - nonstandard MS Active Directory\n"
+" 2. External LDAP - RFC 2307 POSIX schema\n"
+" 3. External LDAP - MS Active Directory schema\n"
 "\n"
 "For help: http://www.citadel.org/doku.php/faq:installation:authmodes\n"
 "\n"
@@ -415,7 +412,6 @@ void progress(char *text, long int curr, long int cmax)
 }
 
 
-
 int uds_connectsock(char *sockpath)
 {
        int s;
@@ -618,116 +614,30 @@ void check_xinetd_entry(void)
                "       server_args     = -h -L %s/citadel\n"
                "       log_on_failure  += USERID\n"
                "}\n",
-               ctdl_bin_dir);
+               ctdl_bin_dir
+       );
        fclose(fp);
 
-       /* Now try to restart the service */
-       rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
+       /* Now try to restart the service.  This will not have the intended effect on Solaris, but who the hell uses Solaris anymore? */
+       rv = system("systemctl restart xinetd >/dev/null 2>&1");
        if (rv != 0) {
-               display_error(_("failed to restart xinetd.\n"));
+               rv = system("service xinetd restart >/dev/null 2>&1");
        }
-}
-
-
-
-/*
- * Offer to disable other MTA's
- */
-void disable_other_mta(const char *mta) {
-       char buf[SIZ];
-       FILE *fp;
-       int lines = 0;
-       int rv;
-
-       snprintf(buf, sizeof buf,
-               "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
-               "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
-               mta, mta
-       );
-       fp = popen(buf, "r");
-       if (fp == NULL) return;
-
-       while (fgets(buf, sizeof buf, fp) != NULL) {
-               ++lines;
-       }
-       fclose(fp);
-       if (lines == 0) return;         /* Nothing to do. */
-
-       /* Offer to replace other MTA with the vastly superior Citadel :)  */
-
-       snprintf(buf, sizeof buf,
-                "%s \"%s\" %s%s%s%s%s%s%s", 
-                _("You appear to have the "), 
-                mta, 
-                _(" email program\n"
-                  "running on your system.  If you want Citadel mail\n"
-                  "connected with "), 
-                mta,
-                _(" you will have to manually integrate\n"
-                  "them.  It is preferable to disable "), 
-                mta,
-                _(", and use Citadel's\n"
-                  "SMTP, POP3, and IMAP services.\n\n"
-                  "May we disable "), 
-                mta, 
-                _("so that Citadel has access to ports\n"
-                  "25, 110, and 143?\n")
-               );
-       if (yesno(buf, 1) == 0) {
-               return;
+       if (rv != 0) {
+               display_error(_("failed to restart xinetd.\n"));
        }
-       
-
-       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);
-       rv = system(buf);
-       if (rv != 0)
-               display_error("%s %s.\n", _("failed to disable other mta"), mta);
-
-       snprintf(buf, sizeof buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
-       rv = system(buf);
-       if (rv != 0)
-               display_error(" %s.\n", _("failed to disable other mta"), mta);
 }
 
-const char *other_mtas[] = {
-       "courier-authdaemon",
-       "courier-imap",
-       "courier-imap-ssl",
-       "courier-pop",
-       "courier-pop3",
-       "courier-pop3d",
-       "cyrmaster",
-       "cyrus",
-       "dovecot",
-       "exim",
-       "exim4",
-       "imapd",
-       "mta",
-       "pop3d",
-       "popd",
-       "postfix",
-       "qmail",
-       "saslauthd",
-       "sendmail",
-       "vmailmgrd",
-       ""
-};
 
 void disable_other_mtas(void)
 {
-       int i = 0;
-       if ((getenv("ACT_AS_MTA") == NULL) || 
-           (getenv("ACT_AS_MTA") &&
-            strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
+       if ((getenv("ACT_AS_MTA") == NULL) || (getenv("ACT_AS_MTA") && strcasecmp(getenv("ACT_AS_MTA"), "yes") == 0)) {
                /* Offer to disable other MTA's on the system. */
-               while (!IsEmptyStr(other_mtas[i]))
-               {
-                       disable_other_mta(other_mtas[i]);
-                       i++;
-               }
+               /* FIXME this has to be rewritten to work in the new systemd-based world. */
        }
 }
 
+
 void strprompt(const char *prompt_title, const char *prompt_text, char *Target, char *DefValue)
 {
        char buf[SIZ] = "";
@@ -841,7 +751,7 @@ void edit_value(int curr)
                break;
        
        case eUID:
-
+               ctdluid = getconf_int("c_ctdluid");
                if (setup_type == UI_SILENT)
                {               
                        if (default_value) {
@@ -850,9 +760,6 @@ void edit_value(int curr)
                }
                else
                {
-#ifdef __CYGWIN__
-                       ctdluid = 0;    /* work-around for Windows */
-#else
                        pw = getpwuid(ctdluid);
                        if (pw == NULL) {
                                set_int_val(curr, &ctdluid, default_value);
@@ -1051,20 +958,18 @@ void fixnss(void) {
  * Messages that are no longer in use.
  * We keep them here so we don't lose the translations if we need them later.
  */
-#if 0
-                               important_message(_("Setup finished"),
-                                                 _("Setup of the Citadel server is complete.\n"
-                                                   "If you will be using WebCit, please run its\n"
-                                                   "setup program now; otherwise, run './citadel'\n"
-                                                   "to log in.\n"));
-                       important_message(_("Setup failed"),
-                                         _("Setup is finished, but the Citadel server failed to start.\n"
-                                           "Go back and check your configuration.\n")
-               important_message(_("Setup finished"),
-                                 _("Setup is finished.  You may now start the server."));
-#endif
-
-
+void niu_messages() {
+important_message(_("Setup finished"),
+_("Setup of the Citadel server is complete.\n"
+"If you will be using WebCit, please run its\n"
+"setup program now; otherwise, run './citadel'\n"
+"to log in.\n"));
+important_message(_("Setup failed"),
+_("Setup is finished, but the Citadel server failed to start.\n"
+"Go back and check your configuration.\n");
+important_message(_("Setup finished"),
+_("Setup is finished.  You may now start the server."));
+}
 
 
 int main(int argc, char *argv[])
@@ -1075,7 +980,6 @@ int main(int argc, char *argv[])
        char aaa[128];
        int relh = 0;
        int home = 0;
-       int nRetries = 0;
        char relhome[PATH_MAX]="";
        char ctdldir[PATH_MAX]=CTDLDIR;
        struct passwd *pw;
@@ -1131,12 +1035,14 @@ int main(int argc, char *argv[])
        /*
         * Connect to the running Citadel server.
         */
-       while ((serv_sock < 0) && (nRetries < 10)) {
+       char *connectingmsg = _("Connecting to Citadel server");
+       for (i=0; ((i<30) && (serv_sock < 0)) ; ++i) {          /* wait for server to start up */
+               progress(connectingmsg, i, 30);
                serv_sock = uds_connectsock(file_citadel_admin_socket);
-               nRetries ++;
-               if (serv_sock < 0)
-                       sleep(1);
+               sleep(1);
        }
+       progress(connectingmsg, 30, 30);
+
        if (serv_sock < 0) { 
                display_error(
                        "%s: %s %s\n", 
@@ -1234,29 +1140,33 @@ int main(int argc, char *argv[])
        /*
         * Create the administrator account.  It's ok if the command fails if this user already exists.
         */
-       progress(activity, 1, 5);
-       snprintf(buf, sizeof buf, "CREU %s|%s", admin_name, admin_pass);
-       serv_puts(buf);
-       progress(activity, 2, 5);
-       serv_gets(buf);
+       if (getconf_int("c_auth_mode") == AUTHMODE_NATIVE) {
+               progress(activity, 1, 5);
+               snprintf(buf, sizeof buf, "CREU %s|%s", admin_name, admin_pass);
+               serv_puts(buf);
+               progress(activity, 2, 5);
+               serv_gets(buf);
+       }
        progress(activity, 3, 5);
 
        /*
         * Assign the desired password and access level to the administrator account.
         */
-       snprintf(buf, sizeof buf, "AGUP %s", admin_name);
-       serv_puts(buf);
-       progress(activity, 4, 5);
-       serv_gets(buf);
-       if (buf[0] == '2') {
-               int admin_flags = extract_int(&buf[4], 2);
-               int admin_times_called = extract_int(&buf[4], 3);
-               int admin_msgs_posted = extract_int(&buf[4], 4);
-               snprintf(buf, sizeof buf, "ASUP %s|%s|%d|%d|%d|6",
-                       admin_name, admin_pass, admin_flags, admin_times_called, admin_msgs_posted
-               );
+       if (getconf_int("c_auth_mode") == AUTHMODE_NATIVE) {
+               snprintf(buf, sizeof buf, "AGUP %s", admin_name);
                serv_puts(buf);
+               progress(activity, 4, 5);
                serv_gets(buf);
+               if (buf[0] == '2') {
+                       int admin_flags = extract_int(&buf[4], 2);
+                       int admin_times_called = extract_int(&buf[4], 3);
+                       int admin_msgs_posted = extract_int(&buf[4], 4);
+                       snprintf(buf, sizeof buf, "ASUP %s|%s|%d|%d|%d|6",
+                               admin_name, admin_pass, admin_flags, admin_times_called, admin_msgs_posted
+                       );
+                       serv_puts(buf);
+                       serv_gets(buf);
+               }
        }
        progress(activity, 5, 5);
 
@@ -1270,15 +1180,15 @@ int main(int argc, char *argv[])
         * Restart citserver
         */
        activity = _("Restarting Citadel server to apply changes");
-       progress(activity, 0, 41);
+       progress(activity, 0, 51);
 
        serv_puts("TIME");
        serv_gets(buf);
        long original_start_time = extract_long(&buf[4], 3);
 
-       progress(activity, 1, 41);
+       progress(activity, 1, 51);
        serv_puts("DOWN 1");
-       progress(activity, 2, 41);
+       progress(activity, 2, 51);
        serv_gets(buf);
        if (buf[0] != '2') {
                display_error("%s\n", buf);
@@ -1289,26 +1199,26 @@ int main(int argc, char *argv[])
        serv_sock = (-1);
 
        for (i=3; i<=6; ++i) {                                  /* wait for server to shut down */
-               progress(activity, i, 41);
+               progress(activity, i, 51);
                sleep(1);
        }
 
-       for (i=7; ((i<=38) && (serv_sock < 0)) ; ++i) {         /* wait for server to start up */
-               progress(activity, i, 41);
+       for (i=7; ((i<=48) && (serv_sock < 0)) ; ++i) {         /* wait for server to start up */
+               progress(activity, i, 51);
                serv_sock = uds_connectsock(file_citadel_admin_socket);
                sleep(1);
        }
 
-       progress(activity, 39, 41);
+       progress(activity, 49, 51);
        serv_gets(buf);
 
-       progress(activity, 40, 41);
+       progress(activity, 50, 51);
        serv_puts("TIME");
        serv_gets(buf);
        long new_start_time = extract_long(&buf[4], 3);
 
        close(serv_sock);
-       progress(activity, 41, 41);
+       progress(activity, 51, 51);
 
        if (    (original_start_time == new_start_time)
                || (new_start_time <= 0)