config migration endless typing meow
authorArt Cancro <ajc@uncensored.citadel.org>
Tue, 5 May 2015 02:38:07 +0000 (22:38 -0400)
committerArt Cancro <ajc@uncensored.citadel.org>
Tue, 5 May 2015 02:38:07 +0000 (22:38 -0400)
citadel/config.c
citadel/ldap.c
citadel/modules/rssclient/serv_rssclient.c
citadel/modules/sieve/serv_sieve.c
citadel/modules/smtp/serv_smtp.c
citadel/modules/smtp/serv_smtpqueue.c
citadel/modules/wiki/serv_wiki.c
citadel/modules/xmpp/xmpp_query_namespace.c

index fffdadc6e0a8adfcba8f6b11c862103cf9a0f5e5..4115f1b5af83ff6f3b8934dfd514f2ccc3c761b3 100644 (file)
@@ -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))
        {
index 9d6ddf16389c57ebb76d44ab99e5c87caca1fd28..97288637fdcad3c2ec4660e1f579dd1544d57038 100644 (file)
@@ -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);
index cc03230c9bccc3c3fcaa0dd22327b274477804f4..ac4e7da7d0e35c27e3b520f29abfdf871c31ffa3 100644 (file)
@@ -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;
index ed69de8587f600d5cb00a265cc63d3085a7f9b32..ddb1e99ba06afd2e3ef40016dee3aa21e1f48a8b 100644 (file)
@@ -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;
                }
index a93bb438e384231052681d5ac4346aba074e8feb..63422fbdcfd92127f52e57d2e2ce62ea79e8ad57 100644 (file)
@@ -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,
index df04bdcc5f713f66ebdb138c9d2bc73ab1067458..56ab4356ae55508e02edbcd4958f5ea5d007ff7f 100644 (file)
  * 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 */
index 79845fa8a341d0d25cbc24521b8138bbac54f1b5..44a38153c76ab49a991a9c5c566b0ed94565e6db 100644 (file)
@@ -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);
 
index df7671798a280cbccf6f04756c08fb5845315ca0..848fcc735897a79eceeab0c876098c399638155b 100644 (file)
@@ -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("<group>%s</group>", xmlesc(xmlbuf1, config.c_humannode, sizeof xmlbuf1));
+       cprintf("<group>%s</group>", xmlesc(xmlbuf1, CtdlGetConfigStr("c_humannode"), sizeof xmlbuf1));
        cprintf("</item>");
 }