]> code.citadel.org Git - citadel.git/blobdiff - citadel/setup.c
Create some directories to hold the source files for the utility
[citadel.git] / citadel / setup.c
index 0c9a1c1b0e42919bf0e77d162d7f54c191b79839..38c8be06c9ff9a5ead5fa0c04938ca71a727d059 100644 (file)
@@ -137,21 +137,16 @@ char *setup_text[] = {
 
 
 
-"How would you like to authenticate users on your Citadel system?\n"
+"Specify which authentication mode you wish to use.\n"
 "\n"
-" 0. Self contained authentication - Citadel maintains its own user database\n"
-"    (This mode is *strongly* recommended)\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"
 "\n"
-" 1. Authenticate users against the host system (unix or linux accounts)\n"
+"For help: http://www.citadel.org/doku.php/faq:installation:authmodes\n"
 "\n"
-" 2. Authenticate users against an external LDAP directory (RFC 2307 compliant)\n"
-"\n"
-" 3. Authenticate users against nonstandard MS Active Directory LDAP\n"
-"\n"
-"WARNING: do *not* change this setting once your system is installed.\n"
-"\n"
-"(Answer \"0\" unless you completely understand this option)\n"
-"Which authentication mode do you want to use?\n",
+"ANSWER \"0\" UNLESS YOU COMPLETELY UNDERSTAND THIS OPTION.\n",
 
 "Please enter the host name or IP address of your LDAP server.\n",
 
@@ -207,14 +202,16 @@ int yesno(char *question, int default_value)
                                question,
                                ( default_value ? "Yes" : "No" )
                        );
-                       fgets(buf, sizeof buf, stdin);
-                       answer = tolower(buf[0]);
-                       if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
-                               answer = default_value;
-                       else if (answer == 'y')
-                               answer = 1;
-                       else if (answer == 'n')
-                               answer = 0;
+                       if (fgets(buf, sizeof buf, stdin))
+                       {
+                               answer = tolower(buf[0]);
+                               if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
+                                       answer = default_value;
+                               else if (answer == 'y')
+                                       answer = 1;
+                               else if (answer == 'n')
+                                       answer = 0;
+                       }
                } while ((answer < 0) || (answer > 1));
                break;
 
@@ -249,7 +246,7 @@ void important_message(char *title, char *msgtext)
                printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                printf("       %s \n\n%s\n\n", title, msgtext);
                printf("Press return to continue...");
-               fgets(buf, sizeof buf, stdin);
+               if (fgets(buf, sizeof buf, stdin));
                break;
 
        case UI_DIALOG:
@@ -387,7 +384,7 @@ void delete_inittab_entry(void)
                 sizeof looking_for,
                 "%s/citserver", 
                 ctdl_sbin_dir
-                );
+               );
 
        /* Now tweak /etc/inittab */
        infp = fopen("/etc/inittab", "r");
@@ -462,7 +459,7 @@ void install_init_scripts(void)
        fp = fopen(initfile, "r");
        if (fp != NULL) {
                if (yesno("Citadel already appears to be configured to start at boot.\n"
-                  "Would you like to keep your boot configuration as is?\n", 1) == 1) {
+                         "Would you like to keep your boot configuration as is?\n", 1) == 1) {
                        return;
                }
                fclose(fp);
