diff options
author | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-14 14:21:32 +0100 |
---|---|---|
committer | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-14 14:21:32 +0100 |
commit | f9d4b50321057009489dbc673b108e6433f4ae38 (patch) | |
tree | 79b850b954d0552c95cab61cd1019c8f615d77be | |
parent | a9bc3d63a38ab46217303b09f8b03d0215c2f5ea (diff) | |
parent | 1af89c35663dd364c8d46523f0d71adc64f8bde4 (diff) | |
download | rspamd-f9d4b50321057009489dbc673b108e6433f4ae38.tar.gz rspamd-f9d4b50321057009489dbc673b108e6433f4ae38.zip |
Merge branch 'master' into lua-coroutine-model
-rw-r--r-- | lualib/lua_dkim_tools.lua | 7 | ||||
-rw-r--r-- | lualib/lua_util.lua | 2 | ||||
-rw-r--r-- | rules/regexp/headers.lua | 4 | ||||
-rw-r--r-- | src/libmime/message.c | 1 | ||||
-rw-r--r-- | src/libserver/dns.c | 36 | ||||
-rw-r--r-- | src/libserver/events.c | 15 | ||||
-rw-r--r-- | src/libserver/events.h | 7 | ||||
-rw-r--r-- | src/libstat/backends/redis_backend.c | 7 | ||||
-rw-r--r-- | src/libstat/learn_cache/redis_cache.c | 8 | ||||
-rw-r--r-- | src/libutil/logger.c | 11 | ||||
-rw-r--r-- | src/lua/lua_http.c | 8 | ||||
-rw-r--r-- | src/lua/lua_logger.c | 25 | ||||
-rw-r--r-- | src/lua/lua_redis.c | 11 | ||||
-rw-r--r-- | src/lua/lua_tcp.c | 17 | ||||
-rw-r--r-- | src/plugins/fuzzy_check.c | 167 | ||||
-rw-r--r-- | src/plugins/lua/dkim_signing.lua | 14 | ||||
-rw-r--r-- | src/plugins/surbl.c | 95 | ||||
-rw-r--r-- | src/rspamd_proxy.c | 5 | ||||
-rw-r--r-- | test/functional/lib/rspamd.py | 20 | ||||
-rw-r--r-- | test/functional/lib/rspamd.robot | 1 |
20 files changed, 314 insertions, 147 deletions
diff --git a/lualib/lua_dkim_tools.lua b/lualib/lua_dkim_tools.lua index e6ba2ea0c..832e8a3ea 100644 --- a/lualib/lua_dkim_tools.lua +++ b/lualib/lua_dkim_tools.lua @@ -178,12 +178,15 @@ local function prepare_dkim_signing(N, task, settings) lua_util.debugm(N, task, 'dkim unconfigured and fallback disabled') return false,{} end + + lua_util.debugm(N, task, 'override selector and key to %s:%s', p.key, p.selector) end if not p.selector and settings.selector_map then local data = settings.selector_map:get_key(dkim_domain) if data then p.selector = data + lua_util.debugm(N, task, 'override selector to "%s" using selector_map', p.selector) elseif not settings.try_fallback then lua_util.debugm(N, task, 'no selector for %s', dkim_domain) return false,{} @@ -194,6 +197,7 @@ local function prepare_dkim_signing(N, task, settings) local data = settings.path_map:get_key(dkim_domain) if data then p.key = data + lua_util.debugm(N, task, 'override key to "%s" using path_map', p.key) elseif not settings.try_fallback then lua_util.debugm(N, task, 'no key for %s', dkim_domain) return false,{} @@ -203,12 +207,15 @@ local function prepare_dkim_signing(N, task, settings) if not p.key then if not settings.use_redis then p.key = settings.path + lua_util.debugm(N, task, 'use default key "%s" from path', p.key) end end if not p.selector then p.selector = settings.selector + lua_util.debugm(N, task, 'use default selector "%s"', p.selector) end + p.domain = dkim_domain return true,p diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 64d949270..0ce0c1874 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -693,7 +693,7 @@ end exports.debugm = function(mod, ...) local logger = require "rspamd_logger" if unconditional_debug or debug_modules[mod] then - logger.logx(log_level, ...) + logger.logx(log_level, mod, ...) end end diff --git a/rules/regexp/headers.lua b/rules/regexp/headers.lua index 3daa58c48..4889c0e7f 100644 --- a/rules/regexp/headers.lua +++ b/rules/regexp/headers.lua @@ -656,13 +656,13 @@ reconf['FAKE_REPLY_C'] = { local has_msmail_pri = 'header_exists(X-MSMail-Priority)' local has_mimeole = 'header_exists(X-MimeOLE)' local has_squirrelmail_in_mailer = 'X-Mailer=/SquirrelMail\\b/H' -local has_office12145_in_mailer = 'X-Mailer=/^Microsoft (?:Office )?Outlook 1[245]\\.0/' +local has_office_version_in_mailer = [[X-Mailer=/^Microsoft (?:Office )?Outlook [12]\d\.0/]] reconf['MISSING_MIMEOLE'] = { re = string.format('(%s) & !(%s) & !(%s) & !(%s)', has_msmail_pri, has_mimeole, has_squirrelmail_in_mailer, - has_office12145_in_mailer), + has_office_version_in_mailer), score = 2.0, description = 'Mime-OLE is needed but absent (e.g. fake Outlook or fake Exchange)', group = 'header' diff --git a/src/libmime/message.c b/src/libmime/message.c index 7c0429c3c..e4c59be63 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1124,6 +1124,7 @@ rspamd_message_parse (struct rspamd_task *task) if (task->subject) { p = task->subject; len = strlen (p); + rspamd_cryptobox_hash_update (&st, p, len); rspamd_url_find_multiple (task->task_pool, p, len, FALSE, NULL, rspamd_url_task_subject_callback, task); } diff --git a/src/libserver/dns.c b/src/libserver/dns.c index 372ac28b7..fbf37363a 100644 --- a/src/libserver/dns.c +++ b/src/libserver/dns.c @@ -15,6 +15,7 @@ */ #include <contrib/librdns/rdns.h> +#include <contrib/librdns/dns_private.h> #include "config.h" #include "dns.h" #include "rspamd.h" @@ -49,6 +50,7 @@ struct rspamd_dns_request_ud { gpointer ud; rspamd_mempool_t *pool; struct rdns_request *req; + struct rdns_reply *reply; }; static void @@ -56,6 +58,21 @@ rspamd_dns_fin_cb (gpointer arg) { struct rspamd_dns_request_ud *reqdata = (struct rspamd_dns_request_ud *)arg; + if (reqdata->reply) { + reqdata->cb (reqdata->reply, reqdata->ud); + } + else { + struct rdns_reply fake_reply; + + memset (&fake_reply, 0, sizeof (fake_reply)); + fake_reply.code = RDNS_RC_TIMEOUT; + fake_reply.request = reqdata->req; + fake_reply.resolver = reqdata->req->resolver; + fake_reply.requested_name = reqdata->req->requested_names[0].name; + + reqdata->cb (&fake_reply, reqdata->ud); + } + rdns_request_release (reqdata->req); if (reqdata->pool == NULL) { @@ -68,7 +85,7 @@ rspamd_dns_callback (struct rdns_reply *reply, gpointer ud) { struct rspamd_dns_request_ud *reqdata = ud; - reqdata->cb (reply, reqdata->ud); + reqdata->reply = reply; if (reqdata->session) { /* @@ -78,8 +95,12 @@ rspamd_dns_callback (struct rdns_reply *reply, gpointer ud) rdns_request_retain (reply->request); rspamd_session_remove_event (reqdata->session, rspamd_dns_fin_cb, reqdata); } - else if (reqdata->pool == NULL) { - g_free (reqdata); + else { + reqdata->cb (reply, reqdata->ud); + + if (reqdata->pool == NULL) { + g_free (reqdata); + } } } @@ -101,13 +122,18 @@ make_dns_request (struct rspamd_dns_resolver *resolver, return FALSE; } + if (session && rspamd_session_is_destroying (session)) { + return FALSE; + } + if (pool != NULL) { reqdata = - rspamd_mempool_alloc (pool, sizeof (struct rspamd_dns_request_ud)); + rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_dns_request_ud)); } else { - reqdata = g_malloc (sizeof (struct rspamd_dns_request_ud)); + reqdata = g_malloc0 (sizeof (struct rspamd_dns_request_ud)); } + reqdata->pool = pool; reqdata->session = session; reqdata->cb = cb; diff --git a/src/libserver/events.c b/src/libserver/events.c index 9b0d049d4..f62005b96 100644 --- a/src/libserver/events.c +++ b/src/libserver/events.c @@ -172,6 +172,13 @@ rspamd_session_add_event (struct rspamd_async_session *session, g_assert_not_reached (); } + if (RSPAMD_SESSION_IS_DESTROYING (session)) { + msg_debug_session ("skip adding event subsystem: %s: session is destroying", + g_quark_to_string (subsystem)); + + return NULL; + } + new_event = rspamd_mempool_alloc (session->pool, sizeof (struct rspamd_async_event)); new_event->fin = fin; @@ -502,4 +509,12 @@ rspamd_session_mempool (struct rspamd_async_session *session) g_assert (session != NULL); return session->pool; +} + +gboolean +rspamd_session_is_destroying (struct rspamd_async_session *session) +{ + g_assert (session != NULL); + + return RSPAMD_SESSION_IS_DESTROYING (session); }
\ No newline at end of file diff --git a/src/libserver/events.h b/src/libserver/events.h index 760bb000c..10ccb8d1d 100644 --- a/src/libserver/events.h +++ b/src/libserver/events.h @@ -148,4 +148,11 @@ void rspamd_session_watcher_pop (struct rspamd_async_session *s, struct rspamd_async_watcher* rspamd_session_get_watcher ( struct rspamd_async_session *s); +/** + * Returns TRUE if an async session is currently destroying + * @param s + * @return + */ +gboolean rspamd_session_is_destroying (struct rspamd_async_session *s); + #endif /* RSPAMD_EVENTS_H */ diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c index 69c14e167..5510cff05 100644 --- a/src/libstat/backends/redis_backend.c +++ b/src/libstat/backends/redis_backend.c @@ -1572,6 +1572,9 @@ rspamd_redis_process_tokens (struct rspamd_task *task, gint ret; const gchar *learned_key = "learns"; + if (rspamd_session_is_destroying (task->s)) { + return FALSE; + } if (tokens == NULL || tokens->len == 0 || rt->redis == NULL) { return FALSE; @@ -1664,6 +1667,10 @@ rspamd_redis_learn_tokens (struct rspamd_task *task, GPtrArray *tokens, goffset off; const gchar *learned_key = "learns"; + if (rspamd_session_is_destroying (task->s)) { + return FALSE; + } + up = rspamd_upstream_get (rt->ctx->write_servers, RSPAMD_UPSTREAM_MASTER_SLAVE, NULL, diff --git a/src/libstat/learn_cache/redis_cache.c b/src/libstat/learn_cache/redis_cache.c index d43ec3665..e17f20d27 100644 --- a/src/libstat/learn_cache/redis_cache.c +++ b/src/libstat/learn_cache/redis_cache.c @@ -438,6 +438,10 @@ rspamd_stat_cache_redis_check (struct rspamd_task *task, struct timeval tv; gchar *h; + if (rspamd_session_is_destroying (task->s)) { + return RSPAMD_LEARN_INGORE; + } + h = rspamd_mempool_get_variable (task->task_pool, "words_hash"); if (h == NULL) { @@ -469,6 +473,10 @@ rspamd_stat_cache_redis_learn (struct rspamd_task *task, gchar *h; gint flag; + if (rspamd_session_is_destroying (task->s)) { + return RSPAMD_LEARN_INGORE; + } + h = rspamd_mempool_get_variable (task->task_pool, "words_hash"); g_assert (h != NULL); diff --git a/src/libutil/logger.c b/src/libutil/logger.c index c9f14ccb6..0e20ec8e0 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -655,7 +655,7 @@ rspamd_common_logv (rspamd_logger_t *rspamd_log, gint level_flags, const gchar *fmt, va_list args) { gchar logbuf[RSPAMD_LOGBUF_SIZE], *end; - gint level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK); + gint level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK), mod_id; if (G_UNLIKELY (rspamd_log == NULL)) { rspamd_log = default_logger; @@ -669,7 +669,14 @@ rspamd_common_logv (rspamd_logger_t *rspamd_log, gint level_flags, } } else { - if (rspamd_logger_need_log (rspamd_log, level, -1)) { + if (level == G_LOG_LEVEL_DEBUG) { + mod_id = rspamd_logger_add_debug_module (module); + } + else { + mod_id = -1; + } + + if (rspamd_logger_need_log (rspamd_log, level_flags, mod_id)) { end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args); if ((level_flags & RSPAMD_LOG_ENCRYPTED) && rspamd_log->pk) { diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index b9a2d7b59..cb2026421 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -377,7 +377,7 @@ lua_http_request (lua_State *L) struct rspamd_http_message *msg; struct lua_http_cbdata *cbd; struct rspamd_dns_resolver *resolver; - struct rspamd_async_session *session; + struct rspamd_async_session *session = NULL; struct rspamd_lua_text *t; struct rspamd_task *task = NULL; struct rspamd_config *cfg = NULL; @@ -700,6 +700,12 @@ lua_http_request (lua_State *L) return 1; } + if (session && rspamd_session_is_destroying (session)) { + lua_pushboolean (L, FALSE); + + return 1; + } + cbd = g_malloc0 (sizeof (*cbd)); cbd->L = L; cbd->cbref = cbref; diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c index fe2fe7d28..75c2984c6 100644 --- a/src/lua/lua_logger.c +++ b/src/lua/lua_logger.c @@ -141,7 +141,7 @@ LUA_FUNCTION_DEF (logger, debugm); LUA_FUNCTION_DEF (logger, slog); /*** - * @function logger.logx(level, id, fmt[, args) + * @function logger.logx(level, module, id, fmt[, args) * Extended interface to make a generic log message on any level * @param {number} log level as a number (see GLogLevelFlags enum for values) * @param {task|cfg|pool|string} id id to log @@ -804,8 +804,29 @@ lua_logger_logx (lua_State *L) { LUA_TRACE_POINT; GLogLevelFlags flags = lua_tonumber (L, 1); + const gchar *modname = lua_tostring (L, 2), *uid = NULL; + gchar logbuf[RSPAMD_LOGBUF_SIZE - 128]; + gboolean ret; + + if (lua_type (L, 3) == LUA_TSTRING) { + uid = luaL_checkstring (L, 3); + } + else { + uid = lua_logger_get_id (L, 3, NULL); + } - return lua_logger_do_log (L, flags, FALSE, 2); + if (uid && modname && lua_type (L, 4) == LUA_TSTRING) { + ret = lua_logger_log_format (L, 4, FALSE, logbuf, sizeof (logbuf) - 1); + + if (ret) { + lua_common_log_line (flags, L, logbuf, uid, modname); + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 0; } diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index cf416a12a..82ef0c53b 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -675,6 +675,10 @@ rspamd_lua_redis_prepare_connection (lua_State *L, gint *pcbref) lua_pop (L, 1); /* table */ + if (session && rspamd_session_is_destroying (session)) { + ret = FALSE; + } + if (ret && addr != NULL) { ctx = g_malloc0 (sizeof (struct lua_redis_ctx)); @@ -1200,6 +1204,13 @@ lua_redis_add_cmd (lua_State *L) LL_PREPEND (sp_ud->c->specific, sp_ud); + if (ud->s && rspamd_session_is_destroying (ud->s)) { + lua_pushboolean (L, 0); + lua_pushstring (L, "session is terminating"); + + return 2; + } + ret = redisAsyncCommandArgv (sp_ud->c->ctx, lua_redis_callback, sp_ud, diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index 6c3f6ec04..797bdcc4e 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -804,7 +804,8 @@ lua_tcp_plan_handler_event (struct lua_tcp_cbdata *cbd, gboolean can_read, } } -static void + +static gboolean lua_tcp_register_event (struct lua_tcp_cbdata *cbd) { if (cbd->session) { @@ -812,9 +813,16 @@ lua_tcp_register_event (struct lua_tcp_cbdata *cbd) (event_finalizer_t) lua_tcp_fin, cbd, g_quark_from_static_string ("lua tcp")); + + if (!cbd->async_ev) { + return FALSE; + } + cbd->w = rspamd_session_get_watcher (cbd->session); rspamd_session_watcher_push (cbd->session); } + + return TRUE; } static gboolean @@ -1232,6 +1240,13 @@ lua_tcp_request (lua_State *L) if (session) { cbd->session = session; + + if (rspamd_session_is_destroying (session)) { + REF_RELEASE (cbd); + lua_pushboolean (L, FALSE); + + return 1; + } } if (rspamd_parse_inet_address (&cbd->addr, host, 0)) { diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index b5c390328..c0fd8aa4c 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -2830,49 +2830,50 @@ register_fuzzy_client_call (struct rspamd_task *task, rspamd_inet_addr_t *addr; gint sock; - /* Get upstream */ - selected = rspamd_upstream_get (rule->servers, RSPAMD_UPSTREAM_ROUND_ROBIN, - NULL, 0); - if (selected) { - addr = rspamd_upstream_addr (selected); - if ((sock = rspamd_inet_address_connect (addr, SOCK_DGRAM, TRUE)) == -1) { - msg_warn_task ("cannot connect to %s(%s), %d, %s", - rspamd_upstream_name (selected), - rspamd_inet_address_to_string_pretty (addr), - errno, - strerror (errno)); - rspamd_upstream_fail (selected, FALSE); - g_ptr_array_free (commands, TRUE); - } - else { - /* Create session for a socket */ - session = - rspamd_mempool_alloc0 (task->task_pool, - sizeof (struct fuzzy_client_session)); - msec_to_tv (rule->ctx->io_timeout, &session->tv); - session->state = 0; - session->commands = commands; - session->task = task; - session->fd = sock; - session->server = selected; - session->rule = rule; - session->addr = addr; - session->results = g_ptr_array_sized_new (32); - - event_set (&session->ev, sock, EV_WRITE, fuzzy_check_io_callback, - session); - event_base_set (session->task->ev_base, &session->ev); - event_add (&session->ev, NULL); + if (!rspamd_session_is_destroying (task->s)) { + /* Get upstream */ + selected = rspamd_upstream_get (rule->servers, RSPAMD_UPSTREAM_ROUND_ROBIN, + NULL, 0); + if (selected) { + addr = rspamd_upstream_addr (selected); + if ((sock = rspamd_inet_address_connect (addr, SOCK_DGRAM, TRUE)) == -1) { + msg_warn_task ("cannot connect to %s(%s), %d, %s", + rspamd_upstream_name (selected), + rspamd_inet_address_to_string_pretty (addr), + errno, + strerror (errno)); + rspamd_upstream_fail (selected, FALSE); + g_ptr_array_free (commands, TRUE); + } else { + /* Create session for a socket */ + session = + rspamd_mempool_alloc0 (task->task_pool, + sizeof (struct fuzzy_client_session)); + msec_to_tv (rule->ctx->io_timeout, &session->tv); + session->state = 0; + session->commands = commands; + session->task = task; + session->fd = sock; + session->server = selected; + session->rule = rule; + session->addr = addr; + session->results = g_ptr_array_sized_new (32); + + event_set (&session->ev, sock, EV_WRITE, fuzzy_check_io_callback, + session); + event_base_set (session->task->ev_base, &session->ev); + event_add (&session->ev, NULL); - evtimer_set (&session->timev, fuzzy_check_timer_callback, - session); - event_base_set (session->task->ev_base, &session->timev); - event_add (&session->timev, &session->tv); + evtimer_set (&session->timev, fuzzy_check_timer_callback, + session); + event_base_set (session->task->ev_base, &session->timev); + event_add (&session->timev, &session->tv); - rspamd_session_add_event (task->s, - fuzzy_io_fin, - session, - g_quark_from_static_string ("fuzzy check")); + rspamd_session_add_event (task->s, + fuzzy_io_fin, + session, + g_quark_from_static_string ("fuzzy check")); + } } } } @@ -3310,48 +3311,48 @@ fuzzy_check_send_lua_learn (struct fuzzy_rule *rule, gint ret = -1; /* Get upstream */ - - while ((selected = rspamd_upstream_get (rule->servers, - RSPAMD_UPSTREAM_SEQUENTIAL, NULL, 0))) { - /* Create UDP socket */ - addr = rspamd_upstream_addr (selected); - - if ((sock = rspamd_inet_address_connect (addr, - SOCK_DGRAM, TRUE)) == -1) { - rspamd_upstream_fail (selected, TRUE); - } - else { - s = - rspamd_mempool_alloc0 (task->task_pool, - sizeof (struct fuzzy_learn_session)); - - msec_to_tv (rule->ctx->io_timeout, &s->tv); - s->task = task; - s->addr = addr; - s->commands = commands; - s->http_entry = NULL; - s->server = selected; - s->saved = saved; - s->fd = sock; - s->err = err; - s->rule = rule; - s->session = task->s; - - event_set (&s->ev, sock, EV_WRITE, fuzzy_controller_io_callback, s); - event_base_set (task->ev_base, &s->ev); - event_add (&s->ev, NULL); - - evtimer_set (&s->timev, fuzzy_controller_timer_callback, s); - event_base_set (s->task->ev_base, &s->timev); - event_add (&s->timev, &s->tv); - - rspamd_session_add_event (task->s, - fuzzy_lua_fin, - s, - g_quark_from_static_string ("fuzzy check")); - - (*saved)++; - ret = 1; + if (!rspamd_session_is_destroying (task->s)) { + while ((selected = rspamd_upstream_get (rule->servers, + RSPAMD_UPSTREAM_SEQUENTIAL, NULL, 0))) { + /* Create UDP socket */ + addr = rspamd_upstream_addr (selected); + + if ((sock = rspamd_inet_address_connect (addr, + SOCK_DGRAM, TRUE)) == -1) { + rspamd_upstream_fail (selected, TRUE); + } else { + s = + rspamd_mempool_alloc0 (task->task_pool, + sizeof (struct fuzzy_learn_session)); + + msec_to_tv (rule->ctx->io_timeout, &s->tv); + s->task = task; + s->addr = addr; + s->commands = commands; + s->http_entry = NULL; + s->server = selected; + s->saved = saved; + s->fd = sock; + s->err = err; + s->rule = rule; + s->session = task->s; + + event_set (&s->ev, sock, EV_WRITE, fuzzy_controller_io_callback, s); + event_base_set (task->ev_base, &s->ev); + event_add (&s->ev, NULL); + + evtimer_set (&s->timev, fuzzy_controller_timer_callback, s); + event_base_set (s->task->ev_base, &s->timev); + event_add (&s->timev, &s->tv); + + rspamd_session_add_event (task->s, + fuzzy_lua_fin, + s, + g_quark_from_static_string ("fuzzy check")); + + (*saved)++; + ret = 1; + } } } diff --git a/src/plugins/lua/dkim_signing.lua b/src/plugins/lua/dkim_signing.lua index 38fb56363..343fb8a84 100644 --- a/src/plugins/lua/dkim_signing.lua +++ b/src/plugins/lua/dkim_signing.lua @@ -106,6 +106,8 @@ local function dkim_signing_cb(task) lua_util.debugm(N, task, "missing DKIM key for %s", rk) else p.rawkey = data + lua_util.debugm(N, task, 'found and parsed key for %s:%s in Redis', + p.domain, p.selector) do_sign() end end @@ -122,7 +124,8 @@ local function dkim_signing_cb(task) end end if settings.selector_prefix then - rspamd_logger.infox(task, "Using selector prefix %s for domain %s", settings.selector_prefix, p.domain); + rspamd_logger.infox(task, "Using selector prefix '%s' for domain '%s'", + settings.selector_prefix, p.domain); local function redis_selector_cb(err, data) if err or type(data) ~= 'string' then rspamd_logger.infox(task, "cannot make request to load DKIM selector for domain %s: %s", p.domain, err) @@ -139,7 +142,7 @@ local function dkim_signing_cb(task) {settings.selector_prefix, p.domain} -- arguments ) if not rret then - rspamd_logger.infox(task, "cannot make request to load DKIM selector for %s", p.domain) + rspamd_logger.infox(task, "cannot make request to load DKIM selector for '%s'", p.domain) end else if not p.selector then @@ -154,13 +157,16 @@ local function dkim_signing_cb(task) local exists,err = rspamd_util.file_exists(p.key) if not exists then if err and err == 'No such file or directory' then - lua_util.debugm(N, task, 'cannot read key from %s: %s', p.key, err) + lua_util.debugm(N, task, 'cannot read key from "%s": %s', p.key, err) else - rspamd_logger.warnx(N, task, 'cannot read key from %s: %s', p.key, err) + rspamd_logger.warnx(N, task, 'cannot read key from "%s": %s', p.key, err) end return false end + lua_util.debugm(N, task, 'key found at "%s", use selector "%s" for domain "%s"', + p.key, p.selector, p.domain) + do_sign() else rspamd_logger.infox(task, 'key path or dkim selector unconfigured; no signing') diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 81496f0a9..5b2375888 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -1638,55 +1638,58 @@ register_redirector_call (struct rspamd_url *url, struct rspamd_task *task, struct rspamd_http_message *msg; struct surbl_ctx *surbl_module_ctx = surbl_get_context (task->cfg); - selected = rspamd_upstream_get (surbl_module_ctx->redirectors, - RSPAMD_UPSTREAM_ROUND_ROBIN, url->host, url->hostlen); + if (!rspamd_session_is_destroying (task->s)) { - if (selected) { - s = rspamd_inet_address_connect (rspamd_upstream_addr (selected), - SOCK_STREAM, TRUE); - } + selected = rspamd_upstream_get (surbl_module_ctx->redirectors, + RSPAMD_UPSTREAM_ROUND_ROBIN, url->host, url->hostlen); - if (s == -1) { - msg_info_surbl ("<%s> cannot create tcp socket failed: %s", - task->message_id, - strerror (errno)); - return; - } + if (selected) { + s = rspamd_inet_address_connect (rspamd_upstream_addr (selected), + SOCK_STREAM, TRUE); + } - param = - rspamd_mempool_alloc (task->task_pool, - sizeof (struct redirector_param)); - param->url = url; - param->task = task; - param->conn = rspamd_http_connection_new (NULL, - surbl_redirector_error, - surbl_redirector_finish, - RSPAMD_HTTP_CLIENT_SIMPLE, - RSPAMD_HTTP_CLIENT, - NULL, - NULL); - param->ctx = surbl_module_ctx; - msg = rspamd_http_new_message (HTTP_REQUEST); - msg->url = rspamd_fstring_assign (msg->url, url->string, url->urllen); - param->sock = s; - param->redirector = selected; - timeout = rspamd_mempool_alloc (task->task_pool, sizeof (struct timeval)); - double_to_tv (surbl_module_ctx->read_timeout, timeout); - - rspamd_session_add_event (task->s, - free_redirector_session, - param, - g_quark_from_static_string ("surbl")); - - rspamd_http_connection_write_message (param->conn, msg, NULL, - NULL, param, s, timeout, task->ev_base); - - msg_info_surbl ( - "<%s> registered redirector call for %*s to %s, according to rule: %s", - task->message_id, - url->urllen, url->string, - rspamd_upstream_name (param->redirector), - rule); + if (s == -1) { + msg_info_surbl ("<%s> cannot create tcp socket failed: %s", + task->message_id, + strerror (errno)); + return; + } + + param = + rspamd_mempool_alloc (task->task_pool, + sizeof (struct redirector_param)); + param->url = url; + param->task = task; + param->conn = rspamd_http_connection_new (NULL, + surbl_redirector_error, + surbl_redirector_finish, + RSPAMD_HTTP_CLIENT_SIMPLE, + RSPAMD_HTTP_CLIENT, + NULL, + NULL); + param->ctx = surbl_module_ctx; + msg = rspamd_http_new_message (HTTP_REQUEST); + msg->url = rspamd_fstring_assign (msg->url, url->string, url->urllen); + param->sock = s; + param->redirector = selected; + timeout = rspamd_mempool_alloc (task->task_pool, sizeof (struct timeval)); + double_to_tv (surbl_module_ctx->read_timeout, timeout); + + rspamd_session_add_event (task->s, + free_redirector_session, + param, + g_quark_from_static_string ("surbl")); + + rspamd_http_connection_write_message (param->conn, msg, NULL, + NULL, param, s, timeout, task->ev_base); + + msg_info_surbl ( + "<%s> registered redirector call for %*s to %s, according to rule: %s", + task->message_id, + url->urllen, url->string, + rspamd_upstream_name (param->redirector), + rule); + } } static gboolean diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index 4af5ee5f4..276e304b9 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -917,9 +917,14 @@ proxy_backend_parse_results (struct rspamd_proxy_session *session, parser = ucl_parser_new (0); if (!ucl_parser_add_chunk (parser, in, inlen)) { + gchar *encoded; + + encoded = rspamd_encode_base64 (in, inlen, 0, NULL); msg_err_session ("cannot parse input: %s", ucl_parser_get_error ( parser)); + msg_err_session ("input encoded: %s", encoded); ucl_parser_free (parser); + g_free (encoded); return FALSE; } diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py index 3db57a87e..2010f4127 100644 --- a/test/functional/lib/rspamd.py +++ b/test/functional/lib/rspamd.py @@ -12,6 +12,7 @@ import string import sys import tempfile import time +from robot.libraries.BuiltIn import BuiltIn if sys.version_info > (3,): long = int @@ -33,6 +34,23 @@ def Check_JSON(j): def cleanup_temporary_directory(directory): shutil.rmtree(directory) +def save_run_results(directory, filenames): + current_directory = os.getcwd() + suite_name = BuiltIn().get_variable_value("${SUITE_NAME}") + test_name = BuiltIn().get_variable_value("${TEST NAME}") + if test_name is None: + # this is suite-level tear down + destination_directory = "%s/robot-save/%s" % (current_directory, suite_name) + else: + destination_directory = "%s/robot-save/%s/%s" % (current_directory, suite_name, test_name) + if not os.path.isdir(destination_directory): + os.makedirs(destination_directory) + for file in filenames.split(' '): + source_file = "%s/%s" % (directory, file) + if os.path.isfile(source_file): + shutil.copy(source_file, "%s/%s" % (destination_directory, file)) + shutil.copy(source_file, "%s/robot-save/%s.last" % (current_directory, file)) + def encode_filename(filename): return "".join(['%%%0X' % ord(b) for b in filename]) @@ -58,6 +76,7 @@ def get_rspamd(): return os.environ['RSPAMD_INSTALLROOT'] + "/bin/rspamd" dname = get_top_dir() return dname + "/src/rspamd" + def get_rspamc(): if os.environ.get('RSPAMC'): return os.environ['RSPAMC'] @@ -65,6 +84,7 @@ def get_rspamc(): return os.environ['RSPAMD_INSTALLROOT'] + "/bin/rspamc" dname = get_top_dir() return dname + "/src/client/rspamc" + def get_rspamadm(): if os.environ.get('RSPAMADM'): return os.environ['RSPAMADM'] diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot index 7b355f85b..ec2fc5e84 100644 --- a/test/functional/lib/rspamd.robot +++ b/test/functional/lib/rspamd.robot @@ -70,6 +70,7 @@ Generic Teardown [Arguments] @{ports} Run Keyword If '${CONTROLLER_ERRORS}' == 'True' Check Controller Errors Shutdown Process With Children ${RSPAMD_PID} + Save Run Results ${TMPDIR} rspamd.log redis.log rspamd.conf Cleanup Temporary Directory ${TMPDIR} Log Logs |