diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-16 12:45:54 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-16 12:45:54 +0000 |
commit | 6954824d00becad87a67a13d510b0ea29c30faaa (patch) | |
tree | d5c8aca1ca998c13e889ce1a3d28559144fc4d93 | |
parent | 19fb007bdaf0fff4980cdf4c0032fee3d46d3013 (diff) | |
parent | 2361f4d5c289951c20eff87c8f22686ed18c66dc (diff) | |
download | rspamd-6954824d00becad87a67a13d510b0ea29c30faaa.tar.gz rspamd-6954824d00becad87a67a13d510b0ea29c30faaa.zip |
Merge pull request #1526 from fatalbanana/dmm
[Minor] DKIM signing: ensure variables in path are replaced
-rw-r--r-- | src/plugins/lua/dkim_signing.lua | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/plugins/lua/dkim_signing.lua b/src/plugins/lua/dkim_signing.lua index 4f3e0dfc7..105ecf63b 100644 --- a/src/plugins/lua/dkim_signing.lua +++ b/src/plugins/lua/dkim_signing.lua @@ -40,6 +40,18 @@ local E = {} local N = 'dkim_signing' local redis_params +local function simple_template(tmpl, keys) + local lpeg = require "lpeg" + + local var_lit = lpeg.P { lpeg.R("az") + lpeg.R("AZ") + lpeg.R("09") + "_" } + local var = lpeg.P { (lpeg.P("$") / "") * ((var_lit^1) / keys) } + local var_braced = lpeg.P { (lpeg.P("${") / "") * ((var_lit^1) / keys) * (lpeg.P("}") / "") } + + local rep = lpeg.Cs((var + var_braced + 1)^0) + + return lpeg.match(rep, tmpl) +end + local function dkim_signing_cb(task) local auser = task:get_user() if settings.auth_only and not auser then @@ -120,8 +132,6 @@ local function dkim_signing_cb(task) if not p.selector then p.selector = settings.selector end - p.key = string.gsub(p.key, '$selector', p.selector) - p.key = string.gsub(p.key, '$domain', dkim_domain) p.domain = dkim_domain if settings.selector_map then @@ -171,6 +181,7 @@ local function dkim_signing_cb(task) end else if (p.key and p.selector) then + p.key = simple_template(p.key, {domain = p.domain, selector = p.selector}) return rspamd_plugins.dkim.sign(task, p) else rspamd_logger.infox(task, 'key path or dkim selector unconfigured; no signing') |