* movemail.c (popmail): Report fchown failure instead of ignoring it.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 21 Feb 2011 22:31:55 +0000 (14:31 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 21 Feb 2011 22:31:55 +0000 (14:31 -0800)
But if the file already has the right ownership, don't worry about it.

lib-src/ChangeLog
lib-src/movemail.c

index d865754..e0a175e 100644 (file)
@@ -1,5 +1,8 @@
 2011-02-21  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * movemail.c (popmail): Report fchown failure instead of ignoring it.
+       But if the file already has the right ownership, don't worry about it.
+
        * make-docfile.c (input_buffer): Rename variables to avoid shadowing.
 
        * movemail.c (main, pop_retr): Rename locals to avoid shadowing.
index a5084f2..bc7fa88 100644 (file)
@@ -723,7 +723,18 @@ popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse
       error ("Error in open: %s, %s", strerror (errno), outfile);
       return EXIT_FAILURE;
     }
-  fchown (mbfi, getuid (), -1);
+
+  if (fchown (mbfi, getuid (), -1) != 0)
+    {
+      int fchown_errno = errno;
+      struct stat st;
+      if (fstat (mbfi, &st) != 0 || st.st_uid != getuid ())
+       {
+         pop_close (server);
+         error ("Error in fchown: %s, %s", strerror (fchown_errno), outfile);
+         return EXIT_FAILURE;
+       }
+    }
 
   if ((mbf = fdopen (mbfi, "wb")) == NULL)
     {