From 37a04a9e42001f376f69d2920315194f3098a0c4 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 10 May 2017 12:04:15 +0100 Subject: [PATCH] [Fix] Do not check DMARC if SPF or DKIM were not checked Issue: #1629 --- src/plugins/dkim_check.c | 16 +++++++++++++++- src/plugins/lua/dmarc.lua | 6 ++++++ src/plugins/spf.c | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index dd61de67f..8dc8ee1ec 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -870,7 +870,21 @@ dkim_symbol_callback (struct rspamd_task *task, void *unused) GError *err = NULL; struct rspamd_mime_header *rh; struct dkim_check_result *res = NULL, *cur; - guint checked = 0, i; + guint checked = 0, i, *dmarc_checks; + + /* Allow dmarc */ + dmarc_checks = rspamd_mempool_get_variable (task->task_pool, "dmarc_checks"); + + if (dmarc_checks) { + (*dmarc_checks) ++; + } + else { + dmarc_checks = rspamd_mempool_alloc (task->task_pool, + sizeof (*dmarc_checks)); + *dmarc_checks = 1; + rspamd_mempool_set_variable (task->task_pool, "dmarc_checks", + dmarc_checks, NULL); + } /* First check if plugin should be enabled */ if ((!dkim_module_ctx->check_authed && task->user != NULL) diff --git a/src/plugins/lua/dmarc.lua b/src/plugins/lua/dmarc.lua index e3cc09bf0..f7a95c5af 100644 --- a/src/plugins/lua/dmarc.lua +++ b/src/plugins/lua/dmarc.lua @@ -255,6 +255,12 @@ local function dmarc_callback(task) local dmarc_domain, efromdom, spf_domain local ip_addr = task:get_ip() local dkim_results = {} + local dmarc_checks = task:get_mempool():get_variable('dmarc_checks', 'int') or 0 + + if dmarc_checks ~= 2 then + rspamd_logger.infox(task, "skip DMARC checks as either SPF or DKIM were not checked"); + return + end if ((not check_authed and task:get_user()) or (not check_local and ip_addr and ip_addr:is_local())) then diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 883fabde4..c9bc5d67d 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -549,6 +549,21 @@ spf_symbol_callback (struct rspamd_task *task, void *unused) const gchar *domain; struct spf_resolved *l; struct rspamd_async_watcher *w; + gint *dmarc_checks; + + /* Allow dmarc */ + dmarc_checks = rspamd_mempool_get_variable (task->task_pool, "dmarc_checks"); + + if (dmarc_checks) { + (*dmarc_checks) ++; + } + else { + dmarc_checks = rspamd_mempool_alloc (task->task_pool, + sizeof (*dmarc_checks)); + *dmarc_checks = 1; + rspamd_mempool_set_variable (task->task_pool, "dmarc_checks", + dmarc_checks, NULL); + } if (radix_find_compressed_addr (spf_module_ctx->whitelist_ip, task->from_addr) != RADIX_NO_VALUE) { -- 2.39.5