]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to disable symbols from the metric config
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Nov 2019 15:44:36 +0000 (15:44 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Nov 2019 15:44:36 +0000 (15:44 +0000)
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/rspamd_symcache.c
src/lua/lua_config.c
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/spf.c

index 96a44f45e22c898456ffc31409b881fe49e56bc8..750e4832507da58d7bf1cec58cced003b2ff8416 100644 (file)
@@ -127,9 +127,10 @@ struct rspamd_symbols_group {
 
 enum rspamd_symbol_flags {
        RSPAMD_SYMBOL_FLAG_NORMAL = 0,
-       RSPAMD_SYMBOL_FLAG_IGNORE = (1 << 1),
+       RSPAMD_SYMBOL_FLAG_IGNORE_METRIC = (1 << 1),
        RSPAMD_SYMBOL_FLAG_ONEPARAM = (1 << 2),
        RSPAMD_SYMBOL_FLAG_UNGROUPPED = (1 << 3),
+       RSPAMD_SYMBOL_FLAG_DISABLED = (1 << 4),
 };
 
 /**
index e5507689495b156e41c2a04d613128d900f8f956..e4924ae20b324bb000ed699199a10dbf45ab4845 100644 (file)
@@ -520,7 +520,23 @@ rspamd_rcl_symbol_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
                }
 
                if (ucl_object_toboolean (elt)) {
-                       flags |= RSPAMD_SYMBOL_FLAG_IGNORE;
+                       flags |= RSPAMD_SYMBOL_FLAG_IGNORE_METRIC;
+               }
+       }
+
+       if ((elt = ucl_object_lookup (obj, "enabled")) != NULL) {
+               if (ucl_object_type (elt) != UCL_BOOLEAN) {
+                       g_set_error (err,
+                                       CFG_RCL_ERROR,
+                                       EINVAL,
+                                       "enabled attribute is not boolean for symbol: '%s'",
+                                       key);
+
+                       return FALSE;
+               }
+
+               if (ucl_object_toboolean (elt)) {
+                       flags |= RSPAMD_SYMBOL_FLAG_DISABLED;
                }
        }
 
index 60f405e12ec014e72887d057eacc06604b270c0a..4e9967945ed6310aa8b1c3451eecb48ce93a8917 100644 (file)
@@ -1495,7 +1495,8 @@ rspamd_symcache_validate (struct rspamd_symcache *cache,
                ignore_symbol = FALSE;
                sym_def = v;
 
-               if (sym_def && (sym_def->flags & RSPAMD_SYMBOL_FLAG_IGNORE)) {
+               if (sym_def && (sym_def->flags &
+                               (RSPAMD_SYMBOL_FLAG_IGNORE_METRIC|RSPAMD_SYMBOL_FLAG_DISABLED))) {
                        ignore_symbol = TRUE;
                }
 
@@ -1512,6 +1513,13 @@ rspamd_symcache_validate (struct rspamd_symcache *cache,
                                }
                        }
                }
+               else if (sym_def->flags & RSPAMD_SYMBOL_FLAG_DISABLED) {
+                       item = g_hash_table_lookup (cache->items_by_symbol, k);
+
+                       if (item) {
+                               item->enabled = FALSE;
+                       }
+               }
        }
 
        return ret;
index b7bddc34bc43d4b614be69a2099f43cd42b8e011..9a2d2f55d506f565892b781a171d72723256d83e 100644 (file)
@@ -2318,7 +2318,7 @@ lua_config_set_metric_symbol (lua_State * L)
                                nshots = 1;
                        }
                        if (strstr (flags_str, "ignore") != NULL) {
-                               flags |= RSPAMD_SYMBOL_FLAG_IGNORE;
+                               flags |= RSPAMD_SYMBOL_FLAG_IGNORE_METRIC;
                        }
                        if (strstr (flags_str, "one_param") != NULL) {
                                flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
@@ -3376,7 +3376,7 @@ lua_metric_symbol_inserter (gpointer k, gpointer v, gpointer ud)
        lua_pushstring (L, "flags");
        lua_createtable (L, 0, 3);
 
-       if (s->flags & RSPAMD_SYMBOL_FLAG_IGNORE) {
+       if (s->flags & RSPAMD_SYMBOL_FLAG_IGNORE_METRIC) {
                lua_pushstring (L, "ignore");
                lua_pushboolean (L, true);
                lua_settable (L, -3);
@@ -3391,6 +3391,11 @@ lua_metric_symbol_inserter (gpointer k, gpointer v, gpointer ud)
                lua_pushboolean (L, true);
                lua_settable (L, -3);
        }
+       if (s->flags & RSPAMD_SYMBOL_FLAG_DISABLED) {
+               lua_pushstring (L, "disabled");
+               lua_pushboolean (L, true);
+               lua_settable (L, -3);
+       }
 
        if (s->cache_item) {
                guint sflags = rspamd_symcache_get_symbol_flags (cbd->cfg->cache, sym);
index 410a38309482d219691f0c8448ded47c1007cb7c..ebe2292a1c4c3ed3dc7e05de5169162ea1201bce 100644 (file)
@@ -538,7 +538,7 @@ dkim_module_config (struct rspamd_config *cfg)
                                0.0,
                                "DKIM check callback",
                                "policies",
-                               RSPAMD_SYMBOL_FLAG_IGNORE,
+                               RSPAMD_SYMBOL_FLAG_IGNORE_METRIC,
                                1,
                                1);
                rspamd_config_add_symbol_group (cfg, "DKIM_CHECK", "dkim");
@@ -585,7 +585,7 @@ dkim_module_config (struct rspamd_config *cfg)
                                0.0,
                                "DKIM trace symbol",
                                "policies",
-                               RSPAMD_SYMBOL_FLAG_IGNORE,
+                               RSPAMD_SYMBOL_FLAG_IGNORE_METRIC,
                                1,
                                1);
                rspamd_config_add_symbol_group (cfg, "DKIM_TRACE", "dkim");
index 5f706e237c334f335feb9c2b8805f5594f067d62..3162c1f0e0917a2119b0054f10e031568837c7bb 100644 (file)
@@ -1060,7 +1060,7 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
                                0.0,
                                "Fuzzy check callback",
                                "fuzzy",
-                               RSPAMD_SYMBOL_FLAG_IGNORE,
+                               RSPAMD_SYMBOL_FLAG_IGNORE_METRIC,
                                1,
                                1);
 
index 3c02eafbe6cb80452f25524fdfb8816dd4318441..6f120786c61f0ac9fda6206c1846efadda1ce5e9 100644 (file)
@@ -349,7 +349,7 @@ spf_module_config (struct rspamd_config *cfg)
                        0.0,
                        "SPF check callback",
                        "policies",
-                       RSPAMD_SYMBOL_FLAG_IGNORE,
+                       RSPAMD_SYMBOL_FLAG_IGNORE_METRIC,
                        1,
                        1);
        rspamd_config_add_symbol_group (cfg, "SPF_CHECK", "spf");