diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:53:08 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:53:08 +0100 |
commit | fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b (patch) | |
tree | c84e6a5d4c5cd78a7a2cc3c7adbc7af5d0541682 /src/plugins/spf.c | |
parent | e0483657ff6cf1adc828ccce457814d61fe90a0d (diff) | |
download | rspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.tar.gz rspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.zip |
Revert "Unify code style."
This reverts commit e0483657ff6cf1adc828ccce457814d61fe90a0d.
Diffstat (limited to 'src/plugins/spf.c')
-rw-r--r-- | src/plugins/spf.c | 175 |
1 files changed, 68 insertions, 107 deletions
diff --git a/src/plugins/spf.c b/src/plugins/spf.c index ecbb40889..8b9e64754 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -32,15 +32,15 @@ * - whitelist (map): map of whitelisted networks */ -#include "cfg_file.h" #include "config.h" -#include "expressions.h" -#include "hash.h" #include "main.h" -#include "map.h" #include "message.h" -#include "spf.h" +#include "cfg_file.h" +#include "expressions.h" #include "util.h" +#include "map.h" +#include "spf.h" +#include "hash.h" #define DEFAULT_SYMBOL_FAIL "R_SPF_FAIL" #define DEFAULT_SYMBOL_SOFTFAIL "R_SPF_SOFTFAIL" @@ -49,21 +49,21 @@ #define DEFAULT_CACHE_MAXAGE 86400 struct spf_ctx { - gint (*filter) (struct rspamd_task * task); - const gchar *symbol_fail; - const gchar *symbol_softfail; - const gchar *symbol_allow; - - rspamd_mempool_t *spf_pool; - radix_tree_t *whitelist_ip; - rspamd_lru_hash_t *spf_hash; + gint (*filter) (struct rspamd_task * task); + const gchar *symbol_fail; + const gchar *symbol_softfail; + const gchar *symbol_allow; + + rspamd_mempool_t *spf_pool; + radix_tree_t *whitelist_ip; + rspamd_lru_hash_t *spf_hash; }; -static struct spf_ctx *spf_module_ctx = NULL; +static struct spf_ctx *spf_module_ctx = NULL; -static void spf_symbol_callback (struct rspamd_task *task, void *unused); -static GList * spf_record_copy (GList *addrs); -static void spf_record_destroy (gpointer list); +static void spf_symbol_callback (struct rspamd_task *task, void *unused); +static GList * spf_record_copy (GList *addrs); +static void spf_record_destroy (gpointer list); /* Initialization */ gint spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx); @@ -83,8 +83,7 @@ spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx) { spf_module_ctx = g_malloc (sizeof (struct spf_ctx)); - spf_module_ctx->spf_pool = rspamd_mempool_new ( - rspamd_mempool_suggest_size ()); + spf_module_ctx->spf_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); *ctx = (struct module_ctx *)spf_module_ctx; @@ -95,71 +94,56 @@ spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx) gint spf_module_config (struct rspamd_config *cfg) { - const ucl_object_t *value; - gint res = TRUE; - guint cache_size, cache_expire; + const ucl_object_t *value; + gint res = TRUE; + guint cache_size, cache_expire; spf_module_ctx->whitelist_ip = radix_tree_create (); - - if ((value = - rspamd_config_get_module_opt (cfg, "spf", "symbol_fail")) != NULL) { + + if ((value = rspamd_config_get_module_opt (cfg, "spf", "symbol_fail")) != NULL) { spf_module_ctx->symbol_fail = ucl_obj_tostring (value); } else { spf_module_ctx->symbol_fail = DEFAULT_SYMBOL_FAIL; } - if ((value = - rspamd_config_get_module_opt (cfg, "spf", "symbol_softfail")) != NULL) { + if ((value = rspamd_config_get_module_opt (cfg, "spf", "symbol_softfail")) != NULL) { spf_module_ctx->symbol_softfail = ucl_obj_tostring (value); } else { spf_module_ctx->symbol_softfail = DEFAULT_SYMBOL_SOFTFAIL; } - if ((value = - rspamd_config_get_module_opt (cfg, "spf", "symbol_allow")) != NULL) { + if ((value = rspamd_config_get_module_opt (cfg, "spf", "symbol_allow")) != NULL) { spf_module_ctx->symbol_allow = ucl_obj_tostring (value); } else { spf_module_ctx->symbol_allow = DEFAULT_SYMBOL_ALLOW; } - if ((value = - rspamd_config_get_module_opt (cfg, "spf", "spf_cache_size")) != NULL) { + if ((value = rspamd_config_get_module_opt (cfg, "spf", "spf_cache_size")) != NULL) { cache_size = ucl_obj_toint (value); } else { cache_size = DEFAULT_CACHE_SIZE; } - if ((value = - rspamd_config_get_module_opt (cfg, "spf", - "spf_cache_expire")) != NULL) { + if ((value = rspamd_config_get_module_opt (cfg, "spf", "spf_cache_expire")) != NULL) { cache_expire = ucl_obj_toint (value); } else { cache_expire = DEFAULT_CACHE_MAXAGE; } - if ((value = - rspamd_config_get_module_opt (cfg, "spf", "whitelist")) != NULL) { - if (!add_map (cfg, ucl_obj_tostring (value), - "SPF whitelist", read_radix_list, fin_radix_list, - (void **)&spf_module_ctx->whitelist_ip)) { + if ((value = rspamd_config_get_module_opt (cfg, "spf", "whitelist")) != NULL) { + 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); } } - register_symbol (&cfg->cache, - spf_module_ctx->symbol_fail, - 1, - spf_symbol_callback, - NULL); + register_symbol (&cfg->cache, spf_module_ctx->symbol_fail, 1, spf_symbol_callback, NULL); register_virtual_symbol (&cfg->cache, spf_module_ctx->symbol_softfail, 1); - register_virtual_symbol (&cfg->cache, spf_module_ctx->symbol_allow, 1); + register_virtual_symbol (&cfg->cache, spf_module_ctx->symbol_allow, 1); - spf_module_ctx->spf_hash = rspamd_lru_hash_new (rspamd_strcase_hash, - rspamd_strcase_equal, - cache_size, - cache_expire, - g_free, - spf_record_destroy); + spf_module_ctx->spf_hash = rspamd_lru_hash_new (rspamd_strcase_hash, rspamd_strcase_equal, + cache_size, cache_expire, g_free, spf_record_destroy); return res; } @@ -169,8 +153,7 @@ spf_module_reconfig (struct rspamd_config *cfg) { rspamd_mempool_delete (spf_module_ctx->spf_pool); radix_tree_free (spf_module_ctx->whitelist_ip); - spf_module_ctx->spf_pool = rspamd_mempool_new ( - rspamd_mempool_suggest_size ()); + spf_module_ctx->spf_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); return spf_module_config (cfg); } @@ -178,30 +161,26 @@ spf_module_reconfig (struct rspamd_config *cfg) static gboolean spf_check_element (struct spf_addr *addr, struct rspamd_task *task) { - gboolean res = FALSE; - guint8 *s, *d, t; - guint nbits, addrlen; - struct in_addr in4s, in4d; - struct in6_addr in6s, in6d; + gboolean res = FALSE; + guint8 *s, *d, t; + guint nbits, addrlen; + struct in_addr in4s, in4d; + struct in6_addr in6s, in6d; /* Basic comparing algorithm */ if ((addr->data.normal.ipv6 && task->from_addr.af == AF_INET6) || - (!addr->data.normal.ipv6 && task->from_addr.af == AF_INET)) { + (!addr->data.normal.ipv6 && task->from_addr.af == AF_INET)) { if (addr->data.normal.ipv6) { addrlen = sizeof (struct in6_addr); - memcpy (&in6s, &addr->data.normal.d.in6, - sizeof (struct in6_addr)); - memcpy (&in6d, &task->from_addr.addr.s6.sin6_addr, - sizeof (struct in6_addr)); + memcpy (&in6s, &addr->data.normal.d.in6, sizeof (struct in6_addr)); + memcpy (&in6d, &task->from_addr.addr.s6.sin6_addr, sizeof (struct in6_addr)); s = (guint8 *)&in6s; d = (guint8 *)&in6d; } else { addrlen = sizeof (struct in_addr); - memcpy (&in4s, &addr->data.normal.d.in4, - sizeof (struct in_addr)); - memcpy (&in4d, &task->from_addr.addr.s4.sin_addr, - sizeof (struct in_addr)); + memcpy (&in4s, &addr->data.normal.d.in4, sizeof (struct in_addr)); + memcpy (&in4d, &task->from_addr.addr.s4.sin_addr, sizeof (struct in_addr)); s = (guint8 *)&in4s; d = (guint8 *)&in4d; } @@ -210,14 +189,12 @@ spf_check_element (struct spf_addr *addr, struct rspamd_task *task) s += addrlen - 1; d += addrlen - 1; /* TODO: improve this cycle by masking by words */ - for (nbits = 0; - nbits < addrlen * CHAR_BIT - addr->data.normal.mask; - nbits++) { + for (nbits = 0; nbits < addrlen * CHAR_BIT - addr->data.normal.mask; nbits ++) { /* Skip bits from the beginning as we know that data is in network byte order */ if (nbits != 0 && nbits % 8 == 0) { /* Move pointer to the next byte */ - s--; - d--; + s --; + d --; t = 0x1; } *s |= t; @@ -243,28 +220,17 @@ spf_check_element (struct spf_addr *addr, struct rspamd_task *task) if (res) { switch (addr->mech) { case SPF_FAIL: - insert_result (task, - spf_module_ctx->symbol_fail, - 1, - g_list_prepend (NULL, addr->spf_string)); + insert_result (task, spf_module_ctx->symbol_fail, 1, g_list_prepend (NULL, addr->spf_string)); task->messages = g_list_prepend (task->messages, "(SPF): spf fail"); break; case SPF_SOFT_FAIL: case SPF_NEUTRAL: - insert_result (task, - spf_module_ctx->symbol_softfail, - 1, - g_list_prepend (NULL, addr->spf_string)); - task->messages = g_list_prepend (task->messages, - "(SPF): spf softfail"); + insert_result (task, spf_module_ctx->symbol_softfail, 1, g_list_prepend (NULL, addr->spf_string)); + task->messages = g_list_prepend (task->messages, "(SPF): spf softfail"); break; default: - insert_result (task, - spf_module_ctx->symbol_allow, - 1, - g_list_prepend (NULL, addr->spf_string)); - task->messages = - g_list_prepend (task->messages, "(SPF): spf allow"); + insert_result (task, spf_module_ctx->symbol_allow, 1, g_list_prepend (NULL, addr->spf_string)); + task->messages = g_list_prepend (task->messages, "(SPF): spf allow"); break; } return TRUE; @@ -276,8 +242,8 @@ spf_check_element (struct spf_addr *addr, struct rspamd_task *task) static gboolean spf_check_list (GList *list, struct rspamd_task *task) { - GList *cur; - struct spf_addr *addr; + GList *cur; + struct spf_addr *addr; cur = list; @@ -300,19 +266,16 @@ spf_check_list (GList *list, struct rspamd_task *task) return FALSE; } -static void +static void spf_plugin_callback (struct spf_record *record, struct rspamd_task *task) { - GList *l; + GList *l; if (record && record->addrs && record->sender_domain) { - if ((l = - rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, - record->sender_domain, task->tv.tv_sec)) == NULL) { + if ((l = rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, record->sender_domain, task->tv.tv_sec)) == NULL) { l = spf_record_copy (record->addrs); - rspamd_lru_hash_insert (spf_module_ctx->spf_hash, - g_strdup (record->sender_domain), + rspamd_lru_hash_insert (spf_module_ctx->spf_hash, g_strdup (record->sender_domain), l, task->tv.tv_sec, record->ttl); } spf_check_list (l, task); @@ -320,18 +283,16 @@ spf_plugin_callback (struct spf_record *record, struct rspamd_task *task) } -static void +static void spf_symbol_callback (struct rspamd_task *task, void *unused) { - gchar *domain; - GList *l; + gchar *domain; + GList *l; if (task->from_addr.af != AF_UNIX) { domain = get_spf_domain (task); if (domain) { - if ((l = - rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, domain, - task->tv.tv_sec)) != NULL) { + if ((l = rspamd_lru_hash_lookup (spf_module_ctx->spf_hash, domain, task->tv.tv_sec)) != NULL) { spf_check_list (l, task); } else if (!resolve_spf (task, spf_plugin_callback)) { @@ -347,8 +308,8 @@ spf_symbol_callback (struct rspamd_task *task, void *unused) static GList * spf_record_copy (GList *addrs) { - GList *cur, *newl = NULL; - struct spf_addr *addr, *newa; + GList *cur, *newl = NULL; + struct spf_addr *addr, *newa; cur = addrs; @@ -380,8 +341,8 @@ spf_record_copy (GList *addrs) static void spf_record_destroy (gpointer list) { - GList *cur = list; - struct spf_addr *addr; + GList *cur = list; + struct spf_addr *addr; while (cur) { addr = cur->data; |