Remove managesieve framework because we are removing sieve
[citadel.git] / citadel / config.c
index f41533c5b13b858f27bf70d4f929c38211a76319..d5dc85d98c15e90a774276555ef19397c023aee6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Read and write the citadel.config file
  *
- * Copyright (c) 1987-2015 by the citadel.org team
+ * Copyright (c) 1987-2020 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.
  */
 
 #include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
 #include <stdio.h>
+#include <netdb.h>
 #include <sys/utsname.h>
 #include <libcitadel.h>
+#include <assert.h>
 #include "config.h"
 #include "ctdl_module.h"
 
@@ -23,15 +27,13 @@ long config_msgnum = 0;
 HashList *ctdlconfig = NULL;   // new configuration
 
 
-void config_warn_if_port_unset(char *key, int default_port)                    \
+void config_warn_if_port_unset(char *key, int default_port)
 {
        int p = CtdlGetConfigInt(key);
        if ((p < -1) || (p == 0) || (p > UINT16_MAX))
        {
-               syslog(LOG_EMERG,
-                       "configuration setting %s is not -1 (disabled) or a valid TCP-Port - check your config! Default setting is: %d",
-                       key, default_port
-               );
+               syslog(LOG_ERR, "config: setting %s is not -1 (disabled) or a valid TCP port - setting to default %d", key, default_port);
+               CtdlSetConfigInt(key, default_port);
        }
 }
 
@@ -40,12 +42,11 @@ void config_warn_if_empty(char *key)
 {
        if (IsEmptyStr(CtdlGetConfigStr(key)))
        {
-               syslog(LOG_EMERG, "configuration setting %s is empty, but must not - check your config!", key);
+               syslog(LOG_ERR, "config: setting %s is empty, but must not - check your config!", key);
        }
 }
 
 
-
 void validate_config(void) {
 
        /*
@@ -56,32 +57,30 @@ void validate_config(void) {
        config_warn_if_empty("c_aideroom");
        config_warn_if_empty("c_twitroom");
        config_warn_if_empty("c_nodename");
-       config_warn_if_empty("c_default_cal_zone");
 
        /*
         * Sanity check for port bindings
         */
-       config_warn_if_port_unset("c_smtp_port", 25);
-       config_warn_if_port_unset("c_pop3_port", 110);
-       config_warn_if_port_unset("c_imap_port", 143);
-       config_warn_if_port_unset("c_msa_port", 587);
-       config_warn_if_port_unset("c_port_number", 504);
-       config_warn_if_port_unset("c_smtps_port", 465);
-       config_warn_if_port_unset("c_pop3s_port", 995);
-       config_warn_if_port_unset("c_imaps_port", 993);
-       config_warn_if_port_unset("c_pftcpdict_port", -1);
-       config_warn_if_port_unset("c_managesieve_port", 2020);
-       config_warn_if_port_unset("c_xmpp_c2s_port", 5222);
-       config_warn_if_port_unset("c_xmpp_s2s_port", 5269);
-       config_warn_if_port_unset("c_nntp_port", 119);
-       config_warn_if_port_unset("c_nntps_port", 563);
+       config_warn_if_port_unset("c_smtp_port",        25);
+       config_warn_if_port_unset("c_pop3_port",        110);
+       config_warn_if_port_unset("c_imap_port",        143);
+       config_warn_if_port_unset("c_msa_port",         587);
+       config_warn_if_port_unset("c_port_number",      504);
+       config_warn_if_port_unset("c_smtps_port",       465);
+       config_warn_if_port_unset("c_pop3s_port",       995);
+       config_warn_if_port_unset("c_imaps_port",       993);
+       config_warn_if_port_unset("c_pftcpdict_port",   -1);
+       config_warn_if_port_unset("c_xmpp_c2s_port",    5222);
+       config_warn_if_port_unset("c_xmpp_s2s_port",    5269);
+       config_warn_if_port_unset("c_nntp_port",        119);
+       config_warn_if_port_unset("c_nntps_port",       563);
 
        if (getpwuid(ctdluid) == NULL) {
-               syslog(LOG_EMERG, "The UID (%d) citadel is configured to use is not defined in your system (/etc/passwd?)!", ctdluid);
+               syslog(LOG_ERR, "config: uid (%d) does not exist ... citserver will run as root", ctdluid);
        }
-       
 }
 
+
 /*
  * Put some sane default values into our configuration.  Some will be overridden when we run setup.
  */
