diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-08-18 15:00:07 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-08-18 15:00:07 +0100 |
commit | 4b0b45c29baba61e43a546446be30a0ccdc1075f (patch) | |
tree | d675aa17be70e956c33a60cbde6a3543e5075110 /src | |
parent | 3f4624d24b2814242415e7cd87f94fb505b897aa (diff) | |
download | rspamd-4b0b45c29baba61e43a546446be30a0ccdc1075f.tar.gz rspamd-4b0b45c29baba61e43a546446be30a0ccdc1075f.zip |
Adopt spf module for new from/rcpt.
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/protocol.c | 16 | ||||
-rw-r--r-- | src/libserver/spf.c | 93 | ||||
-rw-r--r-- | src/libserver/spf.h | 2 |
3 files changed, 24 insertions, 87 deletions
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index e7be5a1c3..38d6452cf 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -229,10 +229,10 @@ gboolean rspamd_protocol_handle_headers (struct rspamd_task *task, struct rspamd_http_message *msg) { - gchar *headern, *err, *tmp; + gchar *headern, *tmp; gboolean res = TRUE, validh; struct rspamd_http_header *h; - InternetAddressList *tmp; + InternetAddressList *tmp_addr; LL_FOREACH (msg->headers, h) { @@ -317,14 +317,14 @@ rspamd_protocol_handle_headers (struct rspamd_task *task, if (task->rcpt_envelope == NULL) { task->rcpt_envelope = internet_address_list_new (); } - tmp = internet_address_list_parse_string (h->value->str); - internet_address_list_append (task->rcpt_envelope, tmp); + tmp_addr = internet_address_list_parse_string (h->value->str); + internet_address_list_append (task->rcpt_envelope, tmp_addr); #ifdef GMIME24 - g_object_unref (tmp); + g_object_unref (tmp_addr); #else - internet_address_list_destroy (tmp); + internet_address_list_destroy (tmp_addr); #endif - debug_task ("read rcpt header, value: %s", tmp); + debug_task ("read rcpt header, value: %v", h->value); } else { msg_info ("wrong header: %s", headern); @@ -484,7 +484,7 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud) msg_info ("<%s> URL: %s - %s: %s", cb->task->message_id, cb->task->user ? - cb->task->user : (cb->task->from ? cb->task->from : "unknown"), + cb->task->user : "unknown", rspamd_inet_address_to_string (&cb->task->from_addr), struri (url)); } diff --git a/src/libserver/spf.c b/src/libserver/spf.c index 56640cead..0ef952a31 100644 --- a/src/libserver/spf.c +++ b/src/libserver/spf.c @@ -1551,35 +1551,14 @@ gchar * get_spf_domain (struct rspamd_task *task) { gchar *domain, *res = NULL; - GList *domains; + const gchar *sender; - if (task->from && - (domain = strchr (task->from, '@')) != NULL && *domain == '@') { - res = rspamd_mempool_strdup (task->task_pool, domain + 1); - if ((domain = strchr (res, '>')) != NULL) { - *domain = '\0'; - } - } - else { - /* Extract from header */ - domains = message_get_header (task->task_pool, - task->message, - "From", - FALSE); + sender = rspamd_task_get_sender (task); - if (domains != NULL) { - res = rspamd_mempool_strdup (task->task_pool, domains->data); - - if ((domain = strrchr (res, '@')) == NULL) { - g_list_free (domains); - return NULL; - } + if (sender != NULL) { + domain = strchr (sender, '@'); + if (domain) { res = rspamd_mempool_strdup (task->task_pool, domain + 1); - g_list_free (domains); - - if ((domain = strchr (res, '>')) != NULL) { - *domain = '\0'; - } } } @@ -1591,31 +1570,27 @@ resolve_spf (struct rspamd_task *task, spf_cb_t callback) { struct spf_record *rec; gchar *domain; - GList *domains; + const gchar *sender; + + sender = rspamd_task_get_sender (task); rec = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct spf_record)); rec->task = task; rec->callback = callback; + /* Add destructor */ rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)spf_record_destructor, rec); /* Extract from data */ - if (task->from && - (domain = strchr (task->from, '@')) != NULL && *domain == '@') { - rec->sender = task->from; - - rec->local_part = rspamd_mempool_strdup (task->task_pool, task->from); - *(rec->local_part + (domain - task->from)) = '\0'; - if (*rec->local_part == '<') { - memmove (rec->local_part, rec->local_part + 1, - strlen (rec->local_part)); - } + if (sender != NULL && (domain = strchr (sender, '@')) != NULL) { + rec->sender = sender; + + rec->local_part = rspamd_mempool_alloc (task->task_pool, + domain - sender); + rspamd_strlcpy (rec->local_part, sender, domain - sender); rec->cur_domain = rspamd_mempool_strdup (task->task_pool, domain + 1); - if ((domain = strchr (rec->cur_domain, '>')) != NULL) { - *domain = '\0'; - } rec->sender_domain = rec->cur_domain; if (make_dns_request (task->resolver, task->s, task->task_pool, @@ -1626,44 +1601,6 @@ resolve_spf (struct rspamd_task *task, spf_cb_t callback) return TRUE; } } - else { - /* Extract from header */ - domains = message_get_header (task->task_pool, - task->message, - "From", - FALSE); - - if (domains != NULL) { - rec->cur_domain = rspamd_mempool_strdup (task->task_pool, - domains->data); - g_list_free (domains); - - if ((domain = strrchr (rec->cur_domain, '@')) == NULL) { - return FALSE; - } - rec->sender = rspamd_mempool_strdup (task->task_pool, - rec->cur_domain); - rec->local_part = rec->cur_domain; - *domain = '\0'; - rec->cur_domain = domain + 1; - - if ((domain = strchr (rec->local_part, '<')) != NULL) { - memmove (rec->local_part, domain + 1, strlen (domain)); - } - - if ((domain = strchr (rec->cur_domain, '>')) != NULL) { - *domain = '\0'; - } - rec->sender_domain = rec->cur_domain; - if (make_dns_request (task->resolver, task->s, task->task_pool, - spf_dns_callback, (void *)rec, RDNS_REQUEST_TXT, - rec->cur_domain)) { - task->dns_requests++; - rec->requests_inflight++; - return TRUE; - } - } - } return FALSE; } diff --git a/src/libserver/spf.h b/src/libserver/spf.h index 18d8229f8..616595c35 100644 --- a/src/libserver/spf.h +++ b/src/libserver/spf.h @@ -60,7 +60,7 @@ struct spf_record { GList *addrs; gchar *cur_domain; - gchar *sender; + const gchar *sender; gchar *sender_domain; gchar *local_part; struct rspamd_task *task; |