/*
* Read and write the citadel.config file
*
- * Copyright (c) 1987-2015 by the citadel.org team
+ * Copyright (c) 1987-2017 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"
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",
+ syslog(LOG_ERR,
+ "config: setting %s is not -1 (disabled) or a valid TCP-Port - check your config! Default setting is: %d",
key, default_port
);
}
{
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) {
/*
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) citadel is configured to use is not defined in your system (/etc/passwd?)!", ctdluid);
}
-
}
+
/*
* Put some sane default values into our configuration. Some will be overridden when we run setup.
*/
}
-
/*
* Migrate a supplied legacy configuration to the new in-db format.
* No individual site should ever have to do this more than once.
}
-
/*
* Called during the initialization of Citadel server.
* It verifies the system's integrity and reads citadel.config into memory.
/* 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);
}
}
-
/*
* Called when Citadel server is shutting down.
* Clears out the config hash table.
}
-
/*
* Set a system config value. Simple key/value here.
*/
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);
}
+/*
+ * 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.
*/
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;
}
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);
}
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;
}
}
-
-/**********************************************************************/
-
-
-
-
-
-
-
-
-
-
void CtdlGetSysConfigBackend(long msgnum, void *userdata) {
config_msgnum = msgnum;
}
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);
conf = NULL;
}
else {
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg != NULL) {
conf = strdup(msg->cm_fields[eMesageText]);
CM_Free(msg);
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);
}
void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) {
CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 1, 0);
}
-