Completed the overhaul of setup.
authorArt Cancro <ajc@uncensored.citadel.org>
Fri, 27 Jan 2012 16:38:18 +0000 (11:38 -0500)
committerArt Cancro <ajc@uncensored.citadel.org>
Fri, 27 Jan 2012 16:38:18 +0000 (11:38 -0500)
citadel/config.c
citadel/include/dtds/config-defs.h
citadel/modules/migrate/serv_migrate.c
citadel/modules/upgrade/serv_upgrade.c
citadel/user_ops.c
citadel/utils/setup.c

index 303e06d4bd7346311a4e40520911e740bcc9ec75..60806b1b7724e4179a6ae4aba52d51a5f4b9a3a7 100644 (file)
@@ -106,17 +106,6 @@ void get_config(void) {
        }
 #endif
 
-       /* Check to see whether 'setup' must first be run to update data file formats */
-       if (config.c_setup_level < REV_MIN) {
-               fprintf(stderr, "Your data files are out of date.  Run setup to update them.\n");
-               fprintf(stderr, "        This program requires level %d.%02d\n",
-                       (REV_LEVEL / 100), (REV_LEVEL % 100));
-               fprintf(stderr, "        Data files are currently at %d.%02d\n",
-                       (config.c_setup_level / 100),
-                       (config.c_setup_level % 100));
-               exit(CTDLEXIT_OOD);
-       }
-
         /* Default maximum message length is 10 megabytes.  This is site
         * configurable.  Also check to make sure the limit has not been
         * set below 8192 bytes.
index cb082da33201f5fa67c2936ded059b339fc4367f..3574dd912f514a6325978be2858ce71cbf05e3e1 100644 (file)
@@ -21,11 +21,11 @@ CFG_VALUE(CHAR(c_twitdetect),                       " twit detect flag                 ");
 CFG_VALUE(STRING_BUF(c_twitroom, ROOMNAMELEN), " twit detect msg move to room     ");
 CFG_VALUE(STRING_BUF(c_moreprompt, 80),                " paginator prompt                 ");
 CFG_VALUE(CHAR(c_restrict),                    " restrict internet mail flag      ");
-NO_ARTV(CFG_VALUE(LONG(c_niu_1),               " (not in use)                     ")); ///////
+NO_ARTV(CFG_VALUE(LONG(c_niu_1),               " (not in use)                     "));
 CFG_VALUE(STRING_BUF(c_site_location, 32),     " physical location of server      ");
 CFG_VALUE(STRING_BUF(c_sysadm, 26),            " name of system administrator     ");
 NO_ARTV(CFG_VALUE(STRING_BUF(c_niu_2, 15),     " (not in use)                     "));
-CFG_VALUE(INTEGER(c_setup_level),              " what rev level we've setup to    ");
+CFG_VALUE(INTEGER(c_setup_level),              " (not in use)                     ");
 CFG_VALUE(INTEGER(c_maxsessions),              " maximum concurrent sessions      ");
 /* c_ip_addr is out of sortorder; its located after c_ldap_bind_pw in the old export */
 CFG_VALUE(STRING_BUF(c_ip_addr, 20),           " IP address to listen on          "); 
index d1d6d04b95795d4adfc2bf51a6ebdb55104e3df5..ddf52aeea170e40116d9ba22c7859289dda8aede 100644 (file)
@@ -1,21 +1,15 @@
 /*
  * This module dumps and/or loads the Citadel database in XML format.
  *
- * Copyright (c) 1987-2010 by the citadel.org team
+ * Copyright (c) 1987-2012 by the citadel.org team
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
+ * This program is open source software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include "sysdep.h"
 #include "user_ops.h"
 #include "control.h"
 #include "euidindex.h"
-
-
 #include "ctdl_module.h"
 
-
-
 #define END_OF_MESSAGE "---eom---dbd---"
 
 char migr_tempfilename1[PATH_MAX];
@@ -68,14 +58,10 @@ char migr_tempfilename2[PATH_MAX];
 FILE *migr_global_message_list;
 
 
-
-
 /*
  * Code which implements the export appears in this section
  */
 
