From f927644354ef6b22db16a66d043ef42a056b82ee Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 27 Jan 2012 11:38:18 -0500 Subject: [PATCH] Completed the overhaul of setup. --- citadel/config.c | 11 --- citadel/include/dtds/config-defs.h | 4 +- citadel/modules/migrate/serv_migrate.c | 22 +----- citadel/modules/upgrade/serv_upgrade.c | 99 ++++++++++++++++++++++++-- citadel/user_ops.c | 20 +++--- citadel/utils/setup.c | 80 +++++++++++++++------ 6 files changed, 168 insertions(+), 68 deletions(-) diff --git a/citadel/config.c b/citadel/config.c index 303e06d4b..60806b1b7 100644 --- a/citadel/config.c +++ b/citadel/config.c @@ -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. diff --git a/citadel/include/dtds/config-defs.h b/citadel/include/dtds/config-defs.h index cb082da33..3574dd912 100644 --- a/citadel/include/dtds/config-defs.h +++ b/citadel/include/dtds/config-defs.h @@ -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 "); diff --git a/citadel/modules/migrate/serv_migrate.c b/citadel/modules/migrate/serv_migrate.c index d1d6d04b9..ddf52aeea 100644 --- a/citadel/modules/migrate/serv_migrate.c +++ b/citadel/modules/migrate/serv_migrate.c @@ -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" @@ -55,12 +49,8 @@ #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("%d\n", config.c_restrict); client_write("", 17); xml_strout(config.c_site_location); client_write("\n", 19); client_write("", 10); xml_strout(config.c_sysadm); client_write("\n", 12); - cprintf("%d\n", config.c_setup_level); cprintf("%d\n", config.c_maxsessions); client_write("", 11); xml_strout(config.c_ip_addr); client_write("\n", 13); cprintf("%d\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); diff --git a/citadel/modules/upgrade/serv_upgrade.c b/citadel/modules/upgrade/serv_upgrade.c index 8e7ef3455..3e8ad1e74 100644 --- a/citadel/modules/upgrade/serv_upgrade.c +++ b/citadel/modules/upgrade/serv_upgrade.c @@ -21,6 +21,7 @@ #include #include #include +#include #if TIME_WITH_SYS_TIME # include @@ -48,12 +49,9 @@ #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, "", 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(); } diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 7d4088c56..29b6f621f 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -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"; diff --git a/citadel/utils/setup.c b/citadel/utils/setup.c index 5eb2ae9d0..98fab1fd6 100644 --- a/citadel/utils/setup.c +++ b/citadel/utils/setup.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -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