}
#endif
+#ifdef SUPPORT_XATTRS
-+ if (preserve_xattrs) {
++ if (preserve_xattrs && f >= 0) {
+ sx.xattr = NULL;
+ if (get_xattr(fname, &sx) < 0)
+ return NULL;
maybe_emit_filelist_progress(flist->count + flist_count_offset);
@@ -1006,11 +1024,19 @@ static struct file_struct *send_file_nam
- if (preserve_acls)
+ if (preserve_acls && f >= 0)
send_acl(&sx, f);
#endif
+#ifdef SUPPORT_XATTRS
-+ if (preserve_xattrs)
++ if (preserve_xattrs && f >= 0)
+ send_xattr(&sx, f);
+#endif
} else {
#ifdef SUPPORT_ACLS
- if (preserve_acls)
+ if (preserve_acls && f >= 0)
free_acl(&sx);
#endif
+#ifdef SUPPORT_XATTRS
-+ if (preserve_xattrs)
++ if (preserve_xattrs && f >= 0)
+ free_xattr(&sx);
+#endif
}
}
--- old/lib/sysxattr.c
+++ new/lib/sysxattr.c
-@@ -0,0 +1,136 @@
+@@ -0,0 +1,135 @@
+/*
+ * Extended attribute support for rsync.
+ *
+ * terminator. We need to change this into a series of null-terminted
+ * strings. Since the size is the same, we can simply transform the
+ * output in place. */
-+ for (off = 0; off < len; ) {
++ for (off = 0; off < len; off += keylen + 1) {
+ keylen = ((unsigned char*)list)[off];
+ if (off + keylen >= len) {
+ /* Should be impossible, but kernel bugs happen! */
+ return -1;
+ }
+ memmove(list+off, list+off+1, keylen);
-+ off += keylen;
-+ list[off++] = '\0';
++ list[off+keylen] = '\0';
+ }
+
+ return len;
* will enable owner-writability using chmod, if necessary.
--- old/rsync.h
+++ new/rsync.h
-@@ -500,6 +500,10 @@ struct idev {
+@@ -501,6 +501,10 @@ struct idev {
#define ACLS_NEED_MASK 1
#endif
#define GID_NONE ((gid_t)-1)
#define HL_CHECK_MASTER 0
-@@ -694,6 +698,9 @@ typedef struct {
+@@ -692,6 +696,9 @@ typedef struct {
struct rsync_acl *acc_acl; /* access ACL */
struct rsync_acl *def_acl; /* default ACL */
#endif
transfer. The resulting value is treated as though it was the permissions
--- old/xattr.c
+++ new/xattr.c
-@@ -0,0 +1,413 @@
+@@ -0,0 +1,417 @@
+/*
+ * Extended Attribute support for rsync.
+ * Written by Jay Fenlason, vaguely based on the ACLs patch.
+ if (errno == ERANGE) {
+ list_len = sys_llistxattr(fname, NULL, 0);
+ if (list_len < 0) {
-+ rsyserr(FERROR, errno, "%s: rsync_xal_get: llistxattr",
++ rsyserr(FERROR, errno,
++ "rsync_xal_get: llistxattr(\"%s\",0) failed",
+ fname);
+ return -1;
+ }
+ list_len = sys_llistxattr(fname, namebuf, namebuf_len);
+ if (list_len < 0) {
+ rsyserr(FERROR, errno,
-+ "%s: rsync_xal_get: re-llistxattr failed",
-+ fname);
++ "rsync_xal_get: llistxattr(\"%s\",%ld) failed",
++ fname, (long)namebuf_len);
+ return -1;
+ }
+ } else {
+ rsyserr(FERROR, errno,
-+ "%s: rsync_xal_get: llistxattr failed:",
-+ fname);
++ "rsync_xal_get: llistxattr(\"%s\",%ld) failed",
++ fname, (long)namebuf_len);
+ return -1;
+ }
+ }
+
-+ for (name = namebuf; list_len > 0; list_len -= name_len, name += name_len) {
++ for (name = namebuf; list_len > 0; name += name_len) {
+ rsync_xa *rxas;
+
+ name_len = strlen(name) + 1;
++ list_len -= name_len;
+
+#ifdef HAVE_LINUX_XATTRS
+ /* We don't send the system namespace. */
+ if (errno == ENOTSUP)
+ return -1;
+ rsyserr(FERROR, errno,
-+ "%s: rsync_xal_get: lgetxattr %s failed",
++ "rsync_xal_get: lgetxattr(\"%s\",\"%s\",0) failed",
+ fname, name);
+ return -1;
+ }
+ if (len != datum_len) {
+ if (len < 0) {
+ rsyserr(FERROR, errno,
-+ "rsync_xal_get: lgetxattr(%s,%s)"
-+ " failed", fname, name);
++ "rsync_xal_get: lgetxattr(\"%s\",\"%s\",%ld)"
++ " failed", fname, name, (long)datum_len);
+ } else {
+ rprintf(FERROR,
-+ "rsync_xal_get: lgetxattr(%s,%s)"
-+ " returned %ld instead of %ld\n",
-+ fname, name,
-+ (long)len, (long)datum_len);
++ "rsync_xal_get: lgetxattr(\"%s\",\"%s\",%ld)"
++ " returned %ld\n", fname, name,
++ (long)datum_len, (long)len);
+ }
+ free(ptr);
+ return -1;
+#else
+ /* We strip the rsync prefix from disguised namespaces
+ * and put everything else in the user namespace. */
-+ if (HAS_PREFIX(rxa->name, RSYNC_PREFIX)) {
++ if (HAS_PREFIX(rxa->name, RSYNC_PREFIX)
++ && rxa->name[RPRE_LEN] != '%') {
+ write_int(f, rxa->name_len - RPRE_LEN);
+ write_int(f, rxa->datum_len);
+ write_buf(f, rxa->name + RPRE_LEN, rxa->name_len - RPRE_LEN);
+ rsync_xa *rxa;
+ size_t name_len = read_int(f);
+ size_t datum_len = read_int(f);
-+ size_t extra_len = am_root < 0 ? RPRE_LEN : 0;
-+#ifndef HAVE_LINUX_XATTRS
++#ifdef HAVE_LINUX_XATTRS
++ size_t extra_len = 0;
++#else
++ size_t extra_len = am_root ? RPRE_LEN : 0;
+ if (datum_len + extra_len < datum_len)
+ out_of_memory("receive_xattr"); /* overflow */
+#endif
+ } else if (tag == 'x') {
+ ndx = read_int(f);
+ if (ndx < 0 || (size_t)ndx >= rsync_xal_l.count) {
-+ rprintf(FERROR, "%s: receive_xattr: xa index %d out of range\n",
-+ f_name(file, NULL), ndx);
++ rprintf(FERROR, "receive_xattr: xa index %d out of"
++ " range for %s\n", ndx, f_name(file, NULL));
+ exit_cleanup(RERR_STREAMIO);
+ }
+ } else {
-+ rprintf(FERROR,
-+ "%s: receive_xattr: unknown extended attribute type tag: %c\n",
-+ f_name(file, NULL), tag);
++ rprintf(FERROR, "receive_xattr: unknown extended attribute"
++ " type tag (%c) for %s\n", tag, f_name(file, NULL));
+ exit_cleanup(RERR_STREAMIO);
+ }
+
+ for (i = 0; i < xalp->count; i++) {
+ int status = sys_lsetxattr(fname, rxas[i].name, rxas[i].datum, rxas[i].datum_len);
+ if (status < 0) {
-+ rsyserr(FERROR, errno, "%s: rsync_xal_set: lsetxattr %s failed",
++ rsyserr(FERROR, errno,
++ "rsync_xal_set: lsetxattr(\"%s\",\"%s\") failed",
+ fname, rxas[i].name);
+ ret = -1;
+ }