commit b65f323: [Minor] Fix strict config checks

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Feb 21 11:21:13 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-02-21 11:08:13 +0000
URL: https://github.com/rspamd/rspamd/commit/b65f3234c48e80ef3494dfb58a9c48cb78822fb7 (HEAD -> master)

[Minor] Fix strict config checks

---
 src/libserver/cfg_file.h  |  2 +-
 src/libserver/cfg_utils.c | 10 +++++++---
 src/lua/lua_common.c      | 14 +++++++++++++-
 src/lua/lua_common.h      |  2 +-
 src/lua/lua_config.c      |  4 ++--
 src/lua/lua_util.c        |  2 +-
 src/rspamadm/configdump.c |  9 ++-------
 src/rspamadm/confighelp.c |  2 +-
 src/rspamadm/configtest.c |  2 +-
 src/rspamd.c              |  4 ++--
 10 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 1d782dd8b..b368464a0 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -656,7 +656,7 @@ void rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars)
  * @param reconfig
  * @return
  */
-gboolean rspamd_init_filters (struct rspamd_config *cfg, bool reconfig);
+gboolean rspamd_init_filters (struct rspamd_config *cfg, bool reconfig, bool strict);
 
 /**
  * Add new symbol to the metric
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index bcebb9f93..6a076e673 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -1532,7 +1532,7 @@ rspamd_check_worker (struct rspamd_config *cfg, worker_t *wrk)
 }
 
 gboolean
-rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
+rspamd_init_filters (struct rspamd_config *cfg, bool reconfig, bool strict)
 {
 	GList *cur;
 	module_t *mod, **pmod;
@@ -1583,8 +1583,12 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
 			}
 			else {
 				if (!mod->module_config_func (cfg)) {
-					msg_info_config ("config of %s failed!", mod->name);
+					msg_err_config ("config of %s failed", mod->name);
 					ret = FALSE;
+
+					if (strict) {
+						return FALSE;
+					}
 				}
 			}
 		}
@@ -1596,7 +1600,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
 		cur = g_list_next (cur);
 	}
 
-	ret = rspamd_init_lua_filters (cfg, 0) && ret;
+	ret = rspamd_init_lua_filters (cfg, 0, strict) && ret;
 
 	return ret;
 }
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 248f1dbc3..2087fe592 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -1075,7 +1075,7 @@ rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name,
 }
 
 gboolean
-rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
+rspamd_init_lua_filters (struct rspamd_config *cfg, bool force_load, bool strict)
 {
 	struct rspamd_config **pcfg;
 	GList *cur;
@@ -1119,6 +1119,10 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
 				rspamd_plugins_table_push_elt (L, "disabled_failed",
 						module->name);
 
+				if (strict) {
+					return FALSE;
+				}
+
 				cur = g_list_next (cur);
 				continue;
 			}
@@ -1143,6 +1147,10 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
 				munmap (data, fsize);
 				g_free (lua_fname);
 
+				if (strict) {
+					return FALSE;
+				}
+
 				cur = g_list_next (cur);
 				continue;
 			}
@@ -1159,6 +1167,10 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
 				rspamd_plugins_table_push_elt (L, "disabled_failed",
 						module->name);
 
+				if (strict) {
+					return FALSE;
+				}
+
 				cur = g_list_next (cur);
 				continue;
 			}
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 6ded08eb9..53e925832 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -203,7 +203,7 @@ rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name,
  * Load and initialize lua plugins
  */
 gboolean
-rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load);
+rspamd_init_lua_filters (struct rspamd_config *cfg, bool force_load, bool strict);
 
 /**
  * Initialize new locked lua_State structure
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 7f993e777..8afe8fbfe 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -4257,7 +4257,7 @@ lua_config_init_modules (lua_State *L)
 
 	if (cfg != NULL) {
 		rspamd_lua_post_load_config (cfg);
-		lua_pushboolean (L, rspamd_init_filters (cfg, FALSE));
+		lua_pushboolean (L, rspamd_init_filters (cfg, false, false));
 	}
 	else {
 		return luaL_error (L, "invalid arguments");
@@ -4282,7 +4282,7 @@ lua_config_init_subsystem (lua_State *L)
 		for (i = 0; i < nparts; i ++) {
 			if (strcmp (parts[i], "filters") == 0) {
 				rspamd_lua_post_load_config (cfg);
-				rspamd_init_filters (cfg, FALSE);
+				rspamd_init_filters (cfg, false, false);
 			}
 			else if (strcmp (parts[i], "langdet") == 0) {
 				if (!cfg->lang_det) {
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 0b52cfbdc..91cc18800 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -884,7 +884,7 @@ lua_util_process_message (lua_State *L)
 
 	if (cfg != NULL && message != NULL) {
 		base = ev_loop_new (EVFLAG_SIGNALFD|EVBACKEND_ALL);
-		rspamd_init_filters (cfg, FALSE);
+		rspamd_init_filters (cfg, false, false);
 		task = rspamd_task_new (NULL, cfg, NULL, NULL, base, FALSE);
 		task->msg.begin = rspamd_mempool_alloc (task->task_pool, mlen);
 		rspamd_strlcpy ((gpointer)task->msg.begin, message, mlen);
diff --git a/src/rspamadm/configdump.c b/src/rspamadm/configdump.c
index de45d1cee..bbd219e3d 100644
--- a/src/rspamadm/configdump.c
+++ b/src/rspamadm/configdump.c
@@ -285,13 +285,8 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd
 		/* Do post-load actions */
 		rspamd_lua_post_load_config (cfg);
 
-		if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) {
-			ret = FALSE;
-		}
-
-		if (ret) {
-			ret = rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_SYMCACHE);
-		}
+		(void)rspamd_init_filters (rspamd_main->cfg, false, false);
+		rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_SYMCACHE);
 	}
 
 	if (ret) {
diff --git a/src/rspamadm/confighelp.c b/src/rspamadm/confighelp.c
index 53f8dbbe9..f5695ed53 100644
--- a/src/rspamadm/confighelp.c
+++ b/src/rspamadm/confighelp.c
@@ -260,7 +260,7 @@ rspamadm_confighelp (gint argc, gchar **argv, const struct rspamadm_command *cmd
 
 	/* Init lua modules */
 	rspamd_lua_set_path (cfg->lua_state, cfg->rcl_obj, ucl_vars);
-	rspamd_init_lua_filters (cfg, TRUE);
+	rspamd_init_lua_filters (cfg, true, false);
 
 	if (argc > 1) {
 		for (i = 1; i < argc; i ++) {
diff --git a/src/rspamadm/configtest.c b/src/rspamadm/configtest.c
index bc7afd9d8..c11458e42 100644
--- a/src/rspamadm/configtest.c
+++ b/src/rspamadm/configtest.c
@@ -140,7 +140,7 @@ rspamadm_configtest (gint argc, gchar **argv, const struct rspamadm_command *cmd
 		/* Do post-load actions */
 		rspamd_lua_post_load_config (cfg);
 
-		if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) {
+		if (!rspamd_init_filters (rspamd_main->cfg, false, strict)) {
 			ret = FALSE;
 		}
 
diff --git a/src/rspamd.c b/src/rspamd.c
index 511408f23..6fbb64fdf 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -341,7 +341,7 @@ reread_config (struct rspamd_main *rspamd_main)
 		 * modules and merely afterwards to init modules
 		 */
 		rspamd_lua_post_load_config (tmp_cfg);
-		rspamd_init_filters (tmp_cfg, TRUE);
+		rspamd_init_filters (tmp_cfg, true, false);
 
 		/* Do post-load actions */
 		rspamd_config_post_load (tmp_cfg,
@@ -944,7 +944,7 @@ load_rspamd_config (struct rspamd_main *rspamd_main,
 		rspamd_lua_post_load_config (cfg);
 
 		if (init_modules) {
-			rspamd_init_filters (cfg, reload);
+			rspamd_init_filters (cfg, reload, false);
 		}
 
 		/* Do post-load actions */


More information about the Commits mailing list