Do not close the (main)_log, if we do not see a chance to open it again.
[exim.git] / src / src / transports / appendfile.c
index f4baf0c771406444e70331a218b2ee861213d333..706af6dde2d61c3da683d167c53223e36a500a54 100644 (file)
@@ -217,6 +217,9 @@ Arguments:
 Returns:     OK, FAIL, or DEFER
 */
 
+void
+openlogs();
+
 static int
 appendfile_transport_setup(transport_instance *tblock, address_item *addrlist,
   transport_feedback *dummy, uid_t uid, gid_t gid, uschar **errmsg)
@@ -231,6 +234,9 @@ dummy = dummy;
 uid = uid;
 gid = gid;
 
+/* we can't wait until we're not privileged anymore */
+open_logs("appendfile");
+
 if (ob->expand_maildir_use_size_file)
        ob->maildir_use_size_file = expand_check_condition(ob->expand_maildir_use_size_file,
                US"`maildir_use_size_file` in transport", tblock->name);
@@ -289,9 +295,9 @@ for (int i = 0; i < 5; i++)
        rest += sizeof("/no_check") - 1;
       }
 
-    while (isspace(*rest)) rest++;
+    Uskip_whitespace(&rest);
 
-    if (*rest != 0)
+    if (*rest)
       {
       *errmsg = string_sprintf("Malformed value \"%s\" (expansion of \"%s\") "
         "in %s transport", s, q, tblock->name);
@@ -714,14 +720,13 @@ check_dir_size(const uschar * dirname, int *countptr, const pcre *regex)
 DIR *dir;
 off_t sum = 0;
 int count = *countptr;
-struct dirent *ent;
-struct stat statbuf;
 
-if (!(dir = opendir(CS dirname))) return 0;
+if (!(dir = exim_opendir(dirname))) return 0;
 
-while ((ent = readdir(dir)))
+for (struct dirent *ent; ent = readdir(dir); )
   {
   uschar * path, * name = US ent->d_name;
+  struct stat statbuf;
 
   if (Ustrcmp(name, ".") == 0 || Ustrcmp(name, "..") == 0) continue;
 
@@ -1287,12 +1292,14 @@ if (!(path = expand_string(fdname)))
     expand_string_message);
   goto ret_panic;
   }
-if (is_tainted(path))
+{ uschar *m;
+if ((m = is_tainted2(path, 0, "Tainted '%s' (file or directory "
+          "name for %s transport) not permitted", path, tblock->name)))
   {
-  addr->message = string_sprintf("Tainted '%s' (file or directory "
-    "name for %s transport) not permitted", path, tblock->name);
+  addr->message = m;
   goto ret_panic;
   }
+}
 
 if (path[0] != '/')
   {
@@ -1784,8 +1791,8 @@ if (!isdirectory)
       if (statbuf.st_nlink != 1)
         {
         addr->basic_errno = ERRNO_NOTREGULAR;
-        addr->message = string_sprintf("mailbox %s%s has too many links (%d)",
-          filename, islink ? " (symlink)" : "", statbuf.st_nlink);
+        addr->message = string_sprintf("mailbox %s%s has too many links (%lu)",
+          filename, islink ? " (symlink)" : "", (unsigned long)statbuf.st_nlink);
         goto RETURN;
 
         }