* Exim - an Internet mail transport agent *
*************************************************/
-/* Copyright (c) University of Cambridge 1995 - 2016 */
+/* Copyright (c) University of Cambridge 1995 - 2018 */
/* See the file NOTICE for conditions of use and distribution. */
/* The main code for delivering a message. */
+/*************************************************
+* read as much as requested *
+*************************************************/
+
+/* The syscall read(2) doesn't always returns as much as we want. For
+several reasons it might get less. (Not talking about signals, as syscalls
+are restartable). When reading from a network or pipe connection the sender
+might send in smaller chunks, with delays between these chunks. The read(2)
+may return such a chunk.
+
+The more the writer writes and the smaller the pipe between write and read is,
+the more we get the chance of reading leass than requested. (See bug 2130)
+
+This function read(2)s until we got all the data we *requested*.
+
+Note: This function may block. Use it only if you're sure about the
+amount of data you will get.
+
+Argument:
+ fd the file descriptor to read from
+ buffer pointer to a buffer of size len
+ len the requested(!) amount of bytes
+
+Returns: the amount of bytes read
+*/
+static ssize_t
+readn(int fd, void * buffer, size_t len)
+{
+ void * next = buffer;
+ void * end = buffer + len;
+
+ while (next < end)
+ {
+ ssize_t got = read(fd, next, end - next);
+
+ /* I'm not sure if there are signals that can interrupt us,
+ for now I assume the worst */
+ if (got == -1 && errno == EINTR) continue;
+ if (got <= 0) return next - buffer;
+ next += got;
+ }
+
+ return len;
+}
+
+
/*************************************************
* Make a new address item *
*************************************************/
s = string_append(s, 2, US" CV=",
testflag(addr, af_cert_verified)
?
-#ifdef EXPERIMENTAL_DANE
+#ifdef SUPPORT_DANE
testflag(addr, af_dane_verified)
? "dane"
:
and all parents are not being included, don't add on the top address. First
of all, do a caseless comparison; if this succeeds, do a caseful comparison
on the local parts. */
- /*XXX dodgy coding. the string at "cmp" might not be nul-terminated if
- we had to extend the allocation! */
- g->s[g->ptr] = '\0';
+ string_from_gstring(g); /* ensure nul-terminated */
if ( strcmpic(cmp, topaddr->address) == 0
&& Ustrncmp(cmp, topaddr->address, Ustrchr(cmp, '@') - cmp) == 0
&& !addr->onetime_parent
-static uschar *
+uschar *
string_timediff(struct timeval * diff)
{
static uschar buf[sizeof("0.000s")];
log_write(0, LOG_MAIN, "<%s>: %s transport output: %s",
addr->address, tb->name, sp);
}
- (void)fclose(f);
+ (void)fclose(f);
}
/* Handle returning options, but only if there is an address to return
tls_out.cipher = addr->cipher;
tls_out.peerdn = addr->peerdn;
tls_out.ocsp = addr->ocsp;
-# ifdef EXPERIMENTAL_DANE
+# ifdef SUPPORT_DANE
tls_out.dane_verified = testflag(addr, af_dane_verified);
# endif
#endif
tls_out.cipher = NULL;
tls_out.peerdn = NULL;
tls_out.ocsp = OCSP_NOT_REQ;
-# ifdef EXPERIMENTAL_DANE
+# ifdef SUPPORT_DANE
tls_out.dane_verified = FALSE;
# endif
#endif
If we get less, we can assume the subprocess do be done and do not expect any further
information from it. */
- got = readn(fd, pipeheader, required);
- if (got != required)
+ if ((got = readn(fd, pipeheader, required)) != required)
{
msg = string_sprintf("got " SSIZE_T_FMT " of %d bytes (pipeheader) "
"from transport process %d for transport %s",
/* Same as above, the transport process will write the bytes announced
in a timely manner, so we can just wait for the bytes, getting less than expected
is considered a problem of the subprocess, we do not expect anything else from it. */
- got = readn(fd, big_buffer, required);
- if (got != required)
+ if ((got = readn(fd, big_buffer, required)) != required)
{
msg = string_sprintf("got only " SSIZE_T_FMT " of " SIZE_T_FMT
" bytes (pipedata) from transport process %d for transport %s",
treat it as if it is a continued connection (apart from the counter used
for the log line mark). */
- if (cutthrough.fd >= 0 && cutthrough.callout_hold_only)
+ if (cutthrough.cctx.sock >= 0 && cutthrough.callout_hold_only)
{
DEBUG(D_deliver)
debug_printf("lazy-callout-close: have conn still open from verification\n");
/* The certificate verification status goes into the flags */
if (tls_out.certificate_verified) setflag(addr, af_cert_verified);
-#ifdef EXPERIMENTAL_DANE
+#ifdef SUPPORT_DANE
if (tls_out.dane_verified) setflag(addr, af_dane_verified);
#endif
release its TLS library context (if any) as responsibility was passed to
the delivery child process. */
- if (cutthrough.fd >= 0 && cutthrough.callout_hold_only)
+ if (cutthrough.cctx.sock >= 0 && cutthrough.callout_hold_only)
{
#ifdef SUPPORT_TLS
- tls_close(FALSE, FALSE);
+ if (cutthrough.is_tls)
+ tls_close(cutthrough.cctx.tls_ctx, TLS_NO_SHUTDOWN);
#endif
- (void) close(cutthrough.fd);
+ (void) close(cutthrough.cctx.sock);
release_cutthrough_connection(US"passed to transport proc");
}
new->dsn_flags = r->dsn_flags & rf_dsnflags;
new->dsn_orcpt = r->orcpt;
DEBUG(D_deliver) debug_printf("DSN: set orcpt: %s flags: %d\n",
- new->dsn_orcpt, new->dsn_flags);
+ new->dsn_orcpt ? new->dsn_orcpt : US"", new->dsn_flags);
switch (process_recipients)
{
"DSN: envid: %s ret: %d\n"
"DSN: Final recipient: %s\n"
"DSN: Remote SMTP server supports DSN: %d\n",
- addr_dsntmp->router->name,
+ addr_dsntmp->router ? addr_dsntmp->router->name : US"(unknown)",
addr_dsntmp->address,
sender_address,
- addr_dsntmp->dsn_orcpt, addr_dsntmp->dsn_flags,
- dsn_envid, dsn_ret,
+ addr_dsntmp->dsn_orcpt ? addr_dsntmp->dsn_orcpt : US"NULL",
+ addr_dsntmp->dsn_flags,
+ dsn_envid ? dsn_envid : US"NULL", dsn_ret,
addr_dsntmp->address,
addr_dsntmp->dsn_aware
);
addr->address);
if ((hu = addr->host_used) && hu->name)
{
- const uschar * s;
fprintf(f, "Remote-MTA: dns; %s\n", hu->name);
#ifdef EXPERIMENTAL_DSN_INFO
+ {
+ const uschar * s;
if (hu->address)
{
uschar * p = hu->port == 25
fprintf(f, "X-Remote-MTA-helo-response: X-str; %s\n", s);
if ((s = addr->message) && *s)
fprintf(f, "X-Exim-Diagnostic: X-str; %s\n", s);
+ }
#endif
print_dsn_diagnostic_code(addr, f);
}
/* Log the end of this message, with queue time if requested. */
if (LOGGING(queue_time_overall))
- log_write(0, LOG_MAIN, "Completed QT=%s",
- string_timesince(&received_time));
+ log_write(0, LOG_MAIN, "Completed QT=%s", string_timesince(&received_time));
else
log_write(0, LOG_MAIN, "Completed");
{
uschar * where;
-if (cutthrough.fd >= 0 && cutthrough.callout_hold_only)
+if (cutthrough.cctx.sock >= 0 && cutthrough.callout_hold_only)
{
- int pfd[2], channel_fd = cutthrough.fd, pid;
+ int channel_fd = cutthrough.cctx.sock;
smtp_peer_options = cutthrough.peer_options;
continue_sequence = 0;
#ifdef SUPPORT_TLS
if (cutthrough.is_tls)
{
+ int pfd[2], pid;
+
smtp_peer_options |= OPTION_TLS;
sending_ip_address = cutthrough.snd_ip;
sending_port = cutthrough.snd_port;
else if (pid == 0) /* child: fork again to totally disconnect */
{
- close(pfd[1]);
- if ((pid = fork()))
- _exit(pid < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
- smtp_proxy_tls(big_buffer, big_buffer_size, pfd[0], 5*60);
- exim_exit(0, US"TLS proxy");
+ if (running_in_test_harness) millisleep(100); /* let parent debug out */
+ /* does not return */
+ smtp_proxy_tls(cutthrough.cctx.tls_ctx, big_buffer, big_buffer_size,
+ pfd, 5*60);
}
+ DEBUG(D_transport) debug_printf("proxy-proc inter-pid %d\n", pid);
close(pfd[0]);
waitpid(pid, NULL, 0);
(void) close(channel_fd); /* release the client socket */