Avoid a non-writable-by-the-user file when copying xattrs.
authorWayne Davison <wayned@samba.org>
Sat, 21 Aug 2010 20:59:33 +0000 (13:59 -0700)
committerWayne Davison <wayned@samba.org>
Sat, 21 Aug 2010 21:14:31 +0000 (14:14 -0700)
Fixes part of the problem in bug 5147.

receiver.c
rsync.c
util.c

index 6688dda75923c10c6a3a245b0afe4467690b7b65..861895ec72c8984fb00224a941a103b07ba3cad7 100644 (file)
@@ -173,7 +173,7 @@ int open_tmpfile(char *fnametmp, const char *fname, struct file_struct *file)
         * access to ensure that there is no race condition.  They will be
         * correctly updated after the right owner and group info is set.
         * (Thanks to snabb@epipe.fi for pointing this out.) */
-       fd = do_mkstemp(fnametmp, file->mode & INITACCESSPERMS);
+       fd = do_mkstemp(fnametmp, (file->mode & INITACCESSPERMS) | S_IWUSR);
 
 #if 0
        /* In most cases parent directories will already exist because their
diff --git a/rsync.c b/rsync.c
index cefbe5f4124fbe8e3a45b3cd883b783592313eed..c9be42477056a9a001e312abea138a764c2921fd 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -644,15 +644,13 @@ int finish_transfer(const char *fname, const char *fnametmp,
        /* move tmp file over real file */
        if (DEBUG_GTE(RECV, 1))
                rprintf(FINFO, "renaming %s to %s\n", fnametmp, fname);
-       ret = robust_rename(fnametmp, fname, temp_copy_name,
-                           file->mode & INITACCESSPERMS);
+       ret = robust_rename(fnametmp, fname, temp_copy_name, file->mode);
        if (ret < 0) {
                rsyserr(FERROR_XFER, errno, "%s %s -> \"%s\"",
                        ret == -2 ? "copy" : "rename",
                        full_fname(fnametmp), fname);
                if (!partialptr || (ret == -2 && temp_copy_name)
-                || robust_rename(fnametmp, partialptr, NULL,
-                                 file->mode & INITACCESSPERMS) < 0)
+                || robust_rename(fnametmp, partialptr, NULL, file->mode) < 0)
                        do_unlink(fnametmp);
                return 0;
        }
diff --git a/util.c b/util.c
index 02085d426a69c2f1d7f6473bbc4252265efd8fe1..9d5f1800762a2ee1088d2dc8a34a1e100d9a42b8 100644 (file)
--- a/util.c
+++ b/util.c
@@ -329,6 +329,11 @@ int copy_file(const char *source, const char *dest, int ofd, mode_t mode)
                        return -1;
                }
 
+#ifdef SUPPORT_XATTRS
+               if (preserve_xattrs)
+                       mode |= S_IWUSR;
+#endif
+               mode &= INITACCESSPERMS;
                if ((ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode)) < 0) {
                        int save_errno = errno;
                        rsyserr(FERROR_XFER, save_errno, "open %s", full_fname(dest));