From f0939c31a6f4f7afec3adf3f31817f998af6e667 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 21 Feb 2011 14:31:55 -0800 Subject: [PATCH] * movemail.c (popmail): Report fchown failure instead of ignoring it. But if the file already has the right ownership, don't worry about it. --- lib-src/ChangeLog | 3 +++ lib-src/movemail.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index d865754cb40..e0a175e8167 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,5 +1,8 @@ 2011-02-21 Paul Eggert + * 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. diff --git a/lib-src/movemail.c b/lib-src/movemail.c index a5084f27f22..bc7fa8824e2 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c @@ -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) { -- 2.39.5