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 - We need to affect the itemized output to know when xattrs are being updated.
15 - We need to affect the --link-dest option to avoid hard-linking two files
16 that differ in their xattrs (when --xattrs was specified).
20 @@ -28,13 +28,13 @@ VERSION=@VERSION@
22 HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
23 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
24 - lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
25 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o lib/sysxattr.o @LIBOBJS@
26 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
27 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
28 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
29 main.o checksum.o match.o syscall.o log.o backup.o
30 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
31 - fileio.o batch.o clientname.o chmod.o acls.o
32 + fileio.o batch.o clientname.o chmod.o acls.o xattr.o
33 OBJS3=progress.o pipe.o
34 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
35 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
38 @@ -29,6 +29,7 @@ extern int am_root;
40 extern int orig_umask;
41 extern int preserve_acls;
42 +extern int preserve_xattrs;
43 extern unsigned int file_struct_len;
45 /* === ACL structures === */
46 @@ -740,6 +741,10 @@ void receive_acl(struct file_struct *fil
47 type = SMB_ACL_TYPE_ACCESS;
48 racl_list = &access_acl_list;
49 ndx_ptr = (char*)file + file_struct_len;
50 +#ifdef SUPPORT_XATTRS
51 + if (preserve_xattrs)
55 char tag = read_byte(f);
57 @@ -799,6 +804,10 @@ void cache_acl(struct file_struct *file,
59 racl_list = &access_acl_list;
60 ndx_ptr = (char*)file + file_struct_len;
61 +#ifdef SUPPORT_XATTRS
62 + if (preserve_xattrs)
68 @@ -914,6 +923,10 @@ int set_acl(const char *fname, const str
70 type = SMB_ACL_TYPE_ACCESS;
71 ndx_ptr = (char*)file + file_struct_len;
72 +#ifdef SUPPORT_XATTRS
73 + if (preserve_xattrs)
81 @@ -30,6 +30,7 @@ extern char *backup_dir;
84 extern int preserve_acls;
85 +extern int preserve_xattrs;
86 extern int preserve_devices;
87 extern int preserve_specials;
88 extern int preserve_links;
89 @@ -136,6 +137,9 @@ static int make_bak_dir(char *fullpath)
91 sx.acc_acl = sx.def_acl = NULL;
93 +#ifdef SUPPORT_XATTRS
96 if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
99 @@ -144,6 +148,12 @@ static int make_bak_dir(char *fullpath)
100 cache_acl(file, &sx);
103 +#ifdef SUPPORT_XATTRS
104 + if (preserve_xattrs) {
105 + get_xattr(rel, &sx);
106 + cache_xattr(file, &sx);
109 set_file_attrs(fullpath, file, NULL, 0);
112 @@ -195,6 +205,9 @@ static int keep_backup(char *fname)
114 sx.acc_acl = sx.def_acl = NULL;
116 +#ifdef SUPPORT_XATTRS
120 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
121 return 1; /* the file could have disappeared */
122 @@ -208,6 +221,12 @@ static int keep_backup(char *fname)
123 cache_acl(file, &sx);
126 +#ifdef SUPPORT_XATTRS
127 + if (preserve_xattrs) {
128 + get_xattr(fname, &sx);
129 + cache_xattr(file, &sx);
133 /* Check to see if this is a device file, or link */
134 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
137 @@ -856,6 +856,35 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
141 +AC_CHECK_HEADERS(attr/xattr.h)
142 +AC_CHECK_HEADERS(sys/xattr.h)
143 +AC_MSG_CHECKING(whether to support extended attributes)
144 +AC_ARG_ENABLE(xattr-support,
145 +AC_HELP_STRING([--enable-xattr-support], [Include extended attribute support (default=no)]),
146 +[ case "$enableval" in
150 + AC_MSG_RESULT(Using Linux xattrs)
151 + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs])
154 + AC_MSG_RESULT(Using OS X xattrs)
155 + AC_DEFINE(HAVE_OSX_XATTRS, 1, [True if you have Mac OS X xattrs])
158 + AC_MSG_RESULT(Xattrs requested but not Linux or OS X. Good luck...)
164 + AC_DEFINE(HAVE_NA_XATTRS, 1, [True if you don't have extended attributes])
167 + AC_DEFINE(HAVE_NO_XATTRL, 1, [True if you don't have extended attributes])
170 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
175 @@ -41,6 +41,7 @@ extern int one_file_system;
176 extern int copy_dirlinks;
177 extern int keep_dirlinks;
178 extern int preserve_acls;
179 +extern int preserve_xattrs;
180 extern int preserve_links;
181 extern int preserve_hard_links;
182 extern int preserve_devices;
183 @@ -498,7 +499,7 @@ static struct file_struct *receive_file_
184 char thisname[MAXPATHLEN];
185 unsigned int l1 = 0, l2 = 0;
186 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
188 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
192 @@ -610,10 +611,16 @@ static struct file_struct *receive_file_
193 xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
196 +#elif defined SUPPORT_XATTRS
199 +#ifdef SUPPORT_XATTRS
200 + if (preserve_xattrs)
204 alloc_len = file_struct_len + dirname_len + basename_len
206 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
209 + linkname_len + sum_len;
210 @@ -622,7 +629,7 @@ static struct file_struct *receive_file_
211 file = (struct file_struct *)bp;
212 memset(bp, 0, file_struct_len);
213 bp += file_struct_len;
215 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
219 @@ -723,6 +730,10 @@ static struct file_struct *receive_file_
221 receive_acl(file, f);
223 +#ifdef SUPPORT_XATTRS
224 + if (preserve_xattrs)
225 + receive_xattr(file, f );
230 @@ -994,6 +1005,13 @@ static struct file_struct *send_file_nam
234 +#ifdef SUPPORT_XATTRS
235 + if (preserve_xattrs) {
237 + if (get_xattr(fname, &sx) < 0)
242 maybe_emit_filelist_progress(flist->count + flist_count_offset);
244 @@ -1006,11 +1024,19 @@ static struct file_struct *send_file_nam
248 +#ifdef SUPPORT_XATTRS
249 + if (preserve_xattrs)
250 + send_xattr(&sx, f);
257 +#ifdef SUPPORT_XATTRS
258 + if (preserve_xattrs)
264 --- old/lib/sysxattr.c
265 +++ new/lib/sysxattr.c
268 + * Extended attribute support for rsync.
270 + * Copyright (C) 2004 Red Hat, Inc.
271 + * Written by Jay Fenlason.
273 + * This program is free software; you can redistribute it and/or modify
274 + * it under the terms of the GNU General Public License as published by
275 + * the Free Software Foundation; either version 2 of the License, or
276 + * (at your option) any later version.
278 + * This program is distributed in the hope that it will be useful,
279 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
280 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
281 + * GNU General Public License for more details.
283 + * You should have received a copy of the GNU General Public License along
284 + * with this program; if not, write to the Free Software Foundation, Inc.,
285 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
289 +#include "sysxattr.h"
291 +#if defined HAVE_LINUX_XATTRS
293 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
295 + return lgetxattr(path, name, value, size);
298 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
300 + return lsetxattr(path, name, value, size, flags);
303 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
305 + return llistxattr(path, list, size);
308 +#elif HAVE_OSX_XATTRS
310 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
312 + return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
315 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
317 + return setxattr(path, name, value, size, 0, XATTR_NOFOLLOW | flags);
320 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
322 + return listxattr(path, list, size, XATTR_NOFOLLOW);
327 +#endif /* No xattrs */
328 --- old/lib/sysxattr.h
329 +++ new/lib/sysxattr.h
331 +#ifdef SUPPORT_XATTRS
332 +#if defined HAVE_ATTR_XATTR_H
333 +#include <attr/xattr.h>
334 +#elif defined HAVE_SYS_XATTR_H
335 +#include <sys/xattr.h>
339 +#if defined HAVE_LINUX_XATTRS || defined HAVE_OSX_XATTRS
341 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
342 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
343 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
352 @@ -48,6 +48,7 @@ int copy_links = 0;
353 int preserve_links = 0;
354 int preserve_hard_links = 0;
355 int preserve_acls = 0;
356 +int preserve_xattrs = 0;
357 int preserve_perms = 0;
358 int preserve_executability = 0;
359 int preserve_devices = 0;
360 @@ -201,6 +202,7 @@ static void print_rsync_version(enum log
361 char const *have_inplace = "no ";
362 char const *hardlinks = "no ";
363 char const *acls = "no ";
364 + char const *xattrs = "no ";
365 char const *links = "no ";
366 char const *ipv6 = "no ";
367 STRUCT_STAT *dumstat;
368 @@ -220,7 +222,9 @@ static void print_rsync_version(enum log
373 +#ifdef SUPPORT_XATTRS
379 @@ -234,9 +238,9 @@ static void print_rsync_version(enum log
380 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
381 rprintf(f, "<http://rsync.samba.org/>\n");
382 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
383 - "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
384 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
385 (int) (sizeof (OFF_T) * 8),
386 - got_socketpair, hardlinks, acls, links);
387 + got_socketpair, hardlinks, acls, xattrs, links);
389 /* Note that this field may not have type ino_t. It depends
390 * on the complicated interaction between largefile feature
391 @@ -290,7 +294,7 @@ void usage(enum logcode F)
392 rprintf(F," -q, --quiet suppress non-error messages\n");
393 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
394 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
395 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
396 + rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
397 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
398 rprintf(F," -r, --recursive recurse into directories\n");
399 rprintf(F," -R, --relative use relative path names\n");
400 @@ -315,6 +319,9 @@ void usage(enum logcode F)
402 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
404 +#ifdef SUPPORT_XATTRS
405 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
407 rprintf(F," -o, --owner preserve owner (super-user only)\n");
408 rprintf(F," -g, --group preserve group\n");
409 rprintf(F," --devices preserve device files (super-user only)\n");
410 @@ -437,6 +444,9 @@ static struct poptOption long_options[]
411 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
412 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
413 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
414 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
415 + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
416 + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
417 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
418 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
419 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
420 @@ -1118,6 +1128,17 @@ int parse_arguments(int *argc, const cha
425 +#ifdef SUPPORT_XATTRS
426 + preserve_xattrs = 1;
427 + preserve_perms = 1;
430 + snprintf(err_buf,sizeof(err_buf),
431 + "extended attributes are not supported on this %s\n",
432 + am_server ? "server" : "client");
434 +#endif /* SUPPORT_XATTRS */
437 /* A large opt value means that set_refuse_options()
438 @@ -1564,6 +1585,10 @@ void server_options(char **args,int *arg
442 +#ifdef SUPPORT_XATTRS
443 + if (preserve_xattrs)
454 extern int preserve_acls;
455 +extern int preserve_xattrs;
456 extern int preserve_perms;
457 extern int preserve_executability;
458 extern int preserve_times;
459 @@ -229,6 +230,10 @@ int set_file_attrs(char *fname, struct f
460 if (preserve_acls && set_acl(fname, file, sxp) == 0)
463 +#ifdef SUPPORT_XATTRS
464 + if (preserve_xattrs && set_xattr(fname, file, sxp) == 0)
469 if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
472 @@ -501,6 +501,10 @@ struct idev {
473 #define ACLS_NEED_MASK 1
476 +#if defined HAVE_LINUX_XATTRS || defined HAVE_OSX_XATTRS
477 +#define SUPPORT_XATTRS 1
480 #define GID_NONE ((gid_t)-1)
482 #define HL_CHECK_MASTER 0
483 @@ -695,6 +699,9 @@ typedef struct {
484 struct rsync_acl *acc_acl; /* access ACL */
485 struct rsync_acl *def_acl; /* default ACL */
487 +#ifdef SUPPORT_XATTRS
492 #define ACL_READY(sx) ((sx).acc_acl != NULL)
495 @@ -301,7 +301,7 @@ to the detailed description below for a
496 -q, --quiet suppress non-error messages
497 --no-motd suppress daemon-mode MOTD (see caveat)
498 -c, --checksum skip based on checksum, not mod-time & size
499 - -a, --archive archive mode; same as -rlptgoD (no -H, -A)
500 + -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
501 --no-OPTION turn off an implied OPTION (e.g. --no-D)
502 -r, --recursive recurse into directories
503 -R, --relative use relative path names
504 @@ -324,6 +324,7 @@ to the detailed description below for a
505 -E, --executability preserve executability
506 --chmod=CHMOD affect file and/or directory permissions
507 -A, --acls preserve ACLs (implies -p) [non-standard]
508 + -X, --xattrs preserve extended attrs (implies -p) [n.s.]
509 -o, --owner preserve owner (super-user only)
510 -g, --group preserve group
511 --devices preserve device files (super-user only)
512 @@ -818,6 +819,11 @@ version makes it incompatible with sendi
513 rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
514 doubling is not needed when pulling files from an older rsync.
516 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
517 +extended attributes to be the same as the local ones. This will work
518 +only if the remote machine's rsync supports this option also. This is
519 +a non-standard option.
521 dit(bf(--chmod)) This option tells rsync to apply one or more
522 comma-separated "chmod" strings to the permission of the files in the
523 transfer. The resulting value is treated as though it was the permissions
528 + * Extended Attribute support for rsync.
529 + * Written by Jay Fenlason, vaguely based on the ACLs patch.
531 + * Copyright (C) 2004 Red Hat, Inc.
532 + * Copyright (C) 2006 Wayne Davison
534 + * This program is free software; you can redistribute it and/or modify
535 + * it under the terms of the GNU General Public License as published by
536 + * the Free Software Foundation; either version 2 of the License, or
537 + * (at your option) any later version.
539 + * This program is distributed in the hope that it will be useful,
540 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
541 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
542 + * GNU General Public License for more details.
544 + * You should have received a copy of the GNU General Public License along
545 + * with this program; if not, write to the Free Software Foundation, Inc.,
546 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
550 +#include "lib/sysxattr.h"
552 +#ifdef SUPPORT_XATTRS
555 +extern unsigned int file_struct_len;
557 +#define RSYNC_XAL_INITIAL 5
558 +#define RSYNC_XAL_LIST_INITIAL 100
567 +static size_t namebuf_len = 0;
568 +static char *namebuf = NULL;
570 +static item_list empty_xattr = EMPTY_ITEM_LIST;
571 +static item_list rsync_xal_l = EMPTY_ITEM_LIST;
573 +#ifdef HAVE_OSX_XATTRS
574 +static char unique_prefix[] = "user.0S%."; /* OSX */
575 +static int upre_len = sizeof unique_prefix - 1;
578 +/* ------------------------------------------------------------------------- */
580 +static void rsync_xal_free(item_list *xalp)
583 + rsync_xa *rxas = xalp->items;
585 + for (i = 0; i < xalp->count; i++) {
586 + free(rxas[i].name);
587 + /* free(rxas[i].value); */
592 +void free_xattr(statx *sxp)
594 + rsync_xal_free(sxp->xattr);
599 +static int rsync_xal_compare_names(const void *x1, const void *x2)
601 + const rsync_xa *xa1 = x1;
602 + const rsync_xa *xa2 = x2;
603 + return strcmp(xa1->name, xa2->name);
606 +static int rsync_xal_get(const char *fname, item_list *xalp)
609 + ssize_t datum_size;
616 + namebuf_len = 1024;
617 + namebuf = new_array(char, namebuf_len);
619 + out_of_memory("rsync_xal_get");
622 + /* The length returned includes all the '\0' terminators. */
623 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
624 + if (name_size > (ssize_t)namebuf_len) {
628 + if (name_size < 0) {
629 + if (errno == ENOTSUP)
631 + if (errno == ERANGE) {
632 + name_size = sys_llistxattr(fname, NULL, 0);
633 + if (name_size < 0) {
634 + rsyserr(FERROR, errno, "%s: rsync_xal_get: llistxattr",
638 + namebuf = realloc_array(namebuf, char, name_size + 1024);
640 + out_of_memory("rsync_xal_get");
641 + namebuf_len = name_size + 1024;
642 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
643 + if (name_size < 0) {
644 + rsyserr(FERROR, errno,
645 + "%s: rsync_xal_get: re-llistxattr failed",
650 + rsyserr(FERROR, errno,
651 + "%s: rsync_xal_get: llistxattr failed:",
656 + if (name_size == 0)
658 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
659 + rsync_xa *rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
661 + len = strlen(name) + 1;
662 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
663 + if (datum_size < 0) {
664 + if (errno == ENOTSUP)
666 + rsyserr(FERROR, errno,
667 + "%s: rsync_xal_get: lgetxattr %s failed",
671 + ptr = new_array(char, len + datum_size);
673 + out_of_memory("rsync_xal_get");
674 + memcpy(ptr, name, len);
675 + rxas->name_len = len;
677 + rxas->datum_len = datum_size;
678 + rxas->datum = ptr + len;
680 + ssize_t size = sys_lgetxattr(fname, name, rxas->datum, datum_size);
681 + if (size != datum_size) {
683 + rsyserr(FERROR, errno,
684 + "rsync_xal_get: lgetxattr(%s,%s)"
685 + " failed", fname, name);
688 + "rsync_xal_get: lgetxattr(%s,%s)"
689 + " returned %d instead of %d\n",
690 + fname, name, size, datum_size);
696 + if (xalp->count > 1)
697 + qsort(xalp->items, xalp->count, sizeof (rsync_xa), rsync_xal_compare_names);
701 +/* Read the xattr(s) for this filename. */
702 +int get_xattr(const char *fname, statx *sxp)
704 + sxp->xattr = new(item_list);
705 + *sxp->xattr = empty_xattr;
706 + if (rsync_xal_get(fname, sxp->xattr) < 0) {
713 +static int find_matching_xattr(item_list *xalp)
716 + item_list *lst = rsync_xal_l.items;
718 + for (i = 0; i < rsync_xal_l.count; i++) {
719 + rsync_xa *rxas1 = lst[i].items;
720 + rsync_xa *rxas2 = xalp->items;
722 + /* Wrong number of elements? */
723 + if (lst[i].count != xalp->count)
725 + /* any elements different? */
726 + for (j = 0; j < xalp->count; j++) {
727 + if (rxas1[j].name_len != rxas2[j].name_len
728 + || rxas1[j].datum_len != rxas2[j].datum_len
729 + || strcmp(rxas1[j].name, rxas2[j].name)
730 + || memcmp(rxas1[j].datum, rxas2[j].datum, rxas2[j].datum_len))
733 + /* no differences found. This is The One! */
734 + if (j == xalp->count)
741 +/* Store *xalp on the end of rsync_xal_l */
742 +static void rsync_xal_store(item_list *xalp)
744 + item_list *new_lst = EXPAND_ITEM_LIST(&rsync_xal_l, item_list, RSYNC_XAL_LIST_INITIAL);
745 + /* Since the following call starts a new list, we know it will hold the
746 + * entire initial-count, not just enough space for one new item. */
747 + *new_lst = empty_xattr;
748 + (void)EXPAND_ITEM_LIST(new_lst, rsync_xa, xalp->count);
749 + memcpy(new_lst->items, xalp->items, xalp->count * sizeof (rsync_xa));
750 + new_lst->count = xalp->count;
754 +/* Send the make_xattr()-generated xattr list for this flist entry. */
755 +void send_xattr(statx *sxp, int f)
757 + int ndx = find_matching_xattr(sxp->xattr);
759 + write_byte(f, 'x');
761 + rsync_xal_free(sxp->xattr);
764 + int count = sxp->xattr->count;
765 + write_byte(f, 'X');
766 + write_int(f, count);
767 + for (rxa = sxp->xattr->items; count--; rxa++) {
768 +#ifdef HAVE_OSX_XATTRS
769 + if (strncmp(rxa->name, "user.", 5) != 0
770 + && strncmp(rxa->name, "system.", 7) != 0) {
771 + write_int(f, rxa->name_len + upre_len);
772 + write_int(f, rxa->datum_len);
773 + write_buf(f, unique_prefix, upre_len);
777 + write_int(f, rxa->name_len);
778 + write_int(f, rxa->datum_len);
780 + write_buf(f, rxa->name, rxa->name_len);
781 + write_buf(f, rxa->datum, rxa->datum_len);
783 + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */
788 +/* ------------------------------------------------------------------------- */
790 +/* receive and build the rsync_xattr_lists */
791 +void receive_xattr(struct file_struct *file, int f)
793 + static item_list temp_xattr = EMPTY_ITEM_LIST;
794 + int tag = read_byte(f);
795 + char *ndx_ptr = (char*)file + file_struct_len;
799 + int i, count = read_int(f);
800 + for (i = 0; i < count; i++) {
803 + size_t name_len = read_int(f);
804 + size_t datum_len = read_int(f);
805 + if (name_len + datum_len < name_len)
806 + out_of_memory("receive_xattr"); /* overflow */
807 + rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count);
808 + ptr = new_array(char, name_len + datum_len);
810 + out_of_memory("receive_xattr");
811 + read_buf(f, ptr, name_len);
812 + read_buf(f, ptr + name_len, datum_len);
813 + rxa->name_len = name_len;
814 + rxa->datum_len = datum_len;
816 + rxa->datum = ptr + name_len;
817 +#ifdef HAVE_OSX_XATTRS
818 + if (strncmp(rxa->name, unique_prefix, upre_len) == 0) {
819 + rxa->name_len -= upre_len;
820 + memmove(rxa->name, rxa->name + upre_len, rxa->name_len);
824 + ndx = rsync_xal_l.count; /* pre-incremented count */
825 + rsync_xal_store(&temp_xattr); /* adds item to rsync_xal_l */
826 + } else if (tag == 'x') {
828 + if (ndx < 0 || (size_t)ndx >= rsync_xal_l.count) {
829 + rprintf(FERROR, "%s: receive_xattr: xa index %d out of range\n",
830 + f_name(file, NULL), ndx);
831 + exit_cleanup(RERR_STREAMIO);
835 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
836 + f_name(file, NULL), tag);
837 + exit_cleanup(RERR_STREAMIO);
838 + ndx = 0; /* silence a compiler warning... */
841 + SIVAL(ndx_ptr, 0, ndx);
844 +/* Turn the xattr data in statx into cached xattr data, setting the index
845 + * values in the file struct. */
846 +void cache_xattr(struct file_struct *file, statx *sxp)
848 + char *ndx_ptr = (char*)file + file_struct_len;
854 + ndx = find_matching_xattr(sxp->xattr);
856 + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */
859 + SIVAL(ndx_ptr, 0, ndx);
862 +static int rsync_xal_set(const char *fname, item_list *xalp)
864 + rsync_xa *rxas = xalp->items;
868 + for (i = 0; i < xalp->count; i++) {
869 + int status = sys_lsetxattr(fname, rxas[i].name, rxas[i].datum, rxas[i].datum_len, 0);
871 + rsyserr(FERROR, errno, "%s: rsync_xal_set: lsetxattr %s failed",
872 + fname, rxas[i].name);
879 +/* Set extended attributes on indicated filename. */
880 +int set_xattr(const char *fname, const struct file_struct *file, UNUSED(statx *sxp))
883 + char *ndx_ptr = (char*)file + file_struct_len;
884 + item_list *lst = rsync_xal_l.items;
887 + return 1; /* FIXME: --dry-run needs to compute this value */
889 + ndx = IVAL(ndx_ptr, 0);
890 + return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */
893 +#endif /* SUPPORT_XATTRS */