]> code.citadel.org Git - citadel.git/blobdiff - citadel/utils/setup.c
* switch to enum for better readability
[citadel.git] / citadel / utils / setup.c
index 38c8be06c9ff9a5ead5fa0c04938ca71a727d059..e83dd2aa3a0c0d40aa990cf94d0c2c83c7ab212f 100644 (file)
@@ -5,6 +5,9 @@
  *
  */
 
+#include "ctdl_module.h"
+
+
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <execinfo.h>
 #endif
 
+#ifdef ENABLE_NLS
+#ifdef HAVE_XLOCALE_H
+#include <xlocale.h>
+#endif
+#include <libintl.h>
+#include <locale.h>
+#define _(string)      gettext(string)
+#else
+#define _(string)      (string)
+#endif
+
 
 #define MAXSETUP 11    /* How many setup questions to ask */
 
 #define PROTO_NAME     "tcp"
 #define NSSCONF                "/etc/nsswitch.conf"
 
+
+typedef enum _SetupStep {
+       eSysAdminName = 1,
+       eSysAdminPW = 2,
+       eUID = 3,
+       eIP_ADDR = 4,
+       eCTDL_Port = 5,
+       eAuthType = 6,
+       eLDAP_Host = 7,
+       eLDAP_Port = 8,
+       eLDAP_Base_DN = 9,
+       eLDAP_Bind_DN =10,
+       eLDAP_Bind_PW =11
+} eSteupStep;
+
+
 int setup_type;
 char setup_directory[PATH_MAX];
 int using_web_installer = 0;
