]> code.citadel.org Git - citadel.git/blobdiff - citadel/setup.c
* compatibility with Berkeley DB < 3.3
[citadel.git] / citadel / setup.c
index fb6cb0333d57fd57432e8f0b51e5f7247939086c..a83f7e1b2506edf9d2a023e2f62499efe40ee5a2 100644 (file)
 #include "config.h"
 #include "tools.h"
 
-#ifdef HAVE_CURSES_H
-#ifdef OK
-#undef OK
-#endif
+#if defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H)
+
+#ifdef HAVE_NCURSES_H
+#include <ncurses.h>
+#else
 #include <curses.h>
 #endif
 
+#endif
+
 #define MAXSETUP 5
 
 #define UI_TEXT                0       /* Default setup type -- text only */
 #define UI_DIALOG      1       /* Use the 'dialog' program (REMOVED) */
 #define UI_CURSES      2       /* Use curses */
+#define UI_SILENT      3       /* Silent running, for use in scripts */
 
 #define SERVICE_NAME   "citadel"
 #define PROTO_NAME     "tcp"
@@ -238,8 +242,10 @@ void hit_any_key(void)
                return;
        }
 #endif
-       printf("Press return to continue...");
-       fgets(junk, 5, stdin);
+       if (setup_type == UI_TEXT) {
+               printf("Press return to continue...");
+               fgets(junk, 5, stdin);
+       }
 }
 
 int yesno(char *question)
@@ -288,13 +294,6 @@ int yesno(char *question)
 
 
 
