From 33773cc81fe34d96d27aba8a3a752958302f93f3 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 7 Apr 2016 12:14:01 +0100 Subject: [PATCH] [Feature] Insert redirected URL to the urls list --- src/libserver/protocol.c | 52 +++++++++++++++++++++++++++------------- src/libserver/url.h | 1 + src/plugins/surbl.c | 7 ++++++ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 35c912f59..e32dfc6e5 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -595,6 +595,39 @@ struct tree_cb_data { struct rspamd_task *task; }; +static ucl_object_t * +rspamd_protocol_extended_url (struct rspamd_url *url) +{ + ucl_object_t *obj, *elt; + + obj = ucl_object_typed_new (UCL_OBJECT); + + elt = ucl_object_fromlstring (url->string, url->urllen); + ucl_object_insert_key (obj, elt, "url", 0, false); + + if (url->surbllen > 0) { + elt = ucl_object_fromlstring (url->surbl, url->surbllen); + ucl_object_insert_key (obj, elt, "surbl", 0, false); + } + if (url->hostlen > 0) { + elt = ucl_object_fromlstring (url->host, url->hostlen); + ucl_object_insert_key (obj, elt, "host", 0, false); + } + + elt = ucl_object_frombool (url->flags & RSPAMD_URL_FLAG_PHISHED); + ucl_object_insert_key (obj, elt, "phished", 0, false); + + elt = ucl_object_frombool (url->flags & RSPAMD_URL_FLAG_REDIRECTED); + ucl_object_insert_key (obj, elt, "redirected", 0, false); + + if (url->phished_url) { + elt = rspamd_protocol_extended_url (url->phished_url); + ucl_object_insert_key (obj, elt, "orig_url", 0, false); + } + + return obj; +} + /* * Callback for writing urls */ @@ -603,7 +636,7 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud) { struct tree_cb_data *cb = ud; struct rspamd_url *url = value; - ucl_object_t *obj, *elt; + ucl_object_t *obj; struct rspamd_task *task = cb->task; const gchar *user_field = "unknown"; gboolean has_user = FALSE; @@ -612,22 +645,7 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud) obj = ucl_object_fromlstring (url->string, url->urllen); } else { - obj = ucl_object_typed_new (UCL_OBJECT); - - elt = ucl_object_fromlstring (url->string, url->urllen); - ucl_object_insert_key (obj, elt, "url", 0, false); - - if (url->surbllen > 0) { - elt = ucl_object_fromlstring (url->surbl, url->surbllen); - ucl_object_insert_key (obj, elt, "surbl", 0, false); - } - if (url->hostlen > 0) { - elt = ucl_object_fromlstring (url->host, url->hostlen); - ucl_object_insert_key (obj, elt, "host", 0, false); - } - - elt = ucl_object_frombool (url->flags & RSPAMD_URL_FLAG_PHISHED); - ucl_object_insert_key (obj, elt, "phished", 0, false); + obj = rspamd_protocol_extended_url (url); } ucl_array_append (cb->top, obj); diff --git a/src/libserver/url.h b/src/libserver/url.h index 4d38e3d79..7dfcb05af 100644 --- a/src/libserver/url.h +++ b/src/libserver/url.h @@ -13,6 +13,7 @@ enum rspamd_url_flags { RSPAMD_URL_FLAG_PHISHED = 1 << 0, RSPAMD_URL_FLAG_NUMERIC = 1 << 1, RSPAMD_URL_FLAG_OBSCURED = 1 << 2, + RSPAMD_URL_FLAG_REDIRECTED = 1 << 3, }; struct rspamd_url { diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index dcf69f8f2..ad2c3be9c 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -1281,6 +1281,13 @@ surbl_redirector_finish (struct rspamd_http_connection *conn, task->task_pool); if (r == URI_ERRNO_OK) { + if (!g_hash_table_lookup (task->urls, redirected_url)) { + g_hash_table_insert (task->urls, redirected_url, + redirected_url); + redirected_url->phished_url = param->url; + redirected_url->flags |= RSPAMD_URL_FLAG_REDIRECTED; + } + make_surbl_requests (redirected_url, param->task, param->suffix, -- 2.39.5