Apply timeout to Fsecure malware response. Bug 1549
[exim.git] / src / src / transport.c
index 31437b1465315decfe13a7a3f4eca846124f08d3..58fc4ec93a5d113940df11a05973f8b5509f1d40 100644 (file)
@@ -66,6 +66,10 @@ optionlist optionlist_transports[] = {
                  (void *)offsetof(transport_instance, driver_name) },
   { "envelope_to_add",   opt_bool|opt_public,
                  (void *)(offsetof(transport_instance, envelope_to_add)) },
+#ifdef EXPERIMENTAL_EVENT
+  { "event_action",     opt_stringptr | opt_public,
+                 (void *)offsetof(transport_instance, event_action) },
+#endif
   { "group",             opt_expand_gid|opt_public,
                  (void *)offsetof(transport_instance, gid) },
   { "headers_add",      opt_stringptr|opt_public|opt_rep_str,
@@ -94,10 +98,6 @@ optionlist optionlist_transports[] = {
                  (void *)offsetof(transport_instance, shadow_condition) },
   { "shadow_transport", opt_stringptr|opt_public,
                  (void *)offsetof(transport_instance, shadow) },
-#ifdef EXPERIMENTAL_TPDA
-  { "tpda_event_action",opt_stringptr | opt_public,
-                 (void *)offsetof(transport_instance, tpda_event_action) },
-#endif
   { "transport_filter", opt_stringptr|opt_public,
                  (void *)offsetof(transport_instance, filter_command) },
   { "transport_filter_timeout", opt_time|opt_public,
@@ -643,8 +643,7 @@ for (h = header_list; h != NULL; h = h->next) if (h->type != htype_old)
       {
       int sep = ':';         /* This is specified as a colon-separated list */
       uschar *s, *ss;
-      uschar buffer[128];
-      while ((s = string_nextinlist(&list, &sep, buffer, sizeof(buffer))))
+      while ((s = string_nextinlist(&list, &sep, NULL, 0)))
        {
        int len;
 
@@ -1016,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. */
 
@@ -1104,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,
@@ -1117,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)
@@ -1126,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:
@@ -1840,10 +1842,8 @@ if ((pid = fork()) == 0)
 
   argv = child_exec_exim(CEE_RETURN_ARGV, TRUE, &i, FALSE, 0);
 
-  #ifdef EXPERIMENTAL_DSN
   /* Call with the dsn flag */
   if (smtp_use_dsn) argv[i++] = US"-MCD";
-  #endif
 
   if (smtp_authenticated) argv[i++] = US"-MCA";