commit 611eae1: [Rework] Distinguish between strict config test mode

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Dec 26 23:35:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-12-26 23:27:49 +0000
URL: https://github.com/rspamd/rspamd/commit/611eae1b23025f80bf5ad36ab62254348feee972 (HEAD -> master)

[Rework] Distinguish between strict config test mode

---
 src/libserver/cfg_utils.c |  2 +-
 src/plugins/chartable.c   |  6 +++---
 src/plugins/dkim_check.c  | 16 ++++++++++-----
 src/plugins/fuzzy_check.c |  9 +++++----
 src/plugins/regexp.c      | 51 ++++++++++++++++++++++++++++++++++-------------
 src/rspamd.c              |  8 ++++++--
 src/rspamd.h              |  2 +-
 7 files changed, 64 insertions(+), 30 deletions(-)

diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index e2f886aa6..439a61793 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -1589,7 +1589,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig, bool strict)
 
 			}
 			else {
-				if (!mod->module_config_func (cfg)) {
+				if (!mod->module_config_func (cfg, strict)) {
 					msg_err_config ("config of %s failed", mod->name);
 					ret = FALSE;
 
diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c
index ce37ebd58..c997862a1 100644
--- a/src/plugins/chartable.c
+++ b/src/plugins/chartable.c
@@ -58,7 +58,7 @@ INIT_LOG_MODULE(chartable)
 
 /* Initialization */
 gint chartable_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
-gint chartable_module_config (struct rspamd_config *cfg);
+gint chartable_module_config (struct rspamd_config *cfg, bool validate);
 gint chartable_module_reconfig (struct rspamd_config *cfg);
 
 module_t chartable_module = {
@@ -109,7 +109,7 @@ chartable_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 
 
 gint
-chartable_module_config (struct rspamd_config *cfg)
+chartable_module_config (struct rspamd_config *cfg, bool validate)
 {
 	const ucl_object_t *value;
 	gint res = TRUE;
@@ -174,7 +174,7 @@ chartable_module_config (struct rspamd_config *cfg)
 gint
 chartable_module_reconfig (struct rspamd_config *cfg)
 {
-	return chartable_module_config (cfg);
+	return chartable_module_config (cfg, false);
 }
 
 static gint latin_confusable[] = {
diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c
index fae0acf0b..c00b87b11 100644
--- a/src/plugins/dkim_check.c
+++ b/src/plugins/dkim_check.c
@@ -113,7 +113,7 @@ static gint lua_dkim_canonicalize_handler (lua_State *L);
 
 /* Initialization */
 gint dkim_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
-gint dkim_module_config (struct rspamd_config *cfg);
+gint dkim_module_config (struct rspamd_config *cfg, bool validate);
 gint dkim_module_reconfig (struct rspamd_config *cfg);
 
 module_t dkim_module = {
@@ -309,7 +309,7 @@ dkim_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 }
 
 gint
-dkim_module_config (struct rspamd_config *cfg)
+dkim_module_config (struct rspamd_config *cfg, bool validate)
 {
 	const ucl_object_t *value;
 	gint res = TRUE, cb_id = -1;
@@ -469,6 +469,10 @@ dkim_module_config (struct rspamd_config *cfg)
 				NULL, RSPAMD_MAP_DEFAULT)) {
 			msg_warn_config ("cannot load dkim domains list from %s",
 					ucl_object_tostring (value));
+
+			if (validate) {
+				return FALSE;
+			}
 		}
 		else {
 			got_trusted = TRUE;
@@ -523,8 +527,10 @@ dkim_module_config (struct rspamd_config *cfg)
 	}
 
 	if (dkim_module_ctx->trusted_only && !got_trusted) {
-		msg_err_config (
-			"trusted_only option is set and no trusted domains are defined; disabling dkim module completely as it is useless in this case");
+		msg_err_config ("trusted_only option is set and no trusted domains are defined");
+		if (validate) {
+			return FALSE;
+		}
 	}
 	else {
 		if (!rspamd_config_is_module_enabled (cfg, "dkim")) {
@@ -896,7 +902,7 @@ lua_dkim_sign_handler (lua_State *L)
 gint
 dkim_module_reconfig (struct rspamd_config *cfg)
 {
-	return dkim_module_config (cfg);
+	return dkim_module_config (cfg, false);
 }
 
 /*
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index 633ce50ae..9d0aa35e1 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -181,7 +181,7 @@ static void fuzzy_symbol_callback (struct rspamd_task *task,
 /* Initialization */
 gint fuzzy_check_module_init (struct rspamd_config *cfg,
 	struct module_ctx **ctx);
-gint fuzzy_check_module_config (struct rspamd_config *cfg);
+gint fuzzy_check_module_config (struct rspamd_config *cfg, bool valdate);
 gint fuzzy_check_module_reconfig (struct rspamd_config *cfg);
 static gint fuzzy_attach_controller (struct module_ctx *ctx,
 	GHashTable *commands);
@@ -940,7 +940,7 @@ fuzzy_check_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 }
 
 gint
-fuzzy_check_module_config (struct rspamd_config *cfg)
+fuzzy_check_module_config (struct rspamd_config *cfg, bool validate)
 {
 	const ucl_object_t *value, *cur, *elt;
 	ucl_object_iter_t it;
@@ -969,7 +969,8 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
 							"table and not %s",
 					lua_typename (L, lua_type (L, -1)));
 			fuzzy_module_ctx->enabled = FALSE;
-		} else {
+		}
+		else {
 			lua_pushstring (L, "process_rule");
 			lua_gettable (L, -2);
 
@@ -1205,7 +1206,7 @@ fuzzy_check_module_reconfig (struct rspamd_config *cfg)
 				fuzzy_module_ctx->process_rule_ref);
 	}
 
-	return fuzzy_check_module_config (cfg);
+	return fuzzy_check_module_config (cfg, false);
 }
 
 /* Finalize IO */
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index a967c46aa..9dde6cddb 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -46,7 +46,7 @@ static void process_regexp_item (struct rspamd_task *task,
 
 /* Initialization */
 gint regexp_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
-gint regexp_module_config (struct rspamd_config *cfg);
+gint regexp_module_config (struct rspamd_config *cfg, bool validate);
 gint regexp_module_reconfig (struct rspamd_config *cfg);
 
 module_t regexp_module = {
@@ -130,7 +130,7 @@ regexp_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 }
 
 gint
-regexp_module_config (struct rspamd_config *cfg)
+regexp_module_config (struct rspamd_config *cfg, bool validate)
 {
 	struct regexp_ctx *regexp_module_ctx = regexp_get_context (cfg);
 	struct regexp_module_item *cur_item = NULL;
@@ -174,7 +174,9 @@ regexp_module_config (struct rspamd_config *cfg)
 			if (!read_regexp_expression (cfg->cfg_pool,
 					cur_item, ucl_object_key (value),
 					ucl_obj_tostring (value), &ud)) {
-				res = FALSE;
+				if (validate) {
+					return FALSE;
+				}
 			}
 			else {
 				rspamd_symcache_add_symbol (cfg->cache,
@@ -228,7 +230,9 @@ regexp_module_config (struct rspamd_config *cfg)
 					if (!read_regexp_expression (cfg->cfg_pool,
 							cur_item, ucl_object_key (value),
 							ucl_obj_tostring (elt), &ud)) {
-						res = FALSE;
+						if (validate) {
+							return FALSE;
+						}
 					}
 					else {
 						valid_expression = TRUE;
@@ -263,7 +267,9 @@ regexp_module_config (struct rspamd_config *cfg)
 								"mime_only attribute is not boolean for symbol: '%s'",
 								cur_item->symbol);
 
-						res = FALSE;
+						if (validate) {
+							return FALSE;
+						}
 					}
 					else {
 						if (ucl_object_toboolean (elt)) {
@@ -314,7 +320,9 @@ regexp_module_config (struct rspamd_config *cfg)
 								"score attribute is not numeric for symbol: '%s'",
 								cur_item->symbol);
 
-						res = FALSE;
+						if (validate) {
+							return FALSE;
+						}
 					}
 					else {
 						score = ucl_object_todouble (elt);
@@ -329,7 +337,9 @@ regexp_module_config (struct rspamd_config *cfg)
 								"one_shot attribute is not boolean for symbol: '%s'",
 								cur_item->symbol);
 
-						res = FALSE;
+						if (validate) {
+							return FALSE;
+						}
 					}
 					else {
 						if (ucl_object_toboolean (elt)) {
@@ -344,7 +354,9 @@ regexp_module_config (struct rspamd_config *cfg)
 								"any_shot attribute is not boolean for symbol: '%s'",
 								cur_item->symbol);
 
-						res = FALSE;
+						if (validate) {
+							return FALSE;
+						}
 					}
 					else {
 						if (ucl_object_toboolean (elt)) {
@@ -359,7 +371,9 @@ regexp_module_config (struct rspamd_config *cfg)
 								"nshots attribute is not numeric for symbol: '%s'",
 								cur_item->symbol);
 
-						res = FALSE;
+						if (validate) {
+							return FALSE;
+						}
 					}
 					else {
 						nshots = ucl_object_toint (elt);
@@ -374,7 +388,9 @@ regexp_module_config (struct rspamd_config *cfg)
 								"one_param attribute is not boolean for symbol: '%s'",
 								cur_item->symbol);
 
-						res = FALSE;
+						if (validate) {
+							return FALSE;
+						}
 					}
 					else {
 						if (ucl_object_toboolean (elt)) {
@@ -391,7 +407,9 @@ regexp_module_config (struct rspamd_config *cfg)
 								"priority attribute is not numeric for symbol: '%s'",
 								cur_item->symbol);
 
-						res = FALSE;
+						if (validate) {
+							return FALSE;
+						}
 					}
 					else {
 						priority = ucl_object_toint (elt);
@@ -427,8 +445,13 @@ regexp_module_config (struct rspamd_config *cfg)
 		}
 	}
 
-	msg_info_config ("init internal regexp module, %d regexp rules and %d "
-			"lua rules are loaded", nre, nlua);
+	if (res) {
+		msg_info_config ("init internal regexp module, %d regexp rules and %d "
+						 "lua rules are loaded", nre, nlua);
+	}
+	else {
+		msg_err_config ("fatal regexp module error");
+	}
 
 	return res;
 }
@@ -436,7 +459,7 @@ regexp_module_config (struct rspamd_config *cfg)
 gint
 regexp_module_reconfig (struct rspamd_config *cfg)
 {
-	return regexp_module_config (cfg);
+	return regexp_module_config (cfg, false);
 }
 
 static gboolean
diff --git a/src/rspamd.c b/src/rspamd.c
index 5a1898c29..17b2956ab 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -968,11 +968,15 @@ load_rspamd_config (struct rspamd_main *rspamd_main,
 		rspamd_lua_post_load_config (cfg);
 
 		if (init_modules) {
-			rspamd_init_filters (cfg, reload, false);
+			if (!rspamd_init_filters (cfg, reload, false)) {
+				return FALSE;
+			}
 		}
 
 		/* Do post-load actions */
-		rspamd_config_post_load (cfg, opts);
+		if (!rspamd_config_post_load (cfg, opts)) {
+			return FALSE;
+		}
 	}
 
 	return TRUE;
diff --git a/src/rspamd.h b/src/rspamd.h
index 2dfb512bc..bc1ed8a86 100644
--- a/src/rspamd.h
+++ b/src/rspamd.h
@@ -212,7 +212,7 @@ typedef struct module_s {
 
 	int (*module_init_func) (struct rspamd_config *cfg, struct module_ctx **ctx);
 
-	int (*module_config_func) (struct rspamd_config *cfg);
+	int (*module_config_func) (struct rspamd_config *cfg, bool validate);
 
 	int (*module_reconfig_func) (struct rspamd_config *cfg);
 


More information about the Commits mailing list