diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-12-01 09:34:26 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-12-01 09:34:26 +0000 |
commit | 28dce54e705f82b439a72592ba15199271b554da (patch) | |
tree | 98c75aff2f43c5bfad5ba48b89cbe608e715607f /lualib | |
parent | 8f8b0300361f387189393807cc9e688a414766e8 (diff) | |
download | rspamd-28dce54e705f82b439a72592ba15199271b554da.tar.gz rspamd-28dce54e705f82b439a72592ba15199271b554da.zip |
[Minor] Fix error cases handling
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/rspamadm/dns_tool.lua | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/lualib/rspamadm/dns_tool.lua b/lualib/rspamadm/dns_tool.lua index a747e8aa7..24a8fecf8 100644 --- a/lualib/rspamadm/dns_tool.lua +++ b/lualib/rspamadm/dns_tool.lua @@ -18,6 +18,7 @@ limitations under the License. local argparse = require "argparse" local rspamd_logger = require "rspamd_logger" local ansicolors = require "ansicolors" +local bit = require "bit" local parser = argparse() :name "rspamadm dns_tool" @@ -105,6 +106,18 @@ local function spf_handler(opts) os.exit(1) end + local function flag_to_str(fl) + if bit.band(fl, rspamd_spf.flags.temp_fail) ~= 0 then + return "temporary failure" + elseif bit.band(fl, rspamd_spf.flags.perm_fail) ~= 0 then + return "permanent failure" + elseif bit.band(fl, rspamd_spf.flags.na) ~= 0 then + return "no spf record" + end + + return "unknown flag: " .. tostring(fl) + end + local function display_spf_results(elt, colored) local dec = function(e) return e end local policy_decode = function(e) @@ -155,17 +168,22 @@ local function spf_handler(opts) os.exit(0) end - printf('SPF record for %s; digest: %s', - highlight(opts.domain or opts.from), highlight(record:get_digest())) - for _,elt in ipairs(record:get_elts()) do - if result and error_or_addr and elt.str and elt.str == error_or_addr.str then - printf("%s", highlight('*** Matched ***')) - display_spf_results(elt, true) - printf('------') - else - display_spf_results(elt, false) - printf('------') + if result then + printf('SPF record for %s; digest: %s', + highlight(opts.domain or opts.from), highlight(record:get_digest())) + for _,elt in ipairs(record:get_elts()) do + if result and error_or_addr and elt.str and elt.str == error_or_addr.str then + printf("%s", highlight('*** Matched ***')) + display_spf_results(elt, true) + printf('------') + else + display_spf_results(elt, false) + printf('------') + end end + else + printf('Error getting SPF record: %s (%s flag)', err, + flag_to_str(flag_or_policy)) end else printf('Cannot get SPF record: %s', err) |