]> code.citadel.org Git - citadel.git/blobdiff - citadel/setup.c
See ChangeLog for 1999-03-0[45] for details.
[citadel.git] / citadel / setup.c
index bf05610ea9551c2f385cab9618a5f9283233471c..9ab1a5e487748fc6573ee66977ec31902c3fe8f6 100644 (file)
@@ -1,7 +1,6 @@
 /*
  * Citadel/UX setup program
- * v4.1 / by Art Cancro
- * see copyright.txt for copyright information
+ * $Id$
  *
  * *** YOU MUST EDIT sysconfig.h >BEFORE< COMPILING SETUP ***
  */
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/utsname.h>
 #include <netdb.h>
 #include <errno.h>
 #include <limits.h>
+#include <pwd.h>
 
 #include "citadel.h"
 #include "axdefs.h"
 #include "sysdep.h"
 #include "config.h"
+#include "tools.h"
 
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
 # ifdef OK
 # undef OK
 # endif
-#include CURSES_INC
+#include <curses.h>
 #endif
 
-#define MAXSETUP 19
+#define MAXSETUP 5
 
 #define UI_TEXT                0       /* Default setup type -- text only */
 #define UI_DIALOG      1       /* Use the 'dialog' program */
@@ -45,24 +47,9 @@ int need_init_q = 0;
 
 char *setup_titles[] = {
        "BBS Home Directory",
-       "Citadel node name",
-       "Fully Qualified Domain Name (FQDN)",
-       "Human-readable node name",
-       "Phone number",
-       "BBS City and State",
        "System Administrator",
        "BBS User ID",
-       "'Room Creator = Room Aide' flag",
-       "Server timeout period",
-       "Initial access level",
-       "Registration requirements",
-       "Twit Detect!",
-       "Twit Detect target room",
-       "Maximum concurrent sessions",
-       "Paginator prompt",
-       "Restrict Internet mail flag",
        "Name of bit bucket subdirectory",
-       "System net password",
        "Server port number",
        };
 
