]> source.dussan.org Git - rspamd.git/commitdiff
Fix keys initialization.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jan 2015 23:06:45 +0000 (23:06 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Jan 2015 23:06:45 +0000 (23:06 +0000)
src/client/rspamdclient.c
src/libserver/protocol.c
src/libserver/task.c
src/libserver/task.h
src/libutil/http.c
src/libutil/http.h
src/worker.c

index c95f982cf6999d29de256bb4a148b6ca71e2ab85..1d119eb18154252523faca66cfda43ace9c3b413 100644 (file)
@@ -251,7 +251,7 @@ rspamd_client_destroy (struct rspamd_client_connection *conn)
                        g_string_free (conn->key, TRUE);
                }
                if (conn->keypair) {
-                       rspamd_http_connection_key_destroy (conn->keypair);
+                       rspamd_http_connection_key_unref (conn->keypair);
                }
                g_string_free (conn->server_name, TRUE);
                g_slice_free1 (sizeof (struct rspamd_client_connection), conn);
index 44bfe5a4ea7217ba5bb9a34f3b8dc1fd9df51486..bc64b7c31554fa87506ea34a009819a89e877676 100644 (file)
@@ -905,6 +905,11 @@ rspamd_protocol_write_reply (struct rspamd_task *task)
        const gchar *ctype = "application/json";
 
        msg = rspamd_http_new_message (HTTP_RESPONSE);
+
+       if (task->peer_key) {
+               msg->peer_key = g_string_new (task->peer_key->str);
+               msg_info ("<%s> writing encrypted reply", task->message_id);
+       }
        if (!task->is_json) {
                /* Turn compatibility on */
                msg->method = HTTP_SYMBOLS;
index bfa9184fb8ca99441026568819330e3a33cd4c0d..18ba08dadd12a6451af3cd4ba3fa7b4d28d8a23b 100644 (file)
@@ -266,6 +266,9 @@ rspamd_task_free (struct rspamd_task *task, gboolean is_soft)
                if (task->settings != NULL) {
                        ucl_object_unref (task->settings);
                }
+               if (task->peer_key != NULL) {
+                       g_string_free (task->peer_key, TRUE);
+               }
                rspamd_mempool_delete (task->task_pool);
                g_slice_free1 (sizeof (struct rspamd_task), task);
        }
index 1261dd1345dfc9f5131d12971c76c21901084ee5..9c05def82c4f1a112effe14c8b38f04a83fca686 100644 (file)
@@ -147,6 +147,7 @@ struct rspamd_task {
        } pre_result;                                               /**< Result of pre-filters                                                  */
 
        ucl_object_t *settings;                                     /**< Settings applied to task                                               */
+       GString *peer_key;                                                                                      /**< Peer's pubkey                                                                      */
 };
 
 /**
index 8fd0e7448150b65a7878c0e1f90e56a17e033ecf..1b2338509ce639fa8517c1b0e821f4b24d827975 100644 (file)
@@ -1197,6 +1197,7 @@ rspamd_http_new_message (enum http_parser_type type)
        new->port = 80;
        new->type = type;
        new->method = HTTP_GET;
+       new->peer_key = NULL;
 
        return new;
 }
@@ -1761,7 +1762,7 @@ rspamd_http_connection_set_key (struct rspamd_http_connection *conn,
 }
 
 void
-rspamd_http_connection_key_destroy (gpointer key)
+rspamd_http_connection_key_unref (gpointer key)
 {
        struct rspamd_http_keypair *kp = (struct rspamd_http_keypair *)key;
 
@@ -1769,6 +1770,17 @@ rspamd_http_connection_key_destroy (gpointer key)
        REF_RELEASE (kp);
 }
 
+gpointer
+rspamd_http_connection_key_ref (gpointer key)
+{
+       struct rspamd_http_keypair *kp = (struct rspamd_http_keypair *)key;
+
+       g_assert (key != NULL);
+       REF_RETAIN (kp);
+
+       return kp;
+}
+
 GString *
 rspamd_http_connection_make_peer_key (const gchar *key)
 {
index b52671e102379be3c8095bb35cc1187a2511b12a..83a284a525e8d0596076528b1ae6f8e2dfc47ad2 100644 (file)
@@ -193,7 +193,13 @@ GString *rspamd_http_connection_print_key (gpointer key, guint how);
  * Release key pointed by an opaque pointer
  * @param key opaque key structure
  */
-void rspamd_http_connection_key_destroy (gpointer key);
+void rspamd_http_connection_key_unref (gpointer key);
+
+/**
+ * Increase refcount for a key pointed by an opaque pointer
+ * @param key opaque key structure
+ */
+gpointer rspamd_http_connection_key_ref (gpointer key);
 
 GString *rspamd_http_connection_make_peer_key (const gchar *key);
 
index 0a6ce4a5ec9bdba4bf4173c94d20a61b4a22d073..91797a6dce6feeb2a3cd61a7d7a212ec4e2f9346 100644 (file)
@@ -129,6 +129,10 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn,
                return 0;
        }
 
+       if (msg->peer_key) {
+               task->peer_key = g_string_new (msg->peer_key->str);
+       }
+
        if (!rspamd_task_process (task, msg, ctx->classify_pool, TRUE)) {
                task->state = WRITE_REPLY;
        }
@@ -354,7 +358,7 @@ start_worker (struct rspamd_worker *worker)
        rspamd_log_close (rspamd_main->logger);
 
        if (ctx->key) {
-               rspamd_http_connection_key_destroy (ctx->key);
+               rspamd_http_connection_key_unref (ctx->key);
        }
 
        exit (EXIT_SUCCESS);