From 88c52d18e496b38205b30eff94c14eef59558f51 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Thu, 1 Jan 2015 20:50:15 +0100 Subject: [PATCH] Add more plausability checks during startup so the admin knows if something is fishy. --- citadel/citserver.c | 1 + citadel/config.c | 43 +++++++++++++++++++++++++++++++++++++++++++ citadel/config.h | 1 + 3 files changed, 45 insertions(+) diff --git a/citadel/citserver.c b/citadel/citserver.c index d0902e266..4a1070b23 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -123,6 +123,7 @@ void master_startup(void) { syslog(LOG_DEBUG, "master_startup() started\n"); time(&server_startup_time); get_config(); + validate_config(); syslog(LOG_INFO, "Checking directory access"); if ((pw = getpwuid(CTDLUID)) == NULL) { diff --git a/citadel/config.c b/citadel/config.c index 28084aa1e..34028abb0 100644 --- a/citadel/config.c +++ b/citadel/config.c @@ -22,6 +22,49 @@ struct config config; struct configlen configlen; +#define STR_NOT_EMPTY(CFG_FIELDNAME) if (IsEmptyStr(config.CFG_FIELDNAME)) \ + syslog(LOG_EMERG, "configuration setting "#CFG_FIELDNAME" is empty, but must not - check your config!"); + +#define TEST_PORT(CFG_PORT, DEFAULTPORT) \ + if ((config.CFG_PORT < -1) || \ + (config.CFG_PORT == 0) || \ + (config.CFG_PORT > UINT16_MAX)) \ + syslog(LOG_EMERG, "configuration setting "#CFG_PORT" is not -1 (disabled) or a valid TCP-Port - check your config! Default setting is: "#DEFAULTPORT); + + +void validate_config(void) { +/* these shouldn't be empty: */ + STR_NOT_EMPTY(c_fqdn); + + STR_NOT_EMPTY(c_baseroom); + STR_NOT_EMPTY(c_aideroom); + STR_NOT_EMPTY(c_twitroom); + STR_NOT_EMPTY(c_nodename); + STR_NOT_EMPTY(c_default_cal_zone); + +/* we bind a lot of ports: */ + TEST_PORT(c_smtp_port, 25); + TEST_PORT(c_pop3_port, 110); + TEST_PORT(c_imap_port, 143); + TEST_PORT(c_msa_port, 587); + TEST_PORT(c_port_number, 504); + TEST_PORT(c_smtps_port, 465); + TEST_PORT(c_pop3s_port, 995); + TEST_PORT(c_imaps_port, 993); + TEST_PORT(c_pftcpdict_port, -1); + TEST_PORT(c_managesieve_port, 2020); + TEST_PORT(c_xmpp_c2s_port, 5222); + TEST_PORT(c_xmpp_s2s_port, 5269); + TEST_PORT(c_nntp_port, 119); + TEST_PORT(c_nntps_port, 563); + + if (config.c_ctdluid == 0) + syslog(LOG_EMERG, "citadel should not be configured to run as root! Check the value of c_ctdluid"); + else if (getpwuid(CTDLUID) == NULL) + syslog(LOG_EMERG, "The UID (%d) citadel is configured to use is not defined in your system (/etc/passwd?)! Check the value of c_ctdluid", CTDLUID); + +} + /* * Put some sane default values into our configuration. Some will be overridden when we run setup. */ diff --git a/citadel/config.h b/citadel/config.h index d1529c5a0..eb61711cc 100644 --- a/citadel/config.h +++ b/citadel/config.h @@ -19,3 +19,4 @@ void put_config(void); char *CtdlGetSysConfig(char *sysconfname); void CtdlPutSysConfig(char *sysconfname, char *sysconfdata); +void validate_config(void); -- 2.30.2