]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Try to support rewritten from in dkim signing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 4 Apr 2019 09:16:48 +0000 (10:16 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 4 Apr 2019 09:20:17 +0000 (10:20 +0100)
src/libserver/dkim.c
src/lua/lua_task.c

index 8100f8ee3d9a60fa101f965188e482a53a3a4a88..9f5cabf6e2ebdbcbaeba6b6adf98117f102b8c87 100644 (file)
@@ -106,6 +106,7 @@ struct rspamd_dkim_common_ctx {
        gsize len;
        gint header_canon_type;
        gint body_canon_type;
+       gboolean is_sign;
        GPtrArray *hlist;
        GHashTable *htable; /* header -> count mapping */
        EVP_MD_CTX *headers_hash;
@@ -2195,6 +2196,33 @@ rspamd_dkim_canonize_header (struct rspamd_dkim_common_ctx *ctx,
                                                (gint)rh->raw_len, rh->raw_value);
                        }
                        else {
+                               if (ctx->is_sign && (rh->type & RSPAMD_HEADER_FROM)) {
+                                       /* Special handling of the From handling when rewrite is done */
+                                       gboolean has_rewrite = FALSE;
+                                       guint i;
+                                       struct rspamd_email_address *addr;
+
+                                       PTR_ARRAY_FOREACH (task->from_mime, i, addr) {
+                                               if ((addr->flags & RSPAMD_EMAIL_ADDR_ORIGINAL)
+                                                       && !(addr->flags & RSPAMD_EMAIL_ADDR_ALIASED)) {
+                                                       has_rewrite = TRUE;
+                                               }
+                                       }
+
+                                       if (has_rewrite) {
+                                               PTR_ARRAY_FOREACH (task->from_mime, i, addr) {
+                                                       if (!(addr->flags & RSPAMD_EMAIL_ADDR_ORIGINAL)) {
+                                                               if (!rspamd_dkim_canonize_header_relaxed (ctx, addr->raw,
+                                                                               header_name, FALSE)) {
+                                                                       return FALSE;
+                                                               }
+
+                                                               return TRUE;
+                                                       }
+                                               }
+                                       }
+                               }
+
                                if (!rspamd_dkim_canonize_header_relaxed (ctx, rh->value,
                                                header_name, FALSE)) {
                                        return FALSE;
@@ -2842,6 +2870,7 @@ rspamd_create_dkim_sign_context (struct rspamd_task *task,
        nctx->common.header_canon_type = headers_canon;
        nctx->common.body_canon_type = body_canon;
        nctx->common.type = type;
+       nctx->common.is_sign = TRUE;
 
        if (type != RSPAMD_DKIM_ARC_SEAL) {
                if (!rspamd_dkim_parse_hdrlist_common (&nctx->common, headers,
index d8ba74ec031f7847dea7c262bb1fce38eebd9db5..ad11f2b416d29e52552a5ffeb82f1b2cdae70824 100644 (file)
@@ -2906,10 +2906,13 @@ lua_import_email_address (lua_State *L, struct rspamd_task *task,
        lua_gettable (L, pos);
 
        if (lua_type (L, -1) == LUA_TSTRING) {
+               gchar *cpy;
                p = lua_tolstring (L, -1, &len);
-               addr->raw = (const gchar *)rspamd_mempool_alloc (task->task_pool, len);
-               memcpy ((gchar *)addr->raw, p, len);
+               cpy = rspamd_mempool_alloc (task->task_pool, len + 1);
+               memcpy (cpy, p, len);
+               cpy[len] = '\0';
                addr->raw_len = len;
+               addr->raw = cpy;
        }
        else {
                /* Construct raw addr */