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 2005-07-07 23:11:55
12 +++ Makefile.in 2005-07-07 23:15:20
13 @@ -27,13 +27,13 @@ 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/inffast.o zlib/inflate.o zlib/inftrees.o \
20 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
21 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
22 main.o checksum.o match.o syscall.o log.o backup.o
23 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
24 - fileio.o batch.o clientname.o acls.o
25 + fileio.o batch.o clientname.o acls.o xattr.o
26 OBJS3=progress.o pipe.o
27 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
28 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
29 --- orig/backup.c 2004-10-06 00:13:09
30 +++ backup.c 2005-03-03 01:20:46
31 @@ -136,6 +136,7 @@ static int make_bak_dir(char *fullpath)
32 do_lchown(fullpath, st.st_uid, st.st_gid);
33 do_chmod(fullpath, st.st_mode);
34 (void)DUP_ACL(end, fullpath, st.st_mode);
35 + (void)DUP_XATTR(end, fullpath );
39 @@ -189,6 +190,7 @@ static int keep_backup(char *fname)
42 PUSH_KEEP_BACKUP_ACL(file, fname, buf);
43 + PUSH_KEEP_BACKUP_XATTR(file, fname, buf);
45 /* Check to see if this is a device file, or link */
46 if (IS_DEVICE(file->mode) && am_root && preserve_devices) {
47 @@ -265,6 +267,7 @@ static int keep_backup(char *fname)
49 set_perms(buf, file, NULL, 0);
50 CLEANUP_KEEP_BACKUP_ACL();
51 + CLEANUP_KEEP_BACKUP_XATTR();
55 --- orig/configure.in 2004-08-19 19:53:27
56 +++ configure.in 2005-05-12 22:57:53
57 @@ -821,6 +821,30 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
61 +AC_CHECK_HEADERS(attr/xattr.h)
62 +AC_MSG_CHECKING(whether to support extended attributes)
63 +AC_ARG_WITH(xattr-support,
64 +[ --with-xattr-support Include extended attribute support (default=no)],
69 + AC_MSG_RESULT(Using Linux xattrs)
70 + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs])
73 + AC_MSG_RESULT(Xattrs requested but not linux. Good luck)
79 + AC_DEFINE(HAVE_NA_XATTRS, 1, [True if you don't have extended attributes])
82 + AC_DEFINE(HAVE_NO_XATTRL, 1, [True if you don't have extended attributes])
85 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
88 --- orig/flist.c 2005-03-16 02:24:11
89 +++ flist.c 2005-05-12 22:55:41
90 @@ -976,6 +976,8 @@ static struct file_struct *send_file_nam
92 if (!MAKE_ACL(file, fname))
94 + if (!MAKE_XATTR(file, fname))
97 maybe_emit_filelist_progress(flist->count + flist_count_offset);
99 @@ -985,9 +987,11 @@ static struct file_struct *send_file_nam
100 flist->files[flist->count++] = file;
101 send_file_entry(file, f, base_flags);
103 + SEND_XATTR(file, f);
105 /* Cleanup unsent ACL(s). */
107 + SEND_XATTR(file, -1);
111 @@ -1325,6 +1329,7 @@ struct file_list *recv_file_list(int f)
112 file = receive_file_entry(flist, flags, f);
114 RECEIVE_ACL(file, f);
115 + RECEIVE_XATTR(file, f );
117 if (S_ISREG(file->mode))
118 stats.total_size += file->length;
119 @@ -1349,6 +1354,7 @@ struct file_list *recv_file_list(int f)
120 clean_flist(flist, relative_paths, 1);
122 SORT_FILE_ACL_INDEX_LISTS();
123 + SORT_FILE_XATTR_INDEX_LISTS();
126 /* Now send the uid/gid list. This was introduced in
127 --- orig/generator.c 2005-05-12 23:34:00
128 +++ generator.c 2005-05-12 23:21:08
129 @@ -720,6 +720,10 @@ static void recv_generator(char *fname,
131 SET_ACL(fname, file);
133 +#ifdef SUPPORT_XATTRS
135 + SET_XATTR(fname, file);
137 if (delete_during && f_out != -1 && !phase && dry_run < 2
138 && (file->flags & FLAG_DEL_HERE))
139 delete_in_dir(the_file_list, fname, file);
140 --- orig/lib/sysxattr.c 2005-05-12 23:23:15
141 +++ lib/sysxattr.c 2005-05-12 23:23:15
143 +/* Extended attribute support for rsync. */
144 +/* This file Copyright (C) 2004 Red Hat, Inc. */
145 +/* Written by Jay Fenlason */
147 +/* This program is free software; you can redistribute it and/or modify
148 + it under the terms of the GNU General Public License as published by
149 + the Free Software Foundation; either version 2 of the License, or
150 + (at your option) any later version.
152 + This program is distributed in the hope that it will be useful,
153 + but WITHOUT ANY WARRANTY; without even the implied warranty of
154 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155 + GNU General Public License for more details.
157 + You should have received a copy of the GNU General Public License
158 + along with this program; if not, write to the Free Software
159 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
164 +#if defined(HAVE_LINUX_XATTRS)
166 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
168 + return lgetxattr(path, name, value, size);
171 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
173 + return lsetxattr(path, name, value, size, flags);
176 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
178 + return llistxattr(path, list, size);
183 +#endif /* No xattrs */
184 --- orig/lib/sysxattr.h 2005-05-12 23:56:31
185 +++ lib/sysxattr.h 2005-05-12 23:56:31
187 +#if defined(HAVE_LINUX_XATTRS)
189 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
190 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
191 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
195 +#endif /* No xattrs */
196 --- orig/options.c 2005-05-12 23:34:38
197 +++ options.c 2005-05-12 23:21:25
198 @@ -44,6 +44,7 @@ int copy_links = 0;
199 int preserve_links = 0;
200 int preserve_hard_links = 0;
201 int preserve_acls = 0;
202 +int preserve_xattrs = 0;
203 int preserve_perms = 0;
204 int preserve_devices = 0;
205 int preserve_uid = 0;
206 @@ -182,6 +183,7 @@ static void print_rsync_version(enum log
207 char const *have_inplace = "no ";
208 char const *hardlinks = "no ";
209 char const *acls = "no ";
210 + char const *xattrs = "no ";
211 char const *links = "no ";
212 char const *ipv6 = "no ";
213 STRUCT_STAT *dumstat;
214 @@ -201,7 +203,9 @@ static void print_rsync_version(enum log
219 +#ifdef SUPPORT_XATTRS
225 @@ -216,9 +220,9 @@ static void print_rsync_version(enum log
226 "Copyright (C) 1996-2005 by Andrew Tridgell and others\n");
227 rprintf(f, "<http://rsync.samba.org/>\n");
228 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
229 - "%shard links, %sACLs, %ssymlinks, batchfiles, \n",
230 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles, \n",
231 (int) (sizeof (OFF_T) * 8),
232 - got_socketpair, hardlinks, acls, links);
233 + got_socketpair, hardlinks, acls, xattrs, links);
235 /* Note that this field may not have type ino_t. It depends
236 * on the complicated interaction between largefile feature
237 @@ -289,6 +293,7 @@ void usage(enum logcode F)
238 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
239 rprintf(F," -p, --perms preserve permissions\n");
240 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
241 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
242 rprintf(F," -o, --owner preserve owner (root only)\n");
243 rprintf(F," -g, --group preserve group\n");
244 rprintf(F," -D, --devices preserve devices (root only)\n");
245 @@ -416,6 +421,7 @@ static struct poptOption long_options[]
246 {"copy-unsafe-links",0, POPT_ARG_NONE, ©_unsafe_links, 0, 0, 0 },
247 {"perms", 'p', POPT_ARG_NONE, &preserve_perms, 0, 0, 0 },
248 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
249 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
250 {"owner", 'o', POPT_ARG_NONE, &preserve_uid, 0, 0, 0 },
251 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
252 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
253 @@ -901,6 +907,17 @@ int parse_arguments(int *argc, const cha
254 #endif /* SUPPORT_ACLS */
258 +#ifdef SUPPORT_XATTRS
259 + preserve_xattrs = 1;
260 + preserve_perms = 1;
262 + snprintf(err_buf,sizeof(err_buf),
263 + "extended attributes are not supported on this %s\n",
264 + am_server ? "server" : "client");
266 +#endif /* SUPPORT_XATTRS */
270 /* A large opt value means that set_refuse_options()
271 @@ -1310,6 +1327,8 @@ void server_options(char **args,int *arg
275 + if (preserve_xattrs)
280 --- orig/rsync.c 2004-07-03 20:11:58
281 +++ rsync.c 2005-03-03 01:31:22
282 @@ -144,6 +144,14 @@ int set_perms(char *fname,struct file_st
283 if (SET_ACL(fname, file) == 0)
286 + /* If this is a directory, SET_XATTR() will be called on the cleanup
287 + * receive_generator() pass--if we called it here, we might clobber
288 + * writability on the directory (SELinux security contexts are stored
289 + * in xattrs). everything else is OK to do now. */
290 + if (!S_ISDIR(st->st_mode)) {
291 + if (SET_XATTR(fname, file) == 0)
295 if (verbose > 1 && flags & PERMS_REPORT) {
296 enum logcode code = daemon_log_format_has_i || dry_run
297 --- orig/rsync.h 2005-05-12 23:32:56
298 +++ rsync.h 2005-05-12 23:19:46
299 @@ -676,6 +676,38 @@ struct stats {
300 #endif /* SUPPORT_ACLS */
301 #include "smb_acls.h"
303 +#ifdef HAVE_LINUX_XATTRS
304 +#define SUPPORT_XATTRS 1
307 +#ifdef SUPPORT_XATTRS
308 +#ifdef HAVE_ATTR_XATTR_H
309 +#include <attr/xattr.h>
311 +#define MAKE_XATTR(file, fname) make_xattr(file, fname)
312 +#define SEND_XATTR(file, f) send_xattr(file, f)
313 +#define RECEIVE_XATTR(file, f) receive_xattr(file, f)
314 +#define SORT_FILE_XATTR_INDEX_LISTS() sort_file_xattr_index_lists()
315 +#define SET_XATTR(fname, file) set_xattr(fname, file)
316 +#define NEXT_XATTR_UID() next_xattr_uid()
317 +#define XATTR_UID_MAP(uid) xattr_uid_map(uid)
318 +#define PUSH_KEEP_BACKUP_XATTR(file, orig, dest) \
319 + push_keep_backup_xattr(file, orig, dest)
320 +#define CLEANUP_KEEP_BACKUP_XATTR() cleanup_keep_backup_xattr()
321 +#define DUP_XATTR(orig, dest) dup_xattr(orig, dest)
322 +#else /* SUPPORT_XATTRS */
323 +#define MAKE_XATTR(file, fname) 1 /* checked return value */
324 +#define SEND_XATTR(file, f)
325 +#define RECEIVE_XATTR(file, f)
326 +#define SORT_FILE_XATTR_INDEX_LISTS()
327 +#define SET_XATTR(fname, file) 0 /* checked return value */
328 +#define NEXT_XATTR_UID()
329 +#define XATTR_UID_MAP(uid)
330 +#define PUSH_KEEP_BACKUP_XATTR(file, orig, dest)
331 +#define CLEANUP_KEEP_BACKUP_XATTR()
332 +#define DUP_XATTR(src, orig) 0 /* checked return value */
333 +#endif /* SUPPORT_XATTRS */
337 /* We have replacement versions of these if they're missing. */
338 --- orig/rsync.yo 2004-07-03 20:11:58
339 +++ rsync.yo 2005-03-03 01:33:53
340 @@ -307,6 +307,7 @@ to the detailed description below for a
341 -K, --keep-dirlinks treat symlinked dir on receiver as dir
342 -p, --perms preserve permissions
343 -A, --acls preserve ACLs (implies -p) [local option]
344 + -X, --xattrs preserve extended attributes (implies -p) [local option]
345 -o, --owner preserve owner (root only)
346 -g, --group preserve group
347 -D, --devices preserve devices (root only)
348 @@ -624,6 +625,11 @@ ACLs to be the same as the local ACLs.
349 remote machine's rsync supports this option also. This is a non-standard
352 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
353 +extended attributes to be the same as the local ones. This will work
354 +only if the remote machine's rsync supports this option also. This is
355 +a non-standard option.
357 dit(bf(-o, --owner)) This option causes rsync to set the owner of the
358 destination file to be the same as the source file. On most systems,
359 only the super-user can set file ownership. By default, the preservation
360 --- orig/xattr.c 2005-05-13 06:10:34
361 +++ xattr.c 2005-05-13 06:10:34
363 +/* Extended Attribute support for rsync */
364 +/* Copyright (C) 2004 Red Hat, Inc */
365 +/* Written by Jay Fenlason, vaguely based on the ACLs patch */
367 +/* This program is free software; you can redistribute it and/or modify
368 + it under the terms of the GNU General Public License as published by
369 + the Free Software Foundation; either version 2 of the License, or
370 + (at your option) any later version.
372 + This program is distributed in the hope that it will be useful,
373 + but WITHOUT ANY WARRANTY; without even the implied warranty of
374 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
375 + GNU General Public License for more details.
377 + You should have received a copy of the GNU General Public License
378 + along with this program; if not, write to the Free Software
379 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
383 +#include "lib/sysxattr.h"
385 +#ifdef SUPPORT_XATTRS
387 +extern int preserve_xattrs;
390 +#define RSYNC_XAL_INITIAL 5
391 +#define RSYNC_XAL_LIST_INITIAL 100
412 +static size_t namebuf_len = 0;
413 +static char *namebuf = NULL;
415 +static size_t datumbuf_len = 0;
416 +static char *datumbuf = NULL;
418 +static rsync_xal curr_rsync_xal = { 0, 0, NULL };
419 +static rsync_xal_list rsync_xal_l = { 0, 0, NULL };
422 +/* ------------------------------------------------------------------------- */
424 +/* the below stuff is only used by the receiver */
426 +/* structure to hold index to rsync_xal_l member corresponding to
427 + * flist->files[i] */
430 + const struct file_struct *file;
437 + file_xal_index *filexalidxs;
438 +} file_xal_index_list;
440 +static file_xal_index_list fxil = {0, 0, NULL };
442 +/* stuff for redirecting calls to set_acl() from set_perms()
443 + * for keep_backup() */
444 +static const struct file_struct *backup_orig_file = NULL;
445 +static const char null_string[] = "";
446 +static const char *backup_orig_fname = null_string;
447 +static const char *backup_dest_fname = null_string;
448 +static rsync_xal backup_xal;
450 +/* ------------------------------------------------------------------------- */
452 +static void rsync_xal_free(rsync_xal *x)
456 + for (i = 0; i < x->count; i++) {
457 + free(x->rxas[i].name);
458 + /* free(x->rxas[i].value); */
463 +static int rsync_xal_compare_names(const void *x1, const void *x2)
465 + const rsync_xa *xa1;
466 + const rsync_xa *xa2;
470 + return strcmp(xa1->name, xa2->name);
473 +static BOOL rsync_xal_get(const char *fname, rsync_xal *x)
476 + ssize_t datum_size;
484 + namebuf = new_array(char, namebuf_len);
485 + datumbuf_len = 100;
486 + datumbuf = new_array(char, datumbuf_len);
487 + if (!namebuf || !datumbuf)
488 + out_of_memory("rsync_xal_get");
491 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
492 + if (name_size > (ssize_t)namebuf_len) {
496 + if (name_size < 0) {
497 + if (errno == ENOTSUP)
499 + if (errno == ERANGE) {
500 + name_size = sys_llistxattr(fname, NULL, 0);
501 + if (name_size < 0) {
502 + rprintf(FERROR, "%s: rsync_xal_get: llistxattr: %s\n",
503 + fname, strerror(errno));
506 + namebuf = realloc_array(namebuf, char, name_size + 1);
508 + out_of_memory("rsync_xal_get");
509 + namebuf_len = name_size;
510 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
511 + if (name_size < 0) {
513 + "%s: rsync_xal_get: re-llistxattr failed: %s\n",
514 + fname, strerror(errno));
519 + "%s: rsync_xal_get: llistxattr failed: %s\n",
520 + fname, strerror(errno));
525 + if (name_size == 0)
527 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
528 + len = strlen(name) + 1;
530 + if (x->count >= x->alloc) {
532 + rsync_xa *new_rxas;
534 + new_alloc = x->alloc < RSYNC_XAL_INITIAL ? RSYNC_XAL_INITIAL : x->alloc * 2;
535 + new_rxas = realloc_array(x->rxas, rsync_xa, new_alloc);
537 + out_of_memory("rsync_xal_get");
538 + x->alloc = new_alloc;
539 + x->rxas = new_rxas;
541 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
542 + if (datum_size > (ssize_t)datumbuf_len) {
546 + if (datum_size < 0) {
547 + if (errno == ENOTSUP)
549 + if (errno == ERANGE) {
550 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
551 + if (datum_size < 0) {
553 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
554 + fname, name, strerror(errno));
557 + datumbuf = realloc_array(datumbuf, char, datum_size + 1);
559 + out_of_memory("rsync_xal_get");
560 + datumbuf_len = datum_size;
561 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
562 + if (datum_size < 0) {
564 + "%s: rsync_xal_get: re-lgetxattr of %s failed: %s\n",
565 + name, fname, strerror(errno));
570 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
571 + fname, name, strerror(errno));
575 + ptr = new_array(char, len + datum_size);
577 + out_of_memory("rsync_xal_get");
580 + memcpy(ptr + len, datumbuf, datum_size);
581 + x->rxas[curr_rsync_xal.count].name_len = len;
582 + x->rxas[curr_rsync_xal.count].name = ptr;
583 + x->rxas[curr_rsync_xal.count].datum_len = datum_size;
584 + x->rxas[curr_rsync_xal.count].datum = ptr + len;
587 + if (x->count > 1) {
588 + qsort(x->rxas, x->count, sizeof (rsync_xa), rsync_xal_compare_names);
594 +/* generate the xattr(s) for this flist entry;
595 + * xattr(s) are either sent or cleaned-up by send_xattr() below */
597 +BOOL make_xattr(const struct file_struct *file, const char *fname)
599 + if (!preserve_xattrs || !file)
602 + rsync_xal_get(fname, &curr_rsync_xal);
606 +static ssize_t rsync_xal_find_matching(void)
611 + for (i = 0; i < rsync_xal_l.count; i++) {
612 + /* Wrong number of elements? */
613 + if (rsync_xal_l.rxals[i].count != curr_rsync_xal.count)
615 + /* any elements different? */
616 + for (j = 0; j < curr_rsync_xal.count; j++) {
617 + if (rsync_xal_l.rxals[i].rxas[j].name_len != curr_rsync_xal.rxas[j].name_len
618 + || rsync_xal_l.rxals[i].rxas[j].datum_len != curr_rsync_xal.rxas[j].datum_len
619 + || strcmp(rsync_xal_l.rxals[i].rxas[j].name, curr_rsync_xal.rxas[j].name)
620 + || memcmp(rsync_xal_l.rxals[i].rxas[j].datum, curr_rsync_xal.rxas[j].datum, curr_rsync_xal.rxas[j].datum_len))
623 + /* no differences found. This is The One! */
624 + if (j == curr_rsync_xal.count)
627 + if (i < rsync_xal_l.count)
629 + return (ssize_t)-1;
632 +/* Store curr_rsync_xal on the end of rsync_xal_l */
633 +static void rsync_xal_store(void)
635 + if (rsync_xal_l.count <= rsync_xal_l.alloc) {
639 + new_alloc = rsync_xal_l.count < RSYNC_XAL_LIST_INITIAL ? RSYNC_XAL_LIST_INITIAL : rsync_xal_l.count * 2;
640 + new_xal = realloc_array(rsync_xal_l.rxals, rsync_xal, new_alloc);
642 + out_of_memory("rsync_xal_store");
643 + rsync_xal_l.alloc = new_alloc;
644 + rsync_xal_l.rxals = new_xal;
646 + rsync_xal_l.rxals[rsync_xal_l.count] = curr_rsync_xal;
647 + rsync_xal_l.count++;
648 + curr_rsync_xal.count = 0;
649 + curr_rsync_xal.alloc = 0;
652 +/* send the make_xattr()-generated xattr list for this flist entry,
653 + * or clean up after an flist entry that's not being sent (f == -1) */
655 +void send_xattr(const struct file_struct *file, int f)
659 + if (!preserve_xattrs || !file)
663 + rsync_xal_free(&curr_rsync_xal);
666 + index = rsync_xal_find_matching();
668 + write_byte(f, 'x');
669 + write_int(f, index);
670 + rsync_xal_free(&curr_rsync_xal);
675 + count = curr_rsync_xal.count;
676 + write_byte(f, 'X');
677 + write_int(f, count);
678 + for (rxa = curr_rsync_xal.rxas; count--; rxa++) {
679 + write_int(f, rxa->name_len);
680 + write_int(f, rxa->datum_len);
681 + write_buf(f, rxa->name, rxa->name_len);
682 + write_buf(f, rxa->datum, rxa->datum_len);
689 +/* ------------------------------------------------------------------------- */
690 +/* receive and build the rsync_xattr_lists */
692 +void receive_xattr(struct file_struct *file, int f)
697 + if (!preserve_xattrs)
699 + fname = f_name(file);
700 + tag = read_byte(f);
701 + if (tag != 'X' && tag != 'x') {
703 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
705 + exit_cleanup(RERR_STREAMIO);
708 + if (fxil.alloc <= fxil.count) {
712 + if (fxil.count < RSYNC_XAL_LIST_INITIAL)
713 + new_alloc = fxil.alloc + RSYNC_XAL_LIST_INITIAL;
715 + new_alloc = fxil.alloc * 2;
716 + new_ptr = realloc_array(fxil.filexalidxs, file_xal_index, new_alloc);
718 + out_of_memory("receive_xattr");
719 + if (verbose >= 3) {
720 + rprintf(FINFO, "receive_xattr to %lu bytes, %s move\n",
721 + (unsigned long)(new_alloc * sizeof (file_xal_index)),
722 + fxil.filexalidxs == new_ptr ? "did not" : "did");
725 + fxil.filexalidxs = new_ptr;
726 + fxil.alloc = new_alloc;
729 + fxil.filexalidxs[fxil.count].file = file;
734 + fxil.filexalidxs[fxil.count].xalidx = rsync_xal_l.count;
736 + count = read_int(f);
737 + curr_rsync_xal.count = count;
738 + curr_rsync_xal.alloc = count;
739 + curr_rsync_xal.rxas = new_array(rsync_xa, count);
740 + if (!curr_rsync_xal.rxas)
741 + out_of_memory("receive_xattr");
742 + for (i = 0; i < count; i++) {
747 + name_len = read_int(f);
748 + datum_len = read_int(f);
749 + ptr = new_array(char, name_len + datum_len);
751 + out_of_memory("receive_xattr");
752 + read_buf(f, ptr, name_len);
753 + read_buf(f, ptr + name_len, datum_len);
754 + curr_rsync_xal.rxas[i].name_len = name_len;
755 + curr_rsync_xal.rxas[i].datum_len = datum_len;
756 + curr_rsync_xal.rxas[i].name = ptr;
757 + curr_rsync_xal.rxas[i].datum = ptr + name_len;
763 + index = read_int(f);
764 + if (index >= rsync_xal_l.count) {
765 + rprintf(FERROR, "%s: receive_xattr: xa index %lu out of range\n",
766 +fname, (unsigned long)index);
767 + exit_cleanup(RERR_STREAMIO);
769 + fxil.filexalidxs[fxil.count].xalidx = index;
774 +static BOOL rsync_xal_set(const char *fname, rsync_xal *x)
781 + for (i = 0; i < x->count; i++) {
782 + status = sys_lsetxattr(fname, x->rxas[i].name, x->rxas[i].datum, x->rxas[i].datum_len, 0);
784 + rprintf(FERROR, "%s: rsync_xal_set: lsetxattr %s failed: %s\n",
785 + fname, x->rxas[i].name, strerror(errno));
792 +/* for duplicating xattrs on backups when using backup_dir */
794 +int dup_xattr(const char *orig, const char *bak)
799 + if (!preserve_xattrs)
802 + ret = rsync_xal_get(orig, &backup_xal);
804 + ret = rsync_xal_set(bak, &backup_xal);
805 + rsync_xal_free(&backup_xal);
809 +void push_keep_backup_xattr(const struct file_struct *file, const char *orig, const char *dest)
811 + if (!preserve_xattrs)
814 + backup_orig_file = file;
815 + backup_orig_fname = orig;
816 + backup_dest_fname = dest;
817 + rsync_xal_get(orig, &backup_xal);
820 +static int set_keep_backup_xal(void)
822 + if (!preserve_xattrs)
824 + return rsync_xal_set(backup_dest_fname, &backup_xal);
827 +void cleanup_keep_backup_xattr(void)
829 + if (!preserve_xattrs)
832 + backup_orig_file = NULL;
833 + backup_orig_fname = null_string;
834 + backup_dest_fname = null_string;
835 + rsync_xal_free(&backup_xal);
838 +static int file_xal_index_compare(const void *x1, const void *x2)
840 + const file_xal_index *xa1;
841 + const file_xal_index *xa2;
845 + return xa1->file == xa2->file ? 0 : xa1->file < xa2->file ? -1 : 1;
848 +void sort_file_xattr_index_lists(void)
850 + if (!preserve_xattrs)
852 + qsort(fxil.filexalidxs, fxil.count, sizeof (file_xal_index), file_xal_index_compare);
855 +static int find_file_xal_index(const struct file_struct *file)
857 + int low = 0, high = fxil.count;
858 + const struct file_struct *file_mid;
861 + rprintf(FERROR, "find_file_xal_index: no entries\n");
862 + exit_cleanup(RERR_STREAMIO);
866 + int mid = (high + low) / 2;
867 + file_mid = fxil.filexalidxs[mid].file;
868 + if (file_mid == file)
869 + return fxil.filexalidxs[mid].xalidx;
870 + if (file_mid > file)
874 + } while (low < high);
876 + file_mid = fxil.filexalidxs[low].file;
877 + if (file_mid == file)
878 + return fxil.filexalidxs[low].xalidx;
881 + "find_file_xal_index: can't find entry for file in list\n");
882 + exit_cleanup(RERR_STREAMIO);
887 +/* set extended attributes on rsync-ed or keep_backup-ed file */
889 +int set_xattr(const char *fname, const struct file_struct *file)
896 + if (dry_run || !preserve_xattrs)
898 + if (file == backup_orig_file) {
899 + if (!strcmp(fname, backup_dest_fname))
900 + return set_keep_backup_xal();
902 + xalidx = find_file_xal_index(file);
903 + x = &(rsync_xal_l.rxals[xalidx]);
904 + updated = rsync_xal_set(fname, x);
908 +#endif /* SUPPORT_XATTRS */