X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Fdk.c;h=713684b2a23793cb9012f5401a05ca2ccf4b26f4;hb=9befc1368218f1662fd3e876b514262a18bfb9a1;hp=5fa57fd3df1fc21003f76f197402f774cc17717d;hpb=d7d7b7b91dd75cec636fc144da7e27eed860f971;p=exim.git diff --git a/src/src/dk.c b/src/src/dk.c index 5fa57fd3d..713684b2a 100644 --- a/src/src/dk.c +++ b/src/src/dk.c @@ -1,10 +1,10 @@ -/* $Cambridge: exim/src/src/dk.c,v 1.9 2006/02/07 11:19:00 ph10 Exp $ */ +/* $Cambridge: exim/src/src/dk.c,v 1.12 2007/01/08 10:50:18 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2006 */ +/* Copyright (c) University of Cambridge 1995 - 2007 */ /* See the file NOTICE for conditions of use and distribution. */ /* Code for DomainKeys support. Other DK relevant code is in @@ -239,8 +239,10 @@ uschar *dk_exim_sign(int dk_fd, uschar *dk_selector, uschar *dk_canon) { uschar *rc = NULL; + uschar *headers = NULL; + int headers_len; int dk_canon_int = DK_CANON_SIMPLE; - char c; + char buf[4096]; int seen_lf = 0; int seen_lfdot = 0; uschar sig[1024]; @@ -269,40 +271,46 @@ uschar *dk_exim_sign(int dk_fd, goto CLEANUP; } - while((sread = read(dk_fd,&c,1)) > 0) { + while((sread = read(dk_fd,&buf,4096)) > 0) { + int pos = 0; + char c; - if ((c == '.') && seen_lfdot) { - /* escaped dot, write "\n.", continue */ - dk_message(dk_context, CUS "\n.", 2); - seen_lf = 0; - seen_lfdot = 0; - continue; - } + while (pos < sread) { + c = buf[pos++]; - if (seen_lfdot) { - /* EOM, write "\n" and break */ - dk_message(dk_context, CUS "\n", 1); - break; - } + if ((c == '.') && seen_lfdot) { + /* escaped dot, write "\n.", continue */ + dk_message(dk_context, CUS "\n.", 2); + seen_lf = 0; + seen_lfdot = 0; + continue; + } - if ((c == '.') && seen_lf) { - seen_lfdot = 1; - continue; - } + if (seen_lfdot) { + /* EOM, write "\n" and break */ + dk_message(dk_context, CUS "\n", 1); + break; + } - if (seen_lf) { - /* normal lf, just send it */ - dk_message(dk_context, CUS "\n", 1); - seen_lf = 0; - } + if ((c == '.') && seen_lf) { + seen_lfdot = 1; + continue; + } - if (c == '\n') { - seen_lf = 1; - continue; - } + if (seen_lf) { + /* normal lf, just send it */ + dk_message(dk_context, CUS "\n", 1); + seen_lf = 0; + } - /* write the char */ - dk_message(dk_context, CUS &c, 1); + if (c == '\n') { + seen_lf = 1; + continue; + } + + /* write the char */ + dk_message(dk_context, CUS &c, 1); + } } /* Handle failed read above. */ @@ -398,7 +406,7 @@ uschar *dk_exim_sign(int dk_fd, } /* Get the signature. */ - dk_internal_status = dk_getsig(dk_context, dk_private_key, sig, 8192); + dk_internal_status = dk_getsig(dk_context, dk_private_key, sig, 1024); /* Check for unuseable key */ if (dk_internal_status != DK_STAT_OK) { @@ -407,13 +415,17 @@ uschar *dk_exim_sign(int dk_fd, goto CLEANUP; } - rc = store_get(1024); + headers_len = dk_headers(dk_context, NULL); + rc = store_get(1024+256+headers_len); + headers = store_malloc(headers_len); + dk_headers(dk_context, CS headers); /* Build DomainKey-Signature header to return. */ - (void)string_format(rc, 1024, "DomainKey-Signature: a=rsa-sha1; q=dns; c=%s;\r\n" - "\ts=%s; d=%s;\r\n" - "\tb=%s;\r\n", dk_canon, dk_selector, dk_domain, sig); + (void)string_format(rc, 1024+256+headers_len, "DomainKey-Signature: a=rsa-sha1; q=dns; c=%s; s=%s; d=%s;\r\n" + "\th=%s;\r\n" + "\tb=%s;\r\n", dk_canon, dk_selector, dk_domain, headers, sig); - log_write(0, LOG_MAIN, "DK: message signed using a=rsa-sha1; q=dns; c=%s; s=%s; d=%s;", dk_canon, dk_selector, dk_domain); + log_write(0, LOG_MAIN, "DK: message signed using a=rsa-sha1; q=dns; c=%s; s=%s; d=%s; h=%s;", dk_canon, dk_selector, dk_domain, headers); + store_free(headers); CLEANUP: if (dk_context != NULL) {