diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-21 14:31:21 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-21 14:31:21 +0000 |
commit | a1846d2e75b9e2f0c396dc7fb719cec6d15c4c14 (patch) | |
tree | 6269a6186f252b6d0b1514e41793ecf2387b97d7 | |
parent | 5f62643beef8244e765181008b37fece116ebde1 (diff) | |
download | rspamd-a1846d2e75b9e2f0c396dc7fb719cec6d15c4c14.tar.gz rspamd-a1846d2e75b9e2f0c396dc7fb719cec6d15c4c14.zip |
[Feature] Support checking for redirector in Lua SURBL
-rw-r--r-- | src/plugins/surbl.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index f079be445..426ff996e 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -75,6 +75,7 @@ static void process_dns_results (struct rspamd_task *task, guint32 addr, struct rspamd_url *url); static gint surbl_register_redirect_handler (lua_State *L); static gint surbl_continue_process_handler (lua_State *L); +static gint surbl_is_redirector_handler (lua_State *L); #define NO_REGEXP (gpointer) - 1 @@ -720,6 +721,9 @@ surbl_module_config (struct rspamd_config *cfg) lua_pushstring (L, "continue_process"); lua_pushcfunction (L, surbl_continue_process_handler); lua_settable (L, -3); + lua_pushstring (L, "is_redirector"); + lua_pushcfunction (L, surbl_is_redirector_handler); + lua_settable (L, -3); /* Finish fuzzy_check key */ lua_settable (L, -3); } @@ -1720,6 +1724,68 @@ surbl_register_redirect_handler (lua_State *L) return 0; } +static gint +surbl_is_redirector_handler (lua_State *L) +{ + const gchar *url; + struct rspamd_task *task; + struct rspamd_url uri; + gsize len; + rspamd_regexp_t *re; + rspamd_ftok_t srch; + gboolean found = FALSE; + gchar *found_tld, *url_cpy; + + task = lua_check_task (L, 1); + url = luaL_checklstring (L, 2, &len); + + if (task && url) { + url_cpy = rspamd_mempool_alloc (task->task_pool, len); + memcpy (url_cpy, url, len); + + if (rspamd_url_parse (&uri, url_cpy, len, task->task_pool)) { + msg_debug_surbl ("check url redirection %*s", uri.urllen, + uri.string); + + if (uri.hostlen <= 0) { + lua_pushboolean (L, false); + + return 1; + } + + /* Search in trie */ + srch.begin = uri.tld; + srch.len = uri.tldlen; + re = g_hash_table_lookup (surbl_module_ctx->redirector_tlds, &srch); + + if (re) { + if (re == NO_REGEXP) { + found = TRUE; + } + else if (rspamd_regexp_search (re, uri.string, 0, + NULL, NULL, TRUE, NULL)) { + found = TRUE; + } + + if (found) { + found_tld = rspamd_mempool_ftokdup (task->task_pool, &srch); + lua_pushboolean (L, true); + lua_pushstring (L, found_tld); + + return 2; + } + } + } + } + else { + return luaL_error (L, "arguments must be: task, url"); + } + + lua_pushboolean (L, false); + + return 1; +} + /* * Accepts two arguments: * url: string with a redirected URL, if url is nil, then it couldn't be resolved |