From 5ebcabcff378c0c56ed187c60f941b33d06013d7 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 4 Feb 2020 09:41:09 +0000 Subject: [PATCH] [Minor] Remove non-reject gtube patterns unless enable_test_patterns is enabled --- src/libmime/message.c | 31 ++++++++++++++++++++++++----- src/libserver/cfg_file.h | 1 + src/libserver/cfg_rcl.c | 6 ++++++ test/functional/configs/milter.conf | 3 ++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/libmime/message.c b/src/libmime/message.c index 95a1ab708..37ac0a223 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -46,11 +46,13 @@ #define SET_PART_UTF(part) ((part)->flags |= RSPAMD_MIME_TEXT_PART_FLAG_UTF) static const gchar gtube_pattern_reject[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*" - "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; + "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; static const gchar gtube_pattern_add_header[] = "YJS*C4JDBQADN1.NSBN3*2IDNEN*" - "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; + "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; static const gchar gtube_pattern_rewrite_subject[] = "ZJS*C4JDBQADN1.NSBN3*2IDNEN*" - "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; + "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; +static const gchar gtube_pattern_no_action[] = "AJS*C4JDBQADN1.NSBN3*2IDNEN*" + "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; struct rspamd_multipattern *gtube_matcher = NULL; static const guint64 words_hash_seed = 0xdeadbabe; @@ -616,6 +618,16 @@ rspamd_multipattern_gtube_cb (struct rspamd_multipattern *mp, gsize len, void *context) { + struct rspamd_task *task = (struct rspamd_task *)context; + + if (strnum > 0) { + if (task->cfg->enable_test_patterns) { + return strnum + 1; + } + + return 0; + } + return strnum + 1; /* To distinguish from zero */ } @@ -639,6 +651,9 @@ rspamd_check_gtube (struct rspamd_task *task, struct rspamd_mime_text_part *part rspamd_multipattern_add_pattern (gtube_matcher, gtube_pattern_rewrite_subject, RSPAMD_MULTIPATTERN_DEFAULT); + rspamd_multipattern_add_pattern (gtube_matcher, + gtube_pattern_no_action, + RSPAMD_MULTIPATTERN_DEFAULT); g_assert (rspamd_multipattern_compile (gtube_matcher, NULL)); } @@ -647,21 +662,27 @@ rspamd_check_gtube (struct rspamd_task *task, struct rspamd_mime_text_part *part part->utf_content->len <= max_check_size) { if ((ret = rspamd_multipattern_lookup (gtube_matcher, part->utf_content->data, part->utf_content->len, - rspamd_multipattern_gtube_cb, NULL, NULL)) > 0) { + rspamd_multipattern_gtube_cb, task, NULL)) > 0) { switch (ret) { case 1: act = METRIC_ACTION_REJECT; break; case 2: + g_assert (task->cfg->enable_test_patterns); act = METRIC_ACTION_ADD_HEADER; break; case 3: + g_assert (task->cfg->enable_test_patterns); act = METRIC_ACTION_REWRITE_SUBJECT; break; + case 4: + g_assert (task->cfg->enable_test_patterns); + act = METRIC_ACTION_NOACTION; + break; } - if (act != METRIC_ACTION_NOACTION) { + if (ret != 0) { task->flags |= RSPAMD_TASK_FLAG_SKIP; task->flags |= RSPAMD_TASK_FLAG_GTUBE; msg_info_task ( diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 07aedb6f8..457d012da 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -375,6 +375,7 @@ struct rspamd_config { gboolean own_lua_state; /**< True if we have created lua_state internally */ gboolean soft_reject_on_timeout; /**< If true emit soft reject on task timeout (if not reject) */ gboolean public_groups_only; /**< Output merely public groups everywhere */ + gboolean enable_test_patterns; /**< Enable test patterns */ gsize max_cores_size; /**< maximum size occupied by rspamd core files */ gsize max_cores_count; /**< maximum number of core files */ diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 9a88bd39c..81f00c155 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -1993,6 +1993,12 @@ rspamd_rcl_config_init (struct rspamd_config *cfg, GHashTable *skip_sections) G_STRUCT_OFFSET (struct rspamd_config, public_groups_only), 0, "Output merely public groups everywhere"); + rspamd_rcl_add_default_handler (sub, + "enable_test_patterns", + rspamd_rcl_parse_struct_boolean, + G_STRUCT_OFFSET (struct rspamd_config, enable_test_patterns), + 0, + "Enable test GTUBE like patterns (not for production!)"); rspamd_rcl_add_default_handler (sub, "enable_experimental", rspamd_rcl_parse_struct_boolean, diff --git a/test/functional/configs/milter.conf b/test/functional/configs/milter.conf index 789040e68..e09ee48d8 100644 --- a/test/functional/configs/milter.conf +++ b/test/functional/configs/milter.conf @@ -2,7 +2,8 @@ options = { filters = ["spf", "dkim", "regexp"] url_tld = "${URL_TLD}" pidfile = "${TMPDIR}/rspamd.pid" - lua_path = "${INSTALLROOT}/share/rspamd/lib/?.lua" + lua_path = "${INSTALLROOT}/share/rspamd/lib/?.lua"; + enable_test_patterns = true; dns { nameserver = ["8.8.8.8", "8.8.4.4"]; retransmits = 10; -- 2.39.5