Logging: mark continued-TLS connection deliveries with "X-*"
[exim.git] / src / src / deliver.c
index f596cb684d6cdf221d96bc79c49ff99634d85e31..7743d37c3eb77ec59b1f798e74c21d73bb7d9d34 100644 (file)
@@ -671,7 +671,7 @@ address_item *aa;
 while (addr->parent)
   {
   addr = addr->parent;
-  if ((addr->child_count -= 1) > 0) return;   /* Incomplete parent */
+  if (--addr->child_count > 0) return;   /* Incomplete parent */
   address_done(addr, now);
 
   /* Log the completion of all descendents only when there is no ancestor with
@@ -944,7 +944,7 @@ for (topaddr = addr; topaddr->parent; topaddr = topaddr->parent) ;
 /* We start with just the local part for pipe, file, and reply deliveries, and
 for successful local deliveries from routers that have the log_as_local flag
 set. File deliveries from filters can be specified as non-absolute paths in
-cases where the transport is goin to complete the path. If there is an error
+cases where the transport is going to complete the path. If there is an error
 before this happens (expansion failure) the local part will not be updated, and
 so won't necessarily look like a path. Add extra text for this case. */
 
@@ -2360,7 +2360,7 @@ if ((pid = fork()) == 0)
             )
         )
       )
-      log_write(0, LOG_MAIN|LOG_PANIC, "Failed writing transport results to pipe: %s\n",
+      log_write(0, LOG_MAIN|LOG_PANIC, "Failed writing transport results to pipe: %s",
        ret == -1 ? strerror(errno) : "short write");
 
     /* Now any messages */
@@ -2371,7 +2371,7 @@ if ((pid = fork()) == 0)
       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\n",
+        log_write(0, LOG_MAIN|LOG_PANIC, "Failed writing transport results to pipe: %s",
          ret == -1 ? strerror(errno) : "short write");
       }
     }
@@ -2975,13 +2975,13 @@ while (addr_local)
        addr3 = store_get(sizeof(address_item));
        *addr3 = *addr2;
        addr3->next = NULL;
-       addr3->shadow_message = (uschar *) &(addr2->shadow_message);
+       addr3->shadow_message = US &addr2->shadow_message;
        addr3->transport = stp;
        addr3->transport_return = DEFER;
        addr3->return_filename = NULL;
        addr3->return_file = -1;
        *last = addr3;
-       last = &(addr3->next);
+       last = &addr3->next;
        }
 
     /* If we found any addresses to shadow, run the delivery, and stick any
@@ -3238,7 +3238,7 @@ uschar *endptr = big_buffer;
 uschar *ptr = endptr;
 uschar *msg = p->msg;
 BOOL done = p->done;
-BOOL unfinished = TRUE;
+BOOL finished = FALSE;
 /* minimum size to read is header size including id, subid and length */
 int required = PIPE_HEADER_SIZE;
 
@@ -3271,7 +3271,7 @@ while (!done)
   There will be only one read if we get all the available data (i.e. don't
   fill the buffer completely). */
 
-  if (remaining < required && unfinished)
+  if (remaining < required && !finished)
     {
     int len;
     int available = big_buffer_size - remaining;
@@ -3301,11 +3301,11 @@ while (!done)
     /* If the length is zero (eof or no-more-data), just process what we
     already have. Note that if the process is still running and we have
     read all the data in the pipe (but less that "available") then we
-    won't read any more, as "unfinished" will get set FALSE. */
+    won't read any more, as "finished" will get set. */
 
     endptr += len;
     remaining += len;
-    unfinished = len == available;
+    finished = len != available;
     }
 
   /* If we are at the end of the available data, exit the loop. */
@@ -3326,8 +3326,8 @@ while (!done)
     }
 
   DEBUG(D_deliver)
