]> code.citadel.org Git - citadel.git/blobdiff - citadel/setup.c
calculate the directories in a central manner.
[citadel.git] / citadel / setup.c
index cfd3acc0769fa2a574b880b80d17e1a6b8241be8..5ac145b22279bf63ee874e3e3f7dedb9361ca415 100644 (file)
@@ -47,6 +47,7 @@ int setup_type;
 char setup_directory[SIZ];
 char citserver_init_entry[SIZ];
 int using_web_installer = 0;
+int enable_home = 1;
 
 #ifdef HAVE_LDAP
 void contemplate_ldap(void);
@@ -62,11 +63,55 @@ char *setup_titles[] =
 };
 
 
+struct config config;
+/* CTDLDIR */
+char ctdl_home_directory[PATH_MAX] = "";
+char ctdl_bio_dir[PATH_MAX]="bio";
+char ctdl_bb_dir[PATH_MAX]="bitbucket";
+char ctdl_data_dir[PATH_MAX]="data";
+char ctdl_file_dir[PATH_MAX]="files";
+char ctdl_hlp_dir[PATH_MAX]="help";
+char ctdl_image_dir[PATH_MAX]="images";
+char ctdl_info_dir[PATH_MAX]="info";
+char ctdl_key_dir[PATH_MAX]="keys";
+char ctdl_message_dir[PATH_MAX]="messages";
+char ctdl_usrpic_dir[PATH_MAX]="userpics";
+char ctdl_etc_dir[PATH_MAX]="";
+char ctdl_run_dir[PATH_MAX]="";
+char ctdl_spool_dir[PATH_MAX]="network";
+char ctdl_netout_dir[PATH_MAX]="network/spoolout";
+char ctdl_netin_dir[PATH_MAX]="network/spoolin";
+
+
+char citadel_rc_file[PATH_MAX]="";
+
+       /* calculate all our path on a central place */
+    /* where to keep our config */
+       
+#define COMPUTE_DIRECTORY(SUBDIR) memcpy(dirbuffer,SUBDIR, sizeof dirbuffer);\
+       snprintf(SUBDIR,sizeof SUBDIR,  "%s%s%s%s%s%s%s", \
+                        (home&!relh)?ctdl_home_directory:basedir, \
+             ((basedir!=ctdldir)&(home&!relh))?basedir:"/", \
+             ((basedir!=ctdldir)&(home&!relh))?"/":"", \
+                        relhome, \
+             (relhome[0]!='\0')?"/":"",\
+                        dirbuffer,\
+                        (dirbuffer[0]!='\0')?"/":"");
+
+
 char *setup_text[] = {
+#ifndef HAVE_RUN_DIR
 "Enter the full pathname of the directory in which the Citadel\n"
 "installation you are creating or updating resides.  If you\n"
 "specify a directory other than the default, you will need to\n"
 "specify the -h flag to the server when you start it up.\n",
+#else
+"Enter the subdirectoryname for an alternating installation of "
+"Citadel. To do a default installation just leave it blank."
+"If you specify a directory other than the default, you will need to\n"
+"specify the -h flag to the server when you start it up.\n"
+"note that it may not have a leading /",
+#endif
 
 "Enter the name of the system administrator (which is probably\n"
 "you).  When an account is created with this name, it will\n"
@@ -193,7 +238,15 @@ void locate_init_entry(char *init_entry, char *looking_for) {
 void shutdown_citserver(void) {
        char looking_for[SIZ];
 
-       snprintf(looking_for, sizeof looking_for, "%s/citserver", setup_directory);
+       snprintf(looking_for, 
+                        sizeof looking_for,
+                        "%s/citserver", 
+#ifndef HAVE_RUN_DIR
+                        setup_directory
+#else
+                        CTDLDIR
+#endif
+                        );
        locate_init_entry(citserver_init_entry, looking_for);
        if (strlen(citserver_init_entry) > 0) {
                set_init_entry(citserver_init_entry, "off");
@@ -320,9 +373,8 @@ void important_message(char *title, char *msgtext)
                break;
 
        case UI_DIALOG:
-               sprintf(buf, "exec %s --backtitle '%s' --msgbox '%s' 19 72",
+               sprintf(buf, "exec %s --msgbox '%s' 19 72",
                        getenv("CTDL_DIALOG"),
-                       title,
                        msgtext);
                system(buf);
                break;
@@ -515,7 +567,15 @@ void check_inittab_entry(void)
        char entryname[5];
 
        /* Determine the fully qualified path name of citserver */
-       snprintf(looking_for, sizeof looking_for, "%s/citserver", setup_directory);
+       snprintf(looking_for, 
+                        sizeof looking_for,
+                        "%s/citserver", 
+#ifndef HAVE_RUN_DIR
+                        setup_directory
+#else
+                        CTDLDIR
+#endif
+                        );
        locate_init_entry(citserver_init_entry, looking_for);
 
        /* If there's already an entry, then we have nothing left to do. */
@@ -524,13 +584,21 @@ void check_inittab_entry(void)
        }
 
        /* Otherwise, prompt the user to create an entry. */
-       snprintf(question, sizeof question,
-               "Do you want this computer configured to start the Citadel\n"
-               "service automatically?  (If you answer yes, an entry in\n"
-               "/etc/inittab pointing to %s will be added.)\n",
-               looking_for);
-       if (yesno(question) == 0)
-               return;
+       if (getenv("CREATE_INITTAB_ENTRY") != NULL) {
+               if (strcasecmp(getenv("CREATE_INITTAB_ENTRY"), "yes")) {
+                       return;
+               }
+       }
+       else {
+               snprintf(question, sizeof question,
+                       "Do you want this computer configured to start the Citadel\n"
+                       "service automatically?  (If you answer yes, an entry in\n"
+                       "/etc/inittab pointing to %s will be added.)\n",
+                       looking_for);
+               if (yesno(question) == 0) {
+                       return;
+               }
+       }
 
        /* Generate a unique entry name for /etc/inittab */
        generate_entry_name(entryname);
@@ -541,8 +609,11 @@ void check_inittab_entry(void)
                display_error(strerror(errno));
        } else {
                fprintf(infp, "# Start the Citadel server...\n");
-               fprintf(infp, "%s:2345:respawn:%s -h%s -x3 -llocal4\n",
-                       entryname, looking_for, setup_directory);
+               fprintf(infp, "%s:2345:respawn:%s %s%s -x3 -llocal4\n",
+                               entryname, 
+                               looking_for, 
+                               (enable_home)?"-h":"", 
+                               (enable_home)?setup_directory:"");
                fclose(infp);
                strcpy(citserver_init_entry, entryname);
        }
@@ -569,13 +640,21 @@ void check_xinetd_entry(void) {
        if (already_citadel) return;    /* Already set up this way. */
 
        /* Otherwise, prompt the user to create an entry. */
-       snprintf(buf, sizeof buf,
-               "Setup can configure the \"xinetd\" service to automatically\n"
-               "connect incoming telnet sessions to Citadel, bypassing the\n"
-               "host system login: prompt.  Would you like to do this?\n"
-       );
-       if (yesno(buf) == 0)
-               return;
+       if (getenv("CREATE_XINETD_ENTRY") != NULL) {
+               if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
+                       return;
+               }
+       }
+       else {
+               snprintf(buf, sizeof buf,
+                       "Setup can configure the \"xinetd\" service to automatically\n"
+                       "connect incoming telnet sessions to Citadel, bypassing the\n"
+                       "host system login: prompt.  Would you like to do this?\n"
+               );
+               if (yesno(buf) == 0) {
+                       return;
+               }
+       }
 
        fp = fopen(filename, "w");
        fprintf(fp,
@@ -591,8 +670,12 @@ void check_xinetd_entry(void) {
                "       server_args     = -h -L %s/citadel\n"
                "       log_on_failure  += USERID\n"
                "}\n",
-               setup_directory
-       );
+#ifndef HAVE_RUN_DIR
+                       setup_directory
+#else
+                       RUN_DIR
+#endif
+                       );
        fclose(fp);
 
        /* Now try to restart the service */
@@ -621,19 +704,29 @@ void disable_other_mta(char *mta) {
        fclose(fp);
        if (lines == 0) return;         /* Nothing to do. */
 
+
        /* 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.  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;
+
+       if (getenv("ACT_AS_MTA")) {
+               if (strcasecmp(getenv("ACT_AS_MTA"), "yes")) {
+                       return;
+               }
+       }
+       else {
+               snprintf(buf, sizeof buf,
+                       "You appear to have the \"%s\" email program\n"
+                       "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;
+               }
+       }
 
        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);
        system(buf);
@@ -660,10 +753,15 @@ int test_server(void) {
         */
        sprintf(cookie, "--test--%d--", getpid());
 
-       sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
-               setup_directory,
-               setup_directory,
-               cookie);
+       sprintf(cmd, "%s/sendcommand %s%s ECHO %s 2>&1",
+#ifndef HAVE_RUN_DIR
+                       setup_directory,
+#else
+                       CTDLDIR,
+#endif
+                       (enable_home)?"-h":"", 
+                       (enable_home)?setup_directory:"",
+                       cookie);
 
        fp = popen(cmd, "r");
        if (fp == NULL) return(errno);
@@ -692,7 +790,7 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
 #endif
        char buf[SIZ];
        char setupmsg[SIZ];
-       char *dialog_result;
+       char dialog_result[PATH_MAX];
        FILE *fp = NULL;
 
        strcpy(setupmsg, "");
@@ -710,10 +808,9 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
                break;
 
        case UI_DIALOG:
-               dialog_result = tmpnam(NULL);
-               sprintf(buf, "exec %s --backtitle '%s' --inputbox '%s' 19 72 '%s' 2>%s",
+               CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
+               sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
                        getenv("CTDL_DIALOG"),
-                       prompt_title,
                        prompt_text,
                        str,
                        dialog_result);
@@ -746,7 +843,7 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
                                (prompt_window_height - 2),
                                str,
                                74,
-                               &result,
+                               (const char **) &result,
                                NEWT_FLAG_RETURNEXIT)
                );
                newtRunForm(form);
@@ -801,7 +898,12 @@ void edit_value(int curr)
        switch (curr) {
 
        case 1:
-               set_str_val(curr, config.c_sysadm);
+               if (getenv("SYSADMIN_NAME")) {
+                       strcpy(config.c_sysadm, getenv("SYSADMIN_NAME"));
+               }
+               else {
+                       set_str_val(curr, config.c_sysadm);
+               }
                break;
 
        case 2:
@@ -898,7 +1000,7 @@ int discover_ui(void)
 int main(int argc, char *argv[])
 {
        int a;
-       int curr;
+       int curr; 
        char aaa[128];
        FILE *fp;
        int old_setup_level = 0;
@@ -907,7 +1009,13 @@ int main(int argc, char *argv[])
        struct passwd *pw;
        struct hostent *he;
        gid_t gid;
-
+       int relh=0;
+       int home=0;
+       const char* basedir;
+       char dirbuffer[PATH_MAX]="";
+       char relhome[PATH_MAX]="";
+       char ctdldir[PATH_MAX]=CTDLDIR;
+       
        /* set an invalid setup type */
        setup_type = (-1);
 
@@ -944,7 +1052,13 @@ int main(int argc, char *argv[])
        }
 
        /* Get started in a valid setup directory. */
-       strcpy(setup_directory, CTDLDIR);
+       strcpy(setup_directory, 
+#ifdef HAVE_RUN_DIR
+                  ""
+#else
+                  CTDLDIR
+#endif
+                  );
        if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
                strcpy(setup_directory, getenv("CITADEL"));
        }
@@ -952,7 +1066,53 @@ int main(int argc, char *argv[])
                set_str_val(0, setup_directory);
        }
 
