From: Vsevolod Stakhov Date: Wed, 1 Oct 2014 16:28:27 +0000 (+0100) Subject: Fix fuzzy_check and spf. X-Git-Tag: 0.7.2~41 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ebdf58dc0aed1014374dc56c0b28fe76f3b0c0b1;p=rspamd.git Fix fuzzy_check and spf. --- diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 3bac2f7b2..323246f71 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -92,7 +92,7 @@ struct fuzzy_ctx { struct rspamd_config *cfg; const gchar *default_symbol; guint32 min_hash_len; - radix_tree_t *whitelist; + radix_compressed_t *whitelist; guint32 min_bytes; guint32 min_height; guint32 min_width; @@ -482,11 +482,12 @@ fuzzy_check_module_config (struct rspamd_config *cfg) if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "whitelist")) != NULL) { - fuzzy_module_ctx->whitelist = radix_tree_create (); + fuzzy_module_ctx->whitelist = radix_create_compressed (); if (!add_map (cfg, ucl_obj_tostring (value), "Fuzzy whitelist", read_radix_list, fin_radix_list, (void **)&fuzzy_module_ctx->whitelist)) { - msg_err ("cannot add whitelist '%s'", ucl_obj_tostring (value)); + rspamd_config_parse_ip_list (ucl_obj_tostring (value), + &fuzzy_module_ctx->whitelist); } } else { @@ -913,10 +914,9 @@ fuzzy_symbol_callback (struct rspamd_task *task, void *unused) GList *cur; /* Check whitelist */ - if (fuzzy_module_ctx->whitelist && task->from_addr.af == AF_INET) { - if (radix32tree_find (fuzzy_module_ctx->whitelist, - ntohl (task->from_addr.addr.s4.sin_addr.s_addr)) != - RADIX_NO_VALUE) { + if (fuzzy_module_ctx->whitelist) { + if (radix_find_compressed_addr (fuzzy_module_ctx->whitelist, + &task->from_addr) != RADIX_NO_VALUE) { msg_info ("<%s>, address %s is whitelisted, skip fuzzy check", task->message_id, rspamd_inet_address_to_string (&task->from_addr)); diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 34eb69a25..e435da36d 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -53,7 +53,7 @@ struct spf_ctx { const gchar *symbol_allow; rspamd_mempool_t *spf_pool; - radix_tree_t *whitelist_ip; + radix_compressed_t *whitelist_ip; rspamd_lru_hash_t *spf_hash; }; @@ -97,7 +97,7 @@ spf_module_config (struct rspamd_config *cfg) gint res = TRUE; guint cache_size, cache_expire; - spf_module_ctx->whitelist_ip = radix_tree_create (); + spf_module_ctx->whitelist_ip = radix_create_compressed (); if ((value = rspamd_config_get_module_opt (cfg, "spf", "symbol_fail")) != NULL) { @@ -140,7 +140,8 @@ spf_module_config (struct rspamd_config *cfg) if (!add_map (cfg, ucl_obj_tostring (value), "SPF whitelist", read_radix_list, fin_radix_list, (void **)&spf_module_ctx->whitelist_ip)) { - msg_warn ("cannot load whitelist from %s", value); + rspamd_config_parse_ip_list (ucl_obj_tostring (value), + &spf_module_ctx->whitelist_ip); } } @@ -165,7 +166,7 @@ gint spf_module_reconfig (struct rspamd_config *cfg) { rspamd_mempool_delete (spf_module_ctx->spf_pool); - radix_tree_free (spf_module_ctx->whitelist_ip); + radix_destroy_compressed (spf_module_ctx->whitelist_ip); memset (spf_module_ctx, 0, sizeof (*spf_module_ctx)); spf_module_ctx->spf_pool = rspamd_mempool_new ( rspamd_mempool_suggest_size ()); @@ -324,7 +325,8 @@ spf_symbol_callback (struct rspamd_task *task, void *unused) gchar *domain; GList *l; - if (task->from_addr.af != AF_UNIX) { + if (radix_find_compressed_addr (spf_module_ctx->whitelist_ip, + &task->from_addr) == RADIX_NO_VALUE) { domain = get_spf_domain (task); if (domain) { if ((l =