]> code.citadel.org Git - citadel.git/blobdiff - citadel/setup.c
* Variable names, comments, documentation, etc... removed the acronym 'BBS'
[citadel.git] / citadel / setup.c
index cc9dc274e4978b3e524a5ae7fb3882edfd4992a0..6c8b336da7c508971b633c98c52110e25cb897b5 100644 (file)
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <limits.h>
 #include <pwd.h>
+#include <time.h>
 
 #include "citadel.h"
 #include "axdefs.h"
@@ -69,7 +70,7 @@ char *setup_text[] = {
 
 "Enter the name of the system administrator (which is probably\n"
 "you).  When an account is created with this name, it will\n"
-"automatically be assigned the highest access level.\n",
+"automatically be given administrator-level access.\n",
 
 "Citadel needs to run under its own user ID.  This would\n"
 "typically be called \"citadel\", but if you are running Citadel\n"
@@ -119,10 +120,10 @@ void set_init_entry(char *which_entry, char *new_state) {
        while(fgets(buf, sizeof buf, fp) != NULL) {
 
                if (num_tokens(buf, ':') == 4) {
-                       extract_token(entry, buf, 0, ':');
-                       extract_token(levels, buf, 1, ':');
-                       extract_token(state, buf, 2, ':');
-                       extract_token(prog, buf, 3, ':'); /* includes 0x0a LF */
+                       extract_token(entry, buf, 0, ':', sizeof entry);
+                       extract_token(levels, buf, 1, ':', sizeof levels);
+                       extract_token(state, buf, 2, ':', sizeof state);
+                       extract_token(prog, buf, 3, ':', sizeof prog); /* includes 0x0a LF */
 
                        if (!strcmp(entry, which_entry)) {
                                strcpy(state, new_state);
@@ -153,12 +154,11 @@ void set_init_entry(char *which_entry, char *new_state) {
 /*
  * Locate the name of an inittab entry for a specific program
  */
-void locate_init_entry(char *init_entry, char *program) {
+void locate_init_entry(char *init_entry, char *looking_for) {
 
        FILE *infp;
        char buf[SIZ];
        int have_entry = 0;
-       char looking_for[SIZ];
        char entry[SIZ];
        char prog[SIZ];
 
@@ -173,8 +173,8 @@ void locate_init_entry(char *init_entry, char *program) {
        } else {
                while (fgets(buf, sizeof buf, infp) != NULL) {
                        buf[strlen(buf) - 1] = 0;
-                       extract_token(entry, buf, 0, ':');      
-                       extract_token(prog, buf, 3, ':');
+                       extract_token(entry, buf, 0, ':', sizeof entry);
+                       extract_token(prog, buf, 3, ':', sizeof prog);
                        if (!strncasecmp(prog, looking_for,
                           strlen(looking_for))) {
                                ++have_entry;
@@ -193,7 +193,7 @@ void locate_init_entry(char *init_entry, char *program) {
 void shutdown_citserver(void) {
        char looking_for[SIZ];
 
-       snprintf(looking_for, sizeof looking_for, "%s/citserver", BBSDIR);
+       snprintf(looking_for, sizeof looking_for, "%s/citserver", setup_directory);
        locate_init_entry(citserver_init_entry, looking_for);
        if (strlen(citserver_init_entry) > 0) {
                set_init_entry(citserver_init_entry, "off");
@@ -278,7 +278,7 @@ int yesno(char *question)
                newtCenteredWindow(76, prompt_window_height, "Question");
                form = newtForm(NULL, NULL, 0);
                for (i=0; i<num_tokens(question, '\n'); ++i) {
-                       extract_token(buf, question, i, '\n');
+                       extract_token(buf, question, i, '\n', sizeof buf);
                        newtFormAddComponent(form, newtLabel(1, 1+i, buf));
                }
                yesbutton = newtButton(10, (prompt_window_height - 4), "Yes");
@@ -332,7 +332,7 @@ void important_message(char *title, char *msgtext)
                newtCenteredWindow(76, 10, title);
                form = newtForm(NULL, NULL, 0);
                for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
-                       extract_token(buf, msgtext, i, '\n');
+                       extract_token(buf, msgtext, i, '\n', sizeof buf);
                        newtFormAddComponent(form, newtLabel(1, 1+i, buf));
                }
                newtFormAddComponent(form, newtButton(35, 5, "OK"));
@@ -515,7 +515,7 @@ void check_inittab_entry(void)
        char entryname[5];
 
        /* Determine the fully qualified path name of citserver */
-       snprintf(looking_for, sizeof looking_for, "%s/citserver", BBSDIR);
+       snprintf(looking_for, sizeof looking_for, "%s/citserver", setup_directory);
        locate_init_entry(citserver_init_entry, looking_for);
 
        /* If there's already an entry, then we have nothing left to do. */
@@ -609,7 +609,9 @@ void disable_other_mta(char *mta) {
        FILE *fp;
        int lines = 0;
 
-       sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null", mta);
+       sprintf(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;
 
@@ -622,9 +624,13 @@ void disable_other_mta(char *mta) {
        /* Offer to replace other MTA with the vastly superior Citadel :)  */
        snprintf(buf, sizeof buf,
                "You appear to have the \"%s\" email program\n"
-               "running on your system.  Would you like to disable it,\n"
-               "allowing Citadel to handle your Internet mail instead?\n",
-               mta
+               "running on your system.  If you want Citadel mail\n"
+               "connected with %s, you will have to manually integrate\n"
+               "them.  It is preferable to disable %s, and use Citadel's\n"
+               "SMTP, POP3, and IMAP services.\n\n"
+               "May we disable %s so that Citadel has access to ports\n"
+               "25, 110, and 143?\n",
+               mta, mta, mta, mta
        );
        if (yesno(buf) == 0)
                return;
@@ -652,7 +658,7 @@ int test_server(void) {
         * to the server and try to get it back.  The cookie does not
         * have to be secret ... just unique.
         */
-       sprintf(cookie, "%ld.%d", time(NULL), getpid());
+       sprintf(cookie, "--test--%d--", getpid());
 
        sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
                setup_directory,
@@ -732,7 +738,7 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
                                prompt_title);
                form = newtForm(NULL, NULL, 0);
                for (i=0; i<num_tokens(prompt_text, '\n'); ++i) {
-                       extract_token(buf, prompt_text, i, '\n');
+                       extract_token(buf, prompt_text, i, '\n', sizeof buf);
                        newtFormAddComponent(form, newtLabel(1, 1+i, buf));
                }
                newtFormAddComponent(form,
@@ -790,7 +796,7 @@ void edit_value(int curr)
 {
        int i;
        struct passwd *pw;
-       char bbsuidname[SIZ];
+       char ctdluidname[SIZ];
 
        switch (curr) {
 
@@ -800,23 +806,23 @@ void edit_value(int curr)
 
        case 2:
 #ifdef __CYGWIN__
-               config.c_bbsuid = 0;    /* XXX Windows hack, prob. insecure */
+               config.c_ctdluid = 0;   /* XXX Windows hack, prob. insecure */
 #else
-               i = config.c_bbsuid;
+               i = config.c_ctdluid;
                pw = getpwuid(i);
                if (pw == NULL) {
                        set_int_val(curr, &i);
-                       config.c_bbsuid = i;
+                       config.c_ctdluid = i;
                }
                else {
-                       strcpy(bbsuidname, pw->pw_name);
-                       set_str_val(curr, bbsuidname);
-                       pw = getpwnam(bbsuidname);
+                       strcpy(ctdluidname, pw->pw_name);
+                       set_str_val(curr, ctdluidname);
+                       pw = getpwnam(ctdluidname);
                        if (pw != NULL) {
-                               config.c_bbsuid = pw->pw_uid;
+                               config.c_ctdluid = pw->pw_uid;
                        }
-                       else if (atoi(bbsuidname) > 0) {
-                               config.c_bbsuid = atoi(bbsuidname);
+                       else if (atoi(ctdluidname) > 0) {
+                               config.c_ctdluid = atoi(ctdluidname);
                        }
                }
 #endif
@@ -932,7 +938,7 @@ int main(int argc, char *argv[])
        }
 
        /* Get started in a valid setup directory. */
-       strcpy(setup_directory, BBSDIR);
+       strcpy(setup_directory, CTDLDIR);
        if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
                strcpy(setup_directory, getenv("CITADEL"));
        }
@@ -1043,20 +1049,20 @@ int main(int argc, char *argv[])
        if (config.c_sleeping == 0) {
                config.c_sleeping = 900;
        }
-       if (config.c_bbsuid == 0) {
+       if (config.c_ctdluid == 0) {
                pw = getpwnam("citadel");
                if (pw != NULL)
-                       config.c_bbsuid = pw->pw_uid;
+                       config.c_ctdluid = pw->pw_uid;
        }
-       if (config.c_bbsuid == 0) {
+       if (config.c_ctdluid == 0) {
                pw = getpwnam("bbs");
                if (pw != NULL)
-                       config.c_bbsuid = pw->pw_uid;
+                       config.c_ctdluid = pw->pw_uid;
        }
-       if (config.c_bbsuid == 0) {
+       if (config.c_ctdluid == 0) {
                pw = getpwnam("guest");
                if (pw != NULL)
-                       config.c_bbsuid = pw->pw_uid;
+                       config.c_ctdluid = pw->pw_uid;
        }
        if (config.c_createax == 0) {
                config.c_createax = 3;
@@ -1081,6 +1087,10 @@ int main(int argc, char *argv[])
        if (config.c_smtp_port == 0) config.c_smtp_port = 25;
        if (config.c_pop3_port == 0) config.c_pop3_port = 110;
        if (config.c_imap_port == 0) config.c_imap_port = 143;
+       if (config.c_msa_port == 0) config.c_msa_port = 587;
+       if (config.c_smtps_port == 0) config.c_smtps_port = 465;
+       if (config.c_pop3s_port == 0) config.c_pop3s_port = 995;
+       if (config.c_imaps_port == 0) config.c_imaps_port = 993;
 
        /* Go through a series of dialogs prompting for config info */
        if (setup_type != UI_SILENT) {
@@ -1090,7 +1100,7 @@ int main(int argc, char *argv[])
        }
 
        /*
-          if (setuid(config.c_bbsuid) != 0) {
+          if (setuid(config.c_ctdluid) != 0) {
           important_message("Citadel Setup",
           "Failed to change the user ID to your Citadel user.");
           cleanup(errno);
@@ -1169,23 +1179,25 @@ NEW_INST:
        disable_other_mta("popd");
        disable_other_mta("pop3d");
        disable_other_mta("exim");
+       disable_other_mta("dovecot");
+       disable_other_mta("hula");
 #endif
 
-       if ((pw = getpwuid(config.c_bbsuid)) == NULL)
+       if ((pw = getpwuid(config.c_ctdluid)) == NULL)
                gid = getgid();
        else
                gid = pw->pw_gid;
 
        progress("Setting file permissions", 0, 4);
-       chown(".", config.c_bbsuid, gid);
+       chown(".", config.c_ctdluid, gid);
        sleep(1);
        progress("Setting file permissions", 1, 4);
-       chown("citadel.config", config.c_bbsuid, gid);
+       chown("citadel.config", config.c_ctdluid, gid);
        sleep(1);
        progress("Setting file permissions", 2, 4);
        snprintf(aaa, sizeof aaa,
                "find . | grep -v chkpwd | xargs chown %ld:%ld 2>/dev/null",
-               (long)config.c_bbsuid, (long)gid);
+               (long)config.c_ctdluid, (long)gid);
        system(aaa);
        sleep(1);
        progress("Setting file permissions", 3, 4);
@@ -1207,7 +1219,10 @@ NEW_INST:
                }
                if (test_server() == 0) {
                        important_message("Setup finished",
-                               "Setup is finished.  You may now log in.");
+                               "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");
                }
                else {
                        important_message("Setup finished",
@@ -1236,18 +1251,34 @@ void contemplate_ldap(void) {
        char slapd_init_entry[SIZ];
        FILE *fp;
 
-       /* If conditions are not ideal, give up on this idea. */
+       /* If conditions are not ideal, give up on this idea... */
        if (using_web_installer == 0) return;
        if (getenv("LDAP_CONFIG") == NULL) return;
        if (getenv("SUPPORT") == NULL) return;
        if (getenv("SLAPD_BINARY") == NULL) return;
        if (getenv("CITADEL") == NULL) return;
 
-       /* Otherwise, prompt the user to create an entry. */
+       /* And if inittab is already starting slapd, bail out... */
+       locate_init_entry(slapd_init_entry, getenv("SLAPD_BINARY"));
+       if (strlen(slapd_init_entry) > 0) {
+               important_message("Citadel Setup",
+                       "You appear to already have a standalone LDAP "
+                       "service\nconfigured for use with Citadel.  No "
+                       "changes will be made.\n");
+               /* set_init_entry(slapd_init_entry, "off"); */
+               return;
+       }
+
+       /* Generate a unique entry name for slapd if we don't have one. */
+       else {
+               generate_entry_name(slapd_init_entry);
+       }
+
+       /* Ask the user if it's ok to set up slapd automatically. */
        snprintf(question, sizeof question,
                "\n"
                "Do you want this computer configured to start a standalone\n"
-               "LDAP service automatically?  (If you answer yes, a custom\n"
+               "LDAP service automatically?  (If you answer yes, a new\n"
                "slapd.conf will be written, and an /etc/inittab entry\n"
                "pointing to %s will be added.)\n"
                "\n",
@@ -1271,8 +1302,13 @@ void contemplate_ldap(void) {
        config.c_ldap_port = 389;
        sprintf(config.c_ldap_bind_dn, "cn=manager,%s", config.c_ldap_base_dn);
 
-       /* FIXME ... make the generated password harder to guess */
-       sprintf(config.c_ldap_bind_pw, "%d%ld", getpid(), time(NULL));
+       /*
+        * Generate a bind password.  If you're some grey hat hacker who
+        * is just dying to get some street cred on Bugtraq, and you think
+        * this password generation scheme is too weak, please submit a patch
+        * instead of just whining about it, ok?
+        */
+       sprintf(config.c_ldap_bind_pw, "%d%ld", getpid(), (long)time(NULL));
 
        write_config_to_disk();
 
@@ -1310,15 +1346,6 @@ void contemplate_ldap(void) {
        /* This is where our OpenLDAP server will keep its data. */
        mkdir("openldap-data", 0700);
 
-       /* If inittab is already starting slapd, disable the old entry. */
-       locate_init_entry(slapd_init_entry, getenv("SLAPD_BINARY"));
-       if (strlen(slapd_init_entry) > 0) {
-               set_init_entry(slapd_init_entry, "off");
-       }
-
-       /* Generate a unique entry name for slapd */
-       generate_entry_name(slapd_init_entry);
-
        /* Now write it out to /etc/inittab.
         * FIXME make it run as some non-root user.
         * The "-d 0" seems superfluous, but it's actually a way to make