-       if (chdir(setup_directory) != 0) {
+       home=(setup_directory[1]!='\0');
+       relh=home&(setup_directory[1]!='/');
+       if (!relh) safestrncpy(ctdl_home_directory, setup_directory,
+                                                                  sizeof ctdl_home_directory);
+       else
+               safestrncpy(relhome, ctdl_home_directory,
+                                       sizeof relhome);
+       
+#ifndef HAVE_ETC_DIR
+       basedir=ctdldir;
+#else
+       basedir=ETC_DIR;
+#endif
+       COMPUTE_DIRECTORY(ctdl_etc_dir);
+
+#ifndef HAVE_RUN_DIR
+       basedir=ctdldir;
+#else
+       basedir=RUN_DIR;
+#endif
+       COMPUTE_DIRECTORY(ctdl_run_dir);
+
+#ifndef HAVE_DATA_DIR
+       basedir=ctdldir;
+#else
+       basedir=DATA_DIR;
+#endif
+       COMPUTE_DIRECTORY(ctdl_bio_dir);
+       COMPUTE_DIRECTORY(ctdl_bb_dir);
+       COMPUTE_DIRECTORY(ctdl_data_dir);
+       COMPUTE_DIRECTORY(ctdl_file_dir);
+       COMPUTE_DIRECTORY(ctdl_hlp_dir);
+       COMPUTE_DIRECTORY(ctdl_image_dir);
+       COMPUTE_DIRECTORY(ctdl_info_dir);
+       COMPUTE_DIRECTORY(ctdl_message_dir);
+       COMPUTE_DIRECTORY(ctdl_usrpic_dir);
+#ifndef HAVE_SPOOL_DIR
+       basedir=ctdldir;
+#else
+       basedir=SPOOL_DIR;
+#endif
+       COMPUTE_DIRECTORY(ctdl_spool_dir);
+       COMPUTE_DIRECTORY(ctdl_netout_dir);
+       COMPUTE_DIRECTORY(ctdl_netin_dir);
+
+
+       if ((home) && (chdir(setup_directory) != 0)) {
                important_message("Citadel Setup",
                          "The directory you specified does not exist.");
                cleanup(errno);
@@ -997,14 +1157,12 @@ int main(int argc, char *argv[])
         * to be when we rewrite it, because we replace the old file with a
         * completely new copy.
         */
+       snprintf(citadel_rc_file, 
+                        sizeof citadel_rc_file,
+                        "%s/citadel.config",
+                        ctdl_etc_dir);
 
-       if ((a = open(
-#ifndef HAVE_ETC_DIR
-                                 "."
-#else
-                                 ETC_DIR
-#endif
-                                 "/citadel.config", O_WRONLY | O_CREAT | O_APPEND,
+       if ((a = open(citadel_rc_file, O_WRONLY | O_CREAT | O_APPEND,
                      S_IRUSR | S_IWUSR)) == -1) {
                display_error("setup: cannot append citadel.config");
                cleanup(errno);
@@ -1019,13 +1177,7 @@ int main(int argc, char *argv[])
        fclose(fp);
 
        /* now we re-open it, and read the old or blank configuration */
-       fp = fopen(
-#ifndef HAVE_ETC_DIR
-                          "."
-#else
-                          ETC_DIR
-#endif
-                          "/citadel.config", "rb");
+       fp = fopen(citadel_rc_file, "rb");
        if (fp == NULL) {
                display_error("setup: cannot open citadel.config");
                cleanup(errno);
@@ -1118,14 +1270,6 @@ int main(int argc, char *argv[])
                }
        }
 
-       /*
-          if (setuid(config.c_ctdluid) != 0) {
-          important_message("Citadel Setup",
-          "Failed to change the user ID to your Citadel user.");
-          cleanup(errno);
-          }
-        */
-
 /***** begin version update section ***** */
        /* take care of any updating that is necessary */
 
@@ -1154,18 +1298,19 @@ NEW_INST:
 
        write_config_to_disk();
 
-       mkdir("info", 0700);
-       chmod("info", 0700);
-       mkdir("bio", 0700);
-       chmod("bio", 0700);
-       mkdir("userpics", 0700);
-       chmod("userpics", 0700);
-       mkdir("messages", 0700);
-       chmod("messages", 0700);
-       mkdir("help", 0700);
-       chmod("help", 0700);
-       mkdir("images", 0700);
-       chmod("images", 0700);
+       mkdir(ctdl_info_dir, 0700);
+       chmod(ctdl_info_dir, 0700);
+       mkdir(ctdl_bio_dir, 0700);
+       chmod(ctdl_bio_dir, 0700);
+       mkdir(ctdl_usrpic_dir, 0700);
+       chmod(ctdl_usrpic_dir, 0700);
+       mkdir(ctdl_message_dir, 0700);
+       chmod(ctdl_message_dir, 0700);
+       mkdir(ctdl_hlp_dir, 0700);
+       chmod(ctdl_hlp_dir, 0700);
+       mkdir(ctdl_image_dir, 0700);
+       chmod(ctdl_image_dir, 0700);
+       /* TODO: where to put this? */
        mkdir("netconfigs", 0700);
        chmod("netconfigs", 0700);
 
@@ -1180,26 +1325,28 @@ NEW_INST:
        check_xinetd_entry();   /* Check /etc/xinetd.d/telnet */
 
        /* Offer to disable other MTA's on the system. */
-       disable_other_mta("sendmail");
-       disable_other_mta("postfix");
-       disable_other_mta("qmail");
-       disable_other_mta("cyrus");
-       disable_other_mta("cyrmaster");
-       disable_other_mta("saslauthd");
-       disable_other_mta("mta");
+       disable_other_mta("courier-authdaemon");
        disable_other_mta("courier-imap");
        disable_other_mta("courier-imap-ssl");
-       disable_other_mta("courier-authdaemon");
+       disable_other_mta("courier-pop");
        disable_other_mta("courier-pop3");
        disable_other_mta("courier-pop3d");
-       disable_other_mta("courier-pop");
-       disable_other_mta("vmailmgrd");
-       disable_other_mta("imapd");
-       disable_other_mta("popd");
-       disable_other_mta("pop3d");
-       disable_other_mta("exim");
+       disable_other_mta("cyrmaster");
+       disable_other_mta("cyrus");
        disable_other_mta("dovecot");
+       disable_other_mta("exim");
+       disable_other_mta("exim4");
        disable_other_mta("hula");
+       disable_other_mta("imapd");
+       disable_other_mta("mta");
+       disable_other_mta("pop3d");
+       disable_other_mta("popd");
+       disable_other_mta("postfix");
+       disable_other_mta("qmail");
+       disable_other_mta("saslauthd");
+       disable_other_mta("sendmail");
+       disable_other_mta("vmailmgrd");
+       disable_other_mta("zimbra");
 #endif
 
        if ((pw = getpwuid(config.c_ctdluid)) == NULL)
@@ -1211,13 +1358,7 @@ NEW_INST:
        chown(".", config.c_ctdluid, gid);
        sleep(1);
        progress("Setting file permissions", 1, 4);
-       chown(
-#ifndef HAVE_ETC_DIR
-                 "."
-#else
-                 ETC_DIR
-#endif
-                 "/citadel.config", config.c_ctdluid, gid);
+       chown(citadel_rc_file, config.c_ctdluid, gid);
        sleep(1);
        progress("Setting file permissions", 2, 4);
        snprintf(aaa, sizeof aaa,
@@ -1226,13 +1367,7 @@ NEW_INST:
        system(aaa);
        sleep(1);
        progress("Setting file permissions", 3, 4);
-       chmod(
-#ifndef HAVE_ETC_DIR
-                 "."
-#else
-                 ETC_DIR
-#endif
-                 "/citadel.config", S_IRUSR | S_IWUSR);
+       chmod(citadel_rc_file, S_IRUSR | S_IWUSR);
        sleep(1);
        progress("Setting file permissions", 4, 4);