@@ -239,6 +269,7 @@ int yesno(char *question, int default_value)
 void important_message(char *title, char *msgtext)
 {
        char buf[SIZ];
+       int rv;
 
        switch (setup_type) {
 
@@ -253,7 +284,7 @@ void important_message(char *title, char *msgtext)
                sprintf(buf, "exec %s --msgbox '%s' 19 72",
                        getenv("CTDL_DIALOG"),
                        msgtext);
-               system(buf);
+               rv = system(buf);
                break;
        case UI_SILENT:
                fprintf(stderr, "%s\n", msgtext);
@@ -378,6 +409,7 @@ void delete_inittab_entry(void)
        char buf[1024];
        char outfilename[32];
        int changes_made = 0;
+       int rv;
 
        /* Determine the fully qualified path name of citserver */
        snprintf(looking_for, 
@@ -415,10 +447,10 @@ void delete_inittab_entry(void)
 
        while (fgets(buf, sizeof buf, infp) != NULL) {
                if (strstr(buf, looking_for) != NULL) {
-                       fwrite("#", 1, 1, outfp);
+                       rv = fwrite("#", 1, 1, outfp);
                        ++changes_made;
                }
-               fwrite(buf, strlen(buf), 1, outfp);
+               rv = fwrite(buf, strlen(buf), 1, outfp);
        }
 
        fclose(infp);
@@ -426,8 +458,8 @@ void delete_inittab_entry(void)
 
        if (changes_made) {
                sprintf(buf, "/bin/mv -f %s /etc/inittab 2>/dev/null", outfilename);
-               system(buf);
-               system("/sbin/init q 2>/dev/null");
+               rv = system(buf);
+               rv = system("/sbin/init q 2>/dev/null");
        }
        else {
                unlink(outfilename);
@@ -445,6 +477,7 @@ void install_init_scripts(void)
        FILE *fp;
        char *initfile = "/etc/init.d/citadel";
        char command[SIZ];
+       int rv;
 
        if ((stat("/etc/init.d/", &etcinitd) == -1) && 
            (errno == ENOENT))
@@ -533,11 +566,11 @@ void install_init_scripts(void)
        chmod(initfile, 0755);
 
        /* Set up the run levels. */
-       system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
+       rv = system("/bin/rm -f /etc/rc?.d/[SK]??citadel 2>/dev/null");
        snprintf(command, sizeof(command), "for x in 2 3 4 5 ; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/S79citadel ; done 2>/dev/null", initfile);
-       system(command);
+       rv = system(command);
        snprintf(command, sizeof(command),"for x in 0 6 S; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/K30citadel ; done 2>/dev/null", initfile);
-       system(command);
+       rv = system(command);
 
 }
 
@@ -555,6 +588,7 @@ void check_xinetd_entry(void) {
        FILE *fp;
        char buf[SIZ];
        int already_citadel = 0;
+       int rv;
 
        fp = fopen(filename, "r+");
        if (fp == NULL) return;         /* Not there.  Oh well... */
@@ -600,7 +634,7 @@ void check_xinetd_entry(void) {
        fclose(fp);
 
        /* Now try to restart the service */
-       system("/etc/init.d/xinetd restart >/dev/null 2>&1");
+       rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
 }
 
 
@@ -612,6 +646,7 @@ void disable_other_mta(char *mta) {
        char buf[SIZ];
        FILE *fp;
        int lines = 0;
+       int rv;
 
        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",
@@ -644,9 +679,9 @@ void disable_other_mta(char *mta) {
        
 
        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);
+       rv = system(buf);
        sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
-       system(buf);
+       rv = system(buf);
 }
 
 
@@ -701,6 +736,7 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
        char setupmsg[SIZ];
        char dialog_result[PATH_MAX];
        FILE *fp = NULL;
+       int rv;
 
        strcpy(setupmsg, "");
 
@@ -724,7 +760,7 @@ void strprompt(char *prompt_title, char *prompt_text, char *str)
                        prompt_text,
                        str,
                        dialog_result);
-               system(buf);
+               rv = system(buf);
                fp = fopen(dialog_result, "r");
                if (fp != NULL) {
                        if (fgets(str, sizeof buf, fp)) {
@@ -785,7 +821,7 @@ void edit_value(int curr)
 
        switch (curr) {
 
-       case 1:
+       case eSysAdminName:
                if (setup_type == UI_SILENT)
                {
                        if (getenv("SYSADMIN_NAME")) {
@@ -797,7 +833,7 @@ void edit_value(int curr)
                }
                break;
 
-       case 2:
+       case eSysAdminPW:
                if (setup_type == UI_SILENT)
                {
                        if (getenv("SYSADMIN_PW")) {
@@ -809,7 +845,7 @@ void edit_value(int curr)
                }
                break;
        
-       case 3:
+       case eUID:
                if (setup_type == UI_SILENT)
                {               
                        if (getenv("CITADEL_UID")) {
@@ -842,7 +878,7 @@ void edit_value(int curr)
                }
                break;
 
-       case 4:
+       case eIP_ADDR:
                if (setup_type == UI_SILENT)
                {
                        if (getenv("IP_ADDR")) {
@@ -854,7 +890,7 @@ void edit_value(int curr)
                }
                break;
 
-       case 5:
+       case eCTDL_Port:
                if (setup_type == UI_SILENT)
                {
                        if (getenv("CITADEL_PORT")) {
@@ -867,7 +903,7 @@ void edit_value(int curr)
                }
                break;
 
-       case 6:
+       case eAuthType:
                if (setup_type == UI_SILENT)
                {
                        const char *auth;
@@ -894,7 +930,7 @@ void edit_value(int curr)
                }
                break;
 
-       case 7:
+       case eLDAP_Host:
                if (setup_type == UI_SILENT)
                {
                        if (getenv("LDAP_HOST")) {
@@ -907,7 +943,7 @@ void edit_value(int curr)
                }
                break;
 
-       case 8:
+       case eLDAP_Port:
                if (setup_type == UI_SILENT)
                {
                        if (getenv("LDAP_PORT")) {
@@ -916,11 +952,14 @@ void edit_value(int curr)
                }
                else
                {
+                       if (config.c_ldap_port == 0) {
+                               config.c_ldap_port = 389;
+                       }
                        set_int_val(curr, &config.c_ldap_port);
                }
                break;
 
-       case 9:
+       case eLDAP_Base_DN:
                if (setup_type == UI_SILENT)
                {
                        if (getenv("LDAP_BASE_DN")) {
@@ -933,7 +972,7 @@ void edit_value(int curr)
                }
                break;
 
-       case 10:
+       case eLDAP_Bind_DN:
                if (setup_type == UI_SILENT)
                {
                        if (getenv("LDAP_BIND_DN")) {
@@ -946,7 +985,7 @@ void edit_value(int curr)
                }
                break;
 
-       case 11:
+       case eLDAP_Bind_PW:
                if (setup_type == UI_SILENT)
                {
                        if (getenv("LDAP_BIND_PW")) {
@@ -970,6 +1009,7 @@ void write_config_to_disk(void)
 {
        FILE *fp;
        int fd;
+       int rv;
 
        if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) {
                display_error("setup: cannot open citadel.config");
@@ -980,7 +1020,7 @@ void write_config_to_disk(void)
                display_error("setup: cannot open citadel.config");
                cleanup(1);
        }
-       fwrite((char *) &config, sizeof(struct config), 1, fp);
+       rv = fwrite((char *) &config, sizeof(struct config), 1, fp);
        fclose(fp);
 }
 
@@ -1018,6 +1058,7 @@ void fixnss(void) {
        int changed = 0;
        int file_changed = 0;
        char new_filename[64];
+       int rv;
 
        fp_read = fopen(NSSCONF, "r");
        if (fp_read == NULL) {
@@ -1083,7 +1124,7 @@ void fixnss(void) {
 
        if (yesno(question, 1)) {
                sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
-               system(buf);
+               rv = system(buf);
                chmod(NSSCONF, 0644);
        }
        unlink(new_filename);