Adding the --fake-super option.
[rsync/rsync.git] / rsync.c
diff --git a/rsync.c b/rsync.c
index 7e97a93..1eda740 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -98,7 +98,7 @@ int read_ndx_and_attrs(int f_in, int *iflag_ptr, uchar *type_ptr,
        int len, iflags = 0;
        struct file_list *flist;
        uchar fnamecmp_type = FNAMECMP_FNAME;
        int len, iflags = 0;
        struct file_list *flist;
        uchar fnamecmp_type = FNAMECMP_FNAME;
-       int verbose_save, ndx;
+       int ndx;
 
   read_loop:
        while (1) {
 
   read_loop:
        while (1) {
@@ -124,8 +124,6 @@ int read_ndx_and_attrs(int f_in, int *iflag_ptr, uchar *type_ptr,
                                NDX_FLIST_OFFSET - dir_flist->count);
                        exit_cleanup(RERR_PROTOCOL);
                }
                                NDX_FLIST_OFFSET - dir_flist->count);
                        exit_cleanup(RERR_PROTOCOL);
                }
-               verbose_save = verbose;
-               verbose = 0; /* TODO allow verbose messages? */
 
                /* Send everything read from f_in to msg_fd_out. */
                send_msg_int(MSG_FLIST, ndx);
 
                /* Send everything read from f_in to msg_fd_out. */
                send_msg_int(MSG_FLIST, ndx);
@@ -133,8 +131,6 @@ int read_ndx_and_attrs(int f_in, int *iflag_ptr, uchar *type_ptr,
                flist = recv_file_list(f_in);
                flist->parent_ndx = ndx;
                stop_flist_forward();
                flist = recv_file_list(f_in);
                flist->parent_ndx = ndx;
                stop_flist_forward();
-
-               verbose = verbose_save;
        }
 
        iflags = protocol_version >= 29 ? read_shortint(f_in)
        }
 
        iflags = protocol_version >= 29 ? read_shortint(f_in)
@@ -261,6 +257,8 @@ int set_file_attrs(const char *fname, struct file_struct *file, statx *sxp,
 #ifdef SUPPORT_XATTRS
        if (preserve_xattrs && fnamecmp)
                set_xattr(fname, file, fnamecmp, sxp);
 #ifdef SUPPORT_XATTRS
        if (preserve_xattrs && fnamecmp)
                set_xattr(fname, file, fnamecmp, sxp);
+       if (am_root < 0)
+               set_stat_xattr(fname, file);
 #endif
 
        if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
 #endif
 
        if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times))
@@ -300,7 +298,9 @@ int set_file_attrs(const char *fname, struct file_struct *file, statx *sxp,
                                        (long)sxp->st.st_gid, (long)F_GID(file));
                        }
                }
                                        (long)sxp->st.st_gid, (long)F_GID(file));
                        }
                }
-               if (do_lchown(fname,
+               if (am_root < 0) {
+                       ;
+               } else if (do_lchown(fname,
                    change_uid ? F_UID(file) : sxp->st.st_uid,
                    change_gid ? F_GID(file) : sxp->st.st_gid) != 0) {
                        /* shouldn't have attempted to change uid or gid
                    change_uid ? F_UID(file) : sxp->st.st_uid,
                    change_gid ? F_GID(file) : sxp->st.st_gid) != 0) {
                        /* shouldn't have attempted to change uid or gid
@@ -309,7 +309,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, statx *sxp,
                            change_uid ? "chown" : "chgrp",
                            full_fname(fname));
                        goto cleanup;
                            change_uid ? "chown" : "chgrp",
                            full_fname(fname));
                        goto cleanup;
-               }
+               } else
                /* a lchown had been done - we have to re-stat if the
                 * destination had the setuid or setgid bits set due
                 * to the side effect of the chown call */
                /* a lchown had been done - we have to re-stat if the
                 * destination had the setuid or setgid bits set due
                 * to the side effect of the chown call */
@@ -336,7 +336,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, statx *sxp,
 
 #ifdef HAVE_CHMOD
        if (!BITS_EQUAL(sxp->st.st_mode, new_mode, CHMOD_BITS)) {
 
 #ifdef HAVE_CHMOD
        if (!BITS_EQUAL(sxp->st.st_mode, new_mode, CHMOD_BITS)) {
-               int ret = do_chmod(fname, new_mode);
+               int ret = am_root < 0 ? 0 : do_chmod(fname, new_mode);
                if (ret < 0) {
                        rsyserr(FERROR, errno,
                                "failed to set permissions on %s",
                if (ret < 0) {
                        rsyserr(FERROR, errno,
                                "failed to set permissions on %s",