-    debug_printf("header read  id:%c,subid:%c,size:%s,required:%d,remaining:%d,unfinished:%d\n",
-                    id, subid, header+2, required, remaining, unfinished);
+    debug_printf("header read  id:%c,subid:%c,size:%s,required:%d,remaining:%d,finished:%d\n",
+                    id, subid, header+2, required, remaining, finished);
 
   /* is there room for the dataset we want to read ? */
   if (required > big_buffer_size - PIPE_HEADER_SIZE)
@@ -3339,22 +3339,22 @@ while (!done)
     break;
     }
 
-  /* we wrote all datasets with atomic write() calls
-     remaining < required only happens if big_buffer was too small
-     to get all available data from pipe. unfinished has to be true
-     as well. */
+  /* We wrote all datasets with atomic write() calls.  Remaining < required only
+  happens if big_buffer was too small to get all available data from pipe;
+  finished has to be false as well. */
+
   if (remaining < required)
     {
-    if (unfinished)
+    if (!finished)
       continue;
     msg = string_sprintf("failed to read pipe from transport process "
-      "%d for transport %s: required size=%d > remaining size=%d and unfinished=false",
+      "%d for transport %s: required size=%d > remaining size=%d and finished=true",
       pid, addr->transport->driver_name, required, remaining);
     done = TRUE;
     break;
     }
 
-  /* step behind the header */
+  /* Step past the header */
   ptr += PIPE_HEADER_SIZE;
 
   /* Handle each possible type of item, assuming the complete item is
@@ -3396,7 +3396,7 @@ while (!done)
 
     /* Cut out any "delete" items on the list. */
 
