From 2361f4d5c289951c20eff87c8f22686ed18c66dc Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Wed, 15 Mar 2017 21:29:58 +0200 Subject: [PATCH] [Minor] DKIM signing: ensure variables in path are replaced - Also use lpeg --- src/plugins/lua/dkim_signing.lua | 15 +++++++++++++-- 1 file 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') -- 2.39.5