]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Rework] Distinguish between strict config test mode
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Dec 2020 23:27:49 +0000 (23:27 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Dec 2020 23:27:49 +0000 (23:27 +0000)
src/libserver/cfg_utils.c
src/plugins/chartable.c
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/regexp.c
src/rspamd.c
src/rspamd.h

index e2f886aa6dfb2c73ac12e7f9354c5b12a23631ab..439a6179318bc1137f5b75493b40274c7187def2 100644 (file)
@@ -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;
 
index ce37ebd58a3afc5f58372042a97582dd88e86250..c997862a14a53ba4f39c576d46234f2e211a6f50 100644 (file)
@@ -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[] = {
index fae0acf0ba9d1ecd1a950113c2ec40ee4adcd8e6..c00b87b1113d06ba70489208e2296399db0d153f 100644 (file)
@@ -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);
 }
 
 /*
index 633ce50aedbce468f6d3bffea66a45c18c39e5df..9d0aa35e16c20d8ff9a8b286d4f8d1fdab015148 100644 (file)
@@ -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 */
index a967c46aa5f73827d103b5bb8f2a0408b324c4ce..9dde6cddb21def4da9d9863bf8d9ed9db0a710cd 100644 (file)
@@ -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
index 5a1898c29b4d98eb4c305dd12dd546dacb83396e..17b2956abf753fb1ecfc8eabe1e74a1cd2b5127f 100644 (file)
@@ -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;
index 2dfb512bce8b7c4f0a2ca8ff1501272eba355beb..bc1ed8a862c620b2e56116e05f895a4900ac7b07 100644 (file)
@@ -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);