-    for (rp = &(addr->retries); (r = *rp); rp = &r->next)
+    for (rp = &addr->retries; (r = *rp); rp = &r->next)
       if (Ustrcmp(r->key, ptr+1) == 0)           /* Found item with same key */
         {
         if ((r->flags & rf_delete) == 0) break;  /* It was not "delete" */
@@ -3408,7 +3408,7 @@ while (!done)
     /* We want to add a delete item only if there is no non-delete item;
     however we still have to step ptr through the data. */
 
-    if (!r || (*ptr & rf_delete) == 0)
+    if (!r || !(*ptr & rf_delete))
       {
       r = store_get(sizeof(retry_item));
       r->next = addr->retries;
@@ -3458,36 +3458,34 @@ while (!done)
     switch (subid)
       {
       case '1':
-      addr->cipher = NULL;
-      addr->peerdn = NULL;
-
-      if (*ptr)
-       addr->cipher = string_copy(ptr);
-      while (*ptr++);
-      if (*ptr)
-       addr->peerdn = string_copy(ptr);
-      break;
+       addr->cipher = NULL;
+       addr->peerdn = NULL;
+
+       if (*ptr)
+         addr->cipher = string_copy(ptr);
+       while (*ptr++);
+       if (*ptr)
+         addr->peerdn = string_copy(ptr);
+       break;
 
       case '2':
-      if (*ptr)
-       (void) tls_import_cert(ptr, &addr->peercert);
-      else
-       addr->peercert = NULL;
-      break;
+       if (*ptr)
+         (void) tls_import_cert(ptr, &addr->peercert);
+       else
+         addr->peercert = NULL;
+       break;
 
       case '3':
-      if (*ptr)
-       (void) tls_import_cert(ptr, &addr->ourcert);
-      else
-       addr->ourcert = NULL;
-      break;
+       if (*ptr)
+         (void) tls_import_cert(ptr, &addr->ourcert);
+       else
+         addr->ourcert = NULL;
+       break;
 
 # ifndef DISABLE_OCSP
       case '4':
-      addr->ocsp = OCSP_NOT_REQ;
-      if (*ptr)
-       addr->ocsp = *ptr - '0';
-      break;
+       addr->ocsp = *ptr ? *ptr - '0' : OCSP_NOT_REQ;
+       break;
 # endif
       }
     while (*ptr++);
@@ -3542,7 +3540,7 @@ while (!done)
       {
 #ifdef SUPPORT_SOCKS
       case '2':        /* proxy information; must arrive before A0 and applies to that addr XXX oops*/
-       proxy_session = TRUE;   /*XXX shouod this be cleared somewhere? */
+       proxy_session = TRUE;   /*XXX should this be cleared somewhere? */
        if (*ptr == 0)
          ptr++;
        else
@@ -4344,7 +4342,7 @@ for (delivery_count = 0; addr_remote; delivery_count++)
          )  )
        && (  !multi_domain
          || (  (
-               !tp->expand_multi_domain || (deliver_set_expansions(next), 1),
+               (void)(!tp->expand_multi_domain || ((void)deliver_set_expansions(next), 1)),
                exp_bool(addr,
                    US"transport", next->transport->name, D_transport,
                    US"multi_domain", next->transport->multi_domain,
@@ -4569,7 +4567,7 @@ for (delivery_count = 0; addr_remote; delivery_count++)
     }
 
   /* Now fork a subprocess to do the remote delivery, but before doing so,
-  ensure that any cached resourses are released so as not to interfere with
+  ensure that any cached resources are released so as not to interfere with
   what happens in the subprocess. */
 
   search_tidyup();
@@ -4713,13 +4711,13 @@ for (delivery_count = 0; addr_remote; delivery_count++)
         if (!addr->peerdn)
          *ptr++ = 0;
        else
-          {
-          ptr += sprintf(CS ptr, "%.512s", addr->peerdn);
-          ptr++;
-          }
+          ptr += sprintf(CS ptr, "%.512s", addr->peerdn) + 1;
 
         rmt_dlv_checked_write(fd, 'X', '1', big_buffer, ptr - big_buffer);
         }
+      else if (continue_proxy)         /* known TLS, but no cipher info */
+        rmt_dlv_checked_write(fd, 'X', '1', US"*\0", 3);
+
       if (addr->peercert)
        {
         ptr = big_buffer;
@@ -5031,6 +5029,7 @@ if (percent_hack_domains)
     address_item *new_parent = store_get(sizeof(address_item));
     *new_parent = *addr;
     addr->parent = new_parent;
+    new_parent->child_count = 1;
     addr->address = new_address;
     addr->unique = string_copy(new_address);
     addr->domain = deliver_domain;
@@ -5901,9 +5900,9 @@ else if (system_filter && process_recipients != RECIP_FAIL_TIMEOUT)
 
     while (p)
       {
-      if (parent->child_count == SHRT_MAX)
+      if (parent->child_count == USHRT_MAX)
         log_write(0, LOG_MAIN|LOG_PANIC_DIE, "system filter generated more "
-          "than %d delivery addresses", SHRT_MAX);
+          "than %d delivery addresses", USHRT_MAX);
       parent->child_count++;
       p->parent = parent;
 
@@ -7141,10 +7140,9 @@ for (addr_dsntmp = addr_succeed; addr_dsntmp; addr_dsntmp = addr_dsntmp->next)
      )
     {
     /* copy and relink address_item and send report with all of them at once later */
-    address_item *addr_next;
-    addr_next = addr_senddsn;
+    address_item * addr_next = addr_senddsn;
     addr_senddsn = store_get(sizeof(address_item));
-    memcpy(addr_senddsn, addr_dsntmp, sizeof(address_item));
+    *addr_senddsn = *addr_dsntmp;
     addr_senddsn->next = addr_next;
     }
   else
@@ -7347,7 +7345,7 @@ while (addr_failed)
   /* Otherwise, handle the sending of a message. Find the error address for
   the first address, then send a message that includes all failed addresses
   that have the same error address. Note the bounce_recipient is a global so
-  that it can be accesssed by $bounce_recipient while creating a customized
+  that it can be accessed by $bounce_recipient while creating a customized
   error message. */
 
   else
@@ -8301,7 +8299,7 @@ if (remove_journal)
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s", fname,
       strerror(errno));
 
-  /* Move the message off the spool if reqested */
+  /* Move the message off the spool if requested */
 
 #ifdef SUPPORT_MOVE_FROZEN_MESSAGES
   if (deliver_freeze && move_frozen_messages)