@@ -76,134 +63,43 @@ char *setup_text[] = {
 "it up.",
 
 "1",
-"This is the name your system is known by on a Citadel/UX network.  It",
-"should be 8 characters or less, and should generally be comprised only of",
-"letters.  You can also use numbers and hyphens if necessary.",
+"Enter the name of the system administrator (which is probably you).",
+"When an account is created with this name, it will automatically be",
+"assigned the highest access level.",
 
 "2",
-"This is the name your system is known by on the Internet.",
-"If you're not on the Internet, simply set this to your",
-"node name followed by '.UUCP'.",
+"You should create a user called 'bbs', 'guest', 'citadel', or something",
+"similar, that will allow users a way into your BBS.  The server will run",
+"under this user ID.  Please specify that (numeric) user ID here.",
 
 "3",
-"This is a longer description of your system, readable by",
-"us mere humans.  It can be up to 20 characters long and it",
-"can have spaces in it.  Note that if you are part of a",
-"Cit86Net, this is the name your system will be known by on",
-"that network.",
+"Select the name of a subdirectory (relative to the main",
+"Citadel directory - do not type an absolute pathname!) in",
+"which to place arriving file transfers that otherwise",
+"don't have a home.",
 
 "4",
-"This is the main dialup number for your system.  If yours",
-"can not be dialed into, then make one up!  It should be in",
-"the format 'US 000 000 0000' - the US is your country code",
-"(look it up if you're not in the United States) and the",
-"rest is, of course, your area code and phone number.",
-"This doesn't have any use in Citadel/UX, but gateways to",
-"other networks may require it, and someday we may use this",
-"to have the networker automatically build a BBS list.",
+"Specify the TCP port number on which your server will run.  Normally, this",
+"will be port 504, which is the official port assigned by the IANA for",
+"Citadel servers.  You'll only need to specify a different port number if",
+"you run multiple BBS's on the same computer and there's something else",
+"already using port 504.",
 
 "5",
-"Enter the geographical location of your system (city and",
-"state/province/country etc.)",
-
 "6",
-"Enter the name of the system administrator (which is probably you).",
-"When an account is created with this name, it will automatically be",
-"assigned the highest access level.",
-
 "7",
-"You should create a user called 'bbs', 'guest', 'citadel', or something",
-"similar, that will allow users a way into your BBS.  The server will run",
-"under this user ID.  Please specify that (numeric) user ID here.",
-
 "8",
-"This is a boolean value.  If you set it to 1, anyone who",
-"creates a class 3 (passworded) or class 4 (invitation",
-"only) room will automatically become the Room Aide for",
-"that room, allowing them to edit it, delete/move messages,",
-"etc.  This is an administrative decision: it works well on",
-"some systems, and not so well on others.  Set this to 0 to",
-"disable this function.",
-
 "9",
-"This setting specifies how long a server session may sit idle before it is",
-"automatically terminated.  The recommended value is 900 seconds (15",
-"minutes).  Note that this has *nothing* to do with any watchdog timer that",
-"is presented to the user.  The server's timeout is intended to kill idle or",
-"zombie sessions running on a network, etc.  ",
-"You MUST set this to a reasonable value.  Setting it to zero will cause",
-"the server to malfunction.",
-
 "10",
-"This is the access level new users are assigned.",
-"",
-"The most common settings for this will be either 1, for",
-"systems which require new user validation by the system",
-"administrator ('sysop' is a word for people who run DOS",
-"boards!), or 4, for systems which give instant access.",
-"The current access levels available are:",
-
 "11",
-"'Registration' refers to the boring part of logging into a BBS for the first",
-"time: typing your name, address, and telephone number.  Set this value to 1",
-"to automatically do registration for new users, or 0 to not auto-register.",
-"Optionally, you could set it to, say, 2, to auto-register on a user's second",
-"call, but there really isn't much point to doing this.  The recommended",
-"value is 1 if you've set your inital access level to 1, or 0 if you've set",
-"your initial access level to something higher.",
-
 "12",
-"Every BBS has its share of problem users.  This is one",
-"good way to deal with them: if you enable this option,",
-"anyone you flag as a 'problem user' (access level 2) can",
-"post anywhere they want, but their messages will all be",
-"automatically moved to a room of your choosing.  Set this",
-"value to 1 to enable Twit Detect, or 0 to disable it.",
-
 "13",
-"This is the name of the room that problem user messages",
-"get moved to if you have Twit Detect enabled.",
-"(Note: don't forget to *create* this room!)",
-
 "14",
-"This is the maximum number of concurrent Citadel sessions which may be",
-"running at any given time.  Use this to keep very busy systems from being",
-"overloaded.",
-"  Set this value to 0 to allow an unlimited number of sessions.",
-
 "15",
-"This is the prompt that appears after each screenful of",
-"text - for users that have chosen that option.  Usually",
-"a simple '<more>' will do, but some folks like to be",
-"creative...",
-
 "16",
-"If you have a gateway set up to allow Citadel users to",
-"send Internet mail, with sendmail, qmail, or whatever, and",
-"you wish to restrict this to only users to whom you have",
-"given this privilege, set this flag to 1.  Otherwise, set",
-"it to 0 to allow everyone to send Internet mail.",
-"(Obviously, if your system doesn't have the ability to",
-"send mail to the outside world, this is all irrelevant.)",
-
 "17",
-"Select the name of a subdirectory (relative to the main",
-"Citadel directory - do not type an absolute pathname!) in",
-"which to place arriving file transfers that otherwise",
-"don't have a home.",
-
 "18",
-"If you use Citadel client/server sessions to transport network spool data",
-"between systems, this is the password other systems will use to authenticate",
-"themselves as network nodes rather than regular callers.",
-
 "19",
-"Specify the TCP port number on which your server will run.  Normally, this",
-"will be port 504, which is the official port assigned by the IANA for",
-"Citadel servers.  You'll only need to specify a different port number if",
-"you run multiple BBS's on the same computer and there's something else",
-"already using port 504.",
-
 "20",
 "21",
 "22",
@@ -231,7 +127,7 @@ struct config config;
 int direction;
 
 void cleanup(int exitcode) {
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
        if (setup_type == UI_CURSES) {
                clear();
                refresh();
@@ -256,7 +152,7 @@ void cleanup(int exitcode) {
        }
 
 
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
 void getlin(int yp, int xp, char *string, int lim)     /* Gets a line from the terminal */
                                /* Where on the screen to start */
                                /* Pointer to string buffer */
@@ -318,7 +214,7 @@ void title(char *text)
 void hit_any_key(void) {
        char junk[5];
 
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
        if (setup_type == UI_CURSES) {
                mvprintw(20, 0, "Press any key to continue... ");
                refresh();
@@ -351,7 +247,7 @@ int yesno(char *question)
                        sprintf(buf, "dialog --yesno \"%s\" 7 80", question);
                        answer = ( (system(buf)==0) ? 1 : 0);
                        break;
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
                case UI_CURSES:
                        do {
                                clear();
@@ -419,7 +315,7 @@ void important_message(char *title, char *msgtext) {
                                title, msgtext);
                        system(buf);
                        break;
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
                case UI_CURSES:
                        clear();
                        move(1, 20);
@@ -480,7 +376,7 @@ void progress(char *text, long int curr, long int cmax)
                                }
                        break;
 
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
                case UI_CURSES:
                        if (curr==0) {
                                clear();
@@ -653,7 +549,7 @@ void set_str_val(int msgpos, char str[]) {
        char tempfile[64];
        FILE *fp;
 
-       sprintf(tempfile, "/tmp/setup.%d", getpid());
+       sprintf(tempfile, "/tmp/setup.%ld", (long)getpid());
 
        switch (setup_type) {
                case UI_TEXT:
@@ -682,7 +578,7 @@ void set_str_val(int msgpos, char str[]) {
                                                str[strlen(str)-1]=0;
                                }
                        break;
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
                case UI_CURSES:
                        clear();
                        move(1, ((80-strlen(setup_titles[msgpos]))/2) );
@@ -726,50 +622,6 @@ void set_long_val(int msgpos, long int *ip)
        }
 
 
-#if 0 /* FIXME: this isn't used, can we remove it? */
-int yesno_s(char *question) {
-       int a;
-       char buf[4096];
-       char tempfile[64];
-       FILE *fp;
-
-       sprintf(tempfile, "/tmp/setup.%d", getpid());
-       switch (setup_type) {
-       
-               case UI_TEXT:
-                       a=yesno(question);
-                       if (a==1) a=yesno("Are you SURE you want to reinitialize this file? ");
-                       return(a);
-                       break;
-
-               case UI_CURSES:
-                       a=yesno(question);
-                       if (a==1) a=yesno("Are you SURE you want to reinitialize this file? ");
-                       return(a);
-                       break;
-
-               case UI_DIALOG:
-                       a = yesno(question);
-                       if (a==0) return(a);
-                       sprintf(buf, "dialog --title \"Confirm file overwrite\" --menu \"\nAre you SURE you want to reinitialize this file?\n\" 13 80 2 NO \"No, don't overwrite\" YES \"Yes, overwrite the existing file\" 2>%s", tempfile);
-                       a = system(buf);
-                       if (a != 0) return(0);
-                       fp = fopen(tempfile, "rb");
-                       fgets(buf, 4095, fp);
-                       fclose(fp);
-                       if (strlen(buf)>0) 
-                               if (buf[strlen(buf)-1]==10)
-                                       buf[strlen(buf)-1]=0;
-                       return( (!strcmp(buf, "YES")) ? 1 : 0 );
-                       break;
-
-               }
-
-       return(0); /* just in case */
-       }
-#endif
-
-
 void edit_value(int curr)
 {
  int a;
@@ -777,70 +629,14 @@ void edit_value(int curr)
  switch(curr) {
 
 case 1:
-       set_str_val(curr, config.c_nodename);
-       break;
-
-case 2:
-       set_str_val(curr, config.c_fqdn);
-       break;
-
-case 3:
-       set_str_val(curr, config.c_humannode);
-       break;
-
-case 4:
-       set_str_val(curr, config.c_phonenum);
-       break;
-
-case 5:
-       set_str_val(curr, config.c_bbs_city);
-       break;
-
-case 6:
        set_str_val(curr, config.c_sysadm);
        break;
 
-case 7:
+case 2:
        set_int_val(curr, &config.c_bbsuid);
        break;
 
-case 8:
-       set_char_val(curr, &config.c_creataide);
-       break;
-
-case 9:
-       set_int_val(curr, &config.c_sleeping);
-       break;
-
-case 10:
-       set_char_val(curr, &config.c_initax);
-       break;
-
-case 11:
-       set_char_val(curr, &config.c_regiscall);
-       break;
-
-case 12:
-       set_char_val(curr, &config.c_twitdetect);
-       break;
-
-case 13:
-       set_str_val(curr, config.c_twitroom);
-       break;
-
-case 14:
-       set_int_val(curr, &config.c_maxsessions);
-       break;
-
-case 15:
-       set_str_val(curr, config.c_moreprompt);
-       break;
-
-case 16:
-       set_char_val(curr, &config.c_restrict);
-       break;
-
-case 17:
+case 3:
        set_str_val(curr, config.c_bucket_dir);
        config.c_bucket_dir[14] = 0;
        for (a=0; a<strlen(config.c_bucket_dir); ++a)
@@ -849,11 +645,7 @@ case 17:
                                &config.c_bucket_dir[a+1]);
        break;
 
-case 18:
-       set_str_val(curr, config.c_net_password);
-       break;
-
-case 19:
+case 4:
        set_int_val(curr, &config.c_port_number);
        break;
 
@@ -866,8 +658,14 @@ case 19:
  */
 void write_config_to_disk(void) {
        FILE *fp;
+       int fd;
 
-       fp=fopen("citadel.config","wb");
+       if ((fd = creat("citadel.config", S_IRUSR | S_IWUSR)) == -1) {
+               display_error("setup: cannot open citadel.config");
+               cleanup(1);
+               }
+
+       fp=fdopen(fd,"wb");
        if (fp==NULL) {
                display_error("setup: cannot open citadel.config");
                cleanup(1);
@@ -884,7 +682,7 @@ void write_config_to_disk(void) {
  */
 int discover_ui(void) {
 
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
        return UI_CURSES;
 #endif
 
@@ -899,13 +697,17 @@ int discover_ui(void) {
 
 
 
-void main(int argc, char *argv[]) {
+int main(int argc, char *argv[]) {
        int a;
        int curr;
        char aaa[128];
        FILE *fp;
        int old_setup_level = 0;
        int info_only = 0;
+       struct utsname my_utsname;
+       struct passwd *pw;
+       struct hostent *he;
+       gid_t gid;
 
        /* set an invalid setup type */
        setup_type = (-1);
@@ -930,7 +732,7 @@ void main(int argc, char *argv[]) {
                setup_type = discover_ui();
                }
 
-#ifdef CURSES_INC
+#ifdef HAVE_CURSES_H
        if (setup_type == UI_CURSES) {
                initscr();
                raw();
@@ -943,6 +745,7 @@ void main(int argc, char *argv[]) {
                cleanup(0);
                }
 
+       /* Get started in a valid setup directory. */
        strcpy(setup_directory, BBSDIR);
        set_str_val(0, setup_directory);
        if (chdir(setup_directory) != 0) {
@@ -951,7 +754,10 @@ void main(int argc, char *argv[]) {
                cleanup(errno);
                }
 
+       /* Determine our host name, in case we need to use it as a default */
+       uname(&my_utsname);
 
+       /* Now begin. */
        switch(setup_type) {
                
                case UI_TEXT:
@@ -975,7 +781,13 @@ void main(int argc, char *argv[]) {
         * completely new copy.  (Neat, eh?)
         */
 
-       fp=fopen("citadel.config","ab");
+       if ((a = open("citadel.config", O_WRONLY | O_CREAT | O_APPEND,
+                     S_IRUSR | S_IWUSR)) == -1) {
+               display_error("setup: cannot append citadel.config");
+               cleanup(errno);
+               }
+
+       fp=fdopen(a,"ab");
        if (fp==NULL) {
                display_error("setup: cannot append citadel.config");
                cleanup(errno);
@@ -995,9 +807,17 @@ void main(int argc, char *argv[]) {
 
        /* set some sample/default values in place of blanks... */
        if (strlen(config.c_nodename)==0)
-               strcpy(config.c_nodename,"mysystem");
-       if (strlen(config.c_fqdn)==0)
-               sprintf(config.c_fqdn,"%s.UUCP",config.c_nodename);
+               safestrncpy(config.c_nodename, my_utsname.nodename,
+                           sizeof config.c_nodename);
+               strtok(config.c_nodename, ".");
+       if (strlen(config.c_fqdn)==0) {
+               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 (strlen(config.c_humannode)==0)
                strcpy(config.c_humannode,"My System");
        if (strlen(config.c_phonenum)==0)
@@ -1022,6 +842,33 @@ void main(int argc, char *argv[]) {
        if (config.c_sleeping == 0) {
                config.c_sleeping = 900;
                }
+       if (config.c_bbsuid == 0) {
+               pw = getpwnam("citadel");
+               if (pw != NULL) config.c_bbsuid = pw->pw_uid;
+               }
+       if (config.c_bbsuid == 0) {
+               pw = getpwnam("bbs");
+               if (pw != NULL) config.c_bbsuid = pw->pw_uid;
+               }
+       if (config.c_bbsuid == 0) {
+               pw = getpwnam("guest");
+               if (pw != NULL) config.c_bbsuid = pw->pw_uid;
+               }
+       
+       /*
+        * Negative values for maxsessions are not allowed.
+        */
+       if (config.c_maxsessions < 0) {
+               config.c_maxsessions = 0;
+               }
+
+       /* We need a system default message expiry policy, because this is
+        * the top level and there's no 'higher' policy to fall back on.
+        */
+       if (config.c_ep.expire_mode == 0) {
+               config.c_ep.expire_mode = EXPIRE_NUMMSGS;
+               config.c_ep.expire_value = 150;
+               }
 
        /* Go through a series of dialogs prompting for config info */
        for (curr = 1; curr <= MAXSETUP; ++curr) {
@@ -1070,6 +917,9 @@ void main(int argc, char *argv[]) {
 
 NEW_INST:
        config.c_setup_level = REV_LEVEL;
+
+/******************************************/
+
        write_config_to_disk();
 
        system("mkdir info 2>/dev/null");               /* Create these */
@@ -1081,21 +931,24 @@ NEW_INST:
        sprintf(aaa,"mkdir %s 2>/dev/null",config.c_bucket_dir);
        system(aaa);
 
-
-       system("rm -fr ./chatpipes 2>/dev/null");       /* Don't need these */
-       system("rm -fr ./expressmsgs 2>/dev/null");
-       unlink("sessions");
+       /* Delete a bunch of old files from Citadel v4; don't need anymore */
+       system("rm -fr ./chatpipes ./expressmsgs sessions 2>/dev/null");
 
        check_services_entry();         /* Check /etc/services */
        check_inittab_entry();          /* Check /etc/inittab */
 
+       if ((pw = getpwuid(config.c_bbsuid)) == NULL)
+               gid = getgid();
+       else
+               gid = pw->pw_gid;
+
        progress("Setting file permissions", 0, 3);
-       chown(".", config.c_bbsuid, getgid());
+       chown(".", config.c_bbsuid, gid);
        progress("Setting file permissions", 1, 3);
-       chown("citadel.config", config.c_bbsuid, getgid());
+       chown("citadel.config", config.c_bbsuid, gid);
        progress("Setting file permissions", 2, 3);
-       sprintf(aaa, "find . -exec chown %d {} \\; 2>/dev/null",
-               config.c_bbsuid);
+       sprintf(aaa, "find . -exec chown %d:%d {} \\; 2>/dev/null",
+               config.c_bbsuid, gid);
        system(aaa);
        progress("Setting file permissions", 3, 3);
 
@@ -1104,4 +957,5 @@ NEW_INST:
 
 
        cleanup(0);
+       return 0;
 }