]> source.dussan.org Git - rspamd.git/commitdiff
* Allow keys without values in kv maps
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 31 May 2012 18:10:50 +0000 (22:10 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 31 May 2012 18:10:50 +0000 (22:10 +0400)
Some fixes to dkim_check strict logic.

src/map.c
src/plugins/dkim_check.c

index c82bd1ceba643fbcebc7815509de5c3d650e2112..9dc5ccfaf9f8992b15ea7d6e3dab08eb255cb0b6 100644 (file)
--- 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;
index 60f29d4e34e7f532657508b776a4693c0e0b3234..ce4fdb1d17676aa92610995b1146e7a8d254cb58 100644 (file)
@@ -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);
                        }
                }
        }