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 @@ -974,7 +985,7 @@ static struct file_struct *send_file_nam
231 unsigned short flags)
233 struct file_struct *file;
235 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
239 @@ -994,6 +1005,13 @@ static struct file_struct *send_file_nam
243 +#ifdef SUPPORT_XATTRS
244 + if (preserve_xattrs) {
246 + if (get_xattr(fname, &sx) < 0)
251 maybe_emit_filelist_progress(flist->count + flist_count_offset);
253 @@ -1006,11 +1024,19 @@ static struct file_struct *send_file_nam
257 +#ifdef SUPPORT_XATTRS
258 + if (preserve_xattrs)
259 + send_xattr(&sx, f);
266 +#ifdef SUPPORT_XATTRS
267 + if (preserve_xattrs)
273 --- old/lib/sysxattr.c
274 +++ new/lib/sysxattr.c
277 + * Extended attribute support for rsync.
279 + * Copyright (C) 2004 Red Hat, Inc.
280 + * Written by Jay Fenlason.
282 + * This program is free software; you can redistribute it and/or modify
283 + * it under the terms of the GNU General Public License as published by
284 + * the Free Software Foundation; either version 2 of the License, or
285 + * (at your option) any later version.
287 + * This program is distributed in the hope that it will be useful,
288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
290 + * GNU General Public License for more details.
292 + * You should have received a copy of the GNU General Public License along
293 + * with this program; if not, write to the Free Software Foundation, Inc.,
294 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
298 +#include "sysxattr.h"
300 +#if defined HAVE_LINUX_XATTRS
302 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
304 + return lgetxattr(path, name, value, size);
307 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
309 + return lsetxattr(path, name, value, size, flags);
312 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
314 + return llistxattr(path, list, size);
317 +#elif HAVE_OSX_XATTRS
319 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
321 + return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
324 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
326 + return setxattr(path, name, value, size, 0, XATTR_NOFOLLOW | flags);
329 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
331 + return listxattr(path, list, size, XATTR_NOFOLLOW);
336 +#endif /* No xattrs */
337 --- old/lib/sysxattr.h
338 +++ new/lib/sysxattr.h
340 +#ifdef SUPPORT_XATTRS
341 +#if defined HAVE_ATTR_XATTR_H
342 +#include <attr/xattr.h>
343 +#elif defined HAVE_SYS_XATTR_H
344 +#include <sys/xattr.h>
348 +#if defined HAVE_LINUX_XATTRS || defined HAVE_OSX_XATTRS
350 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
351 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
352 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
361 @@ -48,6 +48,7 @@ int copy_links = 0;
362 int preserve_links = 0;
363 int preserve_hard_links = 0;
364 int preserve_acls = 0;
365 +int preserve_xattrs = 0;
366 int preserve_perms = 0;
367 int preserve_executability = 0;
368 int preserve_devices = 0;
369 @@ -201,6 +202,7 @@ static void print_rsync_version(enum log
370 char const *have_inplace = "no ";
371 char const *hardlinks = "no ";
372 char const *acls = "no ";
373 + char const *xattrs = "no ";
374 char const *links = "no ";
375 char const *ipv6 = "no ";
376 STRUCT_STAT *dumstat;
377 @@ -220,7 +222,9 @@ static void print_rsync_version(enum log
382 +#ifdef SUPPORT_XATTRS
388 @@ -234,9 +238,9 @@ static void print_rsync_version(enum log
389 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
390 rprintf(f, "<http://rsync.samba.org/>\n");
391 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
392 - "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
393 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
394 (int) (sizeof (OFF_T) * 8),
395 - got_socketpair, hardlinks, acls, links);
396 + got_socketpair, hardlinks, acls, xattrs, links);
398 /* Note that this field may not have type ino_t. It depends
399 * on the complicated interaction between largefile feature
400 @@ -290,7 +294,7 @@ void usage(enum logcode F)
401 rprintf(F," -q, --quiet suppress non-error messages\n");
402 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
403 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
404 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
405 + rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
406 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
407 rprintf(F," -r, --recursive recurse into directories\n");
408 rprintf(F," -R, --relative use relative path names\n");
409 @@ -315,6 +319,9 @@ void usage(enum logcode F)
411 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
413 +#ifdef SUPPORT_XATTRS
414 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
416 rprintf(F," -o, --owner preserve owner (super-user only)\n");
417 rprintf(F," -g, --group preserve group\n");
418 rprintf(F," --devices preserve device files (super-user only)\n");
419 @@ -437,6 +444,9 @@ static struct poptOption long_options[]
420 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
421 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
422 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
423 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
424 + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
425 + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
426 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
427 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
428 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
429 @@ -1118,6 +1128,17 @@ int parse_arguments(int *argc, const cha
434 +#ifdef SUPPORT_XATTRS
435 + preserve_xattrs = 1;
436 + preserve_perms = 1;
439 + snprintf(err_buf,sizeof(err_buf),
440 + "extended attributes are not supported on this %s\n",
441 + am_server ? "server" : "client");
443 +#endif /* SUPPORT_XATTRS */
446 /* A large opt value means that set_refuse_options()
447 @@ -1564,6 +1585,10 @@ void server_options(char **args,int *arg
451 +#ifdef SUPPORT_XATTRS
452 + if (preserve_xattrs)
463 extern int preserve_acls;
464 +extern int preserve_xattrs;
465 extern int preserve_perms;
466 extern int preserve_executability;
467 extern int preserve_times;
468 @@ -229,6 +230,10 @@ int set_file_attrs(char *fname, struct f
469 if (preserve_acls && set_acl(fname, file, sxp) == 0)
472 +#ifdef SUPPORT_XATTRS
473 + if (preserve_xattrs && set_xattr(fname, file, sxp) == 0)
478 if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
481 @@ -501,6 +501,10 @@ struct idev {
482 #define ACLS_NEED_MASK 1
485 +#if defined HAVE_LINUX_XATTRS || defined HAVE_OSX_XATTRS
486 +#define SUPPORT_XATTRS 1
489 #define GID_NONE ((gid_t)-1)
491 #define HL_CHECK_MASTER 0
492 @@ -695,6 +699,9 @@ typedef struct {
493 struct rsync_acl *acc_acl; /* access ACL */
494 struct rsync_acl *def_acl; /* default ACL */
496 +#ifdef SUPPORT_XATTRS
501 #define ACL_READY(sx) ((sx).acc_acl != NULL)
504 @@ -301,7 +301,7 @@ to the detailed description below for a
505 -q, --quiet suppress non-error messages
506 --no-motd suppress daemon-mode MOTD (see caveat)
507 -c, --checksum skip based on checksum, not mod-time & size
508 - -a, --archive archive mode; same as -rlptgoD (no -H, -A)
509 + -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
510 --no-OPTION turn off an implied OPTION (e.g. --no-D)
511 -r, --recursive recurse into directories
512 -R, --relative use relative path names
513 @@ -324,6 +324,7 @@ to the detailed description below for a
514 -E, --executability preserve executability
515 --chmod=CHMOD affect file and/or directory permissions
516 -A, --acls preserve ACLs (implies -p) [non-standard]
517 + -X, --xattrs preserve extended attrs (implies -p) [n.s.]
518 -o, --owner preserve owner (super-user only)
519 -g, --group preserve group
520 --devices preserve device files (super-user only)
521 @@ -818,6 +819,11 @@ version makes it incompatible with sendi
522 rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
523 doubling is not needed when pulling files from an older rsync.
525 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
526 +extended attributes to be the same as the local ones. This will work
527 +only if the remote machine's rsync supports this option also. This is
528 +a non-standard option.
530 dit(bf(--chmod)) This option tells rsync to apply one or more
531 comma-separated "chmod" strings to the permission of the files in the
532 transfer. The resulting value is treated as though it was the permissions
537 + * Extended Attribute support for rsync.
538 + * Written by Jay Fenlason, vaguely based on the ACLs patch.
540 + * Copyright (C) 2004 Red Hat, Inc.
541 + * Copyright (C) 2006 Wayne Davison
543 + * This program is free software; you can redistribute it and/or modify
544 + * it under the terms of the GNU General Public License as published by
545 + * the Free Software Foundation; either version 2 of the License, or
546 + * (at your option) any later version.
548 + * This program is distributed in the hope that it will be useful,
549 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
550 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
551 + * GNU General Public License for more details.
553 + * You should have received a copy of the GNU General Public License along
554 + * with this program; if not, write to the Free Software Foundation, Inc.,
555 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
559 +#include "lib/sysxattr.h"
561 +#ifdef SUPPORT_XATTRS
564 +extern unsigned int file_struct_len;
566 +#define RSYNC_XAL_INITIAL 5
567 +#define RSYNC_XAL_LIST_INITIAL 100
576 +static size_t namebuf_len = 0;
577 +static char *namebuf = NULL;
579 +static item_list empty_xattr = EMPTY_ITEM_LIST;
580 +static item_list rsync_xal_l = EMPTY_ITEM_LIST;
582 +#ifdef HAVE_OSX_XATTRS
583 +static char unique_prefix[] = "user.0S%."; /* OSX */
584 +static int upre_len = sizeof unique_prefix - 1;
587 +/* ------------------------------------------------------------------------- */
589 +static void rsync_xal_free(item_list *xalp)
592 + rsync_xa *rxas = xalp->items;
594 + for (i = 0; i < xalp->count; i++) {
595 + free(rxas[i].name);
596 + /* free(rxas[i].value); */
601 +void free_xattr(statx *sxp)
603 + rsync_xal_free(sxp->xattr);
608 +static int rsync_xal_compare_names(const void *x1, const void *x2)
610 + const rsync_xa *xa1 = x1;
611 + const rsync_xa *xa2 = x2;
612 + return strcmp(xa1->name, xa2->name);
615 +static int rsync_xal_get(const char *fname, item_list *xalp)
618 + ssize_t datum_size;
625 + namebuf_len = 1024;
626 + namebuf = new_array(char, namebuf_len);
628 + out_of_memory("rsync_xal_get");
631 + /* The length returned includes all the '\0' terminators. */
632 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
633 + if (name_size > (ssize_t)namebuf_len) {
637 + if (name_size < 0) {
638 + if (errno == ENOTSUP)
640 + if (errno == ERANGE) {
641 + name_size = sys_llistxattr(fname, NULL, 0);
642 + if (name_size < 0) {
643 + rsyserr(FERROR, errno, "%s: rsync_xal_get: llistxattr",
647 + namebuf = realloc_array(namebuf, char, name_size + 1024);
649 + out_of_memory("rsync_xal_get");
650 + namebuf_len = name_size + 1024;
651 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
652 + if (name_size < 0) {
653 + rsyserr(FERROR, errno,
654 + "%s: rsync_xal_get: re-llistxattr failed",
659 + rsyserr(FERROR, errno,
660 + "%s: rsync_xal_get: llistxattr failed:",
665 + if (name_size == 0)
667 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
668 + rsync_xa *rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
670 + len = strlen(name) + 1;
671 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
672 + if (datum_size < 0) {
673 + if (errno == ENOTSUP)
675 + rsyserr(FERROR, errno,
676 + "%s: rsync_xal_get: lgetxattr %s failed",
680 + ptr = new_array(char, len + datum_size);
682 + out_of_memory("rsync_xal_get");
683 + memcpy(ptr, name, len);
684 + rxas->name_len = len;
686 + rxas->datum_len = datum_size;
687 + rxas->datum = ptr + len;
689 + ssize_t size = sys_lgetxattr(fname, name, rxas->datum, datum_size);
690 + if (size != datum_size) {
692 + rsyserr(FERROR, errno,
693 + "rsync_xal_get: lgetxattr(%s,%s)"
694 + " failed", fname, name);
697 + "rsync_xal_get: lgetxattr(%s,%s)"
698 + " returned %ld instead of %ld\n",
700 + (long)size, (long)datum_size);
706 + if (xalp->count > 1)
707 + qsort(xalp->items, xalp->count, sizeof (rsync_xa), rsync_xal_compare_names);
711 +/* Read the xattr(s) for this filename. */
712 +int get_xattr(const char *fname, statx *sxp)
714 + sxp->xattr = new(item_list);
715 + *sxp->xattr = empty_xattr;
716 + if (rsync_xal_get(fname, sxp->xattr) < 0) {
723 +static int find_matching_xattr(item_list *xalp)
726 + item_list *lst = rsync_xal_l.items;
728 + for (i = 0; i < rsync_xal_l.count; i++) {
729 + rsync_xa *rxas1 = lst[i].items;
730 + rsync_xa *rxas2 = xalp->items;
732 + /* Wrong number of elements? */
733 + if (lst[i].count != xalp->count)
735 + /* any elements different? */
736 + for (j = 0; j < xalp->count; j++) {
737 + if (rxas1[j].name_len != rxas2[j].name_len
738 + || rxas1[j].datum_len != rxas2[j].datum_len
739 + || strcmp(rxas1[j].name, rxas2[j].name)
740 + || memcmp(rxas1[j].datum, rxas2[j].datum, rxas2[j].datum_len))
743 + /* no differences found. This is The One! */
744 + if (j == xalp->count)
751 +/* Store *xalp on the end of rsync_xal_l */
752 +static void rsync_xal_store(item_list *xalp)
754 + item_list *new_lst = EXPAND_ITEM_LIST(&rsync_xal_l, item_list, RSYNC_XAL_LIST_INITIAL);
755 + /* Since the following call starts a new list, we know it will hold the
756 + * entire initial-count, not just enough space for one new item. */
757 + *new_lst = empty_xattr;
758 + (void)EXPAND_ITEM_LIST(new_lst, rsync_xa, xalp->count);
759 + memcpy(new_lst->items, xalp->items, xalp->count * sizeof (rsync_xa));
760 + new_lst->count = xalp->count;
764 +/* Send the make_xattr()-generated xattr list for this flist entry. */
765 +void send_xattr(statx *sxp, int f)
767 + int ndx = find_matching_xattr(sxp->xattr);
769 + write_byte(f, 'x');
771 + rsync_xal_free(sxp->xattr);
774 + int count = sxp->xattr->count;
775 + write_byte(f, 'X');
776 + write_int(f, count);
777 + for (rxa = sxp->xattr->items; count--; rxa++) {
778 +#ifdef HAVE_OSX_XATTRS
779 + if (strncmp(rxa->name, "user.", 5) != 0
780 + && strncmp(rxa->name, "system.", 7) != 0) {
781 + write_int(f, rxa->name_len + upre_len);
782 + write_int(f, rxa->datum_len);
783 + write_buf(f, unique_prefix, upre_len);
787 + write_int(f, rxa->name_len);
788 + write_int(f, rxa->datum_len);
790 + write_buf(f, rxa->name, rxa->name_len);
791 + write_buf(f, rxa->datum, rxa->datum_len);
793 + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */
798 +/* ------------------------------------------------------------------------- */
800 +/* receive and build the rsync_xattr_lists */
801 +void receive_xattr(struct file_struct *file, int f)
803 + static item_list temp_xattr = EMPTY_ITEM_LIST;
804 + int tag = read_byte(f);
805 + char *ndx_ptr = (char*)file + file_struct_len;
809 + int i, count = read_int(f);
810 + for (i = 0; i < count; i++) {
813 + size_t name_len = read_int(f);
814 + size_t datum_len = read_int(f);
815 + if (name_len + datum_len < name_len)
816 + out_of_memory("receive_xattr"); /* overflow */
817 + rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count);
818 + ptr = new_array(char, name_len + datum_len);
820 + out_of_memory("receive_xattr");
821 + read_buf(f, ptr, name_len);
822 + read_buf(f, ptr + name_len, datum_len);
823 + rxa->name_len = name_len;
824 + rxa->datum_len = datum_len;
826 + rxa->datum = ptr + name_len;
827 +#ifdef HAVE_OSX_XATTRS
828 + if (strncmp(rxa->name, unique_prefix, upre_len) == 0) {
829 + rxa->name_len -= upre_len;
830 + memmove(rxa->name, rxa->name + upre_len, rxa->name_len);
834 + ndx = rsync_xal_l.count; /* pre-incremented count */
835 + rsync_xal_store(&temp_xattr); /* adds item to rsync_xal_l */
836 + } else if (tag == 'x') {
838 + if (ndx < 0 || (size_t)ndx >= rsync_xal_l.count) {
839 + rprintf(FERROR, "%s: receive_xattr: xa index %d out of range\n",
840 + f_name(file, NULL), ndx);
841 + exit_cleanup(RERR_STREAMIO);
845 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
846 + f_name(file, NULL), tag);
847 + exit_cleanup(RERR_STREAMIO);
848 + ndx = 0; /* silence a compiler warning... */
851 + SIVAL(ndx_ptr, 0, ndx);
854 +/* Turn the xattr data in statx into cached xattr data, setting the index
855 + * values in the file struct. */
856 +void cache_xattr(struct file_struct *file, statx *sxp)
858 + char *ndx_ptr = (char*)file + file_struct_len;
864 + ndx = find_matching_xattr(sxp->xattr);
866 + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */
869 + SIVAL(ndx_ptr, 0, ndx);
872 +static int rsync_xal_set(const char *fname, item_list *xalp)
874 + rsync_xa *rxas = xalp->items;
878 + for (i = 0; i < xalp->count; i++) {
879 + int status = sys_lsetxattr(fname, rxas[i].name, rxas[i].datum, rxas[i].datum_len, 0);
881 + rsyserr(FERROR, errno, "%s: rsync_xal_set: lsetxattr %s failed",
882 + fname, rxas[i].name);
889 +/* Set extended attributes on indicated filename. */
890 +int set_xattr(const char *fname, const struct file_struct *file, UNUSED(statx *sxp))
893 + char *ndx_ptr = (char*)file + file_struct_len;
894 + item_list *lst = rsync_xal_l.items;
897 + return 1; /* FIXME: --dry-run needs to compute this value */
899 + ndx = IVAL(ndx_ptr, 0);
900 + return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */
903 +#endif /* SUPPORT_XATTRS */