@@ -480,54 +477,57 @@ void install_init_scripts(void)
        }
 
        fprintf(fp,     "#!/bin/sh\n"
-                       "#\n"
-                       "# Init file for Citadel\n"
-                       "#\n"
-                       "# chkconfig: - 79 30\n"
-                       "# description: Citadel service\n"
-                       "# processname: citserver\n"
-                       "# pidfile: %s/citadel.pid\n"
-                       "\n"
-                       "CITADEL_DIR=%s\n"
-                       ,
-                               setup_directory,
-                               setup_directory
-                       );
+               "#\n"
+               "# Init file for Citadel\n"
+               "#\n"
+               "# chkconfig: - 79 30\n"
+               "# description: Citadel service\n"
+               "# processname: citserver\n"
+               "# pidfile: %s/citadel.pid\n\n"
+               "# uncomment this to create coredumps as described in\n"
+               "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
+               "# ulimit -c unlimited\n"
+               "\n"
+               "CITADEL_DIR=%s\n"
+               ,
+               setup_directory,
+               setup_directory
+               );
        fprintf(fp,     "\n"
-                       "test -d /var/run || exit 0\n"
-                       "\n"
-                       "case \"$1\" in\n"
-                       "\n"
-                       "start)         echo -n \"Starting Citadel... \"\n"
-                       "               if $CITADEL_DIR/citserver -lmail -d -h$CITADEL_DIR\n"
-                       "               then\n"
-                       "                       echo \"ok\"\n"
-                       "               else\n"
-                       "                       echo \"failed\"\n"
-                       "               fi\n");
+               "test -d /var/run || exit 0\n"
+               "\n"
+               "case \"$1\" in\n"
+               "\n"
+               "start)         echo -n \"Starting Citadel... \"\n"
+               "               if $CITADEL_DIR/citserver -lmail -d -h$CITADEL_DIR\n"
+               "               then\n"
+               "                       echo \"ok\"\n"
+               "               else\n"
+               "                       echo \"failed\"\n"
+               "               fi\n");
        fprintf(fp,     "               ;;\n"
-                       "stop)          echo -n \"Stopping Citadel... \"\n"
-                       "               if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
-                       "                       echo \"ok\"\n"
-                       "               else\n"
-                       "                       echo \"failed\"\n"
-                       "               fi\n"
-                       "               rm -f %s/citadel.pid 2>/dev/null\n"
-                       ,
-                               setup_directory
-                       );
+               "stop)          echo -n \"Stopping Citadel... \"\n"
+               "               if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then\n"
+               "                       echo \"ok\"\n"
+               "               else\n"
+               "                       echo \"failed\"\n"
+               "               fi\n"
+               "               rm -f %s/citadel.pid 2>/dev/null\n"
+               ,
+               setup_directory
+               );
        fprintf(fp,     "               ;;\n"
-                       "restart)       if $CITADEL_DIR/sendcommand DOWN 1 >/dev/null 2>&1 ; then\n"
-                       "                       echo \"ok\"\n"
-                       "               else\n"
-                       "                       echo \"failed\"\n"
-                       "               fi\n"
-                       "               ;;\n"
-                       "*)             echo \"Usage: $0 {start|stop|restart}\"\n"
-                       "               exit 1\n"
-                       "               ;;\n"
-                       "esac\n"
-       );
+               "restart)       if $CITADEL_DIR/sendcommand DOWN 1 >/dev/null 2>&1 ; then\n"
+               "                       echo \"ok\"\n"
+               "               else\n"
+               "                       echo \"failed\"\n"
+               "               fi\n"
+               "               ;;\n"
+               "*)             echo \"Usage: $0 {start|stop|restart}\"\n"
+               "               exit 1\n"
+               "               ;;\n"
+               "esac\n"
+               );
 
        fclose(fp);
        chmod(initfile, 0755);
@@ -573,10 +573,10 @@ void check_xinetd_entry(void) {
        }
        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"
-               );
+                        "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, 1) == 0) {
                        return;
                }
