1 Depends-On-Patch: acls.diff
3 After applying this patch, run these commands for a successful build:
6 ./configure --enable-acl-support --enable-xattr-support
11 - This patch needs to be rewritten to more efficiently handle large xattrs.
13 - Extraneous xattr values need to be removed from files that are not being
16 - We need to affect the itemized output to know when xattrs are being updated.
18 - We need to affect the --link-dest option to avoid hard-linking two files
19 that differ in their xattrs (when --xattrs was specified).
23 @@ -28,13 +28,13 @@ VERSION=@VERSION@
25 HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
26 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
27 - lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
28 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o lib/sysxattr.o @LIBOBJS@
29 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
30 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
31 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
32 main.o checksum.o match.o syscall.o log.o backup.o
33 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
34 - fileio.o batch.o clientname.o chmod.o acls.o
35 + fileio.o batch.o clientname.o chmod.o acls.o xattr.o
36 OBJS3=progress.o pipe.o
37 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
38 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
41 @@ -31,6 +31,7 @@ extern int read_only;
43 extern int orig_umask;
44 extern int preserve_acls;
45 +extern int preserve_xattrs;
46 extern unsigned int file_struct_len;
48 /* === ACL structures === */
49 @@ -742,6 +743,10 @@ void receive_acl(struct file_struct *fil
50 type = SMB_ACL_TYPE_ACCESS;
51 racl_list = &access_acl_list;
52 ndx_ptr = (char*)file + file_struct_len;
53 +#ifdef SUPPORT_XATTRS
54 + if (preserve_xattrs)
58 char tag = read_byte(f);
60 @@ -801,6 +806,10 @@ void cache_acl(struct file_struct *file,
62 racl_list = &access_acl_list;
63 ndx_ptr = (char*)file + file_struct_len;
64 +#ifdef SUPPORT_XATTRS
65 + if (preserve_xattrs)
71 @@ -921,6 +930,10 @@ int set_acl(const char *fname, const str
73 type = SMB_ACL_TYPE_ACCESS;
74 ndx_ptr = (char*)file + file_struct_len;
75 +#ifdef SUPPORT_XATTRS
76 + if (preserve_xattrs)
84 @@ -30,6 +30,7 @@ extern char *backup_dir;
87 extern int preserve_acls;
88 +extern int preserve_xattrs;
89 extern int preserve_devices;
90 extern int preserve_specials;
91 extern int preserve_links;
92 @@ -136,6 +137,9 @@ static int make_bak_dir(char *fullpath)
94 sx.acc_acl = sx.def_acl = NULL;
96 +#ifdef SUPPORT_XATTRS
99 if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
102 @@ -144,6 +148,12 @@ static int make_bak_dir(char *fullpath)
103 cache_acl(file, &sx);
106 +#ifdef SUPPORT_XATTRS
107 + if (preserve_xattrs) {
108 + get_xattr(rel, &sx);
109 + cache_xattr(file, &sx);
112 set_file_attrs(fullpath, file, NULL, 0);
115 @@ -195,6 +205,9 @@ static int keep_backup(char *fname)
117 sx.acc_acl = sx.def_acl = NULL;
119 +#ifdef SUPPORT_XATTRS
123 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
124 return 1; /* the file could have disappeared */
125 @@ -208,6 +221,12 @@ static int keep_backup(char *fname)
126 cache_acl(file, &sx);
129 +#ifdef SUPPORT_XATTRS
130 + if (preserve_xattrs) {
131 + get_xattr(fname, &sx);
132 + cache_xattr(file, &sx);
136 /* Check to see if this is a device file, or link */
137 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
140 @@ -856,6 +856,35 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
144 +AC_CHECK_HEADERS(attr/xattr.h)
145 +AC_CHECK_HEADERS(sys/xattr.h)
146 +AC_MSG_CHECKING(whether to support extended attributes)
147 +AC_ARG_ENABLE(xattr-support,
148 +AC_HELP_STRING([--enable-xattr-support], [Include extended attribute support (default=no)]),
149 +[ case "$enableval" in
153 + AC_MSG_RESULT(Using Linux xattrs)
154 + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs])
157 + AC_MSG_RESULT(Using OS X xattrs)
158 + AC_DEFINE(HAVE_OSX_XATTRS, 1, [True if you have Mac OS X xattrs])
161 + AC_MSG_RESULT(Xattrs requested but not Linux or OS X. Good luck...)
167 + AC_DEFINE(HAVE_NA_XATTRS, 1, [True if you don't have extended attributes])
170 + AC_DEFINE(HAVE_NO_XATTRL, 1, [True if you don't have extended attributes])
173 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
178 @@ -41,6 +41,7 @@ extern int one_file_system;
179 extern int copy_dirlinks;
180 extern int keep_dirlinks;
181 extern int preserve_acls;
182 +extern int preserve_xattrs;
183 extern int preserve_links;
184 extern int preserve_hard_links;
185 extern int preserve_devices;
186 @@ -498,7 +499,7 @@ static struct file_struct *receive_file_
187 char thisname[MAXPATHLEN];
188 unsigned int l1 = 0, l2 = 0;
189 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
191 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
195 @@ -610,10 +611,16 @@ static struct file_struct *receive_file_
196 xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
199 +#elif defined SUPPORT_XATTRS
202 +#ifdef SUPPORT_XATTRS
203 + if (preserve_xattrs)
207 alloc_len = file_struct_len + dirname_len + basename_len
209 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
212 + linkname_len + sum_len;
213 @@ -622,7 +629,7 @@ static struct file_struct *receive_file_
214 file = (struct file_struct *)bp;
215 memset(bp, 0, file_struct_len);
216 bp += file_struct_len;
218 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
222 @@ -723,6 +730,10 @@ static struct file_struct *receive_file_
224 receive_acl(file, f);
226 +#ifdef SUPPORT_XATTRS
227 + if (preserve_xattrs)
228 + receive_xattr(file, f );
233 @@ -974,7 +985,7 @@ static struct file_struct *send_file_nam
234 unsigned short flags)
236 struct file_struct *file;
238 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
242 @@ -994,6 +1005,13 @@ static struct file_struct *send_file_nam
246 +#ifdef SUPPORT_XATTRS
247 + if (preserve_xattrs) {
249 + if (get_xattr(fname, &sx) < 0)
254 maybe_emit_filelist_progress(flist->count + flist_count_offset);
256 @@ -1006,11 +1024,19 @@ static struct file_struct *send_file_nam
260 +#ifdef SUPPORT_XATTRS
261 + if (preserve_xattrs)
262 + send_xattr(&sx, f);
269 +#ifdef SUPPORT_XATTRS
270 + if (preserve_xattrs)
276 --- old/lib/sysxattr.c
277 +++ new/lib/sysxattr.c
280 + * Extended attribute support for rsync.
282 + * Copyright (C) 2004 Red Hat, Inc.
283 + * Written by Jay Fenlason.
285 + * This program is free software; you can redistribute it and/or modify
286 + * it under the terms of the GNU General Public License as published by
287 + * the Free Software Foundation; either version 2 of the License, or
288 + * (at your option) any later version.
290 + * This program is distributed in the hope that it will be useful,
291 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
292 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
293 + * GNU General Public License for more details.
295 + * You should have received a copy of the GNU General Public License along
296 + * with this program; if not, write to the Free Software Foundation, Inc.,
297 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
301 +#include "sysxattr.h"
303 +#if defined HAVE_LINUX_XATTRS
305 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
307 + return lgetxattr(path, name, value, size);
310 +ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
312 + return fgetxattr(filedes, name, value, size);
315 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
317 + return lsetxattr(path, name, value, size, flags);
320 +int sys_lremovexattr(const char *path, const char *name)
322 + return lremovexattr(path, name);
325 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
327 + return llistxattr(path, list, size);
330 +#elif HAVE_OSX_XATTRS
332 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
334 + return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
337 +ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
339 + return fgetxattr(filedes, name, value, size, 0, 0);
342 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
344 + return setxattr(path, name, value, size, 0, XATTR_NOFOLLOW | flags);
347 +int sys_lremovexattr(const char *path, const char *name)
349 + return removexattr(path, name, XATTR_NOFOLLOW);
352 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
354 + return listxattr(path, list, size, XATTR_NOFOLLOW);
359 +#endif /* No xattrs */
360 --- old/lib/sysxattr.h
361 +++ new/lib/sysxattr.h
363 +#ifdef SUPPORT_XATTRS
365 +#if defined HAVE_ATTR_XATTR_H
366 +#include <attr/xattr.h>
367 +#elif defined HAVE_SYS_XATTR_H
368 +#include <sys/xattr.h>
371 +/* Linux 2.4 does not define this as a distinct errno value: */
373 +#define ENOATTR ENODATA
376 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
377 +ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size);
378 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
379 +int sys_lremovexattr(const char *path, const char *name);
380 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
384 +/* No xattrs available */
389 @@ -48,6 +48,7 @@ int copy_links = 0;
390 int preserve_links = 0;
391 int preserve_hard_links = 0;
392 int preserve_acls = 0;
393 +int preserve_xattrs = 0;
394 int preserve_perms = 0;
395 int preserve_executability = 0;
396 int preserve_devices = 0;
397 @@ -201,6 +202,7 @@ static void print_rsync_version(enum log
398 char const *have_inplace = "no ";
399 char const *hardlinks = "no ";
400 char const *acls = "no ";
401 + char const *xattrs = "no ";
402 char const *links = "no ";
403 char const *ipv6 = "no ";
404 STRUCT_STAT *dumstat;
405 @@ -220,7 +222,9 @@ static void print_rsync_version(enum log
410 +#ifdef SUPPORT_XATTRS
416 @@ -234,9 +238,9 @@ static void print_rsync_version(enum log
417 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
418 rprintf(f, "<http://rsync.samba.org/>\n");
419 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
420 - "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
421 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
422 (int) (sizeof (OFF_T) * 8),
423 - got_socketpair, hardlinks, acls, links);
424 + got_socketpair, hardlinks, acls, xattrs, links);
426 /* Note that this field may not have type ino_t. It depends
427 * on the complicated interaction between largefile feature
428 @@ -290,7 +294,7 @@ void usage(enum logcode F)
429 rprintf(F," -q, --quiet suppress non-error messages\n");
430 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
431 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
432 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
433 + rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
434 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
435 rprintf(F," -r, --recursive recurse into directories\n");
436 rprintf(F," -R, --relative use relative path names\n");
437 @@ -315,6 +319,9 @@ void usage(enum logcode F)
439 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
441 +#ifdef SUPPORT_XATTRS
442 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
444 rprintf(F," -o, --owner preserve owner (super-user only)\n");
445 rprintf(F," -g, --group preserve group\n");
446 rprintf(F," --devices preserve device files (super-user only)\n");
447 @@ -437,6 +444,9 @@ static struct poptOption long_options[]
448 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
449 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
450 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
451 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
452 + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
453 + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
454 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
455 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
456 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
457 @@ -1118,6 +1128,17 @@ int parse_arguments(int *argc, const cha
462 +#ifdef SUPPORT_XATTRS
463 + preserve_xattrs = 1;
464 + preserve_perms = 1;
467 + snprintf(err_buf,sizeof(err_buf),
468 + "extended attributes are not supported on this %s\n",
469 + am_server ? "server" : "client");
471 +#endif /* SUPPORT_XATTRS */
474 /* A large opt value means that set_refuse_options()
475 @@ -1564,6 +1585,10 @@ void server_options(char **args,int *arg
479 +#ifdef SUPPORT_XATTRS
480 + if (preserve_xattrs)
491 extern int preserve_acls;
492 +extern int preserve_xattrs;
493 extern int preserve_perms;
494 extern int preserve_executability;
495 extern int preserve_times;
496 @@ -219,6 +220,10 @@ int set_file_attrs(char *fname, struct f
497 if (daemon_chmod_modes && !S_ISLNK(new_mode))
498 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
500 +#ifdef SUPPORT_XATTRS
501 + if (preserve_xattrs && set_xattr(fname, file, sxp) == 0)
505 /* It's OK to call set_acl() now, even for a dir, as the generator
506 * will enable owner-writability using chmod, if necessary.
509 @@ -501,6 +501,10 @@ struct idev {
510 #define ACLS_NEED_MASK 1
513 +#if defined HAVE_LINUX_XATTRS || defined HAVE_OSX_XATTRS
514 +#define SUPPORT_XATTRS 1
517 #define GID_NONE ((gid_t)-1)
519 #define HL_CHECK_MASTER 0
520 @@ -695,6 +699,9 @@ typedef struct {
521 struct rsync_acl *acc_acl; /* access ACL */
522 struct rsync_acl *def_acl; /* default ACL */
524 +#ifdef SUPPORT_XATTRS
529 #define ACL_READY(sx) ((sx).acc_acl != NULL)
532 @@ -301,7 +301,7 @@ to the detailed description below for a
533 -q, --quiet suppress non-error messages
534 --no-motd suppress daemon-mode MOTD (see caveat)
535 -c, --checksum skip based on checksum, not mod-time & size
536 - -a, --archive archive mode; same as -rlptgoD (no -H, -A)
537 + -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
538 --no-OPTION turn off an implied OPTION (e.g. --no-D)
539 -r, --recursive recurse into directories
540 -R, --relative use relative path names
541 @@ -324,6 +324,7 @@ to the detailed description below for a
542 -E, --executability preserve executability
543 --chmod=CHMOD affect file and/or directory permissions
544 -A, --acls preserve ACLs (implies -p) [non-standard]
545 + -X, --xattrs preserve extended attrs (implies -p) [n.s.]
546 -o, --owner preserve owner (super-user only)
547 -g, --group preserve group
548 --devices preserve device files (super-user only)
549 @@ -818,6 +819,11 @@ version makes it incompatible with sendi
550 rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
551 doubling is not needed when pulling files from an older rsync.
553 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
554 +extended attributes to be the same as the local ones. This will work
555 +only if the remote machine's rsync supports this option also. This is
556 +a non-standard option.
558 dit(bf(--chmod)) This option tells rsync to apply one or more
559 comma-separated "chmod" strings to the permission of the files in the
560 transfer. The resulting value is treated as though it was the permissions
565 + * Extended Attribute support for rsync.
566 + * Written by Jay Fenlason, vaguely based on the ACLs patch.
568 + * Copyright (C) 2004 Red Hat, Inc.
569 + * Copyright (C) 2006 Wayne Davison
571 + * This program is free software; you can redistribute it and/or modify
572 + * it under the terms of the GNU General Public License as published by
573 + * the Free Software Foundation; either version 2 of the License, or
574 + * (at your option) any later version.
576 + * This program is distributed in the hope that it will be useful,
577 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
578 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
579 + * GNU General Public License for more details.
581 + * You should have received a copy of the GNU General Public License along
582 + * with this program; if not, write to the Free Software Foundation, Inc.,
583 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
587 +#include "lib/sysxattr.h"
589 +#ifdef SUPPORT_XATTRS
592 +extern int read_only;
593 +extern int list_only;
594 +extern unsigned int file_struct_len;
596 +#define RSYNC_XAL_INITIAL 5
597 +#define RSYNC_XAL_LIST_INITIAL 100
606 +static size_t namebuf_len = 0;
607 +static char *namebuf = NULL;
609 +static item_list empty_xattr = EMPTY_ITEM_LIST;
610 +static item_list rsync_xal_l = EMPTY_ITEM_LIST;
612 +#ifdef HAVE_OSX_XATTRS
613 +#define UNIQUE_PREFIX "user.0S%." /* OSX */
614 +#define UPRE_LEN (sizeof UNIQUE_PREFIX - 1)
617 +/* ------------------------------------------------------------------------- */
619 +static void rsync_xal_free(item_list *xalp)
622 + rsync_xa *rxas = xalp->items;
624 + for (i = 0; i < xalp->count; i++) {
625 + free(rxas[i].name);
626 + /* free(rxas[i].value); */
631 +void free_xattr(statx *sxp)
633 + rsync_xal_free(sxp->xattr);
638 +static int rsync_xal_compare_names(const void *x1, const void *x2)
640 + const rsync_xa *xa1 = x1;
641 + const rsync_xa *xa2 = x2;
642 + return strcmp(xa1->name, xa2->name);
645 +static int rsync_xal_get(const char *fname, item_list *xalp)
648 + ssize_t datum_size;
655 + namebuf_len = 1024;
656 + namebuf = new_array(char, namebuf_len);
658 + out_of_memory("rsync_xal_get");
661 + /* The length returned includes all the '\0' terminators. */
662 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
663 + if (name_size > (ssize_t)namebuf_len) {
667 + if (name_size < 0) {
668 + if (errno == ENOTSUP)
670 + if (errno == ERANGE) {
671 + name_size = sys_llistxattr(fname, NULL, 0);
672 + if (name_size < 0) {
673 + rsyserr(FERROR, errno, "%s: rsync_xal_get: llistxattr",
677 + namebuf = realloc_array(namebuf, char, name_size + 1024);
679 + out_of_memory("rsync_xal_get");
680 + namebuf_len = name_size + 1024;
681 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
682 + if (name_size < 0) {
683 + rsyserr(FERROR, errno,
684 + "%s: rsync_xal_get: re-llistxattr failed",
689 + rsyserr(FERROR, errno,
690 + "%s: rsync_xal_get: llistxattr failed:",
695 + if (name_size == 0)
697 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
698 + rsync_xa *rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
700 + len = strlen(name) + 1;
701 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
702 + if (datum_size < 0) {
703 + if (errno == ENOTSUP)
705 + rsyserr(FERROR, errno,
706 + "%s: rsync_xal_get: lgetxattr %s failed",
710 + ptr = new_array(char, len + datum_size);
712 + out_of_memory("rsync_xal_get");
713 + memcpy(ptr, name, len);
714 + rxas->name_len = len;
716 + rxas->datum_len = datum_size;
717 + rxas->datum = ptr + len;
719 + ssize_t size = sys_lgetxattr(fname, name, rxas->datum, datum_size);
720 + if (size != datum_size) {
722 + rsyserr(FERROR, errno,
723 + "rsync_xal_get: lgetxattr(%s,%s)"
724 + " failed", fname, name);
727 + "rsync_xal_get: lgetxattr(%s,%s)"
728 + " returned %ld instead of %ld\n",
730 + (long)size, (long)datum_size);
736 + if (xalp->count > 1)
737 + qsort(xalp->items, xalp->count, sizeof (rsync_xa), rsync_xal_compare_names);
741 +/* Read the xattr(s) for this filename. */
742 +int get_xattr(const char *fname, statx *sxp)
744 + sxp->xattr = new(item_list);
745 + *sxp->xattr = empty_xattr;
746 + if (rsync_xal_get(fname, sxp->xattr) < 0) {
753 +static int find_matching_xattr(item_list *xalp)
756 + item_list *lst = rsync_xal_l.items;
758 + for (i = 0; i < rsync_xal_l.count; i++) {
759 + rsync_xa *rxas1 = lst[i].items;
760 + rsync_xa *rxas2 = xalp->items;
762 + /* Wrong number of elements? */
763 + if (lst[i].count != xalp->count)
765 + /* any elements different? */
766 + for (j = 0; j < xalp->count; j++) {
767 + if (rxas1[j].name_len != rxas2[j].name_len
768 + || rxas1[j].datum_len != rxas2[j].datum_len
769 + || strcmp(rxas1[j].name, rxas2[j].name)
770 + || memcmp(rxas1[j].datum, rxas2[j].datum, rxas2[j].datum_len))
773 + /* no differences found. This is The One! */
774 + if (j == xalp->count)
781 +/* Store *xalp on the end of rsync_xal_l */
782 +static void rsync_xal_store(item_list *xalp)
784 + item_list *new_lst = EXPAND_ITEM_LIST(&rsync_xal_l, item_list, RSYNC_XAL_LIST_INITIAL);
785 + /* Since the following call starts a new list, we know it will hold the
786 + * entire initial-count, not just enough space for one new item. */
787 + *new_lst = empty_xattr;
788 + (void)EXPAND_ITEM_LIST(new_lst, rsync_xa, xalp->count);
789 + memcpy(new_lst->items, xalp->items, xalp->count * sizeof (rsync_xa));
790 + new_lst->count = xalp->count;
794 +/* Send the make_xattr()-generated xattr list for this flist entry. */
795 +void send_xattr(statx *sxp, int f)
797 + int ndx = find_matching_xattr(sxp->xattr);
799 + write_byte(f, 'x');
801 + rsync_xal_free(sxp->xattr);
804 + int count = sxp->xattr->count;
805 + write_byte(f, 'X');
806 + write_int(f, count);
807 + for (rxa = sxp->xattr->items; count--; rxa++) {
808 +#ifdef HAVE_OSX_XATTRS
809 + if (strncmp(rxa->name, "user.", 5) != 0
810 + && strncmp(rxa->name, "system.", 7) != 0) {
811 + write_int(f, rxa->name_len + UPRE_LEN);
812 + write_int(f, rxa->datum_len);
813 + write_buf(f, UNIQUE_PREFIX, UPRE_LEN);
817 + write_int(f, rxa->name_len);
818 + write_int(f, rxa->datum_len);
820 + write_buf(f, rxa->name, rxa->name_len);
821 + write_buf(f, rxa->datum, rxa->datum_len);
823 + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */
828 +/* ------------------------------------------------------------------------- */
830 +/* receive and build the rsync_xattr_lists */
831 +void receive_xattr(struct file_struct *file, int f)
833 + static item_list temp_xattr = EMPTY_ITEM_LIST;
834 + int tag = read_byte(f);
835 + char *ndx_ptr = (char*)file + file_struct_len;
839 + int i, count = read_int(f);
840 + for (i = 0; i < count; i++) {
843 + size_t name_len = read_int(f);
844 + size_t datum_len = read_int(f);
845 + if (name_len + datum_len < name_len)
846 + out_of_memory("receive_xattr"); /* overflow */
847 + rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count);
848 + ptr = new_array(char, name_len + datum_len);
850 + out_of_memory("receive_xattr");
851 + read_buf(f, ptr, name_len);
852 + read_buf(f, ptr + name_len, datum_len);
853 + rxa->name_len = name_len;
854 + rxa->datum_len = datum_len;
856 + rxa->datum = ptr + name_len;
857 +#ifdef HAVE_OSX_XATTRS
858 + if (strncmp(rxa->name, UNIQUE_PREFIX, UPRE_LEN) == 0) {
859 + rxa->name_len -= UPRE_LEN;
860 + memmove(rxa->name, rxa->name + UPRE_LEN, rxa->name_len);
864 + ndx = rsync_xal_l.count; /* pre-incremented count */
865 + rsync_xal_store(&temp_xattr); /* adds item to rsync_xal_l */
866 + } else if (tag == 'x') {
868 + if (ndx < 0 || (size_t)ndx >= rsync_xal_l.count) {
869 + rprintf(FERROR, "%s: receive_xattr: xa index %d out of range\n",
870 + f_name(file, NULL), ndx);
871 + exit_cleanup(RERR_STREAMIO);
875 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
876 + f_name(file, NULL), tag);
877 + exit_cleanup(RERR_STREAMIO);
878 + ndx = 0; /* silence a compiler warning... */
881 + SIVAL(ndx_ptr, 0, ndx);
884 +/* Turn the xattr data in statx into cached xattr data, setting the index
885 + * values in the file struct. */
886 +void cache_xattr(struct file_struct *file, statx *sxp)
888 + char *ndx_ptr = (char*)file + file_struct_len;
894 + ndx = find_matching_xattr(sxp->xattr);
896 + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */
899 + SIVAL(ndx_ptr, 0, ndx);
902 +static int rsync_xal_set(const char *fname, item_list *xalp)
904 + rsync_xa *rxas = xalp->items;
908 + for (i = 0; i < xalp->count; i++) {
909 + int status = sys_lsetxattr(fname, rxas[i].name, rxas[i].datum, rxas[i].datum_len, 0);
911 + rsyserr(FERROR, errno, "%s: rsync_xal_set: lsetxattr %s failed",
912 + fname, rxas[i].name);
919 +/* Set extended attributes on indicated filename. */
920 +int set_xattr(const char *fname, const struct file_struct *file, UNUSED(statx *sxp))
923 + char *ndx_ptr = (char*)file + file_struct_len;
924 + item_list *lst = rsync_xal_l.items;
927 + return 1; /* FIXME: --dry-run needs to compute this value */
929 + if (read_only || list_only) {
934 + ndx = IVAL(ndx_ptr, 0);
935 + return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */
938 +#endif /* SUPPORT_XATTRS */