aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-08 15:44:36 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-08 15:44:36 +0000
commit66005f3fa335c9f9acc37a7315ec5ab5d3abde66 (patch)
tree658ee4eba23793133b6cfc137282613feb28479b
parente69038f5a663de4f1815796a5cb74d752d78a2a8 (diff)
downloadrspamd-66005f3fa335c9f9acc37a7315ec5ab5d3abde66.tar.gz
rspamd-66005f3fa335c9f9acc37a7315ec5ab5d3abde66.zip
[Feature] Allow to disable symbols from the metric config
-rw-r--r--src/libserver/cfg_file.h3
-rw-r--r--src/libserver/cfg_rcl.c18
-rw-r--r--src/libserver/rspamd_symcache.c10
-rw-r--r--src/lua/lua_config.c9
-rw-r--r--src/plugins/dkim_check.c4
-rw-r--r--src/plugins/fuzzy_check.c2
-rw-r--r--src/plugins/spf.c2
7 files changed, 39 insertions, 9 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 96a44f45e..750e48325 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -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),
};
/**
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index e55076894..e4924ae20 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -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;
}
}
diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c
index 60f405e12..4e9967945 100644
--- a/src/libserver/rspamd_symcache.c
+++ b/src/libserver/rspamd_symcache.c
@@ -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;
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index b7bddc34b..9a2d2f55d 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -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);
diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c
index 410a38309..ebe2292a1 100644
--- a/src/plugins/dkim_check.c
+++ b/src/plugins/dkim_check.c
@@ -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");
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index 5f706e237..3162c1f0e 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -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);
diff --git a/src/plugins/spf.c b/src/plugins/spf.c
index 3c02eafbe..6f120786c 100644
--- a/src/plugins/spf.c
+++ b/src/plugins/spf.c
@@ -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");