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 @@ -743,6 +744,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 @@ -801,6 +806,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 @@ -916,6 +925,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,30 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
141 +AC_CHECK_HEADERS(attr/xattr.h)
142 +AC_MSG_CHECKING(whether to support extended attributes)
143 +AC_ARG_ENABLE(xattr-support,
144 +AC_HELP_STRING([--enable-xattr-support], [Include extended attribute support (default=no)]),
145 +[ case "$enableval" in
149 + AC_MSG_RESULT(Using Linux xattrs)
150 + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs])
153 + AC_MSG_RESULT(Xattrs requested but not linux. Good luck)
159 + AC_DEFINE(HAVE_NA_XATTRS, 1, [True if you don't have extended attributes])
162 + AC_DEFINE(HAVE_NO_XATTRL, 1, [True if you don't have extended attributes])
165 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
170 @@ -41,6 +41,7 @@ extern int one_file_system;
171 extern int copy_dirlinks;
172 extern int keep_dirlinks;
173 extern int preserve_acls;
174 +extern int preserve_xattrs;
175 extern int preserve_links;
176 extern int preserve_hard_links;
177 extern int preserve_devices;
178 @@ -494,7 +495,7 @@ static struct file_struct *receive_file_
179 char thisname[MAXPATHLEN];
180 unsigned int l1 = 0, l2 = 0;
181 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
183 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
187 @@ -606,10 +607,16 @@ static struct file_struct *receive_file_
188 xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
191 +#elif defined SUPPORT_XATTRS
194 +#ifdef SUPPORT_XATTRS
195 + if (preserve_xattrs)
199 alloc_len = file_struct_len + dirname_len + basename_len
201 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
204 + linkname_len + sum_len;
205 @@ -618,7 +625,7 @@ static struct file_struct *receive_file_
206 file = (struct file_struct *)bp;
207 memset(bp, 0, file_struct_len);
208 bp += file_struct_len;
210 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
214 @@ -719,6 +726,10 @@ static struct file_struct *receive_file_
216 receive_acl(file, f);
218 +#ifdef SUPPORT_XATTRS
219 + if (preserve_xattrs)
220 + receive_xattr(file, f );
225 @@ -989,6 +1000,13 @@ static struct file_struct *send_file_nam
229 +#ifdef SUPPORT_XATTRS
230 + if (preserve_xattrs) {
232 + if (get_xattr(fname, &sx) < 0)
237 maybe_emit_filelist_progress(flist->count + flist_count_offset);
239 @@ -1001,11 +1019,19 @@ static struct file_struct *send_file_nam
243 +#ifdef SUPPORT_XATTRS
244 + if (preserve_xattrs)
245 + send_xattr(&sx, f);
252 +#ifdef SUPPORT_XATTRS
253 + if (preserve_xattrs)
259 --- old/lib/sysxattr.c
260 +++ new/lib/sysxattr.c
263 + * Extended attribute support for rsync.
265 + * Copyright (C) 2004 Red Hat, Inc.
266 + * Written by Jay Fenlason.
268 + * This program is free software; you can redistribute it and/or modify
269 + * it under the terms of the GNU General Public License as published by
270 + * the Free Software Foundation; either version 2 of the License, or
271 + * (at your option) any later version.
273 + * This program is distributed in the hope that it will be useful,
274 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
275 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
276 + * GNU General Public License for more details.
278 + * You should have received a copy of the GNU General Public License along
279 + * with this program; if not, write to the Free Software Foundation, Inc.,
280 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
284 +#include "sysxattr.h"
286 +#if defined HAVE_LINUX_XATTRS
288 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
290 + return lgetxattr(path, name, value, size);
293 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
295 + return lsetxattr(path, name, value, size, flags);
298 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
300 + return llistxattr(path, list, size);
305 +#endif /* No xattrs */
306 --- old/lib/sysxattr.h
307 +++ new/lib/sysxattr.h
309 +#if defined SUPPORT_XATTRS && defined HAVE_ATTR_XATTR_H
310 +#include <attr/xattr.h>
313 +#if defined HAVE_LINUX_XATTRS
315 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
316 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
317 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
321 +#endif /* No xattrs */
324 @@ -48,6 +48,7 @@ int copy_links = 0;
325 int preserve_links = 0;
326 int preserve_hard_links = 0;
327 int preserve_acls = 0;
328 +int preserve_xattrs = 0;
329 int preserve_perms = 0;
330 int preserve_executability = 0;
331 int preserve_devices = 0;
332 @@ -200,6 +201,7 @@ static void print_rsync_version(enum log
333 char const *have_inplace = "no ";
334 char const *hardlinks = "no ";
335 char const *acls = "no ";
336 + char const *xattrs = "no ";
337 char const *links = "no ";
338 char const *ipv6 = "no ";
339 STRUCT_STAT *dumstat;
340 @@ -219,7 +221,9 @@ static void print_rsync_version(enum log
345 +#ifdef SUPPORT_XATTRS
351 @@ -233,9 +237,9 @@ static void print_rsync_version(enum log
352 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
353 rprintf(f, "<http://rsync.samba.org/>\n");
354 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
355 - "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
356 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
357 (int) (sizeof (OFF_T) * 8),
358 - got_socketpair, hardlinks, acls, links);
359 + got_socketpair, hardlinks, acls, xattrs, links);
361 /* Note that this field may not have type ino_t. It depends
362 * on the complicated interaction between largefile feature
363 @@ -288,7 +292,7 @@ void usage(enum logcode F)
364 rprintf(F," -v, --verbose increase verbosity\n");
365 rprintf(F," -q, --quiet suppress non-error messages\n");
366 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
367 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
368 + rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
369 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
370 rprintf(F," -r, --recursive recurse into directories\n");
371 rprintf(F," -R, --relative use relative path names\n");
372 @@ -313,6 +317,9 @@ void usage(enum logcode F)
374 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
376 +#ifdef SUPPORT_XATTRS
377 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
379 rprintf(F," -o, --owner preserve owner (super-user only)\n");
380 rprintf(F," -g, --group preserve group\n");
381 rprintf(F," --devices preserve device files (super-user only)\n");
382 @@ -433,6 +440,9 @@ static struct poptOption long_options[]
383 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
384 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
385 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
386 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
387 + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
388 + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
389 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
390 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
391 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
392 @@ -1113,6 +1123,17 @@ int parse_arguments(int *argc, const cha
397 +#ifdef SUPPORT_XATTRS
398 + preserve_xattrs = 1;
399 + preserve_perms = 1;
402 + snprintf(err_buf,sizeof(err_buf),
403 + "extended attributes are not supported on this %s\n",
404 + am_server ? "server" : "client");
406 +#endif /* SUPPORT_XATTRS */
409 /* A large opt value means that set_refuse_options()
410 @@ -1563,6 +1584,10 @@ void server_options(char **args,int *arg
414 +#ifdef SUPPORT_XATTRS
415 + if (preserve_xattrs)
426 extern int preserve_acls;
427 +extern int preserve_xattrs;
428 extern int preserve_perms;
429 extern int preserve_executability;
430 extern int preserve_times;
431 @@ -229,6 +230,10 @@ int set_file_attrs(char *fname, struct f
432 if (preserve_acls && set_acl(fname, file, sxp) == 0)
435 +#ifdef SUPPORT_XATTRS
436 + if (preserve_xattrs && set_xattr(fname, file, sxp) == 0)
441 if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) {
444 @@ -501,6 +501,10 @@ struct idev {
445 #define ACLS_NEED_MASK 1
448 +#ifdef HAVE_LINUX_XATTRS
449 +#define SUPPORT_XATTRS 1
452 #define GID_NONE ((gid_t)-1)
454 #define HL_CHECK_MASTER 0
455 @@ -693,6 +697,9 @@ typedef struct {
456 struct rsync_acl *acc_acl; /* access ACL */
457 struct rsync_acl *def_acl; /* default ACL */
459 +#ifdef SUPPORT_XATTRS
464 #define ACL_READY(sx) ((sx).acc_acl != NULL)
467 @@ -300,7 +300,7 @@ to the detailed description below for a
468 -v, --verbose increase verbosity
469 -q, --quiet suppress non-error messages
470 -c, --checksum skip based on checksum, not mod-time & size
471 - -a, --archive archive mode; same as -rlptgoD (no -H, -A)
472 + -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
473 --no-OPTION turn off an implied OPTION (e.g. --no-D)
474 -r, --recursive recurse into directories
475 -R, --relative use relative path names
476 @@ -323,6 +323,7 @@ to the detailed description below for a
477 -E, --executability preserve executability
478 --chmod=CHMOD affect file and/or directory permissions
479 -A, --acls preserve ACLs (implies -p) [non-standard]
480 + -X, --xattrs preserve extended attrs (implies -p) [n.s.]
481 -o, --owner preserve owner (super-user only)
482 -g, --group preserve group
483 --devices preserve device files (super-user only)
484 @@ -812,6 +813,11 @@ version makes it incompatible with sendi
485 rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
486 doubling is not needed when pulling files from an older rsync.
488 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
489 +extended attributes to be the same as the local ones. This will work
490 +only if the remote machine's rsync supports this option also. This is
491 +a non-standard option.
493 dit(bf(--chmod)) This option tells rsync to apply one or more
494 comma-separated "chmod" strings to the permission of the files in the
495 transfer. The resulting value is treated as though it was the permissions
500 + * Extended Attribute support for rsync.
501 + * Written by Jay Fenlason, vaguely based on the ACLs patch.
503 + * Copyright (C) 2004 Red Hat, Inc.
504 + * Copyright (C) 2006 Wayne Davison
506 + * This program is free software; you can redistribute it and/or modify
507 + * it under the terms of the GNU General Public License as published by
508 + * the Free Software Foundation; either version 2 of the License, or
509 + * (at your option) any later version.
511 + * This program is distributed in the hope that it will be useful,
512 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
513 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
514 + * GNU General Public License for more details.
516 + * You should have received a copy of the GNU General Public License along
517 + * with this program; if not, write to the Free Software Foundation, Inc.,
518 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
522 +#include "lib/sysxattr.h"
524 +#ifdef SUPPORT_XATTRS
527 +extern unsigned int file_struct_len;
529 +#define RSYNC_XAL_INITIAL 5
530 +#define RSYNC_XAL_LIST_INITIAL 100
539 +static size_t namebuf_len = 0;
540 +static char *namebuf = NULL;
542 +static size_t datumbuf_len = 0;
543 +static char *datumbuf = NULL;
545 +static item_list empty_xattr = EMPTY_ITEM_LIST;
546 +static item_list rsync_xal_l = EMPTY_ITEM_LIST;
548 +/* ------------------------------------------------------------------------- */
550 +static void rsync_xal_free(item_list *xalp)
553 + rsync_xa *rxas = xalp->items;
555 + for (i = 0; i < xalp->count; i++) {
556 + free(rxas[i].name);
557 + /* free(rxas[i].value); */
562 +void free_xattr(statx *sxp)
564 + rsync_xal_free(sxp->xattr);
569 +static int rsync_xal_compare_names(const void *x1, const void *x2)
571 + const rsync_xa *xa1 = x1;
572 + const rsync_xa *xa2 = x2;
573 + return strcmp(xa1->name, xa2->name);
576 +static int rsync_xal_get(const char *fname, item_list *xalp)
579 + ssize_t datum_size;
587 + namebuf = new_array(char, namebuf_len);
588 + datumbuf_len = 100;
589 + datumbuf = new_array(char, datumbuf_len);
590 + if (!namebuf || !datumbuf)
591 + out_of_memory("rsync_xal_get");
594 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
595 + if (name_size > (ssize_t)namebuf_len) {
599 + if (name_size < 0) {
600 + if (errno == ENOTSUP)
602 + if (errno == ERANGE) {
603 + name_size = sys_llistxattr(fname, NULL, 0);
604 + if (name_size < 0) {
605 + rsyserr(FERROR, errno, "%s: rsync_xal_get: llistxattr",
609 + namebuf = realloc_array(namebuf, char, name_size + 1);
611 + out_of_memory("rsync_xal_get");
612 + namebuf_len = name_size;
613 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
614 + if (name_size < 0) {
615 + rsyserr(FERROR, errno,
616 + "%s: rsync_xal_get: re-llistxattr failed",
621 + rsyserr(FERROR, errno,
622 + "%s: rsync_xal_get: llistxattr failed:",
627 + if (name_size == 0)
629 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
630 + rsync_xa *rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
632 + len = strlen(name) + 1;
633 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
634 + if (datum_size > (ssize_t)datumbuf_len) {
638 + if (datum_size < 0) {
639 + if (errno == ENOTSUP)
641 + if (errno == ERANGE) {
642 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
643 + if (datum_size < 0) {
644 + rsyserr(FERROR, errno,
645 + "%s: rsync_xal_get: lgetxattr %s failed",
649 + datumbuf = realloc_array(datumbuf, char, datum_size + 1);
651 + out_of_memory("rsync_xal_get");
652 + datumbuf_len = datum_size;
653 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
654 + if (datum_size < 0) {
655 + rsyserr(FERROR, errno,
656 + "%s: rsync_xal_get: re-lgetxattr of %s failed",
661 + rsyserr(FERROR, errno,
662 + "%s: rsync_xal_get: lgetxattr %s failed",
667 + ptr = new_array(char, len + datum_size);
669 + out_of_memory("rsync_xal_get");
670 + memcpy(ptr, name, len);
672 + memcpy(ptr + len, datumbuf, datum_size);
673 + rxas->name_len = len;
675 + rxas->datum_len = datum_size;
676 + rxas->datum = ptr + len;
678 + if (xalp->count > 1)
679 + qsort(xalp->items, xalp->count, sizeof (rsync_xa), rsync_xal_compare_names);
683 +/* Read the xattr(s) for this filename. */
684 +int get_xattr(const char *fname, statx *sxp)
686 + sxp->xattr = new(item_list);
687 + *sxp->xattr = empty_xattr;
688 + if (rsync_xal_get(fname, sxp->xattr) < 0) {
695 +static int find_matching_xattr(item_list *xalp)
698 + item_list *lst = rsync_xal_l.items;
700 + for (i = 0; i < rsync_xal_l.count; i++) {
701 + rsync_xa *rxas1 = lst[i].items;
702 + rsync_xa *rxas2 = xalp->items;
704 + /* Wrong number of elements? */
705 + if (lst[i].count != xalp->count)
707 + /* any elements different? */
708 + for (j = 0; j < xalp->count; j++) {
709 + if (rxas1[j].name_len != rxas2[j].name_len
710 + || rxas1[j].datum_len != rxas2[j].datum_len
711 + || strcmp(rxas1[j].name, rxas2[j].name)
712 + || memcmp(rxas1[j].datum, rxas2[j].datum, rxas2[j].datum_len))
715 + /* no differences found. This is The One! */
716 + if (j == xalp->count)
723 +/* Store *xalp on the end of rsync_xal_l */
724 +static void rsync_xal_store(item_list *xalp)
726 + item_list *new_lst = EXPAND_ITEM_LIST(&rsync_xal_l, item_list, RSYNC_XAL_LIST_INITIAL);
727 + EXPAND_ITEM_LIST(new_lst, item_list, xalp->count);
728 + memcpy(new_lst->items, xalp->items, xalp->count * sizeof (item_list));
729 + new_lst->count = xalp->count;
733 +/* Send the make_xattr()-generated xattr list for this flist entry. */
734 +void send_xattr(statx *sxp, int f)
736 + int ndx = find_matching_xattr(sxp->xattr);
738 + write_byte(f, 'x');
740 + rsync_xal_free(sxp->xattr);
743 + int count = sxp->xattr->count;
744 + write_byte(f, 'X');
745 + write_int(f, count);
746 + for (rxa = sxp->xattr->items; count--; rxa++) {
747 + write_int(f, rxa->name_len);
748 + write_int(f, rxa->datum_len);
749 + write_buf(f, rxa->name, rxa->name_len);
750 + write_buf(f, rxa->datum, rxa->datum_len);
752 + rsync_xal_store(sxp->xattr);
757 +/* ------------------------------------------------------------------------- */
759 +/* receive and build the rsync_xattr_lists */
760 +void receive_xattr(struct file_struct *file, int f)
762 + static item_list temp_xattr = EMPTY_ITEM_LIST;
763 + int tag = read_byte(f);
764 + char *ndx_ptr = (char*)file + file_struct_len;
768 + int i, count = read_int(f);
769 + for (i = 0; i < count; i++) {
772 + size_t name_len = read_int(f);
773 + size_t datum_len = read_int(f);
774 + if (name_len + datum_len < name_len)
775 + out_of_memory("receive_xattr"); /* overflow */
776 + rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count);
777 + ptr = new_array(char, name_len + datum_len);
779 + out_of_memory("receive_xattr");
780 + read_buf(f, ptr, name_len);
781 + read_buf(f, ptr + name_len, datum_len);
782 + rxa->name_len = name_len;
783 + rxa->datum_len = datum_len;
785 + rxa->datum = ptr + name_len;
787 + ndx = rsync_xal_l.count;
788 + rsync_xal_store(&temp_xattr);
789 + } else if (tag == 'x') {
791 + if (ndx < 0 || (size_t)ndx >= rsync_xal_l.count) {
792 + rprintf(FERROR, "%s: receive_xattr: xa index %d out of range\n",
793 + f_name(file, NULL), ndx);
794 + exit_cleanup(RERR_STREAMIO);
798 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
799 + f_name(file, NULL), tag);
800 + exit_cleanup(RERR_STREAMIO);
801 + ndx = 0; /* silence a compiler warning... */
804 + SIVAL(ndx_ptr, 0, ndx);
807 +/* Turn the xattr data in statx into cached xattr data, setting the index
808 + * values in the file struct. */
809 +void cache_xattr(struct file_struct *file, statx *sxp)
811 + char *ndx_ptr = (char*)file + file_struct_len;
817 + ndx = find_matching_xattr(sxp->xattr);
819 + rsync_xal_store(sxp->xattr);
822 + SIVAL(ndx_ptr, 0, ndx);
825 +static int rsync_xal_set(const char *fname, item_list *xalp)
827 + rsync_xa *rxas = xalp->items;
831 + for (i = 0; i < xalp->count; i++) {
832 + int status = sys_lsetxattr(fname, rxas[i].name, rxas[i].datum, rxas[i].datum_len, 0);
834 + rsyserr(FERROR, errno, "%s: rsync_xal_set: lsetxattr %s failed",
835 + fname, rxas[i].name);
842 +/* Set extended attributes on indicated filename. */
843 +int set_xattr(const char *fname, const struct file_struct *file, UNUSED(statx *sxp))
846 + char *ndx_ptr = (char*)file + file_struct_len;
847 + item_list *lst = rsync_xal_l.items;
850 + return 1; /* FIXME: --dry-run needs to compute this value */
852 + ndx = IVAL(ndx_ptr, 0);
853 + return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */
856 +#endif /* SUPPORT_XATTRS */