-
-
 /*
  * Output a string to the client with these characters escaped:  & < >
  */
@@ -421,7 +407,6 @@ void migr_do_export(void) {
        cprintf("<c_restrict>%d</c_restrict>\n", config.c_restrict);
        client_write("<c_site_location>", 17);  xml_strout(config.c_site_location);     client_write("</c_site_location>\n", 19);
        client_write("<c_sysadm>", 10);         xml_strout(config.c_sysadm);            client_write("</c_sysadm>\n", 12);
-       cprintf("<c_setup_level>%d</c_setup_level>\n", config.c_setup_level);
        cprintf("<c_maxsessions>%d</c_maxsessions>\n", config.c_maxsessions);
        client_write("<c_ip_addr>", 11);        xml_strout(config.c_ip_addr);           client_write("</c_ip_addr>\n", 13);
        cprintf("<c_port_number>%d</c_port_number>\n", config.c_port_number);
@@ -656,7 +641,6 @@ void migr_xml_end(void *data, const char *el) {
        else if (!strcasecmp(el, "c_restrict"))                 config.c_restrict = atoi(migr_chardata);
        else if (!strcasecmp(el, "c_site_location"))            safestrncpy(config.c_site_location, migr_chardata, sizeof config.c_site_location);
        else if (!strcasecmp(el, "c_sysadm"))                   safestrncpy(config.c_sysadm, migr_chardata, sizeof config.c_sysadm);
-       else if (!strcasecmp(el, "c_setup_level"))              config.c_setup_level = atoi(migr_chardata);
        else if (!strcasecmp(el, "c_maxsessions"))              config.c_maxsessions = atoi(migr_chardata);
        else if (!strcasecmp(el, "c_ip_addr"))                  safestrncpy(config.c_ip_addr, migr_chardata, sizeof config.c_ip_addr);
        else if (!strcasecmp(el, "c_port_number"))              config.c_port_number = atoi(migr_chardata);
index 8e7ef34553a73014799218c4d0dff59adad75140..3e8ad1e7412b86899cc96df8279a2aaab54d8281 100644 (file)
@@ -21,6 +21,7 @@
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
+#include <sys/utsname.h>
 
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
 #include "msgbase.h"
 #include "serv_upgrade.h"
 #include "euidindex.h"
-
-
 #include "ctdl_module.h"
 
 
-
 /*
  * Fix up the name for Citadel user 0 and try to remove any extra users with number 0
  */
@@ -256,6 +254,82 @@ void guess_time_zone(void) {
 }
 
 
+/*
+ * Put some sane default values into our configuration.  Some will be overridden when we run setup.
+ */
+void brand_new_installation_set_defaults(void) {
+
+       struct passwd *pw;
+       struct utsname my_utsname;
+       struct hostent *he;
+
+       /* Determine our host name, in case we need to use it as a default */
+       uname(&my_utsname);
+
+       /* set some sample/default values in place of blanks... */
+       char c_nodename[256];
+       safestrncpy(c_nodename, my_utsname.nodename, sizeof 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);
+               }
+       }
+
+       safestrncpy(config.c_humannode, "Citadel Server", sizeof config.c_humannode);
+       safestrncpy(config.c_phonenum, "US 800 555 1212", sizeof config.c_phonenum);
+       config.c_initax = 4;
+       safestrncpy(config.c_moreprompt, "<more>", sizeof config.c_moreprompt);
+       safestrncpy(config.c_twitroom, "Trashcan", sizeof config.c_twitroom);
+       safestrncpy(config.c_baseroom, BASEROOM, sizeof config.c_baseroom);
+       safestrncpy(config.c_aideroom, "Aide", sizeof config.c_aideroom);
+       config.c_port_number = 504;
+       config.c_sleeping = 900;
+       config.c_instant_expunge = 1;
+
+       if (config.c_ctdluid == 0) {
+               pw = getpwnam("citadel");
+               if (pw != NULL) {
+                       config.c_ctdluid = pw->pw_uid;
+               }
+       }
+       if (config.c_ctdluid == 0) {
+               pw = getpwnam("bbs");
+               if (pw != NULL) {
+                       config.c_ctdluid = pw->pw_uid;
+               }
+       }
+       if (config.c_ctdluid == 0) {
+               pw = getpwnam("guest");
+               if (pw != NULL) {
+                       config.c_ctdluid = pw->pw_uid;
+               }
+       }
+       if (config.c_createax == 0) {
+               config.c_createax = 3;
+       }
+
+       /*
+        * Default port numbers for various services
+        */
+       config.c_smtp_port = 25;
+       config.c_pop3_port = 110;
+       config.c_imap_port = 143;
+       config.c_msa_port = 587;
+       config.c_smtps_port = 465;
+       config.c_pop3s_port = 995;
+       config.c_imaps_port = 993;
+       config.c_pftcpdict_port = -1 ;
+       config.c_managesieve_port = 2020;
+       config.c_xmpp_c2s_port = 5222;
+       config.c_xmpp_s2s_port = 5269;
+}
+
+
+
 /*
  * Perform any upgrades that can be done automatically based on our knowledge of the previous
  * version of Citadel server that was running here.
@@ -266,7 +340,7 @@ void update_config(void) {
        get_config();
 
        if (CitControl.version == 0) {
-               config.c_instant_expunge = 1;
+               brand_new_installation_set_defaults();
        }
 
        if (CitControl.version < 606) {
@@ -353,6 +427,23 @@ void check_server_upgrades(void) {
                remove_thread_users();
        }
        CitControl.version = REV_LEVEL;
+
+       /*
+        * 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.
+        * By default, do not expire messages at all.
+        */
+       if (config.c_ep.expire_mode == 0) {
+               config.c_ep.expire_mode = EXPIRE_MANUAL;
+               config.c_ep.expire_value = 0;
+       }
+
        put_control();
 }
 
