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 6688dda..861895e 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.) */
         * 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
 
 #if 0
        /* In most cases parent directories will already exist because their
diff --git a/rsync.c b/rsync.c
index cefbe5f..c9be424 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);
        /* 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)
        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;
        }
                        do_unlink(fnametmp);
                return 0;
        }
diff --git a/util.c b/util.c
index 02085d4..9d5f180 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;
                }
 
                        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));
                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));