From 68e60c48745e40038e9a123fe9381b86d0b1534e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 31 May 2012 22:10:50 +0400 Subject: [PATCH] * Allow keys without values in kv maps Some fixes to dkim_check strict logic. --- src/map.c | 16 ++++++++++++++-- src/plugins/dkim_check.c | 11 ++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/map.c b/src/map.c index c82bd1ceb..9dc5ccfaf 100644 --- a/src/map.c +++ b/src/map.c @@ -587,23 +587,35 @@ abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct ma /* read key */ /* Check here comments, eol and end of buffer */ if (*p == '#') { - if (key != NULL && p - c > 0) { + if (key != NULL && p - c >= 0) { value = memory_pool_alloc (pool, p - c + 1); memcpy (value, c, p - c); value[p - c] = '\0'; value = g_strstrip (value); func (data->cur_data, key, value); + msg_debug ("insert kv pair: %s -> %s", key, value); } data->state = 99; } else if (*p == '\r' || *p == '\n' || p - chunk == len - 1) { - if (key != NULL && p - c > 0) { + if (key != NULL && p - c >= 0) { value = memory_pool_alloc (pool, p - c + 1); memcpy (value, c, p - c); value[p - c] = '\0'; value = g_strstrip (value); func (data->cur_data, key, value); + msg_debug ("insert kv pair: %s -> %s", key, value); + } + else if (key == NULL && p - c > 0) { + /* Key only line */ + key = memory_pool_alloc (pool, p - c + 1); + memcpy (key, c, p - c); + key[p - c] = '\0'; + value = memory_pool_alloc (pool, 1); + *value = '\0'; + func (data->cur_data, key, value); + msg_debug ("insert kv pair: %s -> %s", key, value); } data->state = 100; key = NULL; diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 60f29d4e3..ce4fdb1d1 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -214,18 +214,23 @@ dkim_module_parse_strict (const gchar *value, gint *allow, gint *deny) static void dkim_module_check (struct worker_task *task, rspamd_dkim_context_t *ctx, rspamd_dkim_key_t *key) { - gint res, score_allow, score_deny; + gint res, score_allow = 1, score_deny = 1; const gchar *strict_value; - msg_debug ("check dkim signature for %s domain", ctx->dns_key); + msg_debug ("check dkim signature for %s domain from %s", ctx->domain, ctx->dns_key); res = rspamd_dkim_check (ctx, key, task); if (dkim_module_ctx->strict_domains != NULL) { /* Perform strict check */ - if ((strict_value = g_hash_table_lookup (dkim_module_ctx->strict_domains, ctx->dns_key)) != NULL) { + if ((strict_value = g_hash_table_lookup (dkim_module_ctx->strict_domains, ctx->domain)) != NULL) { if (!dkim_module_parse_strict (strict_value, &score_allow, &score_deny)) { score_allow = dkim_module_ctx->strict_multiplier; score_deny = dkim_module_ctx->strict_multiplier; + msg_debug ("no specific score found for %s domain, using %d for it", ctx->domain, score_deny); + } + else { + msg_debug ("specific score found for %s domain: using %d for deny and %d for allow", + ctx->dns_key, score_deny, score_allow); } } } -- 2.39.5