-void dump_access_levels(void)
-{
-       int a;
-       for (a = 0; a <= 6; ++a)
-               printf("%d %s\n", a, axdefs[a]);
-}
-
 void get_setup_msg(char *dispbuf, int msgnum)
 {
        int a, b;
@@ -434,7 +433,7 @@ void check_services_entry(void)
        char question[128];
        FILE *sfp;
 
-       sprintf(question,
+       snprintf(question, sizeof question,
                "There is no '%s' entry in /etc/services.  Would you like to add one?",
                SERVICE_NAME);
 
@@ -465,10 +464,10 @@ void check_inittab_entry(void)
        char question[128];
        char *ptr;
        int have_entry = 0;
-       char entryname[3];
+       char entryname[5];
 
        /* Determine the fully qualified path name of citserver */
-       sprintf(looking_for, "%s/citserver ", BBSDIR);
+       snprintf(looking_for, sizeof looking_for, "%s/citserver ", BBSDIR);
 
        /* Pound through /etc/inittab line by line.  Set have_entry to 1 if
         * an entry is found which we believe starts citserver.
@@ -484,7 +483,8 @@ void check_inittab_entry(void)
                        ptr = strtok(NULL, ":");
                        ptr = strtok(NULL, ":");
                        if (ptr != NULL) {
-                               if (!strncmp(ptr, looking_for, strlen(looking_for))) {
+                               if (!strncmp(ptr, looking_for,
+                                  strlen(looking_for))) {
                                        ++have_entry;
                                }
                        }
@@ -497,14 +497,15 @@ void check_inittab_entry(void)
                return;
 
        /* Otherwise, prompt the user to create an entry. */
-       sprintf(question,
-               "There is no '%s' entry in /etc/inittab.\nWould you like to add one?",
+       snprintf(question, sizeof question,
+               "There is no '%s' entry in /etc/inittab.\n"
+               "Would you like to add one?",
                looking_for);
        if (yesno(question) == 0)
                return;
 
        /* Generate a unique entry name for /etc/inittab */
-       sprintf(entryname, "c0");
+       snprintf(entryname, sizeof entryname, "c0");
        do {
                ++entryname[1];
                if (entryname[1] > '9') {
@@ -516,7 +517,7 @@ void check_inittab_entry(void)
                                return;
                        }
                }
-               sprintf(buf,
+               snprintf(buf, sizeof buf,
                     "grep %s: /etc/inittab >/dev/null 2>&1", entryname);
        } while (system(buf) == 0);
 
@@ -548,8 +549,6 @@ void set_str_val(int msgpos, char str[])
        case UI_TEXT:
                title(setup_titles[msgpos]);
                print_setup(msgpos);
-               if (msgpos == 11)
-                       dump_access_levels();
                printf("This is currently set to:\n%s\n", str);
                printf("Enter new value or press return to leave unchanged:\n");
                fgets(buf, 4096, stdin);
@@ -577,7 +576,7 @@ void set_str_val(int msgpos, char str[])
 void set_int_val(int msgpos, int *ip)
 {
        char buf[16];
-       sprintf(buf, "%d", (int) *ip);
+       snprintf(buf, sizeof buf, "%d", (int) *ip);
        set_str_val(msgpos, buf);
        *ip = atoi(buf);
 }
@@ -586,7 +585,7 @@ void set_int_val(int msgpos, int *ip)
 void set_char_val(int msgpos, char *ip)
 {
        char buf[16];
-       sprintf(buf, "%d", (int) *ip);
+       snprintf(buf, sizeof buf, "%d", (int) *ip);
        set_str_val(msgpos, buf);
        *ip = (char) atoi(buf);
 }
@@ -595,7 +594,7 @@ void set_char_val(int msgpos, char *ip)
 void set_long_val(int msgpos, long int *ip)
 {
        char buf[16];
-       sprintf(buf, "%ld", *ip);
+       snprintf(buf, sizeof buf, "%ld", *ip);
        set_str_val(msgpos, buf);
        *ip = atol(buf);
 }
@@ -701,6 +700,9 @@ int main(int argc, char *argv[])
                if (!strcmp(argv[a], "-i")) {
                        info_only = 1;
                }
+               if (!strcmp(argv[a], "-q")) {
+                       setup_type = UI_SILENT;
+               }
        }
 
 
@@ -737,7 +739,8 @@ int main(int argc, char *argv[])
        switch (setup_type) {
 
        case UI_TEXT:
-               printf("\n\n\n               *** Citadel/UX setup program ***\n\n");
+               printf("\n\n\n"
+                       "               *** Citadel/UX setup program ***\n\n");
                break;
 
        }
@@ -794,8 +797,9 @@ int main(int argc, char *argv[])
                strcpy(config.c_humannode, "My System");
        if (strlen(config.c_phonenum) == 0)
                strcpy(config.c_phonenum, "US 800 555 1212");
-       if (config.c_initax == 0)
-               config.c_initax = 1;
+       if (config.c_initax == 0) {
+               config.c_initax = 4;
+       }
        if (strlen(config.c_moreprompt) == 0)
                strcpy(config.c_moreprompt, "<more>");
        if (strlen(config.c_twitroom) == 0)
@@ -855,8 +859,10 @@ int main(int argc, char *argv[])
 
 
        /* Go through a series of dialogs prompting for config info */
-       for (curr = 1; curr <= MAXSETUP; ++curr) {
-               edit_value(curr);
+       if (setup_type != UI_SILENT) {
+               for (curr = 1; curr <= MAXSETUP; ++curr) {
+                       edit_value(curr);
+               }
        }
 
        /*
@@ -877,7 +883,8 @@ int main(int argc, char *argv[])
 
        if (old_setup_level < 323) {
                important_message("Citadel/UX Setup",
-                                 "This Citadel/UX installation is too old to be upgraded.");
+                                 "This Citadel/UX installation is too old "
+                                 "to be upgraded.");
                cleanup(1);
        }
        write_config_to_disk();
@@ -929,7 +936,8 @@ NEW_INST:
        progress("Setting file permissions", 1, 5);
        chown("citadel.config", config.c_bbsuid, gid);
        progress("Setting file permissions", 2, 5);
-       sprintf(aaa, "find . | grep -v chkpwd | xargs chown %ld:%ld 2>/dev/null",
+       snprintf(aaa, sizeof aaa,
+               "find . | grep -v chkpwd | xargs chown %ld:%ld 2>/dev/null",
                (long)config.c_bbsuid, (long)gid);
        system(aaa);
        progress("Setting file permissions", 3, 5);
@@ -939,7 +947,6 @@ NEW_INST:
        important_message("Setup finished",
            "Setup is finished.  You may now start the Citadel server.");
 
-
        cleanup(0);
        return 0;
 }