From ab587d5b2ccabd9aa062bcb5a069f9acb6e64438 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Peters?= Date: Mon, 8 May 2017 19:05:00 +0200 Subject: [PATCH] Add ability to read selector from Redis --- src/plugins/lua/dkim_signing.lua | 77 +++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/src/plugins/lua/dkim_signing.lua b/src/plugins/lua/dkim_signing.lua index 08fe0972d..b76a73acb 100644 --- a/src/plugins/lua/dkim_signing.lua +++ b/src/plugins/lua/dkim_signing.lua @@ -185,36 +185,59 @@ local function dkim_signing_cb(task) end if settings.use_redis then - if not p.selector then - rspamd_logger.errx(task, 'No selector specified') - return false - end - p.key = nil - local rk = string.format('%s.%s', p.selector, p.domain) - - local function redis_key_cb(err, data) - if err or type(data) ~= 'string' then - rspamd_logger.infox(rspamd_config, "cannot make request to load DKIM key for %s: %s", - rk, err) - else - p.rawkey = data - if rspamd_plugins.dkim.sign(task, p) then - task:insert_result(settings.symbol, 1.0) + local function try_redis_key(selector) + p.key = nil + p.selector = selector + local rk = string.format('%s.%s', p.selector, p.domain) + local function redis_key_cb(err, data) + if err or type(data) ~= 'string' then + rspamd_logger.infox(rspamd_config, "cannot make request to load DKIM key for %s: %s", + rk, err) + else + p.rawkey = data + if rspamd_plugins.dkim.sign(task, p) then + task:insert_result(settings.symbol, 1.0) + end end end + local ret = rspamd_redis_make_request(task, + redis_params, -- connect params + rk, -- hash key + false, -- is write + redis_key_cb, --callback + 'HGET', -- command + {settings.key_prefix, rk} -- arguments + ) + if not ret then + rspamd_logger.infox(rspamd_config, "cannot make request to load DKIM key for %s", rk) + end end - - local ret = rspamd_redis_make_request(task, - redis_params, -- connect params - rk, -- hash key - false, -- is write - redis_key_cb, --callback - 'HGET', -- command - {settings.key_prefix, rk} -- arguments - ) - - if not ret then - rspamd_logger.infox(rspamd_config, "cannot make request to load DKIM key for %s", rk) + if settings.selector_prefix then + rspamd_logger.infox(rspamd_config, "Using selector prefix %s for domain %s", settings.selector_prefix, p.domain); + local function redis_selector_cb(err, data) + if err or type(data) ~= 'string' then + rspamd_logger.infox(rspamd_config, "cannot make request to load DKIM selector for domain %s: %s", p.domain, err) + else + try_redis_key(data) + end + end + local ret = rspamd_redis_make_request(task, + redis_params, -- connect params + p.domain, -- hash key + false, -- is write + redis_selector_cb, --callback + 'HGET', -- command + {settings.selector_prefix, p.domain} -- arguments + ) + if not ret then + rspamd_logger.infox(rspamd_config, "cannot make request to load DKIM selector for %s", p.domain) + end + else + if not p.selector then + rspamd_logger.errx(task, 'No selector specified') + return false + end + try_redis_key(p.selector) end else if (p.key and p.selector) then -- 2.39.5