*************************************************/
/* Copyright (c) University of Cambridge 1995 - 2018 */
+/* Copyright (c) The Exim Maintainers 2020 */
/* See the file NOTICE for conditions of use and distribution. */
/* The main code for delivering a message. */
deliver_localpart = addr->local_part;
deliver_localpart_prefix = addr->prefix;
+ deliver_localpart_prefix_v = addr->prefix_v;
deliver_localpart_suffix = addr->suffix;
+ deliver_localpart_suffix_v = addr->suffix_v;
for (addr_orig = addr; addr_orig->parent; addr_orig = addr_orig->parent) ;
deliver_domain_orig = addr_orig->domain;
else if (deliver_localpart[0] == '|') address_pipe = addr->local_part;
deliver_localpart = addr->parent->local_part;
deliver_localpart_prefix = addr->parent->prefix;
+ deliver_localpart_prefix_v = addr->parent->prefix_v;
deliver_localpart_suffix = addr->parent->suffix;
+ deliver_localpart_suffix_v = addr->parent->suffix_v;
}
}
addr2->transport_return = addr->transport_return;
addr2->basic_errno = addr->basic_errno;
addr2->more_errno = addr->more_errno;
- addr2->delivery_usec = addr->delivery_usec;
+ addr2->delivery_time = addr->delivery_time;
addr2->special_action = addr->special_action;
addr2->message = addr->message;
addr2->user_message = addr->user_message;
if (*queue_name)
g = string_append(g, 2, US" Q=", queue_name);
-#ifdef EXPERIMENTAL_SRS
+#ifdef EXPERIMENTAL_SRS_ALT
if(addr->prop.srs_sender)
g = string_append(g, 3, US" SRS=<", addr->prop.srs_sender, US">");
#endif
string_timesince(&received_time));
if (LOGGING(deliver_time))
- {
- struct timeval diff = {.tv_sec = addr->more_errno, .tv_usec = addr->delivery_usec};
- g = string_append(g, 2, US" DT=", string_timediff(&diff));
- }
+ g = string_append(g, 2, US" DT=", string_timediff(&addr->delivery_time));
/* string_cat() always leaves room for the terminator. Release the
store we used to build the line after writing it. */
}
}
+if (LOGGING(deliver_time))
+ g = string_append(g, 2, US" DT=", string_timediff(&addr->delivery_time));
+
if (addr->message)
g = string_append(g, 2, US": ", addr->message);
if (addr->message)
g = string_append(g, 2, US": ", addr->message);
+if (LOGGING(deliver_time))
+ g = string_append(g, 2, US" DT=", string_timediff(&addr->delivery_time));
+
(void) string_from_gstring(g);
/* Do the logging. For the message log, "routing failed" for those cases,
if(addr->prop.errors_address)
return_path = addr->prop.errors_address;
-#ifdef EXPERIMENTAL_SRS
+#ifdef EXPERIMENTAL_SRS_ALT
else if (addr->prop.srs_sender)
return_path = addr->prop.srs_sender;
#endif
search_tidyup();
-if ((pid = fork()) == 0)
+if ((pid = exim_fork(US"delivery-local")) == 0)
{
BOOL replicate = TRUE;
uschar *s;
int ret;
- if( (ret = os_pipe_write(pfd[pipe_write], &addr2->transport_return, sizeof(int))) != sizeof(int)
- || (ret = os_pipe_write(pfd[pipe_write], &transport_count, sizeof(transport_count))) != sizeof(transport_count)
- || (ret = os_pipe_write(pfd[pipe_write], &addr2->flags, sizeof(addr2->flags))) != sizeof(addr2->flags)
- || (ret = os_pipe_write(pfd[pipe_write], &addr2->basic_errno, sizeof(int))) != sizeof(int)
- || (ret = os_pipe_write(pfd[pipe_write], &addr2->more_errno, sizeof(int))) != sizeof(int)
- || (ret = os_pipe_write(pfd[pipe_write], &addr2->delivery_usec, sizeof(int))) != sizeof(int)
- || (ret = os_pipe_write(pfd[pipe_write], &addr2->special_action, sizeof(int))) != sizeof(int)
- || (ret = os_pipe_write(pfd[pipe_write], &addr2->transport,
+ if( (ret = write(pfd[pipe_write], &addr2->transport_return, sizeof(int))) != sizeof(int)
+ || (ret = write(pfd[pipe_write], &transport_count, sizeof(transport_count))) != sizeof(transport_count)
+ || (ret = write(pfd[pipe_write], &addr2->flags, sizeof(addr2->flags))) != sizeof(addr2->flags)
+ || (ret = write(pfd[pipe_write], &addr2->basic_errno, sizeof(int))) != sizeof(int)
+ || (ret = write(pfd[pipe_write], &addr2->more_errno, sizeof(int))) != sizeof(int)
+ || (ret = write(pfd[pipe_write], &addr2->delivery_time, sizeof(struct timeval))) != sizeof(struct timeval)
+ || (ret = write(pfd[pipe_write], &addr2->special_action, sizeof(int))) != sizeof(int)
+ || (ret = write(pfd[pipe_write], &addr2->transport,
sizeof(transport_instance *))) != sizeof(transport_instance *)
/* For a file delivery, pass back the local part, in case the original
logging. */
|| (testflag(addr2, af_file)
- && ( (ret = os_pipe_write(pfd[pipe_write], &local_part_length, sizeof(int))) != sizeof(int)
- || (ret = os_pipe_write(pfd[pipe_write], addr2->local_part, local_part_length)) != local_part_length
+ && ( (ret = write(pfd[pipe_write], &local_part_length, sizeof(int))) != sizeof(int)
+ || (ret = write(pfd[pipe_write], addr2->local_part, local_part_length)) != local_part_length
)
)
)
for (i = 0, s = addr2->message; i < 2; i++, s = addr2->user_message)
{
int message_length = s ? Ustrlen(s) + 1 : 0;
- if( (ret = os_pipe_write(pfd[pipe_write], &message_length, sizeof(int))) != sizeof(int)
- || message_length > 0 && (ret = os_pipe_write(pfd[pipe_write], s, message_length)) != message_length
+ if( (ret = write(pfd[pipe_write], &message_length, sizeof(int))) != sizeof(int)
+ || message_length > 0 && (ret = write(pfd[pipe_write], s, message_length)) != message_length
)
log_write(0, LOG_MAIN|LOG_PANIC, "Failed writing transport results to pipe: %s",
ret == -1 ? strerror(errno) : "short write");
for (addr2 = addr; addr2; addr2 = addr2->next)
{
- if ((len = os_pipe_read(pfd[pipe_read], &status, sizeof(int))) > 0)
+ if ((len = read(pfd[pipe_read], &status, sizeof(int))) > 0)
{
int i;
uschar **sptr;
addr2->transport_return = status;
- len = os_pipe_read(pfd[pipe_read], &transport_count,
+ len = read(pfd[pipe_read], &transport_count,
sizeof(transport_count));
- len = os_pipe_read(pfd[pipe_read], &addr2->flags, sizeof(addr2->flags));
- len = os_pipe_read(pfd[pipe_read], &addr2->basic_errno, sizeof(int));
- len = os_pipe_read(pfd[pipe_read], &addr2->more_errno, sizeof(int));
- len = os_pipe_read(pfd[pipe_read], &addr2->delivery_usec, sizeof(int));
- len = os_pipe_read(pfd[pipe_read], &addr2->special_action, sizeof(int));
- len = os_pipe_read(pfd[pipe_read], &addr2->transport,
+ len = read(pfd[pipe_read], &addr2->flags, sizeof(addr2->flags));
+ len = read(pfd[pipe_read], &addr2->basic_errno, sizeof(int));
+ len = read(pfd[pipe_read], &addr2->more_errno, sizeof(int));
+ len = read(pfd[pipe_read], &addr2->delivery_time, sizeof(struct timeval));
+ len = read(pfd[pipe_read], &addr2->special_action, sizeof(int));
+ len = read(pfd[pipe_read], &addr2->transport,
sizeof(transport_instance *));
if (testflag(addr2, af_file))
{
int llen;
- if ( os_pipe_read(pfd[pipe_read], &llen, sizeof(int)) != sizeof(int)
+ if ( read(pfd[pipe_read], &llen, sizeof(int)) != sizeof(int)
|| llen > 64*4 /* limit from rfc 5821, times I18N factor */
)
{
}
/* sanity-checked llen so disable the Coverity error */
/* coverity[tainted_data] */
- if (os_pipe_read(pfd[pipe_read], big_buffer, llen) != llen)
+ if (read(pfd[pipe_read], big_buffer, llen) != llen)
{
log_write(0, LOG_MAIN|LOG_PANIC, "bad local_part read"
" from delivery subprocess");
for (i = 0, sptr = &addr2->message; i < 2; i++, sptr = &addr2->user_message)
{
int message_length;
- len = os_pipe_read(pfd[pipe_read], &message_length, sizeof(int));
+ len = read(pfd[pipe_read], &message_length, sizeof(int));
if (message_length > 0)
{
- len = os_pipe_read(pfd[pipe_read], big_buffer, message_length);
+ len = read(pfd[pipe_read], big_buffer, message_length);
big_buffer[big_buffer_size-1] = '\0'; /* guard byte */
if (len > 0) *sptr = string_copy(big_buffer);
}
"message for %s transport): %s", addr->transport->warn_message,
addr->transport->name, expand_string_message);
- else if ((pid = child_open_exim(&fd)) > 0)
+ else if ((pid = child_open_exim(&fd, US"tpt-warning-message")) > 0)
{
FILE *f = fdopen(fd, "wb");
if (errors_reply_to && !contains_header(US"Reply-To", warn_message))
/* Done with this address */
- if (result == OK)
- {
- addr2->more_errno = deliver_time.tv_sec;
- addr2->delivery_usec = deliver_time.tv_usec;
- }
+ addr2->delivery_time = deliver_time;
post_process_one(addr2, result, logflags, EXIM_DTYPE_TRANSPORT, logchar);
/* If a pipe delivery generated text to be sent back, the result may be
ptr += sizeof(addr->basic_errno);
memcpy(&addr->more_errno, ptr, sizeof(addr->more_errno));
ptr += sizeof(addr->more_errno);
- memcpy(&addr->delivery_usec, ptr, sizeof(addr->delivery_usec));
- ptr += sizeof(addr->delivery_usec);
+ memcpy(&addr->delivery_time, ptr, sizeof(addr->delivery_time));
+ ptr += sizeof(addr->delivery_time);
memcpy(&addr->flags, ptr, sizeof(addr->flags));
ptr += sizeof(addr->flags);
addr->message = *ptr ? string_copy(ptr) : NULL;
DEBUG(D_deliver) debug_printf("header write id:%c,subid:%c,size:%ld,final:%s\n",
id, subid, (long)size, pipe_header);
-if ((ret = os_pipe_writev(fd, iov, 2)) != total_len)
+if ((ret = writev(fd, iov, 2)) != total_len)
log_write(0, LOG_MAIN|LOG_PANIC_DIE,
"Failed writing transport result to pipe (%ld of %ld bytes): %s",
(long)ret, (long)total_len, ret == -1 ? strerror(errno) : "short write");
if(addr->prop.errors_address)
return_path = addr->prop.errors_address;
-#ifdef EXPERIMENTAL_SRS
+#ifdef EXPERIMENTAL_SRS_ALT
else if(addr->prop.srs_sender)
return_path = addr->prop.srs_sender;
#endif
search_tidyup();
- if ((pid = fork()) == 0)
+ if ((pid = exim_fork(US"transport")) == 0)
{
int fd = pfd[pipe_write];
host_item *h;
/* Show pids on debug output if parallelism possible */
if (parmax > 1 && (parcount > 0 || addr_remote))
- {
DEBUG(D_any|D_v) debug_selector |= D_pid;
- DEBUG(D_deliver) debug_printf("Remote delivery process started\n");
- }
/* Reset the random number generator, so different processes don't all
have the same sequence. In the test harness we want different, but
ptr += sizeof(addr->basic_errno);
memcpy(ptr, &addr->more_errno, sizeof(addr->more_errno));
ptr += sizeof(addr->more_errno);
- memcpy(ptr, &addr->delivery_usec, sizeof(addr->delivery_usec));
- ptr += sizeof(addr->delivery_usec);
+ memcpy(ptr, &addr->delivery_time, sizeof(addr->delivery_time));
+ ptr += sizeof(addr->delivery_time);
memcpy(ptr, &addr->flags, sizeof(addr->flags));
ptr += sizeof(addr->flags);
return actual_time;
}
+/************************************************/
+
+static FILE *
+expand_open(const uschar * filename,
+ const uschar * varname, const uschar * reason)
+{
+const uschar * s = expand_cstring(filename);
+FILE * fp = NULL;
+
+if (!s || !*s)
+ log_write(0, LOG_MAIN|LOG_PANIC,
+ "Failed to expand %s: '%s'\n", varname, filename);
+else if (*s != '/' || is_tainted(s))
+ log_write(0, LOG_MAIN|LOG_PANIC,
+ "%s is not %s after expansion: '%s'\n",
+ varname, *s == '/' ? "untainted" : "absolute", s);
+else if (!(fp = Ufopen(s, "rb")))
+ log_write(0, LOG_MAIN|LOG_PANIC, "Failed to open %s for %s "
+ "message texts: %s", s, reason, strerror(errno));
+return fp;
+}
+
/*************************************************
* Deliver one message *
*************************************************/
int fd;
/* create exim process to send message */
- pid = child_open_exim(&fd);
+ pid = child_open_exim(&fd, US"DSN");
DEBUG(D_deliver) debug_printf("DSN: child_open_exim returns: %d\n", pid);
/* Make a subprocess to send a message */
- if ((pid = child_open_exim(&fd)) < 0)
+ if ((pid = child_open_exim(&fd, US"bounce-message")) < 0)
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Process %d (parent %d) failed to "
"create child process to send failure message: %s", getpid(),
getppid(), strerror(errno));
carry on - default texts will be used. */
if (bounce_message_file)
- if (!(emf = Ufopen(bounce_message_file, "rb")))
- log_write(0, LOG_MAIN|LOG_PANIC, "Failed to open %s for error "
- "message texts: %s", bounce_message_file, strerror(errno));
+ emf = expand_open(bounce_message_file,
+ US"bounce_message_file", US"error");
/* Quietly copy to configured additional addresses if required. */
(void)fclose(fp);
rc = child_close(pid, 0); /* Waits for child to close, no timeout */
- /* In the test harness, let the child do it's thing first. */
-
- testharness_pause_ms(500);
-
/* If the process failed, there was some disaster in setting up the
error message. Unless the message is very old, ensure that addr_defer
is non-null, which will have the effect of leaving the message on the
{
header_line *h;
int fd;
- pid_t pid = child_open_exim(&fd);
+ pid_t pid = child_open_exim(&fd, US"delay-warning-message");
if (pid > 0)
{
- uschar *wmf_text;
- FILE *wmf = NULL;
- FILE *f = fdopen(fd, "wb");
+ uschar * wmf_text;
+ FILE * wmf = NULL;
+ FILE * f = fdopen(fd, "wb");
uschar * bound;
transport_ctx tctx = {{0}};
if (warn_message_file)
- if (!(wmf = Ufopen(warn_message_file, "rb")))
- log_write(0, LOG_MAIN|LOG_PANIC, "Failed to open %s for warning "
- "message texts: %s", warn_message_file, strerror(errno));
+ wmf = expand_open(warn_message_file,
+ US"warn_message_file", US"warning");
warnmsg_recipients = recipients;
warnmsg_delay = queue_time < 120*60
goto fail;
where = US"fork";
- if ((pid = fork()) < 0)
+ testharness_pause_ms(150);
+ if ((pid = exim_fork(US"tls-proxy-interproc")) < 0)
goto fail;
- else if (pid == 0) /* child: fork again to totally disconnect */
+ if (pid == 0) /* child: will fork again to totally disconnect */
{
- testharness_pause_ms(100); /* let parent debug out */
- /* does not return */
smtp_proxy_tls(cutthrough.cctx.tls_ctx, big_buffer, big_buffer_size,
pfd, 5*60);
+ /* does not return */
}
- 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 */