From efb16159f32a6f97350b05acef6db949cdad5f2c Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Fri, 24 Sep 2021 17:44:57 +0200 Subject: [PATCH] Add check for missing include "snomasks.default.conf"; Well, not literally, but indirectly :D --- include/h.h | 1 + src/conf.c | 2 +- src/log.c | 34 +++++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/h.h b/include/h.h index dc4d69fc7..ea897457a 100644 --- a/include/h.h +++ b/include/h.h @@ -1123,6 +1123,7 @@ extern LogData *log_data_socket_error(int fd); extern LogData *log_data_link_block(ConfigItem_link *link); extern LogData *log_data_tkl(const char *key, TKL *tkl); extern LogData *log_data_tls_error(void); +extern int log_tests(void); extern void log_blocks_switchover(void); extern void postconf_defaults_log_block(void); extern LogLevel log_level_stringtoval(const char *str); diff --git a/src/conf.c b/src/conf.c index 2336ca291..5b8d1e4ad 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1936,7 +1936,7 @@ void config_test_reset(void) int config_test_all(void) { if ((config_test_blocks() < 0) || (callbacks_check() < 0) || (efunctions_check() < 0) || - reloadable_perm_module_unloaded() || !tls_tests()) + reloadable_perm_module_unloaded() || !tls_tests() || !log_tests()) { return 0; } diff --git a/src/log.c b/src/log.c index 8a608f4d8..d2168289d 100644 --- a/src/log.c +++ b/src/log.c @@ -33,6 +33,7 @@ /* Variables */ Log *logs[NUM_LOG_DESTINATIONS] = { NULL, NULL, NULL, NULL, NULL }; Log *temp_logs[NUM_LOG_DESTINATIONS] = { NULL, NULL, NULL, NULL, NULL }; +static int snomask_num_destinations = 0; /* Forward declarations */ int log_sources_match(LogSource *logsource, LogLevel loglevel, const char *subsystem, const char *event_id, int matched_already); @@ -180,6 +181,7 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) if (!strcmp(cep->name, "snomask")) { destinations++; + snomask_num_destinations++; /* We need to validate the parameter here as well */ if (!cep->value) { @@ -1658,20 +1660,25 @@ void free_log_block(Log *l) } } -void log_blocks_switchover(void) -{ - int i; - for (i=0; i < NUM_LOG_DESTINATIONS; i++) - free_log_block(logs[i]); - memcpy(logs, temp_logs, sizeof(logs)); - memset(temp_logs, 0, sizeof(temp_logs)); -} - /* TODO: if logging to the same file from multiple log { } * blocks, then we would have opened the file twice. * Better to use an extra layer to keep track of files. */ +int log_tests(void) +{ + if (snomask_num_destinations <= 1) + { + unreal_log(ULOG_ERROR, "config", "LOG_SNOMASK_BLOCK_MISSING", NULL, + "Missing log blocks with snomask configuration.\n" + "Please add the following line to your unrealircd.conf: " + "include \"snomasks.default.conf\";"); + return 0; + } + snomask_num_destinations = 0; + return 1; +} + void postconf_defaults_log_block(void) { Log *l; @@ -1711,3 +1718,12 @@ void postconf_defaults_log_block(void) AppendListItem(ls, l->sources); ls = add_log_source("!kick.REMOTE_CLIENT_KICK"); } + +void log_blocks_switchover(void) +{ + int i; + for (i=0; i < NUM_LOG_DESTINATIONS; i++) + free_log_block(logs[i]); + memcpy(logs, temp_logs, sizeof(logs)); + memset(temp_logs, 0, sizeof(temp_logs)); +}