]> source.dussan.org Git - rspamd.git/commitdiff
Rework message store to allow encryption.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 30 Jan 2015 15:19:04 +0000 (15:19 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 30 Jan 2015 15:19:04 +0000 (15:19 +0000)
12 files changed:
src/controller.c
src/libmime/message.c
src/libmime/smtp_utils.c
src/libserver/dkim.c
src/libserver/protocol.c
src/libserver/roll_history.c
src/libserver/task.c
src/libserver/task.h
src/lua/lua_task.c
src/plugins/fuzzy_check.c
src/plugins/regexp.c
src/worker.c

index 715f71dcc66752fa5c72328b6bd1940493b86ef2..16651ea0ba9700662f0a82d7619c73be3bee45be 100644 (file)
@@ -798,7 +798,6 @@ rspamd_controller_handle_learn_common (
        }
 
        task = rspamd_task_new (session->ctx->worker);
-       task->msg = msg->body;
 
        task->resolver = ctx->resolver;
        task->ev_base = ctx->ev_base;
@@ -815,7 +814,8 @@ rspamd_controller_handle_learn_common (
        task->sock = conn_ent->conn->fd;
 
 
-       if (!rspamd_task_process (task, msg, NULL, FALSE)) {
+       /* XXX: Handle encrypted messages */
+       if (!rspamd_task_process (task, msg, msg->body->str, msg->body->len, NULL, FALSE)) {
                msg_warn ("filters cannot be processed for %s", task->message_id);
                rspamd_controller_send_error (conn_ent, 500, task->last_error);
                destroy_session (task->s);
@@ -890,7 +890,6 @@ rspamd_controller_handle_scan (struct rspamd_http_connection_entry *conn_ent,
 
        task = rspamd_task_new (session->ctx->worker);
        task->ev_base = session->ctx->ev_base;
-       task->msg = msg->body;
 
        task->resolver = ctx->resolver;
        task->ev_base = ctx->ev_base;
@@ -905,7 +904,8 @@ rspamd_controller_handle_scan (struct rspamd_http_connection_entry *conn_ent,
        task->http_conn = rspamd_http_connection_ref (conn_ent->conn);
        task->sock = conn_ent->conn->fd;
 
-       if (!rspamd_task_process (task, msg, NULL, FALSE)) {
+       /* XXX: handle encrypted messages */
+       if (!rspamd_task_process (task, msg, msg->body->str, msg->body->len, NULL, FALSE)) {
                msg_warn ("filters cannot be processed for %s", task->message_id);
                rspamd_controller_send_error (conn_ent, 500, task->last_error);
                destroy_session (task->s);
index 94137af157ca73b755927b388e8a2cd14511b320..869d0a06e4096c957b73aa8f18958f01117e170f 100644 (file)
@@ -1465,8 +1465,8 @@ process_message (struct rspamd_task *task)
        gint rc;
 
        tmp = rspamd_mempool_alloc (task->task_pool, sizeof (GByteArray));
-       tmp->data = task->msg->str;
-       tmp->len = task->msg->len;
+       tmp->data = (guint8 *)task->msg.start;
+       tmp->len = task->msg.len;
 
        stream = g_mime_stream_mem_new_with_byte_array (tmp);
        /*
@@ -1478,7 +1478,7 @@ process_message (struct rspamd_task *task)
        if (task->is_mime) {
 
                debug_task ("construct mime parser from string length %d",
-                       (gint)task->msg->len);
+                       (gint)task->msg.len);
                /* create a new parser object to parse the stream */
                parser = g_mime_parser_new_with_stream (stream);
                g_object_unref (stream);
index b29a9d717cf8c3434a3048e25783a3678a0a6c0a..a5a2f26ef092680ccf975d18535366674f8121ef 100644 (file)
@@ -35,8 +35,8 @@ free_smtp_session (gpointer arg)
        if (session) {
                if (session->task) {
                        rspamd_task_free (session->task, FALSE);
-                       if (session->task->msg->str) {
-                               munmap (session->task->msg->str, session->task->msg->len);
+                       if (session->task->msg.start) {
+                               munmap (session->task->msg.start, session->task->msg.len);
                        }
                }
                if (session->rcpt) {
@@ -212,14 +212,14 @@ smtp_metric_callback (gpointer key, gpointer value, gpointer ud)
        cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset,
                        cd->log_size - cd->log_offset,
                        "]), len: %z, time: %s,",
-                       task->msg->len,
+                       task->msg.len,
                        calculate_check_time (&task->tv, &task->ts, task->cfg->clock_res,
                        &task->scan_milliseconds));
 #else
        cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset,
                        cd->log_size - cd->log_offset,
                        "]), len: %z, time: %s,",
-                       task->msg->len,
+                       task->msg.len,
                        calculate_check_time (&task->tv, task->cfg->clock_res,
                        &task->scan_milliseconds));
 #endif
index dc0b731661b8990f4d83f4a279cb2922ddb52f63..e178cfea461a736f85b08fa3f839891893906d6f 100644 (file)
@@ -1591,12 +1591,12 @@ rspamd_dkim_check (rspamd_dkim_context_t *ctx,
 
        g_return_val_if_fail (ctx != NULL,               DKIM_ERROR);
        g_return_val_if_fail (key != NULL,               DKIM_ERROR);
-       g_return_val_if_fail (task->msg != NULL, DKIM_ERROR);
+       g_return_val_if_fail (task->msg.len > 0, DKIM_ERROR);
 
        /* First of all find place of body */
-       p = task->msg->str;
+       p = task->msg.start;
 
-       end = task->msg->str + task->msg->len;
+       end = task->msg.start + task->msg.len;
 
        while (p <= end) {
                /* Search for \r\n\r\n at the end of headers */
index 9632418c41d85fdb2bbb62574a765a1089a7b3aa..25dcee1c01f2ef7adaac39ba0a174d5918a57611 100644 (file)
@@ -735,7 +735,7 @@ rspamd_metric_result_ucl (struct rspamd_task *task,
 
 #ifdef HAVE_CLOCK_GETTIME
        rspamd_printf_gstring (logbuf, "]), len: %z, time: %s, dns req: %d,",
-               task->msg->len, calculate_check_time (&task->tv, &task->ts,
+               task->msg.len, calculate_check_time (&task->tv, &task->ts,
                task->cfg->clock_res, &task->scan_milliseconds), task->dns_requests);
 #else
        rspamd_printf_gstring (logbuf, "]), len: %z, time: %s, dns req: %d,",
index 4e6ee01a815f4a48b859a22be080721b67c82353..5edf5bea0adbb3607e95700f2f9f6c54601bc24d 100644 (file)
@@ -146,7 +146,7 @@ rspamd_roll_history_update (struct roll_history *history,
        }
 
        row->scan_time = task->scan_milliseconds;
-       row->len = (task->msg == NULL ? 0 : task->msg->len);
+       row->len = task->msg.len;
        row->completed = TRUE;
 }
 
index b8d042dc600f0475647c8054901cd9b7a8482a19..699e129abeb54db9aa79ff238b42950ea802cfd6 100644 (file)
@@ -293,29 +293,16 @@ rspamd_task_free_soft (gpointer ud)
 
 gboolean
 rspamd_task_process (struct rspamd_task *task,
-       struct rspamd_http_message *msg, GThreadPool *classify_pool,
+       struct rspamd_http_message *msg, const gchar *start, gsize len,
+       GThreadPool *classify_pool,
        gboolean process_extra_filters)
 {
        gint r;
        GError *err = NULL;
 
-       if (msg->body->len == 0) {
-               msg_err ("got zero length body");
-               task->last_error = "message's body is empty";
-               return FALSE;
-       }
-
-       /* XXX: awful hack */
-       if (msg->peer_key != NULL) {
-               task->msg = rspamd_mempool_alloc (task->task_pool, sizeof (GString));
-               task->msg->len = msg->body->len - 16;
-               task->msg->allocated_len = 0;
-               task->msg->str = msg->body->str + 16;
-       }
-       else {
-               task->msg = msg->body;
-       }
-       debug_task ("got string of length %z", task->msg->len);
+       task->msg.start = start;
+       task->msg.len = len;
+       debug_task ("got string of length %z", task->msg.len);
 
        /* We got body, set wanna_die flag */
        task->s->wanna_die = TRUE;
index 9702befa54de9db7a9059c96b39129560ea54ac5..43349ffa9e6dc68d31089c2a7a61db8775d4c269 100644 (file)
@@ -93,7 +93,10 @@ struct rspamd_task {
        gchar *hostname;                                            /**< hostname reported by MTA                                               */
        GHashTable *request_headers;                                /**< HTTP headers in a request                                              */
        GHashTable *reply_headers;                                  /**< Custom reply headers                                                   */
-       GString *msg;                                               /**< message buffer                                                                 */
+       struct {
+               const gchar *start;
+               gsize len;
+       } msg;                                                      /**< message buffer                                                                 */
        struct rspamd_http_connection *http_conn;                   /**< HTTP server connection                                                 */
        struct rspamd_async_session * s;                             /**< async session object                                                  */
        gint parts_count;                                           /**< mime parts count                                                               */
@@ -181,7 +184,8 @@ gboolean rspamd_task_fin (void *arg);
  * @return task has been successfully parsed and processed
  */
 gboolean rspamd_task_process (struct rspamd_task *task,
-       struct rspamd_http_message *msg, GThreadPool *classify_pool,
+       struct rspamd_http_message *msg, const gchar *start, gsize len,
+       GThreadPool *classify_pool,
        gboolean process_extra_filters);
 
 /**
index 98aba7f1535002381a225b090778c9c0e21ed784..ef52b4544257dd948e5fdca6ca3b6cfba99d09b9 100644 (file)
@@ -716,7 +716,9 @@ lua_task_create_from_buffer (lua_State *L)
                ptask = lua_newuserdata (L, sizeof (gpointer));
                rspamd_lua_setclass (L, "rspamd{task}", -1);
                *ptask = task;
-               task->msg = g_string_new_len (data, len);
+               task->msg.start = rspamd_mempool_alloc (task->task_pool, len + 1);
+               memcpy ((gpointer)task->msg.start, data, len);
+               task->msg.len = len;
        }
        return 1;
 }
@@ -726,7 +728,7 @@ lua_task_process_message (lua_State *L)
 {
        struct rspamd_task *task = lua_check_task (L);
 
-       if (task != NULL && task->msg != NULL && task->msg->len > 0) {
+       if (task != NULL && task->msg.len > 0) {
                if (process_message (task) == 0) {
                        lua_pushboolean (L, TRUE);
                }
index 573ab0868829373ca6385026447ccc967dc8c4dc..2dd05a109c8d810797b24876c8fbe48c4f16f520 100644 (file)
@@ -1260,7 +1260,9 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent,
        task->cfg = ctx->cfg;
 
        /* Allocate message from string */
-       task->msg = msg->body;
+       /* XXX: what about encrypted messsages ? */
+       task->msg.start = msg->body->str;
+       task->msg.len = msg->body->len;
 
        saved = rspamd_mempool_alloc0 (task->task_pool, sizeof (gint));
        err = rspamd_mempool_alloc0 (task->task_pool, sizeof (GError *));
index 39b8af1ec678b9e3da83171d2c5045327ca3a6f3..74ab46ab5b1394e181e8050f417b4f651606f179 100644 (file)
@@ -666,8 +666,8 @@ process_regexp (struct rspamd_regexp *re,
        case REGEXP_MESSAGE:
                debug_task ("checking message regexp: %s", re->regexp_text);
                regexp = re->raw_regexp;
-               ct = task->msg->str;
-               clen = task->msg->len;
+               ct = (guint8 *)task->msg.start;
+               clen = task->msg.len;
 
                if (regexp_module_ctx->max_size != 0 && clen >
                        regexp_module_ctx->max_size) {
index 079fa8fae5ceebc39e16b3f5ea6fa2d4b3b58133..e55483dafa245ee1f6ac0c7002059ed139507b1f 100644 (file)
@@ -133,7 +133,7 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn,
                task->peer_key = rspamd_http_connection_key_ref (msg->peer_key);
        }
 
-       if (!rspamd_task_process (task, msg, ctx->classify_pool, TRUE)) {
+       if (!rspamd_task_process (task, msg, chunk, len, ctx->classify_pool, TRUE)) {
                task->state = WRITE_REPLY;
        }