@@ -683,7 +683,7 @@ int test_server(char *setup_directory, char *relhomestr, int relhome) {
 
        while (fgets(buf, sizeof buf, fp) != NULL) {
                if ( (buf[0]=='2')
-                  && (strstr(buf, cookie) != NULL) ) {
+                    && (strstr(buf, cookie) != NULL) ) {
                        ++found_it;
                }
        }
@@ -697,7 +697,7 @@ int test_server(char *setup_directory, char *relhomestr, int relhome) {
 
 void strprompt(char *prompt_title, char *prompt_text, char *str)
 {
-       char buf[SIZ];
+       char buf[SIZ] = "";
        char setupmsg[SIZ];
        char dialog_result[PATH_MAX];
        FILE *fp = NULL;
@@ -710,8 +710,9 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
                printf("\n%s\n", prompt_text);
                printf("This is currently set to:\n%s\n", str);
                printf("Enter new value or press return to leave unchanged:\n");
-               fgets(buf, sizeof buf, stdin);
-               buf[strlen(buf) - 1] = 0;
+               if (fgets(buf, sizeof buf, stdin)){
+                       buf[strlen(buf) - 1] = 0;
+               }
                if (!IsEmptyStr(buf))
                        strcpy(str, buf);
                break;
@@ -726,9 +727,10 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
                system(buf);
                fp = fopen(dialog_result, "r");
                if (fp != NULL) {
-                       fgets(str, sizeof buf, fp);
-                       if (str[strlen(str)-1] == 10) {
-                               str[strlen(str)-1] = 0;
+                       if (fgets(str, sizeof buf, fp)) {
+                               if (str[strlen(str)-1] == 10) {
+                                       str[strlen(str)-1] = 0;
+                               }
                        }
                        fclose(fp);
                        unlink(dialog_result);
@@ -868,12 +870,22 @@ void edit_value(int curr)
        case 6:
                if (setup_type == UI_SILENT)
                {
-                       if (getenv("ENABLE_UNIX_AUTH")) {
-                               if (!strcasecmp(getenv("ENABLE_UNIX_AUTH"), "yes")) {
+                       const char *auth;
+                       config.c_auth_mode = AUTHMODE_NATIVE;
+                       auth = getenv("ENABLE_UNIX_AUTH");
+                       if (auth != NULL)
+                       {
+                               if ((strcasecmp(auth, "yes") == 0) ||
+                                   (strcasecmp(auth, "host") == 0))
+                               {
                                        config.c_auth_mode = AUTHMODE_HOST;
                                }
-                               else {
-                                       config.c_auth_mode = AUTHMODE_NATIVE;
+                               else if (strcasecmp(auth, "ldap") == 0){
+                                       config.c_auth_mode = AUTHMODE_LDAP;
+                               }
+                               else if ((strcasecmp(auth, "ldap_ad") == 0) ||
+                                        (strcasecmp(auth, "active directory") == 0)){
+                                       config.c_auth_mode = AUTHMODE_LDAP_AD;
                                }
                        }
                }
@@ -1100,6 +1112,7 @@ int main(int argc, char *argv[])
        int home=0;
        char relhome[PATH_MAX]="";
        char ctdldir[PATH_MAX]=CTDLDIR;
+       int rv;
        
        /* set an invalid setup type */
        setup_type = (-1);
@@ -1124,11 +1137,11 @@ int main(int argc, char *argv[])
                }
                else if (!strncmp(argv[a], "-h", 2)) {
                        relh=argv[a][2]!='/';
-                       if (!relh) safestrncpy(ctdl_home_directory, &argv[a][2],
-                                                                  sizeof ctdl_home_directory);
-                       else
-                               safestrncpy(relhome, &argv[a][2],
-                                                       sizeof relhome);
+                       if (!relh) {
+                               safestrncpy(ctdl_home_directory, &argv[a][2], sizeof ctdl_home_directory);
+                       } else {
+                               safestrncpy(relhome, &argv[a][2], sizeof relhome);
+                       }
                        home = 1;
                }
 
@@ -1171,7 +1184,7 @@ int main(int argc, char *argv[])
 
        /* Try to stop Citadel if we can */
        if (!access("/etc/init.d/citadel", X_OK)) {
-               system("/etc/init.d/citadel stop");
+               rv = system("/etc/init.d/citadel stop");
        }
 
        /* Make sure Citadel is not running. */
@@ -1213,8 +1226,9 @@ int main(int argc, char *argv[])
                display_error("setup: cannot append citadel.config");
                cleanup(errno);
        }
-       for (a = 0; a < sizeof(struct config); ++a)
+       for (a = 0; a < sizeof(struct config); ++a) {
                putc(0, fp);
+       }
        fclose(fp);
 
        /* now we re-open it, and read the old or blank configuration */
@@ -1223,7 +1237,7 @@ int main(int argc, char *argv[])
                display_error("setup: cannot open citadel.config");
                cleanup(errno);
        }
-       fread((char *) &config, sizeof(struct config), 1, fp);
+       rv = fread((char *) &config, sizeof(struct config), 1, fp);
        fclose(fp);
 
        /* set some sample/default values in place of blanks... */
@@ -1232,28 +1246,25 @@ int main(int argc, char *argv[])
                            sizeof config.c_nodename);
        strtok(config.c_nodename, ".");
        if (IsEmptyStr(config.c_fqdn) ) {
-               if ((he = gethostbyname(my_utsname.nodename)) != NULL)
-                       safestrncpy(config.c_fqdn, he->h_name,
-                                   sizeof config.c_fqdn);
-               else
-                       safestrncpy(config.c_fqdn, my_utsname.nodename,
-                                   sizeof config.c_fqdn);
+               if ((he = gethostbyname(my_utsname.nodename)) != NULL) {
+                       safestrncpy(config.c_fqdn, he->h_name, sizeof config.c_fqdn);
+               } else {
+                       safestrncpy(config.c_fqdn, my_utsname.nodename, sizeof config.c_fqdn);
+               }
        }
-       if (IsEmptyStr(config.c_humannode))
+       if (IsEmptyStr(config.c_humannode)) {
                strcpy(config.c_humannode, "My System");
-       if (IsEmptyStr(config.c_phonenum))
+       }
+       if (IsEmptyStr(config.c_phonenum)) {
                strcpy(config.c_phonenum, "US 800 555 1212");
+       }
        if (config.c_initax == 0) {
                config.c_initax = 4;
        }
-       if (IsEmptyStr(config.c_moreprompt))
-               strcpy(config.c_moreprompt, "<more>");
-       if (IsEmptyStr(config.c_twitroom))
-               strcpy(config.c_twitroom, "Trashcan");
-       if (IsEmptyStr(config.c_baseroom))
-               strcpy(config.c_baseroom, BASEROOM);
-       if (IsEmptyStr(config.c_aideroom))
-               strcpy(config.c_aideroom, "Aide");
+       if (IsEmptyStr(config.c_moreprompt)) strcpy(config.c_moreprompt, "<more>");
+       if (IsEmptyStr(config.c_twitroom)) strcpy(config.c_twitroom, "Trashcan");
+       if (IsEmptyStr(config.c_baseroom)) strcpy(config.c_baseroom, BASEROOM);
+       if (IsEmptyStr(config.c_aideroom)) strcpy(config.c_aideroom, "Aide");
        if (config.c_port_number == 0) {
                config.c_port_number = 504;
        }
@@ -1262,18 +1273,21 @@ int main(int argc, char *argv[])
        }
        if (config.c_ctdluid == 0) {
                pw = getpwnam("citadel");
-               if (pw != NULL)
+               if (pw != NULL) {
                        config.c_ctdluid = pw->pw_uid;
+               }
        }
        if (config.c_ctdluid == 0) {
                pw = getpwnam("bbs");
-               if (pw != NULL)
+               if (pw != NULL) {
                        config.c_ctdluid = pw->pw_uid;
+               }
        }
        if (config.c_ctdluid == 0) {
                pw = getpwnam("guest");
-               if (pw != NULL)
+               if (pw != NULL) {
                        config.c_ctdluid = pw->pw_uid;
+               }
        }
        if (config.c_createax == 0) {
                config.c_createax = 3;
@@ -1344,44 +1358,44 @@ NEW_INST:
 
        write_config_to_disk();
 
-       mkdir(ctdl_info_dir, 0700);
-       chmod(ctdl_info_dir, 0700);
-       chown(ctdl_info_dir, config.c_ctdluid, -1);
+       rv = mkdir(ctdl_info_dir, 0700);
+       rv = chmod(ctdl_info_dir, 0700);
+       rv = 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);
+       rv = mkdir(ctdl_bio_dir, 0700);
+       rv = chmod(ctdl_bio_dir, 0700);
+       rv = 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);
+       rv = mkdir(ctdl_usrpic_dir, 0700);
+       rv = chmod(ctdl_usrpic_dir, 0700);
+       rv = 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);
+       rv = mkdir(ctdl_message_dir, 0700);
+       rv = chmod(ctdl_message_dir, 0700);
+       rv = 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);
+       rv = mkdir(ctdl_hlp_dir, 0700);
+       rv = chmod(ctdl_hlp_dir, 0700);
+       rv = 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);
+       rv = mkdir(ctdl_image_dir, 0700);
+       rv = chmod(ctdl_image_dir, 0700);
+       rv = 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);
+       rv = mkdir(ctdl_bb_dir, 0700);
+       rv = chmod(ctdl_bb_dir, 0700);
+       rv = 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);
+       rv = mkdir(ctdl_file_dir, 0700);
+       rv = chmod(ctdl_file_dir, 0700);
+       rv = 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);
+       rv = mkdir(ctdl_netcfg_dir, 0700);
+       rv = chmod(ctdl_netcfg_dir, 0700);
+       rv = chown(ctdl_netcfg_dir, 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");
+       rv = system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
        unlink("citadel.log");
        unlink("weekly");
 
@@ -1422,17 +1436,18 @@ NEW_INST:
        /* Check for the 'db' nss and offer to disable it */
        fixnss();
 
-       if ((pw = getpwuid(config.c_ctdluid)) == NULL)
+       if ((pw = getpwuid(config.c_ctdluid)) == NULL) {
                gid = getgid();
-       else
+       } else {
                gid = pw->pw_gid;
+       }
 
        progress("Setting file permissions", 0, 3);
-       chown(ctdl_run_dir, config.c_ctdluid, gid);
+       rv = chown(ctdl_run_dir, config.c_ctdluid, gid);
        progress("Setting file permissions", 1, 3);
-       chown(file_citadel_config, config.c_ctdluid, gid);
+       rv = chown(file_citadel_config, config.c_ctdluid, gid);
        progress("Setting file permissions", 2, 3);
-       chmod(file_citadel_config, S_IRUSR | S_IWUSR);
+       rv = chmod(file_citadel_config, S_IRUSR | S_IWUSR);
        progress("Setting file permissions", 3, 3);
 
        /* 
@@ -1445,7 +1460,7 @@ NEW_INST:
                }
 
                if (!access("/etc/init.d/citadel", X_OK)) {
-                       system("/etc/init.d/citadel start");
+                       rv = system("/etc/init.d/citadel start");
                        sleep(3);
                }
 
@@ -1453,20 +1468,23 @@ NEW_INST:
                        char buf[SIZ];
                        int found_it = 0;
 
-                       snprintf (admin_cmd, sizeof(admin_cmd), "%s/sendcommand \"CREU %s|%s\" 2>&1", 
-                                 ctdl_sbin_dir, config.c_sysadm, admin_pass);
-                       fp = popen(admin_cmd, "r");
-                       if (fp != NULL) {
-                               while (fgets(buf, sizeof buf, fp) != NULL) 
-                               {
-                                       if ((atol(buf) == 574) || (atol(buf) == 200))
-                                               ++found_it;
+                       if (config.c_auth_mode == AUTHMODE_NATIVE) {
+                               snprintf (admin_cmd, sizeof(admin_cmd), "%s/sendcommand \"CREU %s|%s\" 2>&1", 
+                                       ctdl_sbin_dir, config.c_sysadm, admin_pass);
+                               fp = popen(admin_cmd, "r");
+                               if (fp != NULL) {
+                                       while (fgets(buf, sizeof buf, fp) != NULL) 
+                                       {
+                                               if ((atol(buf) == 574) || (atol(buf) == 200))
+                                                       ++found_it;
+                                       }
+                                       pclose(fp);
+                               }
+                       
+                               if (found_it == 0) {
+                                       important_message("Error","Setup failed to create your admin user");
                                }
-                               pclose(fp);
                        }
-               
-                       if (found_it == 0)
-                               important_message("Error","Setup failed to create your admin user");
 
                        if (setup_type != UI_SILENT)
                                important_message("Setup finished",