@@ -129,7 +128,6 @@ void brand_new_installation_set_defaults(void) {
        CtdlSetConfigInt("c_pop3s_port",        995);
        CtdlSetConfigInt("c_imaps_port",        993);
        CtdlSetConfigInt("c_pftcpdict_port",    -1);
-       CtdlSetConfigInt("c_managesieve_port",  2020);
        CtdlSetConfigInt("c_xmpp_c2s_port",     5222);
        CtdlSetConfigInt("c_xmpp_s2s_port",     5269);
        CtdlSetConfigInt("c_nntp_port",         119);
@@ -142,7 +140,6 @@ void brand_new_installation_set_defaults(void) {
 }
 
 
-
 /*
  * Migrate a supplied legacy configuration to the new in-db format.
  * No individual site should ever have to do this more than once.
@@ -203,15 +200,8 @@ void migrate_legacy_config(struct legacy_config *lconfig)
        CtdlSetConfigStr(       "c_journal_dest"        ,       lconfig->c_journal_dest         );
        CtdlSetConfigStr(       "c_default_cal_zone"    ,       lconfig->c_default_cal_zone     );
        CtdlSetConfigInt(       "c_pftcpdict_port"      ,       lconfig->c_pftcpdict_port       );
-       CtdlSetConfigInt(       "c_managesieve_port"    ,       lconfig->c_managesieve_port     );
        CtdlSetConfigInt(       "c_auth_mode"           ,       lconfig->c_auth_mode            );
-       CtdlSetConfigStr(       "c_funambol_host"       ,       lconfig->c_funambol_host        );
-       CtdlSetConfigInt(       "c_funambol_port"       ,       lconfig->c_funambol_port        );
-       CtdlSetConfigStr(       "c_funambol_source"     ,       lconfig->c_funambol_source      );
-       CtdlSetConfigStr(       "c_funambol_auth"       ,       lconfig->c_funambol_auth        );
        CtdlSetConfigInt(       "c_rbl_at_greeting"     ,       lconfig->c_rbl_at_greeting      );
-       CtdlSetConfigStr(       "c_master_user"         ,       lconfig->c_master_user          );
-       CtdlSetConfigStr(       "c_master_pass"         ,       lconfig->c_master_pass          );
        CtdlSetConfigStr(       "c_pager_program"       ,       lconfig->c_pager_program        );
        CtdlSetConfigInt(       "c_imap_keep_from"      ,       lconfig->c_imap_keep_from       );
        CtdlSetConfigInt(       "c_xmpp_c2s_port"       ,       lconfig->c_xmpp_c2s_port        );
@@ -225,7 +215,6 @@ void migrate_legacy_config(struct legacy_config *lconfig)
 }
 
 
-
 /*
  * Called during the initialization of Citadel server.
  * It verifies the system's integrity and reads citadel.config into memory.
@@ -238,12 +227,8 @@ void initialize_config_system(void) {
 
        /* Ensure that we are linked to the correct version of libcitadel */
        if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
-               fprintf(stderr, "You are running libcitadel version %d.%02d\n",
-                       (libcitadel_version_number() / 100), (libcitadel_version_number() % 100)
-               );
-               fprintf(stderr, "citserver was compiled against version %d.%02d\n",
-                       (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100)
-               );
+               fprintf(stderr, "You are running libcitadel version %d\n", libcitadel_version_number());
+               fprintf(stderr, "citserver was compiled against version %d\n", LIBCITADEL_VERSION_NUMBER);
                exit(CTDLEXIT_LIBCITADEL);
        }
 
@@ -259,7 +244,7 @@ void initialize_config_system(void) {
        memset(&lconfig, 0, sizeof(struct legacy_config));
        cfp = fopen(file_citadel_config, "rb");
        if (cfp != NULL) {
-               if (CtdlGetConfigLong("c_config_created_or_migrated") <= 0) {
+               if (CtdlGetConfigLong("c_config_created_or_migrated") > 0) {
                        fprintf(stderr, "Citadel Server found BOTH legacy and new configurations present.\n");
                        fprintf(stderr, "Exiting to prevent data corruption.\n");
                        exit(CTDLEXIT_CONFIG);
@@ -329,6 +314,9 @@ void initialize_config_system(void) {
        if (CtdlGetConfigLong("c_pop3_fastest") == 0)   CtdlSetConfigLong("c_pop3_fastest", 3600);      // once per hour default
        if (CtdlGetConfigLong("c_pop3_fastest") < 300)  CtdlSetConfigLong("c_pop3_fastest", 300);       // 5 minutes min
 
+       /* LDAP sync frequency */
+       if (CtdlGetConfigLong("c_ldap_sync_freq") == 0) CtdlSetConfigLong("c_ldap_sync_freq", 300);     // every 5 minutes default
+
        /* "create new user" only works with native authentication mode */
        if (CtdlGetConfigInt("c_auth_mode") != AUTHMODE_NATIVE) {
                CtdlSetConfigInt("c_disable_newu", 1);
@@ -336,7 +324,6 @@ void initialize_config_system(void) {
 }
 
 
-
 /*
  * Called when Citadel server is shutting down.
  * Clears out the config hash table.
@@ -347,7 +334,6 @@ void shutdown_config_system(void)
 }
 
 
-
 /*
  * Set a system config value.  Simple key/value here.
  */
@@ -356,9 +342,6 @@ void CtdlSetConfigStr(char *key, char *value)
        int key_len = strlen(key);
        int value_len = strlen(value);
 
-       /* FIXME we are noisy logging for now */
-       syslog(LOG_DEBUG, "\033[31mSET CONFIG: '%s' = '%s'\033[0m", key, value);
-
        /* Save it in memory */
        Put(ctdlconfig, key, key_len, strdup(value), NULL);
 
@@ -395,6 +378,29 @@ void CtdlSetConfigInt(char *key, int value)
 }
 
 
+/*
+ * Delete a system config value.
+ */
+void CtdlDelConfig(char *key)
+{
+       int key_len = strlen(key);
+
+       if (IsEmptyStr(key)) return;
+
+       /* Delete from the database. */
+       cdb_delete(CDB_CONFIG, key, key_len);
+
+       /* Delete from the in-memory cache */
+       HashPos *Pos = GetNewHashPos(ctdlconfig, 1);
+       if (GetHashPosFromKey(ctdlconfig, key, key_len, Pos)) {
+               DeleteEntryFromHash(ctdlconfig, Pos);
+       }
+       DeleteHashPos(&Pos);
+
+       assert(Pos == NULL);    // no memory leaks allowed
+}
+
+
 /*
  * Fetch a system config value.  Caller does *not* own the returned value and may not alter it.
  */
@@ -406,16 +412,9 @@ char *CtdlGetConfigStr(char *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))
        {
-               syslog(LOG_DEBUG, "\033[32mGET CONFIG: '%s' = '%s'\033[0m", key, value);
                return value;
        }
 
@@ -424,7 +423,6 @@ char *CtdlGetConfigStr(char *key)
        cdb = cdb_fetch(CDB_CONFIG, key, key_len);
 
        if (cdb == NULL) {      /* nope, not there either. */
-               syslog(LOG_DEBUG, "\033[32mGET CONFIG: '%s' = NULL\033[0m", key);
                return(NULL);
        }
 
@@ -432,7 +430,6 @@ char *CtdlGetConfigStr(char *key)
        value = strdup(cdb->ptr + key_len + 1);         /* The key was stored there too; skip past it */
        cdb_free(cdb);
        Put(ctdlconfig, key, key_len, value, NULL);
-       syslog(LOG_DEBUG, "\033[32mGET CONFIG: '%s' = '%s'\033[0m", key, value);
        return value;
 }
 
@@ -459,18 +456,6 @@ long CtdlGetConfigLong(char *key)
 }
 
 
-
-/**********************************************************************/
-
-
-
-
-
-
-
-
-
-
 void CtdlGetSysConfigBackend(long msgnum, void *userdata) {
        config_msgnum = msgnum;
 }
@@ -489,12 +474,10 @@ char *CtdlGetSysConfig(char *sysconfname) {
                return NULL;
        }
 
-
        /* We want the last (and probably only) config in this room */
        begin_critical_section(S_CONFIG);
        config_msgnum = (-1L);
-       CtdlForEachMessage(MSGS_LAST, 1, NULL, sysconfname, NULL,
-                          CtdlGetSysConfigBackend, NULL);
+       CtdlForEachMessage(MSGS_LAST, 1, NULL, sysconfname, NULL, CtdlGetSysConfigBackend, NULL);
        msgnum = config_msgnum;
        end_critical_section(S_CONFIG);
 
@@ -502,7 +485,7 @@ char *CtdlGetSysConfig(char *sysconfname) {
                conf = NULL;
        }
        else {
-               msg = CtdlFetchMessage(msgnum, 1);
+               msg = CtdlFetchMessage(msgnum, 1, 1);
                if (msg != NULL) {
                        conf = strdup(msg->cm_fields[eMesageText]);
                        CM_Free(msg);
@@ -514,10 +497,12 @@ char *CtdlGetSysConfig(char *sysconfname) {
 
        CtdlGetRoom(&CC->room, hold_rm);
 
-       if (conf != NULL) do {
+       if (conf != NULL) {
+               do {
                        extract_token(buf, conf, 0, '\n', sizeof buf);
                        strcpy(conf, &conf[strlen(buf)+1]);
                } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
+       }
 
        return(conf);
 }
@@ -526,4 +511,3 @@ char *CtdlGetSysConfig(char *sysconfname) {
 void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) {
        CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 1, 0);
 }
-