From a05f6ed694b44ab7d703c3607930344bbcde2901 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sat, 29 Nov 2014 16:53:23 +0000 Subject: [PATCH] Tidying --- src/src/dns.c | 7 ++- src/src/receive.c | 46 +++++++------- src/src/spam.c | 7 +-- src/src/transport.c | 65 ++++++++++---------- test/scripts/5860-DANE-OpenSSL-TPDA/REQUIRES | 2 +- 5 files changed, 65 insertions(+), 62 deletions(-) diff --git a/src/src/dns.c b/src/src/dns.c index 3d047abba..ac52e5621 100644 --- a/src/src/dns.c +++ b/src/src/dns.c @@ -807,7 +807,12 @@ for (i = 0; i < 10; i++) /* If any data records of the correct type were found, we are done. */ - if (type_rr.data != NULL) return DNS_SUCCEED; + if (type_rr.data != NULL) + { + if (!secure_so_far) /* mark insecure if any element of CNAME chain was */ + dns_set_insecure(dnsa); + return DNS_SUCCEED; + } /* If there are no data records, we need to re-scan the DNS using the domain given in the CNAME record, which should exist (otherwise we should diff --git a/src/src/receive.c b/src/src/receive.c index f27dc425e..bd0cf4065 100644 --- a/src/src/receive.c +++ b/src/src/receive.c @@ -1242,42 +1242,40 @@ if (Ustrlen(rfc822_file_path) > 0) if (rc == OK) { uschar temp_path[1024]; - int n; - struct dirent *entry; - DIR *tempdir; + struct dirent * entry; + DIR * tempdir; - (void)string_format(temp_path, 1024, "%s/scan/%s", spool_directory, - message_id); + (void) string_format(temp_path, sizeof(temp_path), "%s/scan/%s", + spool_directory, message_id); tempdir = opendir(CS temp_path); - n = 0; - do + for (;;) { - entry = readdir(tempdir); - if (entry == NULL) break; - if (strncmpic(US entry->d_name,US"__rfc822_",9) == 0) + if (!(entry = readdir(tempdir))) + break; + if (strncmpic(US entry->d_name, US"__rfc822_", 9) == 0) { - (void)string_format(rfc822_file_path, 2048,"%s/scan/%s/%s", spool_directory, message_id, entry->d_name); - debug_printf("RFC822 attachment detected: running MIME ACL for '%s'\n", rfc822_file_path); + (void) string_format(rfc822_file_path, sizeof(rfc822_file_path), + "%s/scan/%s/%s", spool_directory, message_id, entry->d_name); + debug_printf("RFC822 attachment detected: running MIME ACL for '%s'\n", + rfc822_file_path); break; } - } while (1); + } closedir(tempdir); - if (entry != NULL) + if (entry) { - mbox_file = Ufopen(rfc822_file_path,"rb"); - if (mbox_file == NULL) + if ((mbox_file = Ufopen(rfc822_file_path, "rb"))) { - log_write(0, LOG_PANIC, - "acl_smtp_mime: can't open RFC822 spool file, skipping."); - unlink(CS rfc822_file_path); - goto END_MIME_ACL; + /* set RFC822 expansion variable */ + mime_is_rfc822 = 1; + mime_part_count_buffer = mime_part_count; + goto MIME_ACL_CHECK; } - /* set RFC822 expansion variable */ - mime_is_rfc822 = 1; - mime_part_count_buffer = mime_part_count; - goto MIME_ACL_CHECK; + log_write(0, LOG_PANIC, + "acl_smtp_mime: can't open RFC822 spool file, skipping."); + unlink(CS rfc822_file_path); } } diff --git a/src/src/spam.c b/src/src/spam.c index dab57ff12..45a06931c 100644 --- a/src/src/spam.c +++ b/src/src/spam.c @@ -95,11 +95,8 @@ spam(uschar **listptr) spam_ok = 0; /* if we scanned for this username last time, just return */ - if ( spam_ok && Ustrcmp(prev_user_name, user_name) == 0) - if (override) - return OK; - else - return spam_rc; + if (spam_ok && Ustrcmp(prev_user_name, user_name) == 0) + return override ? OK : spam_rc; /* make sure the eml mbox file is spooled up */ mbox_file = spool_mbox(&mbox_size, NULL); diff --git a/src/src/transport.c b/src/src/transport.c index e833894a8..30e4268d1 100644 --- a/src/src/transport.c +++ b/src/src/transport.c @@ -1015,7 +1015,6 @@ char sbuf[2048]; int sread = 0; int wwritten = 0; uschar *dkim_signature = NULL; -off_t size = 0; /* If we can't sign, just call the original function. */ @@ -1103,12 +1102,6 @@ if (dkim_private_key && dkim_domain && dkim_selector) } } -/* Fetch file size */ -size = lseek(dkim_fd, 0, SEEK_END); - -/* Rewind file */ -lseek(dkim_fd, 0, SEEK_SET); - #ifdef HAVE_LINUX_SENDFILE /* We can use sendfile() to shove the file contents to the socket. However only if we don't use TLS, @@ -1116,8 +1109,13 @@ lseek(dkim_fd, 0, SEEK_SET); before the data finally hits the socket. */ if (tls_out.active != fd) { + off_t size = lseek(dkim_fd, 0, SEEK_END); /* Fetch file size */ ssize_t copied = 0; off_t offset = 0; + + /* Rewind file */ + lseek(dkim_fd, 0, SEEK_SET); + while(copied >= 0 && offset < size) copied = sendfile(fd, dkim_fd, &offset, size - offset); if (copied < 0) @@ -1125,42 +1123,47 @@ if (tls_out.active != fd) save_errno = errno; rc = FALSE; } - goto CLEANUP; } +else + #endif -/* Send file down the original fd */ -while((sread = read(dkim_fd, sbuf, 2048)) > 0) { - char *p = sbuf; - /* write the chunk */ + /* Rewind file */ + lseek(dkim_fd, 0, SEEK_SET); - while (sread) + /* Send file down the original fd */ + while((sread = read(dkim_fd, sbuf, 2048)) > 0) { + char *p = sbuf; + /* write the chunk */ + + while (sread) + { #ifdef SUPPORT_TLS - wwritten = tls_out.active == fd - ? tls_write(FALSE, US p, sread) - : write(fd, p, sread); + wwritten = tls_out.active == fd + ? tls_write(FALSE, US p, sread) + : write(fd, p, sread); #else - wwritten = write(fd, p, sread); + wwritten = write(fd, p, sread); #endif - if (wwritten == -1) - { - /* error, bail out */ - save_errno = errno; - rc = FALSE; - goto CLEANUP; + if (wwritten == -1) + { + /* error, bail out */ + save_errno = errno; + rc = FALSE; + goto CLEANUP; + } + p += wwritten; + sread -= wwritten; } - p += wwritten; - sread -= wwritten; } - } -if (sread == -1) - { - save_errno = errno; - rc = FALSE; - goto CLEANUP; + if (sread == -1) + { + save_errno = errno; + rc = FALSE; + } } CLEANUP: diff --git a/test/scripts/5860-DANE-OpenSSL-TPDA/REQUIRES b/test/scripts/5860-DANE-OpenSSL-TPDA/REQUIRES index a80adaf10..7d32fcd49 100644 --- a/test/scripts/5860-DANE-OpenSSL-TPDA/REQUIRES +++ b/test/scripts/5860-DANE-OpenSSL-TPDA/REQUIRES @@ -1,4 +1,4 @@ support Experimental_DANE -support Experimental_EVENT +support Experimental_Event support OpenSSL running IPv4 -- 2.30.2