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 @@ -27,13 +27,13 @@ VERSION=@VERSION@
13 HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
14 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
15 - lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
16 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o lib/sysxattr.o @LIBOBJS@
17 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
18 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
19 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
20 main.o checksum.o match.o syscall.o log.o backup.o
21 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
22 - fileio.o batch.o clientname.o chmod.o acls.o
23 + fileio.o batch.o clientname.o chmod.o acls.o xattr.o
24 OBJS3=progress.o pipe.o
25 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
26 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
29 @@ -136,6 +136,7 @@ static int make_bak_dir(char *fullpath)
30 do_lchown(fullpath, st.st_uid, st.st_gid);
31 do_chmod(fullpath, st.st_mode);
32 (void)DUP_ACL(end, fullpath, st.st_mode);
33 + (void)DUP_XATTR(end, fullpath );
37 @@ -190,6 +191,7 @@ static int keep_backup(char *fname)
40 PUSH_KEEP_BACKUP_ACL(file, fname, buf);
41 + PUSH_KEEP_BACKUP_XATTR(file, fname, buf);
43 /* Check to see if this is a device file, or link */
44 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
45 @@ -267,6 +269,7 @@ static int keep_backup(char *fname)
47 set_file_attrs(buf, file, NULL, 0);
48 CLEANUP_KEEP_BACKUP_ACL();
49 + CLEANUP_KEEP_BACKUP_XATTR();
55 @@ -814,6 +814,30 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
59 +AC_CHECK_HEADERS(attr/xattr.h)
60 +AC_MSG_CHECKING(whether to support extended attributes)
61 +AC_ARG_ENABLE(xattr-support,
62 +AC_HELP_STRING([--enable-xattr-support], [Include extended attribute support (default=no)]),
63 +[ case "$enableval" in
67 + AC_MSG_RESULT(Using Linux xattrs)
68 + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs])
71 + AC_MSG_RESULT(Xattrs requested but not linux. Good luck)
77 + AC_DEFINE(HAVE_NA_XATTRS, 1, [True if you don't have extended attributes])
80 + AC_DEFINE(HAVE_NO_XATTRL, 1, [True if you don't have extended attributes])
83 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
88 @@ -969,6 +969,8 @@ static struct file_struct *send_file_nam
90 if (MAKE_ACL(file, fname) < 0)
92 + if (MAKE_XATTR(file, fname) < 0)
95 if (chmod_modes && !S_ISLNK(file->mode))
96 file->mode = tweak_mode(file->mode, chmod_modes);
97 @@ -981,9 +983,11 @@ static struct file_struct *send_file_nam
98 flist->files[flist->count++] = file;
99 send_file_entry(file, f);
101 + SEND_XATTR(file, f);
103 /* Cleanup unsent ACL(s). */
105 + SEND_XATTR(file, -1);
109 @@ -1373,6 +1377,7 @@ struct file_list *recv_file_list(int f)
110 file = receive_file_entry(flist, flags, f);
112 RECEIVE_ACL(file, f);
113 + RECEIVE_XATTR(file, f );
115 if (S_ISREG(file->mode))
116 stats.total_size += file->length;
117 @@ -1397,6 +1402,7 @@ struct file_list *recv_file_list(int f)
118 clean_flist(flist, relative_paths, 1);
120 SORT_FILE_ACL_INDEX_LISTS();
121 + SORT_FILE_XATTR_INDEX_LISTS();
124 recv_uid_list(f, flist);
127 @@ -908,6 +908,10 @@ static void recv_generator(char *fname,
129 SET_ACL(fname, file);
131 +#ifdef SUPPORT_XATTRS
133 + SET_XATTR(fname, file);
135 if (delete_during && f_out != -1 && !phase && dry_run < 2
136 && (file->flags & FLAG_DEL_HERE))
137 delete_in_dir(the_file_list, fname, file, &st);
138 --- old/lib/sysxattr.c
139 +++ new/lib/sysxattr.c
141 +/* Extended attribute support for rsync. */
142 +/* This file Copyright (C) 2004 Red Hat, Inc. */
143 +/* Written by Jay Fenlason */
145 +/* This program is free software; you can redistribute it and/or modify
146 + it under the terms of the GNU General Public License as published by
147 + the Free Software Foundation; either version 2 of the License, or
148 + (at your option) any later version.
150 + This program is distributed in the hope that it will be useful,
151 + but WITHOUT ANY WARRANTY; without even the implied warranty of
152 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153 + GNU General Public License for more details.
155 + You should have received a copy of the GNU General Public License
156 + along with this program; if not, write to the Free Software
157 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
162 +#if defined(HAVE_LINUX_XATTRS)
164 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
166 + return lgetxattr(path, name, value, size);
169 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
171 + return lsetxattr(path, name, value, size, flags);
174 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
176 + return llistxattr(path, list, size);
181 +#endif /* No xattrs */
182 --- old/lib/sysxattr.h
183 +++ new/lib/sysxattr.h
185 +#if defined(HAVE_LINUX_XATTRS)
187 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
188 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
189 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
193 +#endif /* No xattrs */
196 @@ -45,6 +45,7 @@ int copy_links = 0;
197 int preserve_links = 0;
198 int preserve_hard_links = 0;
199 int preserve_acls = 0;
200 +int preserve_xattrs = 0;
201 int preserve_perms = 0;
202 int preserve_executability = 0;
203 int preserve_devices = 0;
204 @@ -196,6 +197,7 @@ static void print_rsync_version(enum log
205 char const *have_inplace = "no ";
206 char const *hardlinks = "no ";
207 char const *acls = "no ";
208 + char const *xattrs = "no ";
209 char const *links = "no ";
210 char const *ipv6 = "no ";
211 STRUCT_STAT *dumstat;
212 @@ -215,7 +217,9 @@ static void print_rsync_version(enum log
217 +#ifdef SUPPORT_XATTRS
223 @@ -229,9 +233,9 @@ static void print_rsync_version(enum log
224 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
225 rprintf(f, "<http://rsync.samba.org/>\n");
226 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
227 - "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
228 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
229 (int) (sizeof (OFF_T) * 8),
230 - got_socketpair, hardlinks, acls, links);
231 + got_socketpair, hardlinks, acls, xattrs, links);
233 /* Note that this field may not have type ino_t. It depends
234 * on the complicated interaction between largefile feature
235 @@ -303,6 +307,9 @@ void usage(enum logcode F)
237 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
239 +#ifdef SUPPORT_XATTRS
240 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
242 rprintf(F," --chmod=CHMOD change destination permissions\n");
243 rprintf(F," -o, --owner preserve owner (super-user only)\n");
244 rprintf(F," -g, --group preserve group\n");
245 @@ -423,6 +430,9 @@ static struct poptOption long_options[]
246 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
247 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
248 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
249 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
250 + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
251 + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
252 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
253 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
254 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
255 @@ -1088,6 +1098,17 @@ int parse_arguments(int *argc, const cha
260 +#ifdef SUPPORT_XATTRS
261 + preserve_xattrs = 1;
262 + preserve_perms = 1;
265 + snprintf(err_buf,sizeof(err_buf),
266 + "extended attributes are not supported on this %s\n",
267 + am_server ? "server" : "client");
269 +#endif /* SUPPORT_XATTRS */
272 /* A large opt value means that set_refuse_options()
273 @@ -1532,6 +1553,10 @@ void server_options(char **args,int *arg
277 +#ifdef SUPPORT_XATTRS
278 + if (preserve_xattrs)
286 @@ -215,12 +215,15 @@ int set_file_attrs(char *fname, struct f
290 - /* If this is a directory, SET_ACL() will be called on the cleanup
291 - * receive_generator() pass (if we called it here, we might clobber
292 - * writability on the directory). Everything else is OK to do now. */
293 + /* If this is a directory, SET_ACL() and/or SET_XATTR() will be called
294 + * on the cleanup receive_generator() pass -- if we called it here, we
295 + * might clobber writability on the dir (SELinux security contexts are
296 + * stored in xattrs). Everything else is OK to do now. */
297 if (!S_ISDIR(st->st_mode)) {
298 if (SET_ACL(fname, file) == 0)
300 + if (SET_XATTR(fname, file) == 0)
304 if (verbose > 1 && flags & ATTRS_REPORT) {
307 @@ -695,6 +695,38 @@ struct chmod_mode_struct;
308 #endif /* SUPPORT_ACLS */
309 #include "smb_acls.h"
311 +#ifdef HAVE_LINUX_XATTRS
312 +#define SUPPORT_XATTRS 1
315 +#ifdef SUPPORT_XATTRS
316 +#ifdef HAVE_ATTR_XATTR_H
317 +#include <attr/xattr.h>
319 +#define MAKE_XATTR(file, fname) make_xattr(file, fname)
320 +#define SEND_XATTR(file, f) send_xattr(file, f)
321 +#define RECEIVE_XATTR(file, f) receive_xattr(file, f)
322 +#define SORT_FILE_XATTR_INDEX_LISTS() sort_file_xattr_index_lists()
323 +#define SET_XATTR(fname, file) set_xattr(fname, file)
324 +#define NEXT_XATTR_UID() next_xattr_uid()
325 +#define XATTR_UID_MAP(uid) xattr_uid_map(uid)
326 +#define PUSH_KEEP_BACKUP_XATTR(file, orig, dest) \
327 + push_keep_backup_xattr(file, orig, dest)
328 +#define CLEANUP_KEEP_BACKUP_XATTR() cleanup_keep_backup_xattr()
329 +#define DUP_XATTR(orig, dest) dup_xattr(orig, dest)
330 +#else /* SUPPORT_XATTRS */
331 +#define MAKE_XATTR(file, fname) 1 /* checked return value */
332 +#define SEND_XATTR(file, f)
333 +#define RECEIVE_XATTR(file, f)
334 +#define SORT_FILE_XATTR_INDEX_LISTS()
335 +#define SET_XATTR(fname, file) 1 /* checked return value */
336 +#define NEXT_XATTR_UID()
337 +#define XATTR_UID_MAP(uid)
338 +#define PUSH_KEEP_BACKUP_XATTR(file, orig, dest)
339 +#define CLEANUP_KEEP_BACKUP_XATTR()
340 +#define DUP_XATTR(src, orig) 1 /* checked return value */
341 +#endif /* SUPPORT_XATTRS */
345 /* We have replacement versions of these if they're missing. */
348 @@ -318,6 +318,7 @@ to the detailed description below for a
349 -p, --perms preserve permissions
350 -E, --executability preserve executability
351 -A, --acls preserve ACLs (implies -p) [non-standard]
352 + -X, --xattrs preserve extended attrs (implies -p) [n.s.]
353 --chmod=CHMOD change destination permissions
354 -o, --owner preserve owner (super-user only)
355 -g, --group preserve group
356 @@ -752,6 +753,11 @@ dit(bf(-A, --acls)) This option causes r
357 ACLs to be the same as the source ACLs. This nonstandard option only
358 works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
360 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
361 +extended attributes to be the same as the local ones. This will work
362 +only if the remote machine's rsync supports this option also. This is
363 +a non-standard option.
365 dit(bf(--chmod)) This option tells rsync to apply one or more
366 comma-separated "chmod" strings to the permission of the files in the
367 transfer. The resulting value is treated as though it was the permissions
371 +/* Extended Attribute support for rsync */
372 +/* Copyright (C) 2004 Red Hat, Inc */
373 +/* Written by Jay Fenlason, vaguely based on the ACLs patch */
375 +/* This program is free software; you can redistribute it and/or modify
376 + it under the terms of the GNU General Public License as published by
377 + the Free Software Foundation; either version 2 of the License, or
378 + (at your option) any later version.
380 + This program is distributed in the hope that it will be useful,
381 + but WITHOUT ANY WARRANTY; without even the implied warranty of
382 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
383 + GNU General Public License for more details.
385 + You should have received a copy of the GNU General Public License
386 + along with this program; if not, write to the Free Software
387 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
391 +#include "lib/sysxattr.h"
393 +#ifdef SUPPORT_XATTRS
395 +extern int preserve_xattrs;
398 +#define RSYNC_XAL_INITIAL 5
399 +#define RSYNC_XAL_LIST_INITIAL 100
420 +static size_t namebuf_len = 0;
421 +static char *namebuf = NULL;
423 +static size_t datumbuf_len = 0;
424 +static char *datumbuf = NULL;
426 +static rsync_xal curr_rsync_xal = { 0, 0, NULL };
427 +static rsync_xal_list rsync_xal_l = { 0, 0, NULL };
430 +/* ------------------------------------------------------------------------- */
432 +/* the below stuff is only used by the receiver */
434 +/* structure to hold index to rsync_xal_l member corresponding to
435 + * flist->files[i] */
438 + const struct file_struct *file;
445 + file_xal_index *filexalidxs;
446 +} file_xal_index_list;
448 +static file_xal_index_list fxil = {0, 0, NULL };
450 +/* stuff for redirecting calls to set_acl() from set_perms()
451 + * for keep_backup() */
452 +static const struct file_struct *backup_orig_file = NULL;
453 +static const char null_string[] = "";
454 +static const char *backup_orig_fname = null_string;
455 +static const char *backup_dest_fname = null_string;
456 +static rsync_xal backup_xal;
458 +/* ------------------------------------------------------------------------- */
460 +static void rsync_xal_free(rsync_xal *x)
464 + for (i = 0; i < x->count; i++) {
465 + free(x->rxas[i].name);
466 + /* free(x->rxas[i].value); */
471 +static int rsync_xal_compare_names(const void *x1, const void *x2)
473 + const rsync_xa *xa1;
474 + const rsync_xa *xa2;
478 + return strcmp(xa1->name, xa2->name);
481 +static int rsync_xal_get(const char *fname, rsync_xal *x)
484 + ssize_t datum_size;
492 + namebuf = new_array(char, namebuf_len);
493 + datumbuf_len = 100;
494 + datumbuf = new_array(char, datumbuf_len);
495 + if (!namebuf || !datumbuf)
496 + out_of_memory("rsync_xal_get");
499 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
500 + if (name_size > (ssize_t)namebuf_len) {
504 + if (name_size < 0) {
505 + if (errno == ENOTSUP)
507 + if (errno == ERANGE) {
508 + name_size = sys_llistxattr(fname, NULL, 0);
509 + if (name_size < 0) {
510 + rprintf(FERROR, "%s: rsync_xal_get: llistxattr: %s\n",
511 + fname, strerror(errno));
514 + namebuf = realloc_array(namebuf, char, name_size + 1);
516 + out_of_memory("rsync_xal_get");
517 + namebuf_len = name_size;
518 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
519 + if (name_size < 0) {
521 + "%s: rsync_xal_get: re-llistxattr failed: %s\n",
522 + fname, strerror(errno));
527 + "%s: rsync_xal_get: llistxattr failed: %s\n",
528 + fname, strerror(errno));
533 + if (name_size == 0)
535 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
536 + len = strlen(name) + 1;
538 + if (x->count >= x->alloc) {
540 + rsync_xa *new_rxas;
542 + new_alloc = x->alloc < RSYNC_XAL_INITIAL ? RSYNC_XAL_INITIAL : x->alloc * 2;
543 + new_rxas = realloc_array(x->rxas, rsync_xa, new_alloc);
545 + out_of_memory("rsync_xal_get");
546 + x->alloc = new_alloc;
547 + x->rxas = new_rxas;
549 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
550 + if (datum_size > (ssize_t)datumbuf_len) {
554 + if (datum_size < 0) {
555 + if (errno == ENOTSUP)
557 + if (errno == ERANGE) {
558 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
559 + if (datum_size < 0) {
561 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
562 + fname, name, strerror(errno));
565 + datumbuf = realloc_array(datumbuf, char, datum_size + 1);
567 + out_of_memory("rsync_xal_get");
568 + datumbuf_len = datum_size;
569 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
570 + if (datum_size < 0) {
572 + "%s: rsync_xal_get: re-lgetxattr of %s failed: %s\n",
573 + name, fname, strerror(errno));
578 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
579 + fname, name, strerror(errno));
583 + ptr = new_array(char, len + datum_size);
585 + out_of_memory("rsync_xal_get");
588 + memcpy(ptr + len, datumbuf, datum_size);
589 + x->rxas[curr_rsync_xal.count].name_len = len;
590 + x->rxas[curr_rsync_xal.count].name = ptr;
591 + x->rxas[curr_rsync_xal.count].datum_len = datum_size;
592 + x->rxas[curr_rsync_xal.count].datum = ptr + len;
595 + if (x->count > 1) {
596 + qsort(x->rxas, x->count, sizeof (rsync_xa), rsync_xal_compare_names);
602 +/* generate the xattr(s) for this flist entry;
603 + * xattr(s) are either sent or cleaned-up by send_xattr() below */
605 +int make_xattr(const struct file_struct *file, const char *fname)
607 + if (!preserve_xattrs || !file)
610 + rsync_xal_get(fname, &curr_rsync_xal);
611 + return 0; /* TODO: This needs to return 1 if no xattrs changed! */
614 +static ssize_t rsync_xal_find_matching(void)
619 + for (i = 0; i < rsync_xal_l.count; i++) {
620 + /* Wrong number of elements? */
621 + if (rsync_xal_l.rxals[i].count != curr_rsync_xal.count)
623 + /* any elements different? */
624 + for (j = 0; j < curr_rsync_xal.count; j++) {
625 + if (rsync_xal_l.rxals[i].rxas[j].name_len != curr_rsync_xal.rxas[j].name_len
626 + || rsync_xal_l.rxals[i].rxas[j].datum_len != curr_rsync_xal.rxas[j].datum_len
627 + || strcmp(rsync_xal_l.rxals[i].rxas[j].name, curr_rsync_xal.rxas[j].name)
628 + || memcmp(rsync_xal_l.rxals[i].rxas[j].datum, curr_rsync_xal.rxas[j].datum, curr_rsync_xal.rxas[j].datum_len))
631 + /* no differences found. This is The One! */
632 + if (j == curr_rsync_xal.count)
635 + if (i < rsync_xal_l.count)
637 + return (ssize_t)-1;
640 +/* Store curr_rsync_xal on the end of rsync_xal_l */
641 +static void rsync_xal_store(void)
643 + if (rsync_xal_l.count <= rsync_xal_l.alloc) {
647 + new_alloc = rsync_xal_l.count < RSYNC_XAL_LIST_INITIAL ? RSYNC_XAL_LIST_INITIAL : rsync_xal_l.count * 2;
648 + new_xal = realloc_array(rsync_xal_l.rxals, rsync_xal, new_alloc);
650 + out_of_memory("rsync_xal_store");
651 + rsync_xal_l.alloc = new_alloc;
652 + rsync_xal_l.rxals = new_xal;
654 + rsync_xal_l.rxals[rsync_xal_l.count] = curr_rsync_xal;
655 + rsync_xal_l.count++;
656 + curr_rsync_xal.count = 0;
657 + curr_rsync_xal.alloc = 0;
660 +/* send the make_xattr()-generated xattr list for this flist entry,
661 + * or clean up after an flist entry that's not being sent (f == -1) */
663 +void send_xattr(const struct file_struct *file, int f)
667 + if (!preserve_xattrs || !file)
671 + rsync_xal_free(&curr_rsync_xal);
674 + index = rsync_xal_find_matching();
676 + write_byte(f, 'x');
677 + write_int(f, index);
678 + rsync_xal_free(&curr_rsync_xal);
683 + count = curr_rsync_xal.count;
684 + write_byte(f, 'X');
685 + write_int(f, count);
686 + for (rxa = curr_rsync_xal.rxas; count--; rxa++) {
687 + write_int(f, rxa->name_len);
688 + write_int(f, rxa->datum_len);
689 + write_buf(f, rxa->name, rxa->name_len);
690 + write_buf(f, rxa->datum, rxa->datum_len);
697 +/* ------------------------------------------------------------------------- */
698 +/* receive and build the rsync_xattr_lists */
700 +void receive_xattr(struct file_struct *file, int f)
705 + if (!preserve_xattrs)
707 + fname = f_name(file, NULL);
708 + tag = read_byte(f);
709 + if (tag != 'X' && tag != 'x') {
711 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
713 + exit_cleanup(RERR_STREAMIO);
716 + if (fxil.alloc <= fxil.count) {
720 + if (fxil.count < RSYNC_XAL_LIST_INITIAL)
721 + new_alloc = fxil.alloc + RSYNC_XAL_LIST_INITIAL;
723 + new_alloc = fxil.alloc * 2;
724 + new_ptr = realloc_array(fxil.filexalidxs, file_xal_index, new_alloc);
726 + out_of_memory("receive_xattr");
727 + if (verbose >= 3) {
728 + rprintf(FINFO, "receive_xattr to %lu bytes, %s move\n",
729 + (unsigned long)(new_alloc * sizeof (file_xal_index)),
730 + fxil.filexalidxs == new_ptr ? "did not" : "did");
733 + fxil.filexalidxs = new_ptr;
734 + fxil.alloc = new_alloc;
737 + fxil.filexalidxs[fxil.count].file = file;
742 + fxil.filexalidxs[fxil.count].xalidx = rsync_xal_l.count;
744 + count = read_int(f);
745 + curr_rsync_xal.count = count;
746 + curr_rsync_xal.alloc = count;
747 + curr_rsync_xal.rxas = new_array(rsync_xa, count);
748 + if (!curr_rsync_xal.rxas)
749 + out_of_memory("receive_xattr");
750 + for (i = 0; i < count; i++) {
755 + name_len = read_int(f);
756 + datum_len = read_int(f);
757 + ptr = new_array(char, name_len + datum_len);
759 + out_of_memory("receive_xattr");
760 + read_buf(f, ptr, name_len);
761 + read_buf(f, ptr + name_len, datum_len);
762 + curr_rsync_xal.rxas[i].name_len = name_len;
763 + curr_rsync_xal.rxas[i].datum_len = datum_len;
764 + curr_rsync_xal.rxas[i].name = ptr;
765 + curr_rsync_xal.rxas[i].datum = ptr + name_len;
771 + index = read_int(f);
772 + if (index >= rsync_xal_l.count) {
773 + rprintf(FERROR, "%s: receive_xattr: xa index %lu out of range\n",
774 + fname, (unsigned long)index);
775 + exit_cleanup(RERR_STREAMIO);
777 + fxil.filexalidxs[fxil.count].xalidx = index;
782 +static int rsync_xal_set(const char *fname, rsync_xal *x)
787 + for (i = 0; i < x->count; i++) {
788 + int status = sys_lsetxattr(fname, x->rxas[i].name, x->rxas[i].datum, x->rxas[i].datum_len, 0);
790 + rprintf(FERROR, "%s: rsync_xal_set: lsetxattr %s failed: %s\n",
791 + fname, x->rxas[i].name, strerror(errno));
798 +/* for duplicating xattrs on backups when using backup_dir */
800 +int dup_xattr(const char *orig, const char *bak)
804 + if (!preserve_xattrs)
807 + if (rsync_xal_get(orig, &backup_xal) < 0)
808 + ret = rsync_xal_set(bak, &backup_xal);
811 + rsync_xal_free(&backup_xal);
815 +void push_keep_backup_xattr(const struct file_struct *file, const char *orig, const char *dest)
817 + if (!preserve_xattrs)
820 + backup_orig_file = file;
821 + backup_orig_fname = orig;
822 + backup_dest_fname = dest;
823 + rsync_xal_get(orig, &backup_xal);
826 +static int set_keep_backup_xal(void)
828 + if (!preserve_xattrs)
830 + return rsync_xal_set(backup_dest_fname, &backup_xal);
833 +void cleanup_keep_backup_xattr(void)
835 + if (!preserve_xattrs)
838 + backup_orig_file = NULL;
839 + backup_orig_fname = null_string;
840 + backup_dest_fname = null_string;
841 + rsync_xal_free(&backup_xal);
844 +static int file_xal_index_compare(const void *x1, const void *x2)
846 + const file_xal_index *xa1;
847 + const file_xal_index *xa2;
851 + return xa1->file == xa2->file ? 0 : xa1->file < xa2->file ? -1 : 1;
854 +void sort_file_xattr_index_lists(void)
856 + if (!preserve_xattrs)
858 + qsort(fxil.filexalidxs, fxil.count, sizeof (file_xal_index), file_xal_index_compare);
861 +static int find_file_xal_index(const struct file_struct *file)
863 + int low = 0, high = fxil.count;
864 + const struct file_struct *file_mid;
867 + rprintf(FERROR, "find_file_xal_index: no entries\n");
868 + exit_cleanup(RERR_STREAMIO);
872 + int mid = (high + low) / 2;
873 + file_mid = fxil.filexalidxs[mid].file;
874 + if (file_mid == file)
875 + return fxil.filexalidxs[mid].xalidx;
876 + if (file_mid > file)
880 + } while (low < high);
882 + file_mid = fxil.filexalidxs[low].file;
883 + if (file_mid == file)
884 + return fxil.filexalidxs[low].xalidx;
887 + "find_file_xal_index: can't find entry for file in list\n");
888 + exit_cleanup(RERR_STREAMIO);
892 +/* set extended attributes on rsync-ed or keep_backup-ed file */
894 +int set_xattr(const char *fname, const struct file_struct *file)
899 + if (dry_run || !preserve_xattrs)
901 + if (file == backup_orig_file) {
902 + if (!strcmp(fname, backup_dest_fname))
903 + return set_keep_backup_xal();
905 + xalidx = find_file_xal_index(file);
906 + x = &(rsync_xal_l.rxals[xalidx]);
907 + return rsync_xal_set(fname, x);
910 +#endif /* SUPPORT_XATTRS */