1 Depends-On-Patch: acls.diff
3 After applying this patch, run these commands for a successful build:
7 ./configure --with-acl-support --with-xattr-support
11 --- orig/Makefile.in 2004-10-20 06:32:26
12 +++ Makefile.in 2005-03-03 01:20:46
13 @@ -27,14 +27,14 @@ VERSION=@VERSION@
15 HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
16 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
17 - lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
18 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o lib/sysxattr.o @LIBOBJS@
19 ZLIBOBJ=zlib/deflate.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o \
20 zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/trees.o \
21 zlib/zutil.o zlib/adler32.o
22 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
23 main.o checksum.o match.o syscall.o log.o backup.o
24 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
25 - fileio.o batch.o clientname.o acls.o
26 + fileio.o batch.o clientname.o acls.o xattr.o
27 OBJS3=progress.o pipe.o
28 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
29 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
30 --- orig/backup.c 2004-10-06 00:13:09
31 +++ backup.c 2005-03-03 01:20:46
32 @@ -136,6 +136,7 @@ static int make_bak_dir(char *fullpath)
33 do_lchown(fullpath, st.st_uid, st.st_gid);
34 do_chmod(fullpath, st.st_mode);
35 (void)DUP_ACL(end, fullpath, st.st_mode);
36 + (void)DUP_XATTR(end, fullpath );
40 @@ -189,6 +190,7 @@ static int keep_backup(char *fname)
43 PUSH_KEEP_BACKUP_ACL(file, fname, buf);
44 + PUSH_KEEP_BACKUP_XATTR(file, fname, buf);
46 /* Check to see if this is a device file, or link */
47 if (IS_DEVICE(file->mode)) {
48 @@ -264,6 +266,7 @@ static int keep_backup(char *fname)
50 set_perms(buf, file, NULL, 0);
51 CLEANUP_KEEP_BACKUP_ACL();
52 + CLEANUP_KEEP_BACKUP_XATTR();
56 --- orig/configure.in 2004-08-19 19:53:27
57 +++ configure.in 2005-05-12 22:57:53
58 @@ -810,6 +810,30 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
62 +AC_CHECK_HEADERS(attr/xattr.h)
63 +AC_MSG_CHECKING(whether to support extended attributes)
64 +AC_ARG_WITH(xattr-support,
65 +[ --with-xattr-support Include extended attribute support (default=no)],
70 + AC_MSG_RESULT(Using Linux xattrs)
71 + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs])
74 + AC_MSG_RESULT(Xattrs requested but not linux. Good luck)
80 + AC_DEFINE(HAVE_NA_XATTRS, 1, [True if you don't have extended attributes])
83 + AC_DEFINE(HAVE_NO_XATTRL, 1, [True if you don't have extended attributes])
86 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
89 --- orig/flist.c 2005-03-16 02:24:11
90 +++ flist.c 2005-05-12 22:55:41
91 @@ -976,6 +976,8 @@ static struct file_struct *send_file_nam
93 if (!MAKE_ACL(file, fname))
95 + if (!MAKE_XATTR(file, fname))
98 maybe_emit_filelist_progress(flist->count + flist_count_offset);
100 @@ -985,9 +987,11 @@ static struct file_struct *send_file_nam
101 flist->files[flist->count++] = file;
102 send_file_entry(file, f, base_flags);
104 + SEND_XATTR(file, f);
106 /* Cleanup unsent ACL(s). */
108 + SEND_XATTR(file, -1);
112 @@ -1325,6 +1329,7 @@ struct file_list *recv_file_list(int f)
113 file = receive_file_entry(flist, flags, f);
115 RECEIVE_ACL(file, f);
116 + RECEIVE_XATTR(file, f );
118 if (S_ISREG(file->mode))
119 stats.total_size += file->length;
120 @@ -1349,6 +1354,7 @@ struct file_list *recv_file_list(int f)
121 clean_flist(flist, relative_paths, 1);
123 SORT_FILE_ACL_INDEX_LISTS();
124 + SORT_FILE_XATTR_INDEX_LISTS();
127 /* Now send the uid/gid list. This was introduced in
128 --- orig/generator.c 2005-05-12 23:34:00
129 +++ generator.c 2005-05-12 23:21:08
130 @@ -723,6 +723,10 @@ static void recv_generator(char *fname,
132 SET_ACL(fname, file);
134 +#ifdef SUPPORT_XATTRS
136 + SET_XATTR(fname, file);
138 if (delete_during && f_out != -1 && !phase && dry_run < 2
139 && (file->flags & FLAG_DEL_HERE))
140 delete_in_dir(the_file_list, fname, file);
141 --- orig/lib/sysxattr.c 2005-05-12 23:23:15
142 +++ lib/sysxattr.c 2005-05-12 23:23:15
144 +/* Extended attribute support for rsync. */
145 +/* This file Copyright (C) 2004 Red Hat, Inc. */
146 +/* Written by Jay Fenlason */
148 +/* This program is free software; you can redistribute it and/or modify
149 + it under the terms of the GNU General Public License as published by
150 + the Free Software Foundation; either version 2 of the License, or
151 + (at your option) any later version.
153 + This program is distributed in the hope that it will be useful,
154 + but WITHOUT ANY WARRANTY; without even the implied warranty of
155 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
156 + GNU General Public License for more details.
158 + You should have received a copy of the GNU General Public License
159 + along with this program; if not, write to the Free Software
160 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
165 +#if defined(HAVE_LINUX_XATTRS)
167 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
169 + return lgetxattr(path, name, value, size);
172 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
174 + return lsetxattr(path, name, value, size, flags);
177 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
179 + return llistxattr(path, list, size);
184 +#endif /* No xattrs */
185 --- orig/lib/sysxattr.h 2005-05-12 23:56:31
186 +++ lib/sysxattr.h 2005-05-12 23:56:31
188 +#if defined(HAVE_LINUX_XATTRS)
190 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
191 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
192 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
196 +#endif /* No xattrs */
197 --- orig/options.c 2005-05-12 23:34:38
198 +++ options.c 2005-05-12 23:21:25
199 @@ -44,6 +44,7 @@ int copy_links = 0;
200 int preserve_links = 0;
201 int preserve_hard_links = 0;
202 int preserve_acls = 0;
203 +int preserve_xattrs = 0;
204 int preserve_perms = 0;
205 int preserve_devices = 0;
206 int preserve_uid = 0;
207 @@ -182,6 +183,7 @@ static void print_rsync_version(enum log
208 char const *have_inplace = "no ";
209 char const *hardlinks = "no ";
210 char const *acls = "no ";
211 + char const *xattrs = "no ";
212 char const *links = "no ";
213 char const *ipv6 = "no ";
214 STRUCT_STAT *dumstat;
215 @@ -201,7 +203,9 @@ static void print_rsync_version(enum log
220 +#ifdef SUPPORT_XATTRS
226 @@ -216,9 +220,9 @@ static void print_rsync_version(enum log
227 "Copyright (C) 1996-2005 by Andrew Tridgell and others\n");
228 rprintf(f, "<http://rsync.samba.org/>\n");
229 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
230 - "%shard links, %sACLs, %ssymlinks, batchfiles, \n",
231 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles, \n",
232 (int) (sizeof (OFF_T) * 8),
233 - got_socketpair, hardlinks, acls, links);
234 + got_socketpair, hardlinks, acls, xattrs, links);
236 /* Note that this field may not have type ino_t. It depends
237 * on the complicated interaction between largefile feature
238 @@ -289,6 +293,7 @@ void usage(enum logcode F)
239 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
240 rprintf(F," -p, --perms preserve permissions\n");
241 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
242 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
243 rprintf(F," -o, --owner preserve owner (root only)\n");
244 rprintf(F," -g, --group preserve group\n");
245 rprintf(F," -D, --devices preserve devices (root only)\n");
246 @@ -416,6 +421,7 @@ static struct poptOption long_options[]
247 {"copy-unsafe-links",0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 },
248 {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 },
249 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
250 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
251 {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 },
252 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
253 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
254 @@ -901,6 +907,17 @@ int parse_arguments(int *argc, const cha
255 #endif /* SUPPORT_ACLS */
259 +#ifdef SUPPORT_XATTRS
260 + preserve_xattrs = 1;
261 + preserve_perms = 1;
263 + snprintf(err_buf,sizeof(err_buf),
264 + "extended attributes are not supported on this %s\n",
265 + am_server ? "server" : "client");
267 +#endif /* SUPPORT_XATTRS */
271 /* A large opt value means that set_refuse_options()
272 @@ -1310,6 +1327,8 @@ void server_options(char **args,int *arg
276 + if (preserve_xattrs)
281 --- orig/rsync.c 2004-07-03 20:11:58
282 +++ rsync.c 2005-03-03 01:31:22
283 @@ -144,6 +144,14 @@ int set_perms(char *fname,struct file_st
284 if (SET_ACL(fname, file) == 0)
287 + /* If this is a directory, SET_XATTR() will be called on the cleanup
288 + * receive_generator() pass--if we called it here, we might clobber
289 + * writability on the directory (SELinux security contexts are stored
290 + * in xattrs). everything else is OK to do now. */
291 + if (!S_ISDIR(st->st_mode)) {
292 + if (SET_XATTR(fname, file) == 0)
296 if (verbose > 1 && flags & PERMS_REPORT) {
297 enum logcode code = daemon_log_format_has_i || dry_run
298 --- orig/rsync.h 2005-05-12 23:32:56
299 +++ rsync.h 2005-05-12 23:19:46
300 @@ -676,6 +676,38 @@ struct stats {
301 #endif /* SUPPORT_ACLS */
302 #include "smb_acls.h"
304 +#ifdef HAVE_LINUX_XATTRS
305 +#define SUPPORT_XATTRS 1
308 +#ifdef SUPPORT_XATTRS
309 +#ifdef HAVE_ATTR_XATTR_H
310 +#include <attr/xattr.h>
312 +#define MAKE_XATTR(file, fname) make_xattr(file, fname)
313 +#define SEND_XATTR(file, f) send_xattr(file, f)
314 +#define RECEIVE_XATTR(file, f) receive_xattr(file, f)
315 +#define SORT_FILE_XATTR_INDEX_LISTS() sort_file_xattr_index_lists()
316 +#define SET_XATTR(fname, file) set_xattr(fname, file)
317 +#define NEXT_XATTR_UID() next_xattr_uid()
318 +#define XATTR_UID_MAP(uid) xattr_uid_map(uid)
319 +#define PUSH_KEEP_BACKUP_XATTR(file, orig, dest) \
320 + push_keep_backup_xattr(file, orig, dest)
321 +#define CLEANUP_KEEP_BACKUP_XATTR() cleanup_keep_backup_xattr()
322 +#define DUP_XATTR(orig, dest) dup_xattr(orig, dest)
323 +#else /* SUPPORT_XATTRS */
324 +#define MAKE_XATTR(file, fname) 1 /* checked return value */
325 +#define SEND_XATTR(file, f)
326 +#define RECEIVE_XATTR(file, f)
327 +#define SORT_FILE_XATTR_INDEX_LISTS()
328 +#define SET_XATTR(fname, file) 0 /* checked return value */
329 +#define NEXT_XATTR_UID()
330 +#define XATTR_UID_MAP(uid)
331 +#define PUSH_KEEP_BACKUP_XATTR(file, orig, dest)
332 +#define CLEANUP_KEEP_BACKUP_XATTR()
333 +#define DUP_XATTR(src, orig) 0 /* checked return value */
334 +#endif /* SUPPORT_XATTRS */
338 /* We have replacement versions of these if they're missing. */
339 --- orig/rsync.yo 2004-07-03 20:11:58
340 +++ rsync.yo 2005-03-03 01:33:53
341 @@ -318,6 +318,7 @@ to the detailed description below for a
342 -K, --keep-dirlinks treat symlinked dir on receiver as dir
343 -p, --perms preserve permissions
344 -A, --acls preserve ACLs (implies -p) [local option]
345 + -X, --xattrs preserve extended attributes (implies -p) [local option]
346 -o, --owner preserve owner (root only)
347 -g, --group preserve group
348 -D, --devices preserve devices (root only)
349 @@ -635,6 +636,11 @@ ACLs to be the same as the local ACLs.
350 remote machine's rsync supports this option also. This is a non-standard
353 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
354 +extended attributes to be the same as the local ones. This will work
355 +only if the remote machine's rsync supports this option also. This is
356 +a non-standard option.
358 dit(bf(-o, --owner)) This option causes rsync to set the owner of the
359 destination file to be the same as the source file. On most systems,
360 only the super-user can set file ownership. By default, the preservation
361 --- orig/xattr.c 2005-05-13 06:10:34
362 +++ xattr.c 2005-05-13 06:10:34
364 +/* Extended Attribute support for rsync */
365 +/* Copyright (C) 2004 Red Hat, Inc */
366 +/* Written by Jay Fenlason, vaguely based on the ACLs patch */
368 +/* This program is free software; you can redistribute it and/or modify
369 + it under the terms of the GNU General Public License as published by
370 + the Free Software Foundation; either version 2 of the License, or
371 + (at your option) any later version.
373 + This program is distributed in the hope that it will be useful,
374 + but WITHOUT ANY WARRANTY; without even the implied warranty of
375 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376 + GNU General Public License for more details.
378 + You should have received a copy of the GNU General Public License
379 + along with this program; if not, write to the Free Software
380 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
384 +#include "lib/sysxattr.h"
386 +#ifdef SUPPORT_XATTRS
388 +extern int preserve_xattrs;
391 +#define RSYNC_XAL_INITIAL 5
392 +#define RSYNC_XAL_LIST_INITIAL 100
413 +static size_t namebuf_len = 0;
414 +static char *namebuf = NULL;
416 +static size_t datumbuf_len = 0;
417 +static char *datumbuf = NULL;
419 +static rsync_xal curr_rsync_xal = { 0, 0, NULL };
420 +static rsync_xal_list rsync_xal_l = { 0, 0, NULL };
423 +/* ------------------------------------------------------------------------- */
425 +/* the below stuff is only used by the receiver */
427 +/* structure to hold index to rsync_xal_l member corresponding to
428 + * flist->files[i] */
431 + const struct file_struct *file;
438 + file_xal_index *filexalidxs;
439 +} file_xal_index_list;
441 +static file_xal_index_list fxil = {0, 0, NULL };
443 +/* stuff for redirecting calls to set_acl() from set_perms()
444 + * for keep_backup() */
445 +static const struct file_struct *backup_orig_file = NULL;
446 +static const char null_string[] = "";
447 +static const char *backup_orig_fname = null_string;
448 +static const char *backup_dest_fname = null_string;
449 +static rsync_xal backup_xal;
451 +/* ------------------------------------------------------------------------- */
453 +static void rsync_xal_free(rsync_xal *x)
457 + for (i = 0; i < x->count; i++) {
458 + free(x->rxas[i].name);
459 + /* free(x->rxas[i].value); */
464 +static int rsync_xal_compare_names(const void *x1, const void *x2)
466 + const rsync_xa *xa1;
467 + const rsync_xa *xa2;
471 + return strcmp(xa1->name, xa2->name);
474 +static BOOL rsync_xal_get(const char *fname, rsync_xal *x)
477 + ssize_t datum_size;
485 + namebuf = new_array(char, namebuf_len);
486 + datumbuf_len = 100;
487 + datumbuf = new_array(char, datumbuf_len);
488 + if (!namebuf || !datumbuf)
489 + out_of_memory("rsync_xal_get");
492 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
493 + if (name_size > (ssize_t)namebuf_len) {
497 + if (name_size < 0) {
498 + if (errno == ENOTSUP)
500 + if (errno == ERANGE) {
501 + name_size = sys_llistxattr(fname, NULL, 0);
502 + if (name_size < 0) {
503 + rprintf(FERROR, "%s: rsync_xal_get: llistxattr: %s\n",
504 + fname, strerror(errno));
507 + namebuf = realloc_array(namebuf, char, name_size + 1);
509 + out_of_memory("rsync_xal_get");
510 + namebuf_len = name_size;
511 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
512 + if (name_size < 0) {
514 + "%s: rsync_xal_get: re-llistxattr failed: %s\n",
515 + fname, strerror(errno));
520 + "%s: rsync_xal_get: llistxattr failed: %s\n",
521 + fname, strerror(errno));
526 + if (name_size == 0)
528 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
529 + len = strlen(name) + 1;
531 + if (x->count >= x->alloc) {
533 + rsync_xa *new_rxas;
535 + new_alloc = x->alloc < RSYNC_XAL_INITIAL ? RSYNC_XAL_INITIAL : x->alloc * 2;
536 + new_rxas = realloc_array(x->rxas, rsync_xa, new_alloc);
538 + out_of_memory("rsync_xal_get");
539 + x->alloc = new_alloc;
540 + x->rxas = new_rxas;
542 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
543 + if (datum_size > (ssize_t)datumbuf_len) {
547 + if (datum_size < 0) {
548 + if (errno == ENOTSUP)
550 + if (errno == ERANGE) {
551 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
552 + if (datum_size < 0) {
554 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
555 + fname, name, strerror(errno));
558 + datumbuf = realloc_array(datumbuf, char, datum_size + 1);
560 + out_of_memory("rsync_xal_get");
561 + datumbuf_len = datum_size;
562 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
563 + if (datum_size < 0) {
565 + "%s: rsync_xal_get: re-lgetxattr of %s failed: %s\n",
566 + name, fname, strerror(errno));
571 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
572 + fname, name, strerror(errno));
576 + ptr = new_array(char, len + datum_size);
578 + out_of_memory("rsync_xal_get");
581 + memcpy(ptr + len, datumbuf, datum_size);
582 + x->rxas[curr_rsync_xal.count].name_len = len;
583 + x->rxas[curr_rsync_xal.count].name = ptr;
584 + x->rxas[curr_rsync_xal.count].datum_len = datum_size;
585 + x->rxas[curr_rsync_xal.count].datum = ptr + len;
588 + if (x->count > 1) {
589 + qsort(x->rxas, x->count, sizeof (rsync_xa), rsync_xal_compare_names);
595 +/* generate the xattr(s) for this flist entry;
596 + * xattr(s) are either sent or cleaned-up by send_xattr() below */
598 +BOOL make_xattr(const struct file_struct *file, const char *fname)
600 + if (!preserve_xattrs || !file)
603 + rsync_xal_get(fname, &curr_rsync_xal);
607 +static ssize_t rsync_xal_find_matching(void)
612 + for (i = 0; i < rsync_xal_l.count; i++) {
613 + /* Wrong number of elements? */
614 + if (rsync_xal_l.rxals[i].count != curr_rsync_xal.count)
616 + /* any elements different? */
617 + for (j = 0; j < curr_rsync_xal.count; j++) {
618 + if (rsync_xal_l.rxals[i].rxas[j].name_len != curr_rsync_xal.rxas[j].name_len
619 + || rsync_xal_l.rxals[i].rxas[j].datum_len != curr_rsync_xal.rxas[j].datum_len
620 + || strcmp(rsync_xal_l.rxals[i].rxas[j].name, curr_rsync_xal.rxas[j].name)
621 + || memcmp(rsync_xal_l.rxals[i].rxas[j].datum, curr_rsync_xal.rxas[j].datum, curr_rsync_xal.rxas[j].datum_len))
624 + /* no differences found. This is The One! */
625 + if (j == curr_rsync_xal.count)
628 + if (i < rsync_xal_l.count)
630 + return (ssize_t)-1;
633 +/* Store curr_rsync_xal on the end of rsync_xal_l */
634 +static void rsync_xal_store(void)
636 + if (rsync_xal_l.count <= rsync_xal_l.alloc) {
640 + new_alloc = rsync_xal_l.count < RSYNC_XAL_LIST_INITIAL ? RSYNC_XAL_LIST_INITIAL : rsync_xal_l.count * 2;
641 + new_xal = realloc_array(rsync_xal_l.rxals, rsync_xal, new_alloc);
643 + out_of_memory("rsync_xal_store");
644 + rsync_xal_l.alloc = new_alloc;
645 + rsync_xal_l.rxals = new_xal;
647 + rsync_xal_l.rxals[rsync_xal_l.count] = curr_rsync_xal;
648 + rsync_xal_l.count++;
649 + curr_rsync_xal.count = 0;
650 + curr_rsync_xal.alloc = 0;
653 +/* send the make_xattr()-generated xattr list for this flist entry,
654 + * or clean up after an flist entry that's not being sent (f == -1) */
656 +void send_xattr(const struct file_struct *file, int f)
660 + if (!preserve_xattrs || !file)
664 + rsync_xal_free(&curr_rsync_xal);
667 + index = rsync_xal_find_matching();
669 + write_byte(f, 'x');
670 + write_int(f, index);
671 + rsync_xal_free(&curr_rsync_xal);
676 + count = curr_rsync_xal.count;
677 + write_byte(f, 'X');
678 + write_int(f, count);
679 + for (rxa = curr_rsync_xal.rxas; count--; rxa++) {
680 + write_int(f, rxa->name_len);
681 + write_int(f, rxa->datum_len);
682 + write_buf(f, rxa->name, rxa->name_len);
683 + write_buf(f, rxa->datum, rxa->datum_len);
690 +/* ------------------------------------------------------------------------- */
691 +/* receive and build the rsync_xattr_lists */
693 +void receive_xattr(struct file_struct *file, int f)
698 + if (!preserve_xattrs)
700 + fname = f_name(file);
701 + tag = read_byte(f);
702 + if (tag != 'X' && tag != 'x') {
704 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
706 + exit_cleanup(RERR_STREAMIO);
709 + if (fxil.alloc <= fxil.count) {
713 + if (fxil.count < RSYNC_XAL_LIST_INITIAL)
714 + new_alloc = fxil.alloc + RSYNC_XAL_LIST_INITIAL;
716 + new_alloc = fxil.alloc * 2;
717 + new_ptr = realloc_array(fxil.filexalidxs, file_xal_index, new_alloc);
719 + out_of_memory("receive_xattr");
720 + if (verbose >= 3) {
721 + rprintf(FINFO, "receive_xattr to %lu bytes, %s move\n",
722 + (unsigned long)(new_alloc * sizeof (file_xal_index)),
723 + fxil.filexalidxs == new_ptr ? "did not" : "did");
726 + fxil.filexalidxs = new_ptr;
727 + fxil.alloc = new_alloc;
730 + fxil.filexalidxs[fxil.count].file = file;
735 + fxil.filexalidxs[fxil.count].xalidx = rsync_xal_l.count;
737 + count = read_int(f);
738 + curr_rsync_xal.count = count;
739 + curr_rsync_xal.alloc = count;
740 + curr_rsync_xal.rxas = new_array(rsync_xa, count);
741 + if (!curr_rsync_xal.rxas)
742 + out_of_memory("receive_xattr");
743 + for (i = 0; i < count; i++) {
748 + name_len = read_int(f);
749 + datum_len = read_int(f);
750 + ptr = new_array(char, name_len + datum_len);
752 + out_of_memory("receive_xattr");
753 + read_buf(f, ptr, name_len);
754 + read_buf(f, ptr + name_len, datum_len);
755 + curr_rsync_xal.rxas[i].name_len = name_len;
756 + curr_rsync_xal.rxas[i].datum_len = datum_len;
757 + curr_rsync_xal.rxas[i].name = ptr;
758 + curr_rsync_xal.rxas[i].datum = ptr + name_len;
764 + index = read_int(f);
765 + if (index >= rsync_xal_l.count) {
766 + rprintf(FERROR, "%s: receive_xattr: xa index %lu out of range\n",
767 +fname, (unsigned long)index);
768 + exit_cleanup(RERR_STREAMIO);
770 + fxil.filexalidxs[fxil.count].xalidx = index;
775 +static BOOL rsync_xal_set(const char *fname, rsync_xal *x)
782 + for (i = 0; i < x->count; i++) {
783 + status = sys_lsetxattr(fname, x->rxas[i].name, x->rxas[i].datum, x->rxas[i].datum_len, 0);
785 + rprintf(FERROR, "%s: rsync_xal_set: lsetxattr %s failed: %s\n",
786 + fname, x->rxas[i].name, strerror(errno));
793 +/* for duplicating xattrs on backups when using backup_dir */
795 +int dup_xattr(const char *orig, const char *bak)
800 + if (!preserve_xattrs)
803 + ret = rsync_xal_get(orig, &backup_xal);
805 + ret = rsync_xal_set(bak, &backup_xal);
806 + rsync_xal_free(&backup_xal);
810 +void push_keep_backup_xattr(const struct file_struct *file, const char *orig, const char *dest)
812 + if (!preserve_xattrs)
815 + backup_orig_file = file;
816 + backup_orig_fname = orig;
817 + backup_dest_fname = dest;
818 + rsync_xal_get(orig, &backup_xal);
821 +static int set_keep_backup_xal(void)
823 + if (!preserve_xattrs)
825 + return rsync_xal_set(backup_dest_fname, &backup_xal);
828 +void cleanup_keep_backup_xattr(void)
830 + if (!preserve_xattrs)
833 + backup_orig_file = NULL;
834 + backup_orig_fname = null_string;
835 + backup_dest_fname = null_string;
836 + rsync_xal_free(&backup_xal);
839 +static int file_xal_index_compare(const void *x1, const void *x2)
841 + const file_xal_index *xa1;
842 + const file_xal_index *xa2;
846 + return xa1->file == xa2->file ? 0 : xa1->file < xa2->file ? -1 : 1;
849 +void sort_file_xattr_index_lists(void)
851 + if (!preserve_xattrs)
853 + qsort(fxil.filexalidxs, fxil.count, sizeof (file_xal_index), file_xal_index_compare);
856 +static int find_file_xal_index(const struct file_struct *file)
858 + int low = 0, high = fxil.count;
859 + const struct file_struct *file_mid;
862 + rprintf(FERROR, "find_file_xal_index: no entries\n");
863 + exit_cleanup(RERR_STREAMIO);
867 + int mid = (high + low) / 2;
868 + file_mid = fxil.filexalidxs[mid].file;
869 + if (file_mid == file)
870 + return fxil.filexalidxs[mid].xalidx;
871 + if (file_mid > file)
875 + } while (low < high);
877 + file_mid = fxil.filexalidxs[low].file;
878 + if (file_mid == file)
879 + return fxil.filexalidxs[low].xalidx;
882 + "find_file_xal_index: can't find entry for file in list\n");
883 + exit_cleanup(RERR_STREAMIO);
888 +/* set extended attributes on rsync-ed or keep_backup-ed file */
890 +int set_xattr(const char *fname, const struct file_struct *file)
897 + if (dry_run || !preserve_xattrs)
899 + if (file == backup_orig_file) {
900 + if (!strcmp(fname, backup_dest_fname))
901 + return set_keep_backup_xal();
903 + xalidx = find_file_xal_index(file);
904 + x = &(rsync_xal_l.rxals[xalidx]);
905 + updated = rsync_xal_set(fname, x);
909 +#endif /* SUPPORT_XATTRS */