diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-22 16:00:25 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-07-22 16:00:25 +0100 |
commit | d814e862c3e34199c77134c27105c08bd975e178 (patch) | |
tree | 1d476f2383986fc31d0d68206977abb91e961472 /src/plugins/spf.c | |
parent | 23084e297df504c84fcb07c951246473cbab9293 (diff) | |
download | rspamd-d814e862c3e34199c77134c27105c08bd975e178.tar.gz rspamd-d814e862c3e34199c77134c27105c08bd975e178.zip |
[Fix] Allow to set 0 size for spf/dkim caches
Issue: #2991
Diffstat (limited to 'src/plugins/spf.c')
-rw-r--r-- | src/plugins/spf.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 9c54bb696..841d74e2c 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -351,20 +351,22 @@ spf_module_config (struct rspamd_config *cfg) SYMBOL_TYPE_VIRTUAL, cb_id); - spf_module_ctx->spf_hash = rspamd_lru_hash_new ( - cache_size, - NULL, - (GDestroyNotify)spf_record_unref); - - msg_info_config ("init internal spf module"); + if (cache_size > 0) { + spf_module_ctx->spf_hash = rspamd_lru_hash_new ( + cache_size, + NULL, + (GDestroyNotify) spf_record_unref); + rspamd_mempool_add_destructor (cfg->cfg_pool, + (rspamd_mempool_destruct_t)rspamd_lru_hash_destroy, + spf_module_ctx->spf_hash); + } rspamd_mempool_add_destructor (cfg->cfg_pool, - (rspamd_mempool_destruct_t)rspamd_lru_hash_destroy, - spf_module_ctx->spf_hash); - rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)rspamd_map_helper_destroy_radix, spf_module_ctx->whitelist_ip); + msg_info_config ("init internal spf module"); + return res; } @@ -543,7 +545,7 @@ static void spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task, gpointer ud) { - struct spf_resolved *l; + struct spf_resolved *l = NULL; struct rspamd_symcache_item *item = (struct rspamd_symcache_item *)ud; struct spf_ctx *spf_module_ctx = spf_get_context (task->cfg); @@ -575,7 +577,8 @@ spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task, spf_record_ref (record); - if ((l = rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, + if (!spf_module_ctx->spf_hash || + (l = rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, record->domain, task->task_timestamp)) == NULL) { l = record; @@ -584,17 +587,19 @@ spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task, !record->perm_failed && !record->na) { - rspamd_lru_hash_insert (spf_module_ctx->spf_hash, - record->domain, spf_record_ref (l), - task->task_timestamp, record->ttl); - - msg_info_task ("stored record for %s (0x%xuL) in LRU cache for %d seconds, " - "%d/%d elements in the cache", - record->domain, - record->digest, - record->ttl, - rspamd_lru_hash_size (spf_module_ctx->spf_hash), - rspamd_lru_hash_capacity (spf_module_ctx->spf_hash)); + if (spf_module_ctx->spf_hash) { + rspamd_lru_hash_insert (spf_module_ctx->spf_hash, + record->domain, spf_record_ref (l), + task->task_timestamp, record->ttl); + + msg_info_task ("stored record for %s (0x%xuL) in LRU cache for %d seconds, " + "%d/%d elements in the cache", + record->domain, + record->digest, + record->ttl, + rspamd_lru_hash_size (spf_module_ctx->spf_hash), + rspamd_lru_hash_capacity (spf_module_ctx->spf_hash)); + } } } @@ -655,8 +660,8 @@ spf_symbol_callback (struct rspamd_task *task, rspamd_symcache_item_async_inc (task, item, M); if (domain) { - if ((l = - rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, domain, + if (spf_module_ctx->spf_hash && + (l = rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, domain, task->task_timestamp)) != NULL) { spf_record_ref (l); spf_check_list (l, task, TRUE); |