index 7d4088c56fb20c023eeb724f2d8fd5fcfc8fbfee..29b6f621f0abd3403a22ea8e63dc7744fadbb5a7 100644 (file)
@@ -2102,18 +2102,18 @@ CTDL_MODULE_INIT(user_ops)
                CtdlRegisterProtoHook(cmd_invt, "INVT", "Invite a user to a room");
                CtdlRegisterProtoHook(cmd_kick, "KICK", "Kick a user out of a room");
                CtdlRegisterProtoHook(cmd_forg, "FORG", "Forget a room");
-               CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Get Next Unregistered User");
                CtdlRegisterProtoHook(cmd_vali, "VALI", "Validate new users");
                CtdlRegisterProtoHook(cmd_list, "LIST", "List users");
-               CtdlRegisterProtoHook(cmd_chek, "CHEK", "Autoconverted. TODO: document me.");
-               CtdlRegisterProtoHook(cmd_qusr, "QUSR", "Autoconverted. TODO: document me.");
-               CtdlRegisterProtoHook(cmd_agup, "AGUP", "Autoconverted. TODO: document me.");
-               CtdlRegisterProtoHook(cmd_asup, "ASUP", "Autoconverted. TODO: document me.");
-               CtdlRegisterProtoHook(cmd_seen, "SEEN", "Autoconverted. TODO: document me.");
-               CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Autoconverted. TODO: document me.");
-               CtdlRegisterProtoHook(cmd_view, "VIEW", "Autoconverted. TODO: document me.");
-               CtdlRegisterProtoHook(cmd_renu, "RENU", "Autoconverted. TODO: document me.");
-               CtdlRegisterProtoHook(cmd_newu, "NEWU", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_chek, "CHEK", "assorted info we need to check at login");
+               CtdlRegisterProtoHook(cmd_qusr, "QUSR", "check to see if a user exists");
+               CtdlRegisterProtoHook(cmd_agup, "AGUP", "Administratively Get User Parameters");
+               CtdlRegisterProtoHook(cmd_asup, "ASUP", "Administratively Set User Parameters");
+               CtdlRegisterProtoHook(cmd_seen, "SEEN", "Manipulate seen/unread message flags");
+               CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Fetch seen/unread message flags");
+               CtdlRegisterProtoHook(cmd_view, "VIEW", "Set preferred view for user/room combination");
+               CtdlRegisterProtoHook(cmd_renu, "RENU", "Rename a user");
+               CtdlRegisterProtoHook(cmd_newu, "NEWU", "Log in as a new user");
        }
        /* return our Subversion id for the Log */
        return "user_ops";
