aboutsummaryrefslogtreecommitdiffstats
path: root/rules
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-08-06 13:45:27 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-08-06 13:45:27 +0100
commite227bedc4f24b1ab5cf7feae0d2acb076ddcb312 (patch)
treeb6ee7e007a5b8bdaf6ea8ffa07d18ff82dd0d8fe /rules
parentaa0bc71c67e825ca4cbe34dd2c2e4cc86312c1e3 (diff)
downloadrspamd-e227bedc4f24b1ab5cf7feae0d2acb076ddcb312.tar.gz
rspamd-e227bedc4f24b1ab5cf7feae0d2acb076ddcb312.zip
[Rework] Resolve rdns in a separate function
Historically, it was done in `once_received` module, however, that check must be done early, even before settings (as they could rely on hostname). Hence, it was discussed to move this code to a separate rule.
Diffstat (limited to 'rules')
-rw-r--r--rules/misc.lua55
1 files changed, 55 insertions, 0 deletions
diff --git a/rules/misc.lua b/rules/misc.lua
index faf4a8fb8..cbe90e561 100644
--- a/rules/misc.lua
+++ b/rules/misc.lua
@@ -862,3 +862,58 @@ rspamd_config.COMPLETELY_EMPTY = {
group = 'blankspam',
score = 15
}
+
+-- Check for the hostname if it was not set
+local rnds_check_id = rspamd_config:register_symbol {
+ name = 'RDNS_CHECK',
+ callback = function(task)
+ if not task:get_hostname() then
+ -- Try to resolve
+ local task_ip = task:get_ip()
+ if task_ip and task_ip:is_valid() then
+ local rspamd_logger = require "rspamd_logger"
+ local function rdns_dns_cb(_, to_resolve, results, err)
+ if err and (err ~= 'requested record is not found' and err ~= 'no records with this name') then
+ rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, err)
+ task:insert_result('RDNS_DNSFAIL', 1.0)
+ end
+
+ if not results then
+ task:insert_result('RDNS_NONE', 1.0)
+ else
+ rspamd_logger.infox(task, 'source hostname has not been passed to Rspamd from MTA, ' ..
+ 'but we could resolve source IP address PTR %s as "%s"',
+ to_resolve, results[1])
+ task:set_hostname(results[1])
+ end
+ end
+ task:get_resolver():resolve_ptr({ task = task,
+ name = task_ip:to_string(),
+ callback = rdns_dns_cb,
+ forced = true
+ })
+ end
+ end
+ end,
+ type = 'prefilter',
+ priority = lua_util.symbols_priorities.top,
+ description = 'Check if hostname has been resolved by MTA',
+}
+
+rspamd_config:register_symbol {
+ type = 'virtual',
+ name = 'RDNS_DNSFAIL',
+ score = 0.0,
+ description = 'DNS failure resolving RDNS',
+ group = 'hfilter',
+ parent = rnds_check_id,
+
+}
+rspamd_config:register_symbol {
+ type = 'virtual',
+ name = 'RDNS_NONE',
+ score = 2.0,
+ description = 'DNS failure resolving RDNS',
+ group = 'hfilter',
+ parent = rnds_check_id,
+} \ No newline at end of file