]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Remove non-reject gtube patterns unless enable_test_patterns is enabled
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 4 Feb 2020 09:41:09 +0000 (09:41 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 4 Feb 2020 09:41:09 +0000 (09:41 +0000)
src/libmime/message.c
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
test/functional/configs/milter.conf

index 95a1ab708e54c9e461f841a39bfa531fa1cbc694..37ac0a2236fccbfd5825330f73ebc3e32e68bde3 100644 (file)
 #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 (
index 07aedb6f85090abadef2cf793cdeb12f8b79352f..457d012da437386e04a27255a8d4ba2d2e9c0878 100644 (file)
@@ -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                                               */
index 9a88bd39cd88bbee3410f7877f42db0191523965..81f00c15585c49e7b44a27c8a98132f1fb697542 100644 (file)
@@ -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,
index 789040e68bc48a4729e2e3190f1d8c2f0d226b06..e09ee48d85c21327a7989355aa3638361ad5fb50 100644 (file)
@@ -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;