]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] rbl: support checking returncodes by regex
authorAndrew Lewis <nerf@judo.za.org>
Tue, 24 Oct 2023 11:53:03 +0000 (13:53 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 24 Oct 2023 11:53:03 +0000 (13:53 +0200)
lualib/plugins/rbl.lua
src/plugins/lua/rbl.lua
test/functional/configs/merged-override.conf

index 1a25c1ed364d53f28b5e2c76806531f41001aeaf..bc5fbe278cc955f29a518377ff2122d57cb2733a 100644 (file)
@@ -107,7 +107,7 @@ local rule_schema_tbl = {
   ipv6 = ts.boolean:is_optional(),
   is_whitelist = ts.boolean:is_optional(),
   local_exclude_ip_map = ts.string:is_optional(),
-  matcher = ts.one_of { "equality", "luapattern" }:is_optional(),
+  matcher = ts.one_of { "equality", "luapattern", "regexp" }:is_optional(),
   monitored_address = ts.string:is_optional(),
   no_ip = ts.boolean:is_optional(),
   process_script = ts.string:is_optional(),
index b6467c103f733cb2ba1a38d522251598c0bbea91..a36131b1b3a5fe1d49a8c428936e3390222d06f9 100644 (file)
@@ -21,6 +21,7 @@ end
 
 local hash = require 'rspamd_cryptobox_hash'
 local rspamd_logger = require 'rspamd_logger'
+local rspamd_regexp = require 'rspamd_regexp'
 local rspamd_util = require 'rspamd_util'
 local rspamd_ip = require "rspamd_ip"
 local fun = require 'fun'
@@ -225,6 +226,18 @@ matchers.luapattern = function(to_match, pattern)
   return string.find(to_match, '^' .. pattern .. '$') and true or false
 end
 
+matchers.regexp = function(to_match, pattern)
+  local re = rspamd_regexp.get_cached(pattern)
+  if not re then
+    re = rspamd_regexp.create_cached(pattern)
+    if not re then
+      rspamd_logger.errx('regexp did not compile: %s', pattern)
+      return false
+    end
+  end
+  return re:match(to_match)
+end
+
 local function rbl_dns_process(task, rbl, to_resolve, results, err, resolve_table_elt, match)
   local function make_option(ip, label)
     if ip then
index 28d554b8386867554a6a464b09fbdc1102436bdb..0c9b7a3e22c5040b623b5c81c3488c4fa3cab043 100644 (file)
@@ -269,9 +269,10 @@ rbl {
         from = 'FAKE_RBL',
       }
       unknown = true;
+      matcher = "regexp";
       returncodes = {
-        "CODE_2" = "127.0.0.2";
-        "CODE_3" = "127.0.0.3";
+        "CODE_2" = '^127\.0\.0\.2$';
+        "CODE_3" = '^127\.0\.0\.3$';
       }
     }
     fake_whitelist {
@@ -283,9 +284,10 @@ rbl {
       rbl = "fake.wl";
       symbol = "FAKE_WL_RBL_UNKNOWN";
       unknown = true;
+      #matcher = "luapattern";
       returncodes = {
-        "FAKE_WL_RBL_CODE_2" = "127.0.0.2";
-        "FAKE_WL_RBL_CODE_3" = "127.0.0.3";
+        "FAKE_WL_RBL_CODE_2" = "127%.0%.0%.2";
+        "FAKE_WL_RBL_CODE_3" = "127%.0%.0%.3";
       }
     }
     RSPAMD_EMAILBL {