index 5eb2ae9d00016884b5b3233cc3e636e3e506a5ea..98fab1fd65fdc57b6bfd4e8f758b98b9ef861ad3 100644 (file)
@@ -21,7 +21,6 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/utsname.h>
 #include <sys/wait.h>
 #include <signal.h>
 #include <netdb.h>
@@ -306,7 +305,7 @@ int yesno(const char *question, int default_value)
                break;
 
        case UI_DIALOG:
-               sprintf(buf, "exec %s %s --yesno '%s' 15 75",
+               snprintf(buf, sizeof buf, "exec %s %s --yesno '%s' 15 75",
                        getenv("CTDL_DIALOG"),
                        ( default_value ? "" : "--defaultno" ),
                        question);
@@ -339,7 +338,7 @@ void important_message(const char *title, const char *msgtext)
                break;
 
        case UI_DIALOG:
-               sprintf(buf, "exec %s --msgbox '%s' 19 72",
+               snprintf(buf, sizeof buf, "exec %s --msgbox '%s' 19 72",
                        getenv("CTDL_DIALOG"),
                        msgtext);
                int rv = system(buf);
@@ -403,7 +402,7 @@ void progress(char *text, long int curr, long int cmax)
 
        case UI_DIALOG:
                if (curr == 0) {
-                       sprintf(buf, "exec %s --gauge '%s' 7 72 0",
+                       snprintf(buf, sizeof buf, "exec %s --gauge '%s' 7 72 0",
                                getenv("CTDL_DIALOG"),
                                text);
                        fp = popen(buf, "w");
@@ -610,7 +609,7 @@ void disable_other_mta(const char *mta) {
        int lines = 0;
        int rv;
 
-       sprintf(buf,
+       snprintf(buf, sizeof 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",
                mta, mta
@@ -649,12 +648,12 @@ void disable_other_mta(const 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);
+       snprintf(buf, sizeof 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);
        rv = system(buf);
        if (rv != 0)
                display_error("%s %s.\n", _("failed to disable other mta"), mta);
 
-       sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
+       snprintf(buf, sizeof buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
        rv = system(buf);
        if (rv != 0)
                display_error(" %s.\n", _("failed to disable other mta"), mta);
@@ -724,7 +723,7 @@ void strprompt(const char *prompt_title, const char *prompt_text, char *Target,
 
        case UI_DIALOG:
                CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
-               sprintf(buf, "exec %s --nocancel --inputbox '%s' 19 72 '%s' 2>%s",
+               snprintf(buf, sizeof buf, "exec %s --nocancel --inputbox '%s' 19 72 '%s' 2>%s",
                        getenv("CTDL_DIALOG"),
                        prompt_text,
                        Target,
@@ -995,7 +994,7 @@ void fixnss(void) {
        );
 
        if (yesno(question, 1)) {
-               sprintf(buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
+               snprintf(buf, sizeof buf, "/bin/mv -f %s %s", new_filename, NSSCONF);
                rv = system(buf);
                if (rv != 0) {
                        fprintf(stderr, "failed to edit %s.\n", NSSCONF);
@@ -1283,7 +1282,6 @@ int main(int argc, char *argv[])
                ++a;
        }
 
-
        /*
         * Now begin.
         */
@@ -1291,10 +1289,7 @@ int main(int argc, char *argv[])
        /* _("Citadel Setup"),  */
 
        if (setup_type == UI_TEXT) {
-               printf("\n\n\n"
-                       "              *** %s ***\n\n",
-                       _("Citadel setup program")
-               );
+               printf("\n\n\n         *** %s ***\n\n", _("Citadel setup program"));
        }
 
        if (setup_type == UI_DIALOG) {
@@ -1312,9 +1307,22 @@ int main(int argc, char *argv[])
                ) {
                        curr += 5;      /* skip LDAP questions if we're not authenticating against LDAP */
                }
-       }
 
-       //config.c_setup_level = REV_LEVEL;
+               if (curr == eSysAdminName) {
+                       if (atoi(configs[52]) == AUTHMODE_NATIVE) {
+                                               /* for native auth mode, fetch the admin's existing pw */
+                               snprintf(buf, sizeof buf, "AGUP %s", configs[13]);
+                               serv_puts(buf);
+                               serv_gets(buf);
+                               if (buf[0] == '2') {
+                                       extract_token(admin_pass, &buf[4], 1, '|', sizeof admin_pass);
+                               }
+                       }
+                       else {
+                               ++curr;         /* skip the password question for non-native auth modes */
+                       }
+               }
+       }
 
        if ((pw = getpwuid(atoi(configs[69]))) == NULL) {
                gid = getgid();
@@ -1325,19 +1333,45 @@ int main(int argc, char *argv[])
        create_run_directories(atoi(configs[69]), gid);
 
        activity = _("Reconfiguring Citadel server");
-       progress(activity, 0, NUM_CONFIGS+1);
+       progress(activity, 0, NUM_CONFIGS+3);
        sleep(1);                                       /* Let the message appear briefly */
        serv_puts("CONF SET");
        serv_gets(buf);
        if (buf[0] == '4') {
                for (i=0; i<NUM_CONFIGS; ++i) {
-                       progress(activity, i+1, NUM_CONFIGS+1);
+                       progress(activity, i+1, NUM_CONFIGS+3);
                        serv_puts(configs[i]);
                }
                serv_puts("000");
        }
        sleep(1);                                       /* Let the message appear briefly */
-       progress(activity, NUM_CONFIGS+1, NUM_CONFIGS+1);
+
+       /*
+        * Create the administrator account.  It's ok if the command fails if this user already exists.
+        */
+       progress(activity, NUM_CONFIGS+1, NUM_CONFIGS+3);
+       snprintf(buf, sizeof buf, "CREU %s|%s", configs[13], admin_pass);
+       serv_puts(buf);
+       progress(activity, NUM_CONFIGS+2, NUM_CONFIGS+3);
+       serv_gets(buf);
+       progress(activity, NUM_CONFIGS+3, NUM_CONFIGS+3);
+
+       /*
+        * Assign the desired password and access level to the administrator account.
+        */
+       snprintf(buf, sizeof buf, "AGUP %s", configs[13]);
+       serv_puts(buf);
+       serv_gets(buf);
+       if (buf[0] == '2') {
+               int admin_flags = extract_int(&buf[4], 2);
+               int admin_times_called = extract_int(&buf[4], 3);
+               int admin_msgs_posted = extract_int(&buf[4], 4);
+               snprintf(buf, sizeof buf, "ASUP %s|%s|%d|%d|%d|6",
+                       configs[13], admin_pass, admin_flags, admin_times_called, admin_msgs_posted
+               );
+               serv_puts(buf);
+               serv_gets(buf);
+       }
 
 #ifndef __CYGWIN__
        check_xinetd_entry();   /* Check /etc/xinetd.d/telnet */
@@ -1374,12 +1408,12 @@ int main(int argc, char *argv[])
        close(serv_sock);
        serv_sock = (-1);
 
-       for (i=3; i<=6; ++i) {
+       for (i=3; i<=6; ++i) {                                  /* wait for server to shut down */
                progress(activity, i, 41);
                sleep(1);
        }
 
-       for (i=7; ((i<=38) && (serv_sock < 0)) ; ++i) {
+       for (i=7; ((i<=38) && (serv_sock < 0)) ; ++i) {         /* wait for server to start up */
                progress(activity, i, 41);
                serv_sock = uds_connectsock(file_citadel_admin_socket);
                sleep(1);
@@ -1396,7 +1430,9 @@ int main(int argc, char *argv[])
        close(serv_sock);
        progress(activity, 41, 41);
 
-       if (original_start_time == new_start_time) {
+       if (    (original_start_time == new_start_time)
+               || (new_start_time <= 0)
+       ) {
                display_error("%s\n",
                        _("Setup failed to restart Citadel server.  Please restart it manually.")
                );