From: Art Cancro Date: Tue, 5 May 2015 02:38:07 +0000 (-0400) Subject: config migration endless typing meow X-Git-Tag: Release_902~167^2~5 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=78840faa2a5b99edf2ff1f27c80106c661fee608 config migration endless typing meow --- diff --git a/citadel/config.c b/citadel/config.c index fffdadc6e..4115f1b5a 100644 --- a/citadel/config.c +++ b/citadel/config.c @@ -256,7 +256,7 @@ void initialize_config_system(void) { exit(CTDLEXIT_HOME); } - memset(&config, 0, sizeof(struct legacy_config)); + memset(&lconfig, 0, sizeof(struct legacy_config)); cfp = fopen(file_citadel_config, "rb"); if (cfp != NULL) { if (CtdlGetConfigLong("c_config_created_or_migrated") <= 0) { @@ -264,7 +264,7 @@ void initialize_config_system(void) { fprintf(stderr, "Exiting to prevent data corruption.\n"); exit(CTDLEXIT_CONFIG); } - rv = fread((char *) &config, sizeof(struct legacy_config), 1, cfp); + rv = fread((char *) &lconfig, sizeof(struct legacy_config), 1, cfp); if (rv != 1) { fprintf(stderr, @@ -401,6 +401,14 @@ char *CtdlGetConfigStr(char *key) struct cdbdata *cdb; int key_len = strlen(key); + if (IsEmptyStr(key)) return(NULL); + + /* Temporary hack to make sure we didn't mess up any porting - FIXME remove this after testing thoroughly */ + if (!strncmp(key, "config", 6)) { + syslog(LOG_EMERG, "You requested a key starting with 'config' which probably means a porting error: %s", key); + abort(); + } + /* First look in memory */ if (GetHash(ctdlconfig, key, key_len, (void *)&value)) { diff --git a/citadel/ldap.c b/citadel/ldap.c index 9d6ddf163..97288637f 100644 --- a/citadel/ldap.c +++ b/citadel/ldap.c @@ -2,7 +2,7 @@ * These functions implement the portions of AUTHMODE_LDAP and AUTHMODE_LDAP_AD which * actually speak to the LDAP server. * - * Copyright (c) 2011-2014 by the citadel.org development team. + * Copyright (c) 2011-2015 by the citadel.org development team. * * 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. @@ -22,6 +22,7 @@ int ctdl_require_ldap_version = 3; #include "citadel_ldap.h" #include "ctdl_module.h" #include "user_ops.h" +#include "config.h" #ifdef HAVE_LDAP #define LDAP_DEPRECATED 1 /* Suppress libldap's warning that we are using deprecated API calls */ @@ -37,7 +38,7 @@ int ctdl_ldap_initialize(LDAP **ld) { char server_url[256]; int ret; - snprintf(server_url, sizeof server_url, "ldap://%s:%d", config.c_ldap_host, config.c_ldap_port); + snprintf(server_url, sizeof server_url, "ldap://%s:%d", CtdlGetConfigStr("c_ldap_host"), CtdlGetConfigInt("c_ldap_port")); ret = ldap_initialize(ld, server_url); if (ret != LDAP_SUCCESS) { syslog(LOG_ALERT, "LDAP: Could not connect to %s : %s", @@ -80,12 +81,12 @@ int CtdlTryUserLDAP(char *username, ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ctdl_require_ldap_version); ldap_set_option(ldserver, LDAP_OPT_REFERRALS, (void *)LDAP_OPT_OFF); - striplt(config.c_ldap_bind_dn); - striplt(config.c_ldap_bind_pw); - syslog(LOG_DEBUG, "LDAP bind DN: %s", config.c_ldap_bind_dn); + striplt(CtdlGetConfigStr("c_ldap_bind_dn")); + striplt(CtdlGetConfigStr("c_ldap_bind_pw")); + syslog(LOG_DEBUG, "LDAP bind DN: %s", CtdlGetConfigStr("c_ldap_bind_dn")); i = ldap_simple_bind_s(ldserver, - (!IsEmptyStr(config.c_ldap_bind_dn) ? config.c_ldap_bind_dn : NULL), - (!IsEmptyStr(config.c_ldap_bind_pw) ? config.c_ldap_bind_pw : NULL) + (!IsEmptyStr(CtdlGetConfigStr("c_ldap_bind_dn")) ? CtdlGetConfigStr("c_ldap_bind_dn") : NULL), + (!IsEmptyStr(CtdlGetConfigStr("c_ldap_bind_pw")) ? CtdlGetConfigStr("c_ldap_bind_pw") : NULL) ); if (i != LDAP_SUCCESS) { syslog(LOG_ALERT, "LDAP: Cannot bind: %s (%d)", ldap_err2string(i), i); @@ -95,7 +96,7 @@ int CtdlTryUserLDAP(char *username, tv.tv_sec = 10; tv.tv_usec = 0; - if (config.c_auth_mode == AUTHMODE_LDAP_AD) { + if (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD) { if (lookup_based_on_username != 0) snprintf(searchstring, sizeof(searchstring), "(displayName=%s)",username); else @@ -111,7 +112,7 @@ int CtdlTryUserLDAP(char *username, syslog(LOG_DEBUG, "LDAP search: %s", searchstring); (void) ldap_search_ext_s( ldserver, /* ld */ - config.c_ldap_base_dn, /* base */ + CtdlGetConfigStr("c_ldap_base_dn"), /* base */ LDAP_SCOPE_SUBTREE, /* scope */ searchstring, /* filter */ NULL, /* attrs (all attributes) */ @@ -143,7 +144,7 @@ int CtdlTryUserLDAP(char *username, syslog(LOG_DEBUG, "dn = %s", user_dn); } - if (config.c_auth_mode == AUTHMODE_LDAP_AD) { + if (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD) { values = ldap_get_values(ldserver, search_result, "displayName"); if (values) { if (values[0]) { @@ -165,7 +166,7 @@ int CtdlTryUserLDAP(char *username, } /* If we know the username is the CN/displayName, we already set the uid*/ if (lookup_based_on_username==0) { - if (config.c_auth_mode == AUTHMODE_LDAP_AD) { + if (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD) { values = ldap_get_values(ldserver, search_result, "objectGUID"); if (values) { if (values[0]) { @@ -322,12 +323,12 @@ int Ctdl_LDAP_to_vCard(char *ldap_dn, struct vCard *v) ldap_set_option(ldserver, LDAP_OPT_PROTOCOL_VERSION, &ctdl_require_ldap_version); ldap_set_option(ldserver, LDAP_OPT_REFERRALS, (void *)LDAP_OPT_OFF); - striplt(config.c_ldap_bind_dn); - striplt(config.c_ldap_bind_pw); - syslog(LOG_DEBUG, "LDAP bind DN: %s", config.c_ldap_bind_dn); + striplt(CtdlGetConfigStr("c_ldap_bind_dn")); + striplt(CtdlGetConfigStr("c_ldap_bind_pw")); + syslog(LOG_DEBUG, "LDAP bind DN: %s", CtdlGetConfigStr("c_ldap_bind_dn")); i = ldap_simple_bind_s(ldserver, - (!IsEmptyStr(config.c_ldap_bind_dn) ? config.c_ldap_bind_dn : NULL), - (!IsEmptyStr(config.c_ldap_bind_pw) ? config.c_ldap_bind_pw : NULL) + (!IsEmptyStr(CtdlGetConfigStr("c_ldap_bind_dn")) ? CtdlGetConfigStr("c_ldap_bind_dn") : NULL), + (!IsEmptyStr(CtdlGetConfigStr("c_ldap_bind_pw")) ? CtdlGetConfigStr("c_ldap_bind_pw") : NULL) ); if (i != LDAP_SUCCESS) { syslog(LOG_ALERT, "LDAP: Cannot bind: %s (%d)", ldap_err2string(i), i); diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c index cc03230c9..ac4e7da7d 100644 --- a/citadel/modules/rssclient/serv_rssclient.c +++ b/citadel/modules/rssclient/serv_rssclient.c @@ -1,7 +1,7 @@ /* * Bring external RSS feeds into rooms. * - * Copyright (c) 2007-2012 by the citadel.org team + * Copyright (c) 2007-2015 by the citadel.org team * * 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. @@ -365,7 +365,7 @@ int rss_format_item(AsyncIO *IO, networker_save_message *SaveMsg) CM_SetField(&SaveMsg->Msg, eAuthor, HKEY("rss")); } - CM_SetField(&SaveMsg->Msg, eNodeName, CFG_KEY(c_nodename)); + CM_SetField(&SaveMsg->Msg, eNodeName, CtdlGetConfigStr("c_nodename"), strlen(CtdlGetConfigStr("c_nodename"))); if (SaveMsg->title != NULL) { long len; char *Sbj; diff --git a/citadel/modules/sieve/serv_sieve.c b/citadel/modules/sieve/serv_sieve.c index ed69de858..ddb1e99ba 100644 --- a/citadel/modules/sieve/serv_sieve.c +++ b/citadel/modules/sieve/serv_sieve.c @@ -2,7 +2,7 @@ * This module glues libSieve to the Citadel server in order to implement * the Sieve mailbox filtering language (RFC 3028). * - * Copyright (c) 1987-2012 by the citadel.org team + * Copyright (c) 1987-2015 by the citadel.org team * * 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. @@ -626,7 +626,7 @@ void sieve_do_msg(long msgnum, void *userdata) { } if (haschar(my.envelope_from, '@') == 0) { strcat(my.envelope_from, "@"); - strcat(my.envelope_from, config.c_fqdn); + strcat(my.envelope_from, CtdlGetConfigStr("c_fqdn")); } /* Keep track of the envelope-to address (use body-to if not found) */ @@ -652,7 +652,7 @@ void sieve_do_msg(long msgnum, void *userdata) { } if (haschar(my.envelope_to, '@') == 0) { strcat(my.envelope_to, "@"); - strcat(my.envelope_to, config.c_fqdn); + strcat(my.envelope_to, CtdlGetConfigStr("c_fqdn")); } CM_Free(msg); @@ -1185,7 +1185,7 @@ void cmd_msiv(char *argbuf) { extract_token(script_name, argbuf, 1, '|', sizeof script_name); if (!IsEmptyStr(script_name)) { cprintf("%d Transmit script now\n", SEND_LISTING); - script_content = CtdlReadMessageBody(HKEY("000"), config.c_maxmsglen, NULL, 0, 0); + script_content = CtdlReadMessageBody(HKEY("000"), CtdlGetConfigLong("c_maxmsglen"), NULL, 0, 0); msiv_putscript(&u, script_name, script_content); changes_made = 1; } diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index a93bb438e..63422fbdc 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -20,7 +20,7 @@ * The VRFY and EXPN commands have been removed from this implementation * because nobody uses these commands anymore, except for spammers. * - * Copyright (c) 1998-2013 by the citadel.org team + * Copyright (c) 1998-2015 by the citadel.org team * * 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. @@ -154,7 +154,7 @@ void smtp_greeting(int is_msa) /* If this config option is set, reject connections from problem * addresses immediately instead of after they execute a RCPT */ - if ( (config.c_rbl_at_greeting) && (sSMTP->is_msa == 0) ) { + if ( (CtdlGetConfigInt("c_rbl_at_greeting")) && (sSMTP->is_msa == 0) ) { if (rbl_check(message_to_spammer)) { if (server_shutting_down) cprintf("421 %s\r\n", message_to_spammer); @@ -178,7 +178,7 @@ void smtp_greeting(int is_msa) /* Note: the FQDN *must* appear as the first thing after the 220 code. * Some clients (including citmail.c) depend on it being there. */ - cprintf("220 %s ESMTP Citadel server ready.\r\n", config.c_fqdn); + cprintf("220 %s ESMTP Citadel server ready.\r\n", CtdlGetConfigStr("c_fqdn")); } @@ -284,7 +284,7 @@ void smtp_hello(long offset, long which_command) cprintf("250-Greetings and joyous salutations.\r\n"); } cprintf("250-HELP\r\n"); - cprintf("250-SIZE %ld\r\n", config.c_maxmsglen); + cprintf("250-SIZE %ld\r\n", CtdlGetConfigLong("c_maxmsglen")); #ifdef HAVE_OPENSSL /* @@ -674,7 +674,7 @@ void smtp_mail(long offset, long flags) { /* Otherwise, make sure outsiders aren't trying to forge mail from * this system (unless, of course, c_allow_spoofing is enabled) */ - else if (config.c_allow_spoofing == 0) { + else if (CtdlGetConfigInt("c_allow_spoofing") == 0) { process_rfc822_addr(ChrPtr(sSMTP->from), user, node, name); syslog(LOG_DEBUG, "Claimed envelope sender is '%s' == '%s' @ '%s' ('%s')", ChrPtr(sSMTP->from), user, node, name @@ -730,7 +730,7 @@ void smtp_rcpt(long offset, long flags) /* RBL check */ if ( (!CCC->logged_in) /* Don't RBL authenticated users */ && (!sSMTP->is_lmtp) ) { /* Don't RBL LMTP clients */ - if (config.c_rbl_at_greeting == 0) { /* Don't RBL again if we already did it */ + if (CtdlGetConfigInt("c_rbl_at_greeting") == 0) { /* Don't RBL again if we already did it */ if (rbl_check(message_to_spammer)) { if (server_shutting_down) cprintf("421 %s\r\n", message_to_spammer); @@ -826,7 +826,7 @@ void smtp_data(long offset, long flags) " by %s; %s\n", ChrPtr(sSMTP->helo_node), (long int) CCC->cs_UDSclientUID, - config.c_fqdn, + CtdlGetConfigStr("c_fqdn"), nowstamp); } else { @@ -837,11 +837,11 @@ void smtp_data(long offset, long flags) ChrPtr(sSMTP->helo_node), CCC->cs_host, CCC->cs_addr, - config.c_fqdn, + CtdlGetConfigStr("c_fqdn"), nowstamp); } } - body = CtdlReadMessageBodyBuf(HKEY("."), config.c_maxmsglen, defbody, 1, NULL); + body = CtdlReadMessageBodyBuf(HKEY("."), CtdlGetConfigLong("c_maxmsglen"), defbody, 1, NULL); FreeStrBuf(&defbody); if (body == NULL) { cprintf("550 Unable to save message: internal error.\r\n"); @@ -861,12 +861,12 @@ void smtp_data(long offset, long flags) * to something ugly like "0000058008.Sent Items>" when the message * is read with a Citadel client. */ - if ( (CCC->logged_in) && (config.c_rfc822_strict_from != CFG_SMTP_FROM_NOFILTER) ) { + if ( (CCC->logged_in) && (CtdlGetConfigInt("c_rfc822_strict_from") != CFG_SMTP_FROM_NOFILTER) ) { int validemail = 0; if (!CM_IsEmpty(msg, erFc822Addr) && - ((config.c_rfc822_strict_from == CFG_SMTP_FROM_CORRECT) || - (config.c_rfc822_strict_from == CFG_SMTP_FROM_REJECT) ) ) + ((CtdlGetConfigInt("c_rfc822_strict_from") == CFG_SMTP_FROM_CORRECT) || + (CtdlGetConfigInt("c_rfc822_strict_from") == CFG_SMTP_FROM_REJECT) ) ) { if (!IsEmptyStr(CCC->cs_inet_email)) validemail = strcmp(CCC->cs_inet_email, msg->cm_fields[erFc822Addr]) == 0; @@ -884,14 +884,14 @@ void smtp_data(long offset, long flags) } } - if (!validemail && (config.c_rfc822_strict_from == CFG_SMTP_FROM_REJECT)) { + if (!validemail && (CtdlGetConfigInt("c_rfc822_strict_from") == CFG_SMTP_FROM_REJECT)) { syslog(LOG_ERR, "invalid sender '%s' - rejecting this message", msg->cm_fields[erFc822Addr]); cprintf("550 Invalid sender '%s' - rejecting this message.\r\n", msg->cm_fields[erFc822Addr]); return; } - CM_SetField(msg, eNodeName, CFG_KEY(c_nodename)); - CM_SetField(msg, eHumanNode, CFG_KEY(c_humannode)); + CM_SetField(msg, eNodeName, CtdlGetConfigStr("c_nodename"), strlen(CtdlGetConfigStr("c_nodename"))); + CM_SetField(msg, eHumanNode, CtdlGetConfigStr("c_humannode"), strlen(CtdlGetConfigStr("c_humannode"))); CM_SetField(msg, eOriginalRoom, HKEY(MAILROOM)); if (sSMTP->preferred_sender_name != NULL) CM_SetField(msg, eAuthor, SKEY(sSMTP->preferred_sender_name)); @@ -1143,7 +1143,7 @@ CTDL_MODULE_INIT(smtp) #endif - CtdlRegisterServiceHook(config.c_smtp_port, /* SMTP MTA */ + CtdlRegisterServiceHook(CtdlGetConfigInt("c_smtp_port"), /* SMTP MTA */ NULL, smtp_mta_greeting, smtp_command_loop, @@ -1151,7 +1151,7 @@ CTDL_MODULE_INIT(smtp) CitadelServiceSMTP_MTA); #ifdef HAVE_OPENSSL - CtdlRegisterServiceHook(config.c_smtps_port, + CtdlRegisterServiceHook(CtdlGetConfigInt("c_smtps_port"), /* SMTPS MTA */ NULL, smtps_greeting, smtp_command_loop, @@ -1159,7 +1159,7 @@ CTDL_MODULE_INIT(smtp) CitadelServiceSMTPS_MTA); #endif - CtdlRegisterServiceHook(config.c_msa_port, /* SMTP MSA */ + CtdlRegisterServiceHook(CtdlGetConfigInt("c_msa_port"), /* SMTP MSA */ NULL, smtp_msa_greeting, smtp_command_loop, diff --git a/citadel/modules/smtp/serv_smtpqueue.c b/citadel/modules/smtp/serv_smtpqueue.c index df04bdcc5..56ab4356a 100644 --- a/citadel/modules/smtp/serv_smtpqueue.c +++ b/citadel/modules/smtp/serv_smtpqueue.c @@ -20,21 +20,15 @@ * The VRFY and EXPN commands have been removed from this implementation * because nobody uses these commands anymore, except for spammers. * - * Copyright (c) 1998-2012 by the citadel.org team + * Copyright (c) 1998-2015 by the citadel.org team * - * 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. + * 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. */ #include "sysdep.h" @@ -606,7 +600,7 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt, ParsedURL *Relay) boundary = NewStrBufPlain(HKEY("=_Citadel_Multipart_")); StrBufAppendPrintf(boundary, "%s_%04x%04x", - config.c_fqdn, + CtdlGetConfigStr("c_fqdn"), getpid(), ++seq); @@ -725,7 +719,7 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt, ParsedURL *Relay) /* If not, post it in the Aide> room */ if (successful_bounce == 0) { - CtdlSubmitMsg(bmsg, NULL, config.c_aideroom, QP_EADDR); + CtdlSubmitMsg(bmsg, NULL, CtdlGetConfigStr("c_aideroom"), QP_EADDR); } /* Free up the memory we used */ diff --git a/citadel/modules/wiki/serv_wiki.c b/citadel/modules/wiki/serv_wiki.c index 79845fa8a..44a38153c 100644 --- a/citadel/modules/wiki/serv_wiki.c +++ b/citadel/modules/wiki/serv_wiki.c @@ -1,7 +1,7 @@ /* * Server-side module for Wiki rooms. This handles things like version control. * - * Copyright (c) 2009-2012 by the citadel.org team + * Copyright (c) 2009-2015 by the citadel.org team * * 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. @@ -303,7 +303,7 @@ int wiki_upload_beforesave(struct CtdlMessage *msg, recptypes *recp) { uuid, Now, CCC->user.fullname, - config.c_nodename); + CtdlGetConfigStr("c_nodename")); memolen = CtdlEncodeBase64(encoded_memo, memo, memolen, 0); diff --git a/citadel/modules/xmpp/xmpp_query_namespace.c b/citadel/modules/xmpp/xmpp_query_namespace.c index df7671798..848fcc735 100644 --- a/citadel/modules/xmpp/xmpp_query_namespace.c +++ b/citadel/modules/xmpp/xmpp_query_namespace.c @@ -61,7 +61,7 @@ void xmpp_roster_item(struct CitContext *cptr) { xmlesc(xmlbuf1, cptr->cs_inet_email, sizeof xmlbuf1), xmlesc(xmlbuf2, cptr->user.fullname, sizeof xmlbuf2) ); - cprintf("%s", xmlesc(xmlbuf1, config.c_humannode, sizeof xmlbuf1)); + cprintf("%s", xmlesc(xmlbuf1, CtdlGetConfigStr("c_humannode"), sizeof xmlbuf1)); cprintf(""); }