commit a5ab9b2: Merge pull request #2657 from prehor/feature/arc-domain

GitHub noreply at github.com
Fri Feb 15 11:56:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-02-15 11:55:55 +0000
URL: https://github.com/rspamd/rspamd/commit/a5ab9b2960b6275de5b69bae1c4cc96b96622813 (HEAD -> master)

Merge pull request #2657 from prehor/feature/arc-domain
Allow setting static domain for ARC signatures

 lualib/lua_dkim_tools.lua | 2 ++
 1 file changed, 2 insertions(+)

diff --combined lualib/lua_dkim_tools.lua
index 4302d24ad,15463632b..e07f3db5b
--- a/lualib/lua_dkim_tools.lua
+++ b/lualib/lua_dkim_tools.lua
@@@ -22,57 -22,21 +22,57 @@@ local lua_util = require "lua_util
  local rspamd_util = require "rspamd_util"
  local logger = require "rspamd_logger"
  
 -local function check_violation(N, task, domain, selector)
 +local function check_violation(N, task, domain)
    -- Check for DKIM_REJECT
    local sym_check = 'R_DKIM_REJECT'
  
    if N == 'arc' then sym_check = 'ARC_REJECT' end
    if task:has_symbol(sym_check) then
      local sym = task:get_symbol(sym_check)
 -    logger.infox(task, 'skip signing for %s:%s: violation %s found: %s',
 -        domain, selector, sym_check, sym.options)
 +    logger.infox(task, 'skip signing for %s: violation %s found: %s',
 +        domain, sym_check, sym.options)
      return false
    end
  
    return true
  end
  
 +local function insert_or_update_prop(N, task, p, prop, origin, data)
 +  if #p == 0 then
 +    local k = {}
 +    k[prop] = data
 +    table.insert(p, k)
 +    lua_util.debugm(N, task, 'add %s "%s" using %s', prop, data, origin)
 +  else
 +    for _, k in ipairs(p) do
 +      if not k[prop] then
 +        k[prop] = data
 +        lua_util.debugm(N, task, 'set %s to "%s" using %s', prop, data, origin)
 +      end
 +    end
 +  end
 +end
 +
 +local function get_mempool_selectors(N, task)
 +  local p = {}
 +  local key_var = "dkim_key"
 +  local selector_var = "dkim_selector"
 +  if N == "arc" then
 +    key_var = "arc_key"
 +    selector_var = "arc_selector"
 +  end
 +
 +  p.key = task:get_mempool():get_variable(key_var)
 +  p.selector = task:get_mempool():get_variable(selector_var)
 +
 +  if (not p.key or not p.selector) then
 +    return false, {}
 +  end
 +
 +  lua_util.debugm(N, task, 'override selector and key to %s:%s', p.key, p.selector)
 +  return true, p
 +end
 +
  local function parse_dkim_http_headers(N, task, settings)
    -- Configure headers
    local headers = {
@@@ -102,14 -66,11 +102,14 @@@
        end
      end
  
 -    return true,{
 -      rawkey = tostring(key),
 +    local p = {}
 +    local k = {
        domain = tostring(domain),
 -      selector = tostring(selector)
 +      rawkey = tostring(key),
 +      selector = tostring(selector),
      }
 +    table.insert(p, k)
 +    return true, p
    end
  
    lua_util.debugm(N, task, 'no sign header %s', headers.sign_header)
@@@ -174,6 -135,8 +174,8 @@@ local function prepare_dkim_signing(N, 
        return udom
      elseif settings[dtype] == 'recipient' then
        return tdom
+     else
+       return settings[dtype]:lower()
      end
    end
  
@@@ -253,71 -216,76 +255,71 @@@
    local p = {}
  
    if settings.domain[dkim_domain] then
 -    p.selector = settings.domain[dkim_domain].selector
 -    p.key = settings.domain[dkim_domain].path
 -  end
 -
 -  if not p.key and p.selector then
 -    local key_var = "dkim_key"
 -    local selector_var = "dkim_selector"
 -    if N == "arc" then
 -      key_var = "arc_key"
 -      selector_var = "arc_selector"
 +    -- support old style selector/paths
 +    if settings.domain[dkim_domain].selector or
 +       settings.domain[dkim_domain].path then
 +      local k = {}
 +      k.selector = settings.domain[dkim_domain].selector
 +      k.key = settings.domain[dkim_domain].path
 +      table.insert(p, k)
      end
 -
 -    p.key = task:get_mempool():get_variable(key_var)
 -    local selector_override = task:get_mempool():get_variable(selector_var)
 -
 -    if selector_override then
 -      p.selector = selector_override
 +    for _, s in ipairs((settings.domain[dkim_domain].selectors or {})) do
 +      lua_util.debugm(N, task, 'adding selector: %1', s)
 +      local k = {}
 +      k.selector = s.selector
 +      k.key = s.path
 +      table.insert(p, k)
      end
 +  end
  
 -    if (not p.key or not p.selector) and (not (settings.try_fallback or
 -        settings.use_redis or settings.selector_map
 -        or settings.path_map)) then
 -      lua_util.debugm(N, task, 'dkim unconfigured and fallback disabled')
 -      return false,{}
 +  if #p == 0 then
 +    local ret, k = get_mempool_selectors(N, task)
 +    if ret then
 +      table.insert(p, k)
 +      lua_util.debugm(N, task, 'using mempool selector %s with key %s',
 +                      k.selector, k.key)
      end
 -
 -    lua_util.debugm(N, task, 'override selector and key to %s:%s', p.key, p.selector)
    end
  
 -  if not p.selector and settings.selector_map then
 +  if settings.selector_map then
      local data = settings.selector_map:get_key(dkim_domain)
      if data then
 -      p.selector = data
 -      lua_util.debugm(N, task, 'override selector to "%s" using selector_map', p.selector)
 -    elseif not settings.try_fallback then
 -      lua_util.debugm(N, task, 'no selector for %s', dkim_domain)
 -      return false,{}
 +      insert_or_update_prop(N, task, p, 'selector', 'selector_map', data)
 +    else
 +      lua_util.debugm(N, task, 'no selector in map for %s', dkim_domain)
      end
    end
  
 -  if not p.key and settings.path_map then
 +  if settings.path_map then
      local data = settings.path_map:get_key(dkim_domain)
      if data then
 -      p.key = data
 -      lua_util.debugm(N, task, 'override key to "%s" using path_map', p.key)
 -    elseif not settings.try_fallback then
 -      lua_util.debugm(N, task, 'no key for %s', dkim_domain)
 -      return false,{}
 +      insert_or_update_prop(N, task, p, 'key', 'path_map', data)
 +    else
 +      lua_util.debugm(N, task, 'no key in map for %s', dkim_domain)
      end
    end
  
 -  if not p.key then
 -    if not settings.use_redis then
 -      p.key = settings.path
 -      lua_util.debugm(N, task, 'use default key "%s" from path', p.key)
 -    end
 +  if #p == 0 and not settings.try_fallback then
 +    lua_util.debugm(N, task, 'dkim unconfigured and fallback disabled')
 +    return false,{}
    end
  
 -  if not p.selector then
 -    p.selector = settings.selector
 -    lua_util.debugm(N, task, 'use default selector "%s"', p.selector)
 +  if not settings.use_redis then
 +    insert_or_update_prop(N, task, p, 'key',
 +        'default path', settings.path)
    end
  
 +  insert_or_update_prop(N, task, p, 'selector',
 +        'default selector', settings.selector)
 +
    if settings.check_violation then
 -    if not check_violation(N, task, p.domain, p.selector) then
 +    if not check_violation(N, task, p.domain) then
        return false,{}
      end
    end
  
 -  p.domain = dkim_domain
 +  insert_or_update_prop(N, task, p, 'domain', 'dkim_domain',
 +    dkim_domain)
  
    return true,p
  end


More information about the Commits mailing list