]> code.citadel.org Git - citadel.git/blobdiff - citadel/setup.c
* added message subject to all those tiny messages
[citadel.git] / citadel / setup.c
index 274601a3f3445878b89219526b02a0ac3d4c00c3..8a178efeec6b81abc32e807b96efecf3b4ccd090 100644 (file)
@@ -43,6 +43,7 @@
 
 #define SERVICE_NAME   "citadel"
 #define PROTO_NAME     "tcp"
+#define NSSCONF                "/etc/nsswitch.conf"
 
 int setup_type;
 char setup_directory[SIZ];
@@ -50,6 +51,13 @@ char citserver_init_entry[SIZ];
 int using_web_installer = 0;
 int enable_home = 1;
 
+/**
+ *     We will set have_sysv_init to nonzero if the host operating system
+ *     has a System V style init driven by /etc/inittab.  This will cause
+ *     setup to offer to automatically start and stop the Citadel service.
+ */
+int have_sysv_init = 0;
+
 #ifdef HAVE_LDAP
 void contemplate_ldap(void);
 #endif
@@ -77,7 +85,7 @@ char *setup_text[] = {
 "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 "
+"Enter the subdirectory name for an alternate 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"
@@ -580,7 +588,7 @@ void check_inittab_entry(void)
                display_error(strerror(errno));
        } else {
                fprintf(infp, "# Start the Citadel server...\n");
-               fprintf(infp, "%s:2345:respawn:%s %s%s -x3 -llocal4\n",
+               fprintf(infp, "%s:2345:respawn:%s %s%s -llocal4\n",
                                entryname, 
                                looking_for, 
                                (enable_home)?"-h":"", 
@@ -921,13 +929,7 @@ void write_config_to_disk(void)
        FILE *fp;
        int fd;
 
-       if ((fd = creat(
-#ifndef HAVE_ETC_DIR
-                                       "."
-#else
-                                       ETC_DIR
-#endif
-                                       "/citadel.config", S_IRUSR | S_IWUSR)) == -1) {
+       if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
                display_error("setup: cannot open citadel.config");
                cleanup(1);
        }
@@ -968,6 +970,96 @@ int discover_ui(void)
 
 
 
+/*
+ * Strip "db" entries out of /etc/nsswitch.conf
+ */
+void fixnss(void) {
+       FILE *fp_read;
+       int fd_write;
+       char buf[256];
+       char buf_nc[256];
+       char question[512];
+       int i;
+       int changed = 0;
+       int file_changed = 0;
+       char new_filename[64];
+
+       fp_read = fopen(NSSCONF, "r");
+       if (fp_read == NULL) {
+               return;
+       }
+
+       strcpy(new_filename, "/tmp/ctdl_fixnss_XXXXXX");
+       fd_write = mkstemp(new_filename);
+       if (fd_write < 0) {
+               fclose(fp_read);
+               return;
+       }
+
+       while (fgets(buf, sizeof buf, fp_read) != NULL) {
+               changed = 0;
+               strcpy(buf_nc, buf);
+               for (i=0; i<strlen(buf_nc); ++i) {
+                       if (buf_nc[i] == '#') {
+                               buf_nc[i] = 0;
+                       }
+               }
+               for (i=0; i<strlen(buf_nc); ++i) {
+                       if (!strncasecmp(&buf_nc[i], "db", 2)) {
+                               if (i > 0) {
+                                       if ((isspace(buf_nc[i+2])) || (buf_nc[i+2]==0)) {
+                                               changed = 1;
+                                               file_changed = 1;
+                                               strcpy(&buf_nc[i], &buf_nc[i+2]);
+                                               strcpy(&buf[i], &buf[i+2]);
+                                               if (buf[i]==32) {
+                                                       strcpy(&buf_nc[i], &buf_nc[i+1]);
+                                                       strcpy(&buf[i], &buf[i+1]);
+                                               }
+                                       }
+                               }
+                       }
+               }
+               if (write(fd_write, buf, strlen(buf)) != strlen(buf)) {
+                       fclose(fp_read);
+                       close(fd_write);
+                       unlink(new_filename);
+                       return;
+               }
+       }
+
+       fclose(fp_read);
+       
+       if (!file_changed) {
+               unlink(new_filename);
+               return;
+       }
+
+       snprintf(question, sizeof question,
+               "\n"
+               "/etc/nsswitch.conf is configured to use the 'db' module for\n"
+               "one or more services.  This is not necessary on most systems,\n"
+               "and it is known to crash the Citadel server when delivering\n"
+               "mail to the Internet.\n"
+               "\n"
+               "Do you want this module to be automatically disabled?\n"
+               "\n"
+       );
+
+       if (yesno(question)) {
+               sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
+               system(buf);
+       }
+       unlink(new_filename);
+}
+
+
+
+
+
+
+
+
 int main(int argc, char *argv[])
 {
        int a;
@@ -988,7 +1080,14 @@ int main(int argc, char *argv[])
        /* set an invalid setup type */
        setup_type = (-1);
 
-        /* Check to see if we're running the web installer */
+       /* Learn whether to skip the auto-service-start questions */
+       fp = fopen("/etc/inittab", "r");
+       if (fp != NULL) {
+               have_sysv_init = 1;
+               fclose(fp);
+       }
+
+       /* Check to see if we're running the web installer */
        if (getenv("CITADEL_INSTALLER") != NULL) {
                using_web_installer = 1;
        }
@@ -1037,39 +1136,47 @@ int main(int argc, char *argv[])
 
        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);
+       if (!relh) {
+               safestrncpy(ctdl_home_directory, setup_directory, sizeof ctdl_home_directory);
+       }
+       else {
+               safestrncpy(relhome, ctdl_home_directory, sizeof relhome);
+       }
 
        calc_dirs_n_files(relh, home, relhome, ctdldir);
        
        enable_home=(relh|home);
 
-       if ((home) && (chdir(setup_directory) != 0)) {
-               important_message("Citadel Setup",
-                         "The directory you specified does not exist.");
-               cleanup(errno);
+       if (home) {
+               if (chdir(setup_directory) == 0) {
+                       strcpy(file_citadel_config, "./citadel.config");
+               }
+               else {
+                       important_message("Citadel Setup",
+                               "The directory you specified does not exist.");
+                       cleanup(errno);
+               }
        }
 
        /* Determine our host name, in case we need to use it as a default */
        uname(&my_utsname);
 
-       /* See if we need to shut down the Citadel service. */
-       for (a=0; a<=3; ++a) {
-               progress("Shutting down the Citadel service...", a, 3);
-               if (a == 0) shutdown_citserver();
-               sleep(1);
-       }
+       if (have_sysv_init) {
+               /* See if we need to shut down the Citadel service. */
+               for (a=0; a<=3; ++a) {
+                       progress("Shutting down the Citadel service...", a, 3);
+                       if (a == 0) shutdown_citserver();
+                       sleep(1);
+               }
 
-       /* Make sure it's stopped. */
-       if (test_server() == 0) {
-               important_message("Citadel Setup",
-                       "The Citadel service is still running.\n"
-                       "Please stop the service manually and run "
-                       "setup again.");
-               cleanup(1);
+               /* Make sure it's stopped. */
+               if (test_server() == 0) {
+                       important_message("Citadel Setup",
+                               "The Citadel service is still running.\n"
+                               "Please stop the service manually and run "
+                               "setup again.");
+                       cleanup(1);
+               }
        }
 
        /* Now begin. */
@@ -1077,7 +1184,7 @@ int main(int argc, char *argv[])
 
        case UI_TEXT:
                printf("\n\n\n"
-                       "               *** Citadel setup program ***\n\n");
+                       "              *** Citadel setup program ***\n\n");
                break;
 
        }
@@ -1192,6 +1299,8 @@ int main(int argc, char *argv[])
        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;
+       if (config.c_pftcpdict_port == 0) config.c_pftcpdict_port = -1;
+       if (config.c_managesieve_port == 0) config.c_managesieve_port = 2020;
 
        /* Go through a series of dialogs prompting for config info */
        if (setup_type != UI_SILENT) {
@@ -1230,19 +1339,44 @@ NEW_INST:
 
        mkdir(ctdl_info_dir, 0700);
        chmod(ctdl_info_dir, 0700);
+       chown(ctdl_info_dir, config.c_ctdluid, -1);
+
        mkdir(ctdl_bio_dir, 0700);
        chmod(ctdl_bio_dir, 0700);
+       chown(ctdl_bio_dir, config.c_ctdluid, -1);
+
        mkdir(ctdl_usrpic_dir, 0700);
        chmod(ctdl_usrpic_dir, 0700);
+       chown(ctdl_usrpic_dir, config.c_ctdluid, -1);
+
        mkdir(ctdl_message_dir, 0700);
        chmod(ctdl_message_dir, 0700);
+       chown(ctdl_message_dir, config.c_ctdluid, -1);
+
        mkdir(ctdl_hlp_dir, 0700);
        chmod(ctdl_hlp_dir, 0700);
+       chown(ctdl_hlp_dir, config.c_ctdluid, -1);
+
        mkdir(ctdl_image_dir, 0700);
        chmod(ctdl_image_dir, 0700);
+       chown(ctdl_image_dir, config.c_ctdluid, -1);
+
+       mkdir(ctdl_bb_dir, 0700);
+       chmod(ctdl_bb_dir, 0700);
+       chown(ctdl_bb_dir, config.c_ctdluid, -1);
+
+       mkdir(ctdl_file_dir, 0700);
+       chmod(ctdl_file_dir, 0700);
+       chown(ctdl_file_dir, config.c_ctdluid, -1);
+
+       mkdir(ctdl_netcfg_dir, 0700);
+       chmod(ctdl_netcfg_dir, 0700);
+       chown(ctdl_netcfg_dir, config.c_ctdluid, -1);
+
        /* TODO: where to put this? */
        mkdir("netconfigs", 0700);
        chmod("netconfigs", 0700);
+       chown("netconfigs", config.c_ctdluid, -1);
 
        /* Delete files and directories used by older Citadel versions */
        system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
@@ -1251,7 +1385,9 @@ NEW_INST:
 
        check_services_entry(); /* Check /etc/services */
 #ifndef __CYGWIN__
-       check_inittab_entry();  /* Check /etc/inittab */
+       if (have_sysv_init) {
+               check_inittab_entry();  /* Check /etc/inittab */
+       }
        check_xinetd_entry();   /* Check /etc/xinetd.d/telnet */
 
        /* Offer to disable other MTA's on the system. */
@@ -1279,6 +1415,9 @@ NEW_INST:
        disable_other_mta("zimbra");
 #endif
 
+       /* Check for the 'db' nss and offer to disable it */
+       fixnss();
+
        if ((pw = getpwuid(config.c_ctdluid)) == NULL)
                gid = getgid();
        else
@@ -1291,10 +1430,15 @@ NEW_INST:
        chown(file_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_ctdluid, (long)gid);
-       system(aaa);
+                        "%schkpwd",
+                        ctdl_sbin_dir);
+       chown(aaa,0,0); /*  config.c_ctdluid, gid); chkpwd needs to be root owned*/
+       sleep(1);
+       progress("Setting file permissions", 3, 4);
+       chmod(aaa, 04755); 
+
        sleep(1);
        progress("Setting file permissions", 3, 4);
        chmod(file_citadel_config, S_IRUSR | S_IWUSR);
@@ -1307,7 +1451,7 @@ NEW_INST:
 #endif
 
        /* See if we can start the Citadel service. */
-       if (strlen(citserver_init_entry) > 0) {
+       if ( (have_sysv_init) && (strlen(citserver_init_entry) > 0) ) {
                for (a=0; a<=3; ++a) {
                        progress("Starting the Citadel service...", a, 3);
                        if (a == 0) start_citserver();
@@ -1348,6 +1492,7 @@ void contemplate_ldap(void) {
        FILE *fp;
 
        /* If conditions are not ideal, give up on this idea... */
+       if (!have_sysv_init) return;
        if (using_web_installer == 0) return;
        if (getenv("LDAP_CONFIG") == NULL) return;
        if (getenv("SUPPORT") == NULL) return;