X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/4191cb150300d310ab5fa22ce2cfb02b6f6051b0..443245384239776d29f5386050f56247c7404c1e:/src/src/dkim.c diff --git a/src/src/dkim.c b/src/src/dkim.c index 0153024df..9e76c51a0 100644 --- a/src/src/dkim.c +++ b/src/src/dkim.c @@ -2,9 +2,10 @@ * Exim - an Internet mail transport agent * *************************************************/ +/* Copyright (c) The Exim Maintainers 2020 - 2023 */ /* Copyright (c) University of Cambridge, 1995 - 2018 */ -/* Copyright (c) The Exim Maintainers 2020 - 2021*/ /* See the file NOTICE for conditions of use and distribution. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* Code for DKIM support. Other DKIM relevant code is in receive.c, transport.c and transports/smtp.c */ @@ -82,7 +83,7 @@ for (dns_record * rr = dns_next_rr(dnsa, &dnss, RESET_ANSWERS); return string_from_gstring(g); } - g->ptr = 0; /* overwrite previous record */ + gstring_reset(g); /* overwrite previous record */ } bad: @@ -288,7 +289,7 @@ else break; } -log_write(0, LOG_MAIN, "%s", string_from_gstring(logmsg)); +log_write(0, LOG_MAIN, "%Y", logmsg); return; } @@ -623,6 +624,7 @@ if (dkim->dot_stuffed) store_pool = POOL_MAIN; +GET_OPTION("dkim_domain"); if ((s = dkim->dkim_domain) && !(dkim_domain = expand_cstring(s))) /* expansion error, do not send message. */ { errwhen = US"dkim_domain"; goto expand_bad; } @@ -651,6 +653,7 @@ if (dkim_domain) /* Set $dkim_selector expansion variable to each selector in list, for this domain. */ + GET_OPTION("dkim_selector"); if (!(dkim_sel = expand_string(dkim->dkim_selector))) { errwhen = US"dkim_selector"; goto expand_bad; } @@ -668,6 +671,7 @@ if (dkim_domain) /* Get canonicalization to use */ + GET_OPTION("dkim_canon"); dkim_canon_expanded = dkim->dkim_canon ? expand_string(dkim->dkim_canon) : US"relaxed"; if (!dkim_canon_expanded) /* expansion error, do not send message. */ @@ -685,6 +689,7 @@ if (dkim_domain) pdkim_canon = PDKIM_CANON_RELAXED; } + GET_OPTION("dkim_sign_headers"); if ( dkim->dkim_sign_headers && !(dkim_sign_headers_expanded = expand_string(dkim->dkim_sign_headers))) { errwhen = US"dkim_sign_header"; goto expand_bad; } @@ -692,6 +697,7 @@ if (dkim_domain) /* Get private key to use. */ + GET_OPTION("dkim_private_key"); if (!(dkim_private_key_expanded = expand_string(dkim->dkim_private_key))) { errwhen = US"dkim_private_key"; goto expand_bad; } @@ -706,21 +712,28 @@ if (dkim_domain) expand_file_big_buffer(dkim_private_key_expanded))) goto bad; + GET_OPTION("dkim_hash"); if (!(dkim_hash_expanded = expand_string(dkim->dkim_hash))) { errwhen = US"dkim_hash"; goto expand_bad; } + GET_OPTION("dkim_identity"); if (dkim->dkim_identity) if (!(dkim_identity_expanded = expand_string(dkim->dkim_identity))) { errwhen = US"dkim_identity"; goto expand_bad; } else if (!*dkim_identity_expanded) dkim_identity_expanded = NULL; + GET_OPTION("dkim_timestamps"); if (dkim->dkim_timestamps) if (!(dkim_timestamps_expanded = expand_string(dkim->dkim_timestamps))) { errwhen = US"dkim_timestamps"; goto expand_bad; } else - xval = (tval = (unsigned long) time(NULL)) - + strtoul(CCS dkim_timestamps_expanded, NULL, 10); + { + tval = (unsigned long) time(NULL); + xval = strtoul(CCS dkim_timestamps_expanded, NULL, 10); + if (xval > 0) + xval += tval; + } if (!(sig = pdkim_init_sign(&dkim_sign_ctx, dkim_signing_domain, dkim_signing_selector, @@ -740,6 +753,9 @@ if (dkim_domain) if (!pdkim_set_sig_bodyhash(&dkim_sign_ctx, sig)) goto bad; + dkim_signing_record = string_append_listele(dkim_signing_record, ':', dkim_signing_domain); + dkim_signing_record = string_append_listele(dkim_signing_record, ':', dkim_signing_selector); + if (!dkim_sign_ctx.sig) /* link sig to context chain */ dkim_sign_ctx.sig = sig; else @@ -821,7 +837,7 @@ authres_dkim(gstring * g) { int start = 0; /* compiler quietening */ -DEBUG(D_acl) start = g->ptr; +DEBUG(D_acl) start = gstring_length(g); for (pdkim_signature * sig = dkim_signatures; sig; sig = sig->next) { @@ -883,10 +899,10 @@ for (pdkim_signature * sig = dkim_signatures; sig; sig = sig->next) } DEBUG(D_acl) - if (g->ptr == start) - debug_printf("DKIM: no authres\n"); + if (gstring_length(g) == start) + debug_printf("DKIM:\tno authres\n"); else - debug_printf("DKIM: authres '%.*s'\n", g->ptr - start - 3, g->s + start + 3); + debug_printf("DKIM:\tauthres '%.*s'\n", g->ptr - start - 3, g->s + start + 3); return g; }