]> 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 c129d2de78d606d4565c1cde1bf4dd7cea783e42..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);
@@ -172,8 +173,8 @@ void locate_init_entry(char *init_entry, char *looking_for) {
        } 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;
@@ -277,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");
@@ -331,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"));
@@ -623,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;
@@ -653,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,
@@ -733,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,
@@ -791,7 +796,7 @@ void edit_value(int curr)
 {
        int i;
        struct passwd *pw;
-       char bbsuidname[SIZ];
+       char ctdluidname[SIZ];
 
        switch (curr) {
 
@@ -801,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
@@ -933,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"));
        }
@@ -1044,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;
@@ -1083,6 +1088,9 @@ int main(int argc, char *argv[])
        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) {
@@ -1092,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);
@@ -1172,23 +1180,24 @@ NEW_INST:
        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);
@@ -1210,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",
@@ -1290,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();