--- old/backup.c
+++ new/backup.c
-@@ -130,7 +130,7 @@ static int make_bak_dir(char *fullpath)
+@@ -128,7 +128,7 @@ static int make_bak_dir(char *fullpath)
if (p >= rel) {
/* Try to transfer the directory settings of the
* actual dir that the files are coming from. */
rsyserr(FERROR, errno,
"make_bak_dir stat %s failed",
full_fname(rel));
-@@ -201,7 +201,7 @@ static int keep_backup(const char *fname
+@@ -199,7 +199,7 @@ static int keep_backup(const char *fname
int ret_code;
/* return if no file to keep */
sx.acc_acl = sx.def_acl = NULL;
--- old/clientserver.c
+++ new/clientserver.c
-@@ -625,6 +625,11 @@ static int rsync_module(int f_in, int f_
- ret = parse_arguments(&argc, (const char ***) &argv, 0);
- quiet = 0; /* Don't let someone try to be tricky. */
+@@ -630,6 +630,11 @@ static int rsync_module(int f_in, int f_
+ if (lp_ignore_errors(module_id))
+ ignore_errors = 1;
+ if (lp_fake_super(i))
+ am_root = -1;
--- old/flist.c
+++ new/flist.c
-@@ -191,7 +191,7 @@ static int readlink_stat(const char *pat
+@@ -194,12 +194,12 @@ static int readlink_stat(const char *pat
+ rprintf(FINFO,"copying unsafe symlink \"%s\" -> \"%s\"\n",
+ path, linkbuf);
+ }
+- return do_stat(path, stp);
++ return x_stat(path, stp, NULL);
+ }
}
return 0;
#else
#endif
}
-@@ -199,17 +199,17 @@ int link_stat(const char *path, STRUCT_S
+@@ -207,17 +207,17 @@ int link_stat(const char *path, STRUCT_S
{
#ifdef SUPPORT_LINKS
if (copy_links)
#endif
}
-@@ -244,26 +244,6 @@ static int is_excluded(char *fname, int
+@@ -252,26 +252,6 @@ static int is_excluded(char *fname, int
return 0;
}
- return mode;
-}
-
- static void send_directory(int f, struct file_list *flist,
- char *fbuf, int len);
+ static void send_directory(int f, struct file_list *flist, int ndx,
+ char *fbuf, int len, int flags);
-@@ -803,7 +783,7 @@ struct file_struct *make_file(const char
+@@ -925,7 +905,7 @@ struct file_struct *make_file(const char
if (save_errno == ENOENT) {
#ifdef SUPPORT_LINKS
/* Avoid "vanished" error if symlink points nowhere. */
&& S_ISLNK(st.st_mode)) {
io_error |= IOERR_GENERAL;
rprintf(FERROR, "symlink has no referent: %s\n",
-@@ -962,7 +942,7 @@ struct file_struct *make_file(const char
+@@ -1097,7 +1077,7 @@ struct file_struct *make_file(const char
int save_mode = file->mode;
file->mode = S_IFDIR; /* Find a directory with our name. */
- if (flist_find(the_file_list, file) >= 0
+ if (flist_find(dir_flist, file) >= 0
- && do_stat(thisname, &st2) == 0 && S_ISDIR(st2.st_mode)) {
+ && x_stat(thisname, &st2, NULL) == 0 && S_ISDIR(st2.st_mode)) {
file->modtime = st2.st_mtime;
- file->length = st2.st_size;
+ file->len32 = 0;
file->mode = st2.st_mode;
--- old/loadparm.c
+++ new/loadparm.c
{"owner", 'o', POPT_ARG_VAL, &preserve_uid, 1, 0, 0 },
{"no-owner", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
{"no-o", 0, POPT_ARG_VAL, &preserve_uid, 0, 0, 0 },
-@@ -1177,6 +1181,14 @@ int parse_arguments(int *argc, const cha
+@@ -1183,6 +1187,14 @@ int parse_arguments(int *argc, const cha
}
#endif
"--write-batch and --read-batch can not be used together\n");
--- old/rsync.c
+++ new/rsync.c
-@@ -249,7 +249,9 @@ int set_file_attrs(char *fname, struct f
+@@ -299,7 +299,9 @@ int set_file_attrs(char *fname, struct f
(long)sxp->st.st_gid, (long)F_GID(file));
}
}
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
-@@ -258,7 +260,7 @@ int set_file_attrs(char *fname, struct f
+@@ -308,7 +310,7 @@ int set_file_attrs(char *fname, struct f
change_uid ? "chown" : "chgrp",
full_fname(fname));
goto cleanup;
/* 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 */
-@@ -275,6 +277,8 @@ int set_file_attrs(char *fname, struct f
+@@ -325,6 +327,8 @@ int set_file_attrs(char *fname, struct f
#ifdef SUPPORT_XATTRS
if (preserve_xattrs && set_xattr(fname, file, sxp) == 0)
updated = 1;
#endif
#ifdef SUPPORT_ACLS
/* It's OK to call set_acl() now, even for a dir, as the generator
-@@ -289,7 +293,7 @@ int set_file_attrs(char *fname, struct f
+@@ -339,7 +343,7 @@ int set_file_attrs(char *fname, struct f
#ifdef HAVE_CHMOD
- if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
+ 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) {
"failed to set permissions on %s",
--- old/rsync.h
+++ new/rsync.h
-@@ -726,6 +726,12 @@ typedef struct {
+@@ -813,6 +813,12 @@ typedef struct {
#include "proto.h"
/* We have replacement versions of these if they're missing. */
#ifndef HAVE_ASPRINTF
int asprintf(char **ptr, const char *format, ...);
-@@ -944,6 +950,26 @@ int inet_pton(int af, const char *src, v
+@@ -1031,6 +1037,26 @@ int inet_pton(int af, const char *src, v
const char *get_panic_action(void);
#endif
-S, --sparse handle sparse files efficiently
-n, --dry-run show what would have been transferred
-W, --whole-file copy files whole (without rsync algorithm)
-@@ -847,7 +848,7 @@ permission value can be applied to the f
+@@ -846,7 +847,7 @@ permission value can be applied to the f
dit(bf(-o, --owner)) This option causes rsync to set the owner of the
destination file to be the same as the source file, but only if the
receiving rsync is being run as the super-user (see also the bf(--super)
Without this option, the owner is set to the invoking user on the
receiving side.
-@@ -870,7 +871,7 @@ default, but may fall back to using the
+@@ -869,7 +870,7 @@ default, but may fall back to using the
dit(bf(--devices)) This option causes rsync to transfer character and
block device files to the remote system to recreate these devices.
This option has no effect if the receiving rsync is not run as the
dit(bf(--specials)) This option causes rsync to transfer special files
such as named sockets and fifos.
-@@ -900,6 +901,33 @@ also for ensuring that you will get erro
+@@ -899,6 +900,33 @@ also for ensuring that you will get erro
being running as the super-user. To turn off super-user activities, the
super-user can use bf(--no-super).
int preserve_perms = 0;
--- old/xattr.c
+++ new/xattr.c
-@@ -30,6 +30,9 @@ extern int am_root;
- extern int read_only;
- extern int list_only;
- extern int preserve_xattrs;
-+extern int preserve_uid;
-+extern int preserve_gid;
-+extern int flist_extra_ndx;
- extern unsigned int file_struct_len;
-
- #define RSYNC_XAL_INITIAL 5
-@@ -44,11 +47,16 @@ extern unsigned int file_struct_len;
+@@ -42,11 +42,16 @@ extern int list_only;
#define SPRE_LEN ((int)sizeof SYSTEM_PREFIX - 1)
#ifdef HAVE_LINUX_XATTRS
typedef struct {
char *datum, *name;
-@@ -149,6 +157,10 @@ static int rsync_xal_get(const char *fna
+@@ -147,6 +152,10 @@ static int rsync_xal_get(const char *fna
continue;
#endif
datum_len = sys_lgetxattr(fname, name, NULL, 0);
if (datum_len < 0) {
if (errno == ENOTSUP)
-@@ -178,6 +190,13 @@ static int rsync_xal_get(const char *fna
+@@ -176,6 +185,13 @@ static int rsync_xal_get(const char *fna
return -1;
}
}
rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
rxas->name = ptr + datum_len;
rxas->datum = ptr;
-@@ -298,13 +317,9 @@ void receive_xattr(struct file_struct *f
+@@ -296,13 +312,9 @@ void receive_xattr(struct file_struct *f
rsync_xa *rxa;
size_t name_len = read_int(f);
size_t datum_len = read_int(f);
if (name_len + datum_len + extra_len < name_len)
out_of_memory("receive_xattr"); /* overflow */
ptr = new_array(char, name_len + datum_len + extra_len);
-@@ -315,9 +330,14 @@ void receive_xattr(struct file_struct *f
+@@ -313,9 +325,14 @@ void receive_xattr(struct file_struct *f
read_buf(f, ptr, datum_len);
#ifdef HAVE_LINUX_XATTRS
/* Non-root can only save the user namespace. */
}
#else
/* This OS only has a user namespace, so we either
-@@ -335,6 +355,12 @@ void receive_xattr(struct file_struct *f
+@@ -333,6 +350,12 @@ void receive_xattr(struct file_struct *f
continue;
}
#endif
rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count);
rxa->name = name;
rxa->datum = ptr;
-@@ -412,4 +438,149 @@ int set_xattr(const char *fname, const s
+@@ -410,4 +433,150 @@ int set_xattr(const char *fname, const s
return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */
}
+ fst.st_mode &= (_S_IFMT | CHMOD_BITS);
+ fmode = file->mode & (_S_IFMT | CHMOD_BITS);
+
-+ if (IS_DEVICE(fmode) || IS_SPECIAL(fmode))
-+ rdev = MAKEDEV(F_DMAJOR(file), F_DMINOR(file));
-+ else
++ if (IS_DEVICE(fmode) || IS_SPECIAL(fmode)) {
++ uint32 *devp = F_RDEV_P(file);
++ rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp));
++ } else
+ rdev = 0;
+
+ /* Dump the special permissions and enable full owner access. */