]> code.citadel.org Git - citadel.git/blobdiff - citadel/config.c
random acts of style cleanup
[citadel.git] / citadel / config.c
index f3357d9d7b1bbc771879d007213a7a8f583e76d2..9abc9af4bac644a425c41e909a62bdcce8efa87f 100644 (file)
@@ -1,16 +1,11 @@
-/*
- * Read and write the citadel.config file
- *
- * Copyright (c) 1987-2021 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.
- */
+//
+// Read and write the citadel.config file
+//
+// Copyright (c) 1987-2021 by the citadel.org team
+//
+// This program is open source software.  Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License, version 3.
+// The program is distributed without any warranty, expressed or implied.
 
 #include "sysdep.h"
 #include <stdlib.h>
@@ -27,8 +22,7 @@ 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))
        {
@@ -38,10 +32,8 @@ void config_warn_if_port_unset(char *key, int default_port)
 }
 
 
-void config_warn_if_empty(char *key)
-{
-       if (IsEmptyStr(CtdlGetConfigStr(key)))
-       {
+void config_warn_if_empty(char *key) {
+       if (IsEmptyStr(CtdlGetConfigStr(key))) {
                syslog(LOG_ERR, "config: setting %s is empty, but must not - check your config!", key);
        }
 }
@@ -144,8 +136,7 @@ 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.
  */
-void migrate_legacy_config(struct legacy_config *lconfig)
-{
+void migrate_legacy_config(struct legacy_config *lconfig) {
        CtdlSetConfigStr(       "c_nodename"            ,       lconfig->c_nodename             );
        CtdlSetConfigStr(       "c_fqdn"                ,       lconfig->c_fqdn                 );
        CtdlSetConfigStr(       "c_humannode"           ,       lconfig->c_humannode            );
@@ -270,15 +261,6 @@ void initialize_config_system(void) {
                brand_new_installation_set_defaults();
        }
 
-       /* Only allow LDAP auth mode if we actually have LDAP support */
-#ifndef HAVE_LDAP
-       if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP) || (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD)) {
-               fprintf(stderr, "Your system is configured for LDAP authentication,\n"
-                               "but you are running a server built without OpenLDAP support.\n");
-               exit(CTDL_EXIT_UNSUP_AUTH);
-       }
-#endif
-
         /* 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.
@@ -319,8 +301,7 @@ void initialize_config_system(void) {
  * Called when Citadel server is shutting down.
  * Clears out the config hash table.
  */
-void shutdown_config_system(void) 
-{
+void shutdown_config_system(void) {
        DeleteHash(&ctdlconfig);
 }
 
@@ -328,8 +309,7 @@ void shutdown_config_system(void)
 /*
  * Set a system config value.  Simple key/value here.
  */
-void CtdlSetConfigStr(char *key, char *value)
-{
+void CtdlSetConfigStr(char *key, char *value) {
        int key_len = strlen(key);
        int value_len = strlen(value);
 
@@ -350,8 +330,7 @@ void CtdlSetConfigStr(char *key, char *value)
 /*
  * Set a numeric system config value (long integer)
  */
-void CtdlSetConfigLong(char *key, long value)
-{
+void CtdlSetConfigLong(char *key, long value) {
        char longstr[256];
        sprintf(longstr, "%ld", value);
        CtdlSetConfigStr(key, longstr);
@@ -361,8 +340,7 @@ void CtdlSetConfigLong(char *key, long value)
 /*
  * Set a numeric system config value (integer)
  */
-void CtdlSetConfigInt(char *key, int value)
-{
+void CtdlSetConfigInt(char *key, int value) {
        char intstr[256];
        sprintf(intstr, "%d", value);
        CtdlSetConfigStr(key, intstr);
@@ -372,8 +350,7 @@ void CtdlSetConfigInt(char *key, int value)
 /*
  * Delete a system config value.
  */
-void CtdlDelConfig(char *key)
-{
+void CtdlDelConfig(char *key) {
        int key_len = strlen(key);
 
        if (IsEmptyStr(key)) return;
@@ -395,8 +372,7 @@ void CtdlDelConfig(char *key)
 /*
  * Fetch a system config value.  Caller does *not* own the returned value and may not alter it.
  */
-char *CtdlGetConfigStr(char *key)
-{
+char *CtdlGetConfigStr(char *key) {
        char *value = NULL;
        struct cdbdata *cdb;
        int key_len = strlen(key);
@@ -428,8 +404,7 @@ char *CtdlGetConfigStr(char *key)
 /*
  * Fetch a system config value - integer
  */
-int CtdlGetConfigInt(char *key)
-{
+int CtdlGetConfigInt(char *key) {
        char *s = CtdlGetConfigStr(key);
        if (s) return atoi(s);
        return 0;
@@ -439,8 +414,7 @@ int CtdlGetConfigInt(char *key)
 /*
  * Fetch a system config value - long integer
  */
-long CtdlGetConfigLong(char *key)
-{
+long CtdlGetConfigLong(char *key) {
        char *s = CtdlGetConfigStr(key);
        if (s) return atol(s);
        return 0;
@@ -452,9 +426,12 @@ void CtdlGetSysConfigBackend(long msgnum, void *userdata) {
 }
 
 
+/*
+ * This is for fetching longer configuration sets which are stored in the message base.
+ */
 char *CtdlGetSysConfig(char *sysconfname) {
        char hold_rm[ROOMNAMELEN];
-       long msgnum;
+       long msgnum = -1;
        char *conf;
        struct CtdlMessage *msg;
        char buf[SIZ];
@@ -465,14 +442,22 @@ 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);
-       msgnum = config_msgnum;
-       end_critical_section(S_CONFIG);
+       /* The new way: hunt for the message number in the config database */
+       msgnum = CtdlGetConfigLong(sysconfname);
+
+       /* Legacy format: hunt through the local system configuration room for a message with a matching MIME type */
+       if (msgnum <= 0) {
+               begin_critical_section(S_CONFIG);
+               config_msgnum = -1;
+               CtdlForEachMessage(MSGS_LAST, 1, NULL, sysconfname, NULL, CtdlGetSysConfigBackend, NULL);
+               msgnum = config_msgnum;
+               end_critical_section(S_CONFIG);
+               if (msgnum > 0) {
+                       CtdlSetConfigLong(sysconfname, msgnum);         // store it the new way so we don't have to do this again
+               }
+       }
 
-       if (msgnum < 0L) {
+       if (msgnum <= 0) {
                conf = NULL;
        }
        else {
@@ -488,7 +473,7 @@ char *CtdlGetSysConfig(char *sysconfname) {
 
        CtdlGetRoom(&CC->room, hold_rm);
 
-       if (conf != NULL) {
+       if (conf != NULL) {             // Strip the MIME headers, leaving only the content
                do {
                        extract_token(buf, conf, 0, '\n', sizeof buf);
                        strcpy(conf, &conf[strlen(buf)+1]);
@@ -499,6 +484,24 @@ char *CtdlGetSysConfig(char *sysconfname) {
 }
 
 
+/*
+ * This is for storing longer configuration sets which are stored in the message base.
+ */
 void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) {
-       CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 1, 0);
+       long old_msgnum = -1;
+       long new_msgnum = -1;
+
+       // Search for the previous copy of this config item, so we can delete it
+       old_msgnum = CtdlGetConfigLong(sysconfname);
+
+       // Go ahead and save it, and write the new msgnum to the config database so we can find it again
+       new_msgnum = CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 0);
+       if (new_msgnum > 0) {
+               CtdlSetConfigLong(sysconfname, new_msgnum);
+
+               // Now delete the old copy
+               if (old_msgnum > 0) {
+                       CtdlDeleteMessages(SYSCONFIGROOM, &old_msgnum, 1, "");
+               }
+       }
 }