logging
[exim.git] / src / src / deliver.c
index a1fb602e9d02b38d6ad83d42bb2176cae64d9fd2..1fd3d46c0b967d6e0247d980eec51af35421195d 100644 (file)
@@ -285,9 +285,9 @@ int fd = Uopen(filename, O_WRONLY|O_APPEND|O_CREAT, mode);
 
 if (fd < 0 && errno == ENOENT)
   {
-  uschar temp[16];
-  sprintf(CS temp, "msglog/%s", message_subdir);
-  if (message_subdir[0] == 0) temp[6] = 0;
+  uschar * temp = string_sprintf("msglog%s%s%s%s",
+                   *queue_name ? "/" : "", queue_name,
+                   *message_subdir ? "/" : "", message_subdir);
   (void)directory_make(spool_directory, temp, MSGLOG_DIRECTORY_MODE, TRUE);
   fd = Uopen(filename, O_WRONLY|O_APPEND|O_CREAT, mode);
   }
@@ -880,6 +880,9 @@ if (LOGGING(sender_on_delivery) || msg)
       sender_address,
   US">");
 
+if (*queue_name)
+  s = string_append(s, &size, &ptr, 2, US" Q=", queue_name);
+
 #ifdef EXPERIMENTAL_SRS
 if(addr->prop.srs_sender)
   s = string_append(s, &size, &ptr, 3, US" SRS=<", addr->prop.srs_sender, US">");
@@ -1076,21 +1079,9 @@ malformed, it won't ever have gone near LDAP.) */
 if (addr->message)
   {
   const uschar * s = string_printing(addr->message);
-  if (s != addr->message)
-    addr->message = US s;
-    /* deconst cast ok as string_printing known to have alloc'n'copied */
-  if (  (  Ustrstr(s, "failed to expand") != NULL
-       || Ustrstr(s, "expansion of ")    != NULL
-       )
-     && (  Ustrstr(s, "mysql")   != NULL
-        || Ustrstr(s, "pgsql")   != NULL
-       || Ustrstr(s, "redis")   != NULL
-       || Ustrstr(s, "sqlite")  != NULL
-       || Ustrstr(s, "ldap:")   != NULL
-       || Ustrstr(s, "ldapdn:") != NULL
-       || Ustrstr(s, "ldapm:")  != NULL
-     )  )
-    addr->message = string_sprintf("Temporary internal error");
+
+  /* deconst cast ok as string_printing known to have alloc'n'copied */
+  addr->message = expand_hide_passwords(US s);
   }
 
 /* If we used a transport that has one of the "return_output" options set, and
@@ -1279,6 +1270,9 @@ else if (result == DEFER || result == PANIC)
 
     s = string_cat(s, &size, &ptr, log_address);
 
+    if (*queue_name)
+      s = string_append(s, &size, &ptr, 2, US" Q=", queue_name);
+
     /* Either driver_name contains something and driver_kind contains
     " router" or " transport" (note the leading space), or driver_name is
     a null string and driver_kind contains "routing" without the leading
@@ -1400,6 +1394,9 @@ else
   if (LOGGING(sender_on_delivery))
     s = string_append(s, &size, &ptr, 3, US" F=<", sender_address, US">");
 
+  if (*queue_name)
+    s = string_append(s, &size, &ptr, 2, US" Q=", queue_name);
+
   /* Return path may not be set if no delivery actually happened */
 
   if (used_return_path && LOGGING(return_path_on_delivery))
@@ -1958,7 +1955,8 @@ if (  !shadowing
   {
   uschar *error;
   addr->return_filename =
-    string_sprintf("%s/msglog/%s/%s-%d-%d", spool_directory, message_subdir,
+    string_sprintf("%s/msglog/%s/%s/%s-%d-%d",
+      spool_directory, queue_name, message_subdir,
       message_id, getpid(), return_count++);
   addr->return_file = open_msglog_file(addr->return_filename, 0400, &error);
   if (addr->return_file < 0)
@@ -4384,11 +4382,10 @@ for (delivery_count = 0; addr_remote; delivery_count++)
     a dup-with-new-file-pointer. */
 
     (void)close(deliver_datafile);
-    sprintf(CS spoolname, "%s/input/%s/%s-D", spool_directory, message_subdir,
-      message_id);
-    deliver_datafile = Uopen(spoolname, O_RDWR | O_APPEND, 0);
+    snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-D",
+      spool_directory, queue_name, message_subdir, message_id);
 
-    if (deliver_datafile < 0)
+    if ((deliver_datafile = Uopen(spoolname, O_RDWR | O_APPEND, 0)) < 0)
       log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Failed to reopen %s for remote "
         "parallel delivery: %s", spoolname, strerror(errno));
 
@@ -5243,8 +5240,8 @@ if ((rc = spool_read_header(spoolname, TRUE, TRUE)) != spool_read_OK)
   if (errno == ERRNO_SPOOLFORMAT)
     {
     struct stat statbuf;
-    sprintf(CS big_buffer, "%s/input/%s/%s", spool_directory, message_subdir,
-      spoolname);
+    sprintf(CS big_buffer, "%s/input/%s/%s/%s",
+      spool_directory, queue_name, message_subdir, spoolname);
     if (Ustat(big_buffer, &statbuf) == 0)
       log_write(0, LOG_MAIN, "Format error in spool file %s: "
         "size=" OFF_T_FMT, spoolname, statbuf.st_size);
@@ -5269,13 +5266,17 @@ if ((rc = spool_read_header(spoolname, TRUE, TRUE)) != spool_read_OK)
 
   if (now - received_time > keep_malformed)
     {
-    sprintf(CS spoolname, "%s/msglog/%s/%s", spool_directory, message_subdir, id);
+    snprintf(CS spoolname, sizeof(spoolname), "%s/msglog/%s/%s/%s",
+      spool_directory, queue_name, message_subdir, id);
     Uunlink(spoolname);
-    sprintf(CS spoolname, "%s/input/%s/%s-D", spool_directory, message_subdir, id);
+    snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-D",
+      spool_directory, queue_name, message_subdir, id);
     Uunlink(spoolname);
-    sprintf(CS spoolname, "%s/input/%s/%s-H", spool_directory, message_subdir, id);
+    snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-H",
+      spool_directory, queue_name, message_subdir, id);
     Uunlink(spoolname);
-    sprintf(CS spoolname, "%s/input/%s/%s-J", spool_directory, message_subdir, id);
+    snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-J",
+      spool_directory, queue_name, message_subdir, id);
     Uunlink(spoolname);
     log_write(0, LOG_MAIN, "Message removed because older than %s",
       readconf_printtime(keep_malformed));
@@ -5295,9 +5296,10 @@ existence, as it will get further successful deliveries added to it in this
 run, and it will be deleted if this function gets to its end successfully.
 Otherwise it might be needed again. */
 
-sprintf(CS spoolname, "%s/input/%s/%s-J", spool_directory, message_subdir, id);
-jread = Ufopen(spoolname, "rb");
-if (jread)
+snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-J",
+  spool_directory, queue_name, message_subdir, id);
+
+if ((jread = Ufopen(spoolname, "rb")))
   {
   while (Ufgets(big_buffer, big_buffer_size, jread))
     {
@@ -5416,10 +5418,10 @@ if (message_logs)
   uschar *error;
   int fd;
 
-  sprintf(CS spoolname, "%s/msglog/%s/%s", spool_directory, message_subdir, id);
-  fd = open_msglog_file(spoolname, SPOOL_MODE, &error);
-
-  if (fd < 0)
+  snprintf(CS spoolname, sizeof(spoolname), "%s/msglog/%s/%s/%s",
+    spool_directory, queue_name, message_subdir, id);
+  
+  if ((fd = open_msglog_file(spoolname, SPOOL_MODE, &error)) < 0)
     {
     log_write(0, LOG_MAIN|LOG_PANIC, "Couldn't %s message log %s: %s", error,
       spoolname, strerror(errno));
@@ -6650,10 +6652,10 @@ therein are added to the non-recipients. */
 
 if (addr_local || addr_remote)
   {
-  sprintf(CS spoolname, "%s/input/%s/%s-J", spool_directory, message_subdir, id);
-  journal_fd = Uopen(spoolname, O_WRONLY|O_APPEND|O_CREAT, SPOOL_MODE);
-
-  if (journal_fd < 0)
+  snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-J",
+    spool_directory, queue_name, message_subdir, id);
+  
+  if ((journal_fd = Uopen(spoolname, O_WRONLY|O_APPEND|O_CREAT, SPOOL_MODE)) <0)
     {
     log_write(0, LOG_MAIN|LOG_PANIC, "Couldn't open journal file %s: %s",
       spoolname, strerror(errno));
@@ -7517,12 +7519,13 @@ if (!addr_defer)
   {
   if (message_logs)
     {
-    sprintf(CS spoolname, "%s/msglog/%s/%s", spool_directory, message_subdir,
-      id);
+    snprintf(CS spoolname, sizeof(spoolname), "%s/msglog/%s/%s/%s",
+      spool_directory, queue_name, message_subdir, id);
     if (preserve_message_logs)
       {
       int rc;
-      sprintf(CS big_buffer, "%s/msglog.OLD/%s", spool_directory, id);
+      sprintf(CS big_buffer, "%s/msglog.OLD/%s/%s",
+       spool_directory, queue_name, id);
       if ((rc = Urename(spoolname, big_buffer)) < 0)
         {
         (void)directory_make(spool_directory, US"msglog.OLD",
@@ -7541,11 +7544,13 @@ if (!addr_defer)
 
   /* Remove the two message files. */
 
-  sprintf(CS spoolname, "%s/input/%s/%s-D", spool_directory, message_subdir, id);
+  snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-D",
+    spool_directory, queue_name, message_subdir, id);
   if (Uunlink(spoolname) < 0)
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s",
       spoolname, strerror(errno));
-  sprintf(CS spoolname, "%s/input/%s/%s-H", spool_directory, message_subdir, id);
+  snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-H",
+    spool_directory, queue_name, message_subdir, id);
   if (Uunlink(spoolname) < 0)
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s",
       spoolname, strerror(errno));
@@ -8015,7 +8020,8 @@ if (journal_fd >= 0) (void)close(journal_fd);
 
 if (remove_journal)
   {
-  sprintf(CS spoolname, "%s/input/%s/%s-J", spool_directory, message_subdir, id);
+  snprintf(CS spoolname, sizeof(spoolname), "%s/input/%s/%s/%s-J",
+    spool_directory, queue_name, message_subdir, id);
   if (Uunlink(spoolname) < 0 && errno != ENOENT)
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s", spoolname,
       strerror(errno));