Commit | Line | Data |
---|---|---|
bbdff76a WD |
1 | Depends-On-Patch: acls.diff |
2 | ||
3 | After applying this patch, run these commands for a successful build: | |
4 | ||
27e96866 | 5 | ./prepare-source |
f787c90c | 6 | ./configure --enable-acl-support --enable-xattr-support |
bbdff76a WD |
7 | make |
8 | ||
0f6fb3c8 WD |
9 | TODO: |
10 | ||
11 | - This patch needs to be rewritten to more efficiently handle large xattrs. | |
12 | ||
13 | - We need to affect the itemized output to know when xattrs are being updated. | |
14 | ||
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). | |
17 | ||
9a7eef96 WD |
18 | --- old/Makefile.in |
19 | +++ new/Makefile.in | |
1ed0b5c9 | 20 | @@ -28,13 +28,13 @@ VERSION=@VERSION@ |
bbdff76a WD |
21 | |
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@ | |
4bf6f8c7 WD |
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 | |
bbdff76a WD |
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 \ | |
610969d1 WD |
31 | - fileio.o batch.o clientname.o chmod.o acls.o |
32 | + fileio.o batch.o clientname.o chmod.o acls.o xattr.o | |
bbdff76a WD |
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 \ | |
0f6fb3c8 WD |
36 | --- old/acls.c |
37 | +++ new/acls.c | |
38 | @@ -29,6 +29,7 @@ extern int am_root; | |
39 | extern int dry_run; | |
40 | extern int orig_umask; | |
41 | extern int preserve_acls; | |
42 | +extern int preserve_xattrs; | |
43 | extern unsigned int file_struct_len; | |
44 | ||
45 | /* === ACL structures === */ | |
4959107f | 46 | @@ -740,6 +741,10 @@ void receive_acl(struct file_struct *fil |
0f6fb3c8 WD |
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) | |
52 | + ndx_ptr += 4; | |
53 | +#endif | |
54 | do { | |
55 | char tag = read_byte(f); | |
56 | int ndx; | |
4959107f | 57 | @@ -799,6 +804,10 @@ void cache_acl(struct file_struct *file, |
0f6fb3c8 WD |
58 | racl = sxp->acc_acl; |
59 | racl_list = &access_acl_list; | |
60 | ndx_ptr = (char*)file + file_struct_len; | |
61 | +#ifdef SUPPORT_XATTRS | |
62 | + if (preserve_xattrs) | |
63 | + ndx_ptr += 4; | |
64 | +#endif | |
65 | do { | |
66 | if (!racl) | |
67 | ndx = -1; | |
4959107f | 68 | @@ -914,6 +923,10 @@ int set_acl(const char *fname, const str |
0f6fb3c8 WD |
69 | |
70 | type = SMB_ACL_TYPE_ACCESS; | |
71 | ndx_ptr = (char*)file + file_struct_len; | |
72 | +#ifdef SUPPORT_XATTRS | |
73 | + if (preserve_xattrs) | |
74 | + ndx_ptr += 4; | |
75 | +#endif | |
76 | do { | |
77 | acl_duo *duo_item; | |
78 | BOOL eq; | |
9a7eef96 WD |
79 | --- old/backup.c |
80 | +++ new/backup.c | |
dc52bc1a | 81 | @@ -30,6 +30,7 @@ extern char *backup_dir; |
93d6ca6d WD |
82 | |
83 | extern int am_root; | |
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; | |
0f6fb3c8 WD |
89 | @@ -136,6 +137,9 @@ static int make_bak_dir(char *fullpath) |
90 | #ifdef SUPPORT_ACLS | |
91 | sx.acc_acl = sx.def_acl = NULL; | |
92 | #endif | |
93 | +#ifdef SUPPORT_XATTRS | |
94 | + sx.xattr = NULL; | |
95 | +#endif | |
96 | if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS))) | |
97 | continue; | |
98 | #ifdef SUPPORT_ACLS | |
99 | @@ -144,6 +148,12 @@ static int make_bak_dir(char *fullpath) | |
100 | cache_acl(file, &sx); | |
101 | } | |
09cc6650 WD |
102 | #endif |
103 | +#ifdef SUPPORT_XATTRS | |
0f6fb3c8 WD |
104 | + if (preserve_xattrs) { |
105 | + get_xattr(rel, &sx); | |
106 | + cache_xattr(file, &sx); | |
107 | + } | |
09cc6650 | 108 | +#endif |
0f6fb3c8 WD |
109 | set_file_attrs(fullpath, file, NULL, 0); |
110 | free(file); | |
bbdff76a | 111 | } |
0f6fb3c8 WD |
112 | @@ -195,6 +205,9 @@ static int keep_backup(char *fname) |
113 | #ifdef SUPPORT_ACLS | |
114 | sx.acc_acl = sx.def_acl = NULL; | |
09cc6650 WD |
115 | #endif |
116 | +#ifdef SUPPORT_XATTRS | |
0f6fb3c8 | 117 | + sx.xattr = NULL; |
09cc6650 | 118 | +#endif |
bbdff76a | 119 | |
0f6fb3c8 WD |
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); | |
124 | } | |
09cc6650 WD |
125 | #endif |
126 | +#ifdef SUPPORT_XATTRS | |
0f6fb3c8 WD |
127 | + if (preserve_xattrs) { |
128 | + get_xattr(fname, &sx); | |
129 | + cache_xattr(file, &sx); | |
130 | + } | |
09cc6650 | 131 | +#endif |
bbdff76a | 132 | |
0f6fb3c8 WD |
133 | /* Check to see if this is a device file, or link */ |
134 | if ((am_root && preserve_devices && IS_DEVICE(file->mode)) | |
9a7eef96 WD |
135 | --- old/configure.in |
136 | +++ new/configure.in | |
49de5440 | 137 | @@ -856,6 +856,35 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_ |
bbdff76a WD |
138 | AC_MSG_RESULT(no) |
139 | ) | |
140 | ||
141 | +AC_CHECK_HEADERS(attr/xattr.h) | |
49de5440 | 142 | +AC_CHECK_HEADERS(sys/xattr.h) |
bbdff76a | 143 | +AC_MSG_CHECKING(whether to support extended attributes) |
f787c90c WD |
144 | +AC_ARG_ENABLE(xattr-support, |
145 | +AC_HELP_STRING([--enable-xattr-support], [Include extended attribute support (default=no)]), | |
3b05e91f | 146 | +[ case "$enableval" in |
bbdff76a WD |
147 | + yes) |
148 | + case "$host_os" in | |
149 | + *linux*) | |
150 | + AC_MSG_RESULT(Using Linux xattrs) | |
151 | + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs]) | |
152 | + ;; | |
49de5440 WD |
153 | + darwin*) |
154 | + AC_MSG_RESULT(Using OS X xattrs) | |
155 | + AC_DEFINE(HAVE_OSX_XATTRS, 1, [True if you have Mac OS X xattrs]) | |
156 | + ;; | |
bbdff76a | 157 | + *) |
49de5440 | 158 | + AC_MSG_RESULT(Xattrs requested but not Linux or OS X. Good luck...) |
bbdff76a WD |
159 | + ;; |
160 | + esac | |
161 | + ;; | |
162 | + *) | |
163 | + AC_MSG_RESULT(no) | |
164 | + AC_DEFINE(HAVE_NA_XATTRS, 1, [True if you don't have extended attributes]) | |
165 | + esac ], | |
166 | + AC_MSG_RESULT(no) | |
167 | + AC_DEFINE(HAVE_NO_XATTRL, 1, [True if you don't have extended attributes]) | |
168 | +) | |
169 | + | |
170 | AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig]) | |
171 | AC_OUTPUT | |
172 | ||
9a7eef96 WD |
173 | --- old/flist.c |
174 | +++ new/flist.c | |
dc52bc1a | 175 | @@ -41,6 +41,7 @@ extern int one_file_system; |
93d6ca6d WD |
176 | extern int copy_dirlinks; |
177 | extern int keep_dirlinks; | |
178 | extern int preserve_acls; | |
179 | +extern int preserve_xattrs; | |
180 | extern int preserve_links; | |
181 | extern int preserve_hard_links; | |
182 | extern int preserve_devices; | |
de565f59 | 183 | @@ -498,7 +499,7 @@ static struct file_struct *receive_file_ |
0f6fb3c8 WD |
184 | char thisname[MAXPATHLEN]; |
185 | unsigned int l1 = 0, l2 = 0; | |
186 | int alloc_len, basename_len, dirname_len, linkname_len, sum_len; | |
187 | -#ifdef SUPPORT_ACLS | |
188 | +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS | |
189 | int xtra_len; | |
190 | #endif | |
191 | OFF_T file_length; | |
de565f59 | 192 | @@ -610,10 +611,16 @@ static struct file_struct *receive_file_ |
0f6fb3c8 WD |
193 | xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4; |
194 | else | |
195 | xtra_len = 0; | |
196 | +#elif defined SUPPORT_XATTRS | |
197 | + xtra_len = 0; | |
198 | +#endif | |
199 | +#ifdef SUPPORT_XATTRS | |
200 | + if (preserve_xattrs) | |
201 | + xtra_len += 4; | |
202 | #endif | |
203 | ||
204 | alloc_len = file_struct_len + dirname_len + basename_len | |
205 | -#ifdef SUPPORT_ACLS | |
206 | +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS | |
207 | + xtra_len | |
208 | #endif | |
209 | + linkname_len + sum_len; | |
de565f59 | 210 | @@ -622,7 +629,7 @@ static struct file_struct *receive_file_ |
0f6fb3c8 WD |
211 | file = (struct file_struct *)bp; |
212 | memset(bp, 0, file_struct_len); | |
213 | bp += file_struct_len; | |
214 | -#ifdef SUPPORT_ACLS | |
215 | +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS | |
216 | bp += xtra_len; | |
217 | #endif | |
218 | ||
de565f59 | 219 | @@ -723,6 +730,10 @@ static struct file_struct *receive_file_ |
0f6fb3c8 WD |
220 | if (preserve_acls) |
221 | receive_acl(file, f); | |
222 | #endif | |
223 | +#ifdef SUPPORT_XATTRS | |
224 | + if (preserve_xattrs) | |
225 | + receive_xattr(file, f ); | |
226 | +#endif | |
227 | ||
228 | return file; | |
229 | } | |
a071aea2 WD |
230 | @@ -974,7 +985,7 @@ static struct file_struct *send_file_nam |
231 | unsigned short flags) | |
232 | { | |
233 | struct file_struct *file; | |
234 | -#ifdef SUPPORT_ACLS | |
235 | +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS | |
236 | statx sx; | |
237 | #endif | |
238 | ||
de565f59 | 239 | @@ -994,6 +1005,13 @@ static struct file_struct *send_file_nam |
0f6fb3c8 WD |
240 | return NULL; |
241 | } | |
09cc6650 WD |
242 | #endif |
243 | +#ifdef SUPPORT_XATTRS | |
0f6fb3c8 WD |
244 | + if (preserve_xattrs) { |
245 | + sx.xattr = NULL; | |
246 | + if (get_xattr(fname, &sx) < 0) | |
247 | + return NULL; | |
248 | + } | |
09cc6650 | 249 | +#endif |
bbdff76a | 250 | |
a2f9a486 WD |
251 | maybe_emit_filelist_progress(flist->count + flist_count_offset); |
252 | ||
de565f59 | 253 | @@ -1006,11 +1024,19 @@ static struct file_struct *send_file_nam |
93d6ca6d | 254 | if (preserve_acls) |
0f6fb3c8 | 255 | send_acl(&sx, f); |
93d6ca6d | 256 | #endif |
09cc6650 | 257 | +#ifdef SUPPORT_XATTRS |
93d6ca6d | 258 | + if (preserve_xattrs) |
0f6fb3c8 | 259 | + send_xattr(&sx, f); |
09cc6650 | 260 | +#endif |
bbdff76a | 261 | } else { |
93d6ca6d | 262 | #ifdef SUPPORT_ACLS |
93d6ca6d | 263 | if (preserve_acls) |
0f6fb3c8 | 264 | free_acl(&sx); |
09cc6650 WD |
265 | #endif |
266 | +#ifdef SUPPORT_XATTRS | |
93d6ca6d | 267 | + if (preserve_xattrs) |
0f6fb3c8 | 268 | + free_xattr(&sx); |
09cc6650 | 269 | +#endif |
bbdff76a WD |
270 | } |
271 | return file; | |
272 | } | |
9a7eef96 WD |
273 | --- old/lib/sysxattr.c |
274 | +++ new/lib/sysxattr.c | |
49de5440 | 275 | @@ -0,0 +1,61 @@ |
dc52bc1a WD |
276 | +/* |
277 | + * Extended attribute support for rsync. | |
278 | + * | |
279 | + * Copyright (C) 2004 Red Hat, Inc. | |
280 | + * Written by Jay Fenlason. | |
281 | + * | |
282 | + * This program is free software; you can redistribute it and/or modify | |
283 | + * it under the terms of the GNU General Public License as published by | |
284 | + * the Free Software Foundation; either version 2 of the License, or | |
285 | + * (at your option) any later version. | |
286 | + * | |
287 | + * This program is distributed in the hope that it will be useful, | |
288 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
289 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
290 | + * GNU General Public License for more details. | |
291 | + * | |
292 | + * You should have received a copy of the GNU General Public License along | |
293 | + * with this program; if not, write to the Free Software Foundation, Inc., | |
294 | + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. | |
295 | + */ | |
bbdff76a WD |
296 | + |
297 | +#include "rsync.h" | |
0f6fb3c8 | 298 | +#include "sysxattr.h" |
bbdff76a | 299 | + |
09cc6650 | 300 | +#if defined HAVE_LINUX_XATTRS |
bbdff76a WD |
301 | + |
302 | +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size) | |
303 | +{ | |
304 | + return lgetxattr(path, name, value, size); | |
305 | +} | |
306 | + | |
307 | +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags) | |
308 | +{ | |
309 | + return lsetxattr(path, name, value, size, flags); | |
310 | +} | |
311 | + | |
312 | +ssize_t sys_llistxattr(const char *path, char *list, size_t size) | |
313 | +{ | |
314 | + return llistxattr(path, list, size); | |
315 | +} | |
316 | + | |
49de5440 WD |
317 | +#elif HAVE_OSX_XATTRS |
318 | + | |
319 | +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size) | |
320 | +{ | |
321 | + return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW); | |
322 | +} | |
323 | + | |
324 | +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags) | |
325 | +{ | |
326 | + return setxattr(path, name, value, size, 0, XATTR_NOFOLLOW | flags); | |
327 | +} | |
328 | + | |
329 | +ssize_t sys_llistxattr(const char *path, char *list, size_t size) | |
330 | +{ | |
331 | + return listxattr(path, list, size, XATTR_NOFOLLOW); | |
332 | +} | |
333 | + | |
bbdff76a WD |
334 | +#else |
335 | + | |
336 | +#endif /* No xattrs */ | |
9a7eef96 WD |
337 | --- old/lib/sysxattr.h |
338 | +++ new/lib/sysxattr.h | |
49de5440 WD |
339 | @@ -0,0 +1,19 @@ |
340 | +#ifdef SUPPORT_XATTRS | |
341 | +#if defined HAVE_ATTR_XATTR_H | |
0f6fb3c8 | 342 | +#include <attr/xattr.h> |
49de5440 WD |
343 | +#elif defined HAVE_SYS_XATTR_H |
344 | +#include <sys/xattr.h> | |
345 | +#endif | |
0f6fb3c8 WD |
346 | +#endif |
347 | + | |
49de5440 | 348 | +#if defined HAVE_LINUX_XATTRS || defined HAVE_OSX_XATTRS |
bbdff76a WD |
349 | + |
350 | +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size); | |
351 | +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags); | |
352 | +ssize_t sys_llistxattr(const char *path, char *list, size_t size); | |
353 | + | |
354 | +#else | |
355 | + | |
49de5440 WD |
356 | +/* No xattrs */ |
357 | + | |
358 | +#endif | |
9a7eef96 WD |
359 | --- old/options.c |
360 | +++ new/options.c | |
dc52bc1a | 361 | @@ -48,6 +48,7 @@ int copy_links = 0; |
bbdff76a WD |
362 | int preserve_links = 0; |
363 | int preserve_hard_links = 0; | |
364 | int preserve_acls = 0; | |
365 | +int preserve_xattrs = 0; | |
366 | int preserve_perms = 0; | |
4a65fe72 | 367 | int preserve_executability = 0; |
bbdff76a | 368 | int preserve_devices = 0; |
4959107f | 369 | @@ -201,6 +202,7 @@ static void print_rsync_version(enum log |
bbdff76a WD |
370 | char const *have_inplace = "no "; |
371 | char const *hardlinks = "no "; | |
372 | char const *acls = "no "; | |
373 | + char const *xattrs = "no "; | |
374 | char const *links = "no "; | |
375 | char const *ipv6 = "no "; | |
376 | STRUCT_STAT *dumstat; | |
4959107f | 377 | @@ -220,7 +222,9 @@ static void print_rsync_version(enum log |
bbdff76a WD |
378 | #ifdef SUPPORT_ACLS |
379 | acls = ""; | |
380 | #endif | |
381 | - | |
382 | +#ifdef SUPPORT_XATTRS | |
383 | + xattrs = ""; | |
384 | +#endif | |
385 | #ifdef SUPPORT_LINKS | |
386 | links = ""; | |
387 | #endif | |
4959107f | 388 | @@ -234,9 +238,9 @@ static void print_rsync_version(enum log |
3b05e91f | 389 | rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n"); |
bbdff76a WD |
390 | rprintf(f, "<http://rsync.samba.org/>\n"); |
391 | rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, " | |
bc5988ec WD |
392 | - "%shard links, %sACLs, %ssymlinks, batchfiles,\n", |
393 | + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n", | |
bbdff76a WD |
394 | (int) (sizeof (OFF_T) * 8), |
395 | - got_socketpair, hardlinks, acls, links); | |
396 | + got_socketpair, hardlinks, acls, xattrs, links); | |
397 | ||
398 | /* Note that this field may not have type ino_t. It depends | |
399 | * on the complicated interaction between largefile feature | |
4959107f | 400 | @@ -290,7 +294,7 @@ void usage(enum logcode F) |
1b57ecb0 | 401 | rprintf(F," -q, --quiet suppress non-error messages\n"); |
4959107f | 402 | rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n"); |
1b57ecb0 WD |
403 | rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n"); |
404 | - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n"); | |
405 | + rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n"); | |
406 | rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n"); | |
407 | rprintf(F," -r, --recursive recurse into directories\n"); | |
408 | rprintf(F," -R, --relative use relative path names\n"); | |
4959107f | 409 | @@ -315,6 +319,9 @@ void usage(enum logcode F) |
3610c43c | 410 | #ifdef SUPPORT_ACLS |
bbdff76a | 411 | rprintf(F," -A, --acls preserve ACLs (implies --perms)\n"); |
3610c43c WD |
412 | #endif |
413 | +#ifdef SUPPORT_XATTRS | |
bbdff76a | 414 | + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n"); |
3610c43c | 415 | +#endif |
4a65fe72 | 416 | rprintf(F," -o, --owner preserve owner (super-user only)\n"); |
bbdff76a | 417 | rprintf(F," -g, --group preserve group\n"); |
1ed0b5c9 | 418 | rprintf(F," --devices preserve device files (super-user only)\n"); |
4959107f | 419 | @@ -437,6 +444,9 @@ static struct poptOption long_options[] |
489b0a72 WD |
420 | {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
421 | {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
422 | {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
423 | + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 }, | |
424 | + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 }, | |
425 | + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 }, | |
426 | {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 }, | |
427 | {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
428 | {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
4959107f | 429 | @@ -1118,6 +1128,17 @@ int parse_arguments(int *argc, const cha |
489b0a72 | 430 | return 0; |
3610c43c | 431 | #endif |
bbdff76a WD |
432 | |
433 | + case 'X': | |
434 | +#ifdef SUPPORT_XATTRS | |
435 | + preserve_xattrs = 1; | |
436 | + preserve_perms = 1; | |
489b0a72 | 437 | + break; |
bbdff76a WD |
438 | +#else |
439 | + snprintf(err_buf,sizeof(err_buf), | |
440 | + "extended attributes are not supported on this %s\n", | |
441 | + am_server ? "server" : "client"); | |
442 | + return 0; | |
443 | +#endif /* SUPPORT_XATTRS */ | |
bbdff76a WD |
444 | |
445 | default: | |
446 | /* A large opt value means that set_refuse_options() | |
4959107f | 447 | @@ -1564,6 +1585,10 @@ void server_options(char **args,int *arg |
bbdff76a WD |
448 | if (preserve_acls) |
449 | argstr[x++] = 'A'; | |
3610c43c WD |
450 | #endif |
451 | +#ifdef SUPPORT_XATTRS | |
bbdff76a WD |
452 | + if (preserve_xattrs) |
453 | + argstr[x++] = 'X'; | |
3610c43c | 454 | +#endif |
bbdff76a WD |
455 | if (preserve_uid) |
456 | argstr[x++] = 'o'; | |
457 | if (preserve_gid) | |
9a7eef96 WD |
458 | --- old/rsync.c |
459 | +++ new/rsync.c | |
ff318e90 WD |
460 | @@ -33,6 +33,7 @@ |
461 | extern int verbose; | |
93d6ca6d | 462 | extern int dry_run; |
93d6ca6d WD |
463 | extern int preserve_acls; |
464 | +extern int preserve_xattrs; | |
465 | extern int preserve_perms; | |
466 | extern int preserve_executability; | |
467 | extern int preserve_times; | |
1ed0b5c9 | 468 | @@ -229,6 +230,10 @@ int set_file_attrs(char *fname, struct f |
0f6fb3c8 | 469 | if (preserve_acls && set_acl(fname, file, sxp) == 0) |
09cc6650 | 470 | updated = 1; |
e5754c5f | 471 | #endif |
09cc6650 | 472 | +#ifdef SUPPORT_XATTRS |
0f6fb3c8 | 473 | + if (preserve_xattrs && set_xattr(fname, file, sxp) == 0) |
09cc6650 WD |
474 | + updated = 1; |
475 | +#endif | |
bbdff76a | 476 | |
493b02f6 | 477 | #ifdef HAVE_CHMOD |
1ed0b5c9 | 478 | if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) { |
9a7eef96 WD |
479 | --- old/rsync.h |
480 | +++ new/rsync.h | |
1ed0b5c9 | 481 | @@ -501,6 +501,10 @@ struct idev { |
0f6fb3c8 | 482 | #define ACLS_NEED_MASK 1 |
09cc6650 | 483 | #endif |
bbdff76a | 484 | |
49de5440 | 485 | +#if defined HAVE_LINUX_XATTRS || defined HAVE_OSX_XATTRS |
bbdff76a WD |
486 | +#define SUPPORT_XATTRS 1 |
487 | +#endif | |
488 | + | |
0f6fb3c8 WD |
489 | #define GID_NONE ((gid_t)-1) |
490 | ||
491 | #define HL_CHECK_MASTER 0 | |
de565f59 | 492 | @@ -695,6 +699,9 @@ typedef struct { |
0f6fb3c8 WD |
493 | struct rsync_acl *acc_acl; /* access ACL */ |
494 | struct rsync_acl *def_acl; /* default ACL */ | |
495 | #endif | |
496 | +#ifdef SUPPORT_XATTRS | |
497 | + item_list *xattr; | |
bbdff76a | 498 | +#endif |
0f6fb3c8 | 499 | } statx; |
bbdff76a | 500 | |
0f6fb3c8 | 501 | #define ACL_READY(sx) ((sx).acc_acl != NULL) |
9a7eef96 WD |
502 | --- old/rsync.yo |
503 | +++ new/rsync.yo | |
4959107f | 504 | @@ -301,7 +301,7 @@ to the detailed description below for a |
1b57ecb0 | 505 | -q, --quiet suppress non-error messages |
4959107f | 506 | --no-motd suppress daemon-mode MOTD (see caveat) |
1b57ecb0 WD |
507 | -c, --checksum skip based on checksum, not mod-time & size |
508 | - -a, --archive archive mode; same as -rlptgoD (no -H, -A) | |
509 | + -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X) | |
510 | --no-OPTION turn off an implied OPTION (e.g. --no-D) | |
511 | -r, --recursive recurse into directories | |
512 | -R, --relative use relative path names | |
4959107f | 513 | @@ -324,6 +324,7 @@ to the detailed description below for a |
4a65fe72 | 514 | -E, --executability preserve executability |
063cf77b | 515 | --chmod=CHMOD affect file and/or directory permissions |
4a65fe72 WD |
516 | -A, --acls preserve ACLs (implies -p) [non-standard] |
517 | + -X, --xattrs preserve extended attrs (implies -p) [n.s.] | |
4a65fe72 | 518 | -o, --owner preserve owner (super-user only) |
bbdff76a | 519 | -g, --group preserve group |
1ed0b5c9 | 520 | --devices preserve device files (super-user only) |
4959107f | 521 | @@ -818,6 +819,11 @@ version makes it incompatible with sendi |
3fcc541f WD |
522 | rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This |
523 | doubling is not needed when pulling files from an older rsync. | |
bbdff76a WD |
524 | |
525 | +dit(bf(-X, --xattrs)) This option causes rsync to update the remote | |
526 | +extended attributes to be the same as the local ones. This will work | |
527 | +only if the remote machine's rsync supports this option also. This is | |
528 | +a non-standard option. | |
529 | + | |
4a65fe72 WD |
530 | dit(bf(--chmod)) This option tells rsync to apply one or more |
531 | comma-separated "chmod" strings to the permission of the files in the | |
532 | transfer. The resulting value is treated as though it was the permissions | |
9a7eef96 WD |
533 | --- old/xattr.c |
534 | +++ new/xattr.c | |
bb6b64ea | 535 | @@ -0,0 +1,368 @@ |
dc52bc1a WD |
536 | +/* |
537 | + * Extended Attribute support for rsync. | |
0f6fb3c8 | 538 | + * Written by Jay Fenlason, vaguely based on the ACLs patch. |
dc52bc1a WD |
539 | + * |
540 | + * Copyright (C) 2004 Red Hat, Inc. | |
0f6fb3c8 | 541 | + * Copyright (C) 2006 Wayne Davison |
dc52bc1a WD |
542 | + * |
543 | + * This program is free software; you can redistribute it and/or modify | |
544 | + * it under the terms of the GNU General Public License as published by | |
545 | + * the Free Software Foundation; either version 2 of the License, or | |
546 | + * (at your option) any later version. | |
547 | + * | |
548 | + * This program is distributed in the hope that it will be useful, | |
549 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
550 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
551 | + * GNU General Public License for more details. | |
552 | + * | |
553 | + * You should have received a copy of the GNU General Public License along | |
554 | + * with this program; if not, write to the Free Software Foundation, Inc., | |
555 | + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. | |
556 | + */ | |
bbdff76a WD |
557 | + |
558 | +#include "rsync.h" | |
559 | +#include "lib/sysxattr.h" | |
560 | + | |
561 | +#ifdef SUPPORT_XATTRS | |
562 | + | |
bbdff76a | 563 | +extern int dry_run; |
0f6fb3c8 | 564 | +extern unsigned int file_struct_len; |
bbdff76a WD |
565 | + |
566 | +#define RSYNC_XAL_INITIAL 5 | |
567 | +#define RSYNC_XAL_LIST_INITIAL 100 | |
568 | + | |
569 | +typedef struct { | |
bbdff76a | 570 | + char *name; |
bbdff76a | 571 | + char *datum; |
0f6fb3c8 WD |
572 | + size_t name_len; |
573 | + size_t datum_len; | |
bbdff76a WD |
574 | +} rsync_xa; |
575 | + | |
bbdff76a WD |
576 | +static size_t namebuf_len = 0; |
577 | +static char *namebuf = NULL; | |
578 | + | |
0f6fb3c8 WD |
579 | +static item_list empty_xattr = EMPTY_ITEM_LIST; |
580 | +static item_list rsync_xal_l = EMPTY_ITEM_LIST; | |
bbdff76a | 581 | + |
517cc92f WD |
582 | +#ifdef HAVE_OSX_XATTRS |
583 | +static char unique_prefix[] = "user.0S%."; /* OSX */ | |
584 | +static int upre_len = sizeof unique_prefix - 1; | |
585 | +#endif | |
586 | + | |
bbdff76a WD |
587 | +/* ------------------------------------------------------------------------- */ |
588 | + | |
0f6fb3c8 | 589 | +static void rsync_xal_free(item_list *xalp) |
bbdff76a WD |
590 | +{ |
591 | + size_t i; | |
0f6fb3c8 | 592 | + rsync_xa *rxas = xalp->items; |
bbdff76a | 593 | + |
0f6fb3c8 WD |
594 | + for (i = 0; i < xalp->count; i++) { |
595 | + free(rxas[i].name); | |
596 | + /* free(rxas[i].value); */ | |
bbdff76a | 597 | + } |
0f6fb3c8 | 598 | + xalp->count = 0; |
bbdff76a WD |
599 | +} |
600 | + | |
0f6fb3c8 | 601 | +void free_xattr(statx *sxp) |
bbdff76a | 602 | +{ |
0f6fb3c8 WD |
603 | + rsync_xal_free(sxp->xattr); |
604 | + free(sxp->xattr); | |
605 | + sxp->xattr = NULL; | |
606 | +} | |
bbdff76a | 607 | + |
0f6fb3c8 WD |
608 | +static int rsync_xal_compare_names(const void *x1, const void *x2) |
609 | +{ | |
610 | + const rsync_xa *xa1 = x1; | |
611 | + const rsync_xa *xa2 = x2; | |
bbdff76a WD |
612 | + return strcmp(xa1->name, xa2->name); |
613 | +} | |
614 | + | |
0f6fb3c8 | 615 | +static int rsync_xal_get(const char *fname, item_list *xalp) |
bbdff76a WD |
616 | +{ |
617 | + ssize_t name_size; | |
618 | + ssize_t datum_size; | |
619 | + ssize_t left; | |
620 | + char *name; | |
621 | + size_t len; | |
622 | + char *ptr; | |
623 | + | |
624 | + if (!namebuf) { | |
49de5440 | 625 | + namebuf_len = 1024; |
bbdff76a | 626 | + namebuf = new_array(char, namebuf_len); |
49de5440 | 627 | + if (!namebuf) |
bbdff76a WD |
628 | + out_of_memory("rsync_xal_get"); |
629 | + } | |
630 | + | |
49de5440 | 631 | + /* The length returned includes all the '\0' terminators. */ |
bbdff76a WD |
632 | + name_size = sys_llistxattr(fname, namebuf, namebuf_len); |
633 | + if (name_size > (ssize_t)namebuf_len) { | |
634 | + name_size = -1; | |
635 | + errno = ERANGE; | |
636 | + } | |
637 | + if (name_size < 0) { | |
638 | + if (errno == ENOTSUP) | |
0f6fb3c8 | 639 | + return 0; |
bbdff76a WD |
640 | + if (errno == ERANGE) { |
641 | + name_size = sys_llistxattr(fname, NULL, 0); | |
642 | + if (name_size < 0) { | |
0f6fb3c8 WD |
643 | + rsyserr(FERROR, errno, "%s: rsync_xal_get: llistxattr", |
644 | + fname); | |
e5754c5f | 645 | + return -1; |
bbdff76a | 646 | + } |
49de5440 | 647 | + namebuf = realloc_array(namebuf, char, name_size + 1024); |
bbdff76a WD |
648 | + if (!namebuf) |
649 | + out_of_memory("rsync_xal_get"); | |
49de5440 | 650 | + namebuf_len = name_size + 1024; |
bbdff76a WD |
651 | + name_size = sys_llistxattr(fname, namebuf, namebuf_len); |
652 | + if (name_size < 0) { | |
0f6fb3c8 WD |
653 | + rsyserr(FERROR, errno, |
654 | + "%s: rsync_xal_get: re-llistxattr failed", | |
655 | + fname); | |
e5754c5f | 656 | + return -1; |
bbdff76a WD |
657 | + } |
658 | + } else { | |
0f6fb3c8 WD |
659 | + rsyserr(FERROR, errno, |
660 | + "%s: rsync_xal_get: llistxattr failed:", | |
661 | + fname); | |
e5754c5f | 662 | + return -1; |
bbdff76a WD |
663 | + } |
664 | + } | |
bbdff76a | 665 | + if (name_size == 0) |
e5754c5f | 666 | + return 0; |
bbdff76a | 667 | + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) { |
0f6fb3c8 | 668 | + rsync_xa *rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL); |
bbdff76a | 669 | + |
0f6fb3c8 | 670 | + len = strlen(name) + 1; |
49de5440 | 671 | + datum_size = sys_lgetxattr(fname, name, NULL, 0); |
bbdff76a WD |
672 | + if (datum_size < 0) { |
673 | + if (errno == ENOTSUP) | |
e5754c5f | 674 | + return -1; |
49de5440 WD |
675 | + rsyserr(FERROR, errno, |
676 | + "%s: rsync_xal_get: lgetxattr %s failed", | |
677 | + fname, name); | |
678 | + return -1; | |
bbdff76a WD |
679 | + } |
680 | + ptr = new_array(char, len + datum_size); | |
681 | + if (!ptr) | |
682 | + out_of_memory("rsync_xal_get"); | |
0f6fb3c8 | 683 | + memcpy(ptr, name, len); |
0f6fb3c8 WD |
684 | + rxas->name_len = len; |
685 | + rxas->name = ptr; | |
686 | + rxas->datum_len = datum_size; | |
687 | + rxas->datum = ptr + len; | |
49de5440 WD |
688 | + if (datum_size) { |
689 | + ssize_t size = sys_lgetxattr(fname, name, rxas->datum, datum_size); | |
690 | + if (size != datum_size) { | |
691 | + if (size < 0) { | |
692 | + rsyserr(FERROR, errno, | |
693 | + "rsync_xal_get: lgetxattr(%s,%s)" | |
694 | + " failed", fname, name); | |
695 | + } else { | |
696 | + rprintf(FERROR, | |
697 | + "rsync_xal_get: lgetxattr(%s,%s)" | |
bb6b64ea WD |
698 | + " returned %ld instead of %ld\n", |
699 | + fname, name, | |
700 | + (long)size, (long)datum_size); | |
49de5440 WD |
701 | + } |
702 | + return -1; | |
703 | + } | |
704 | + } | |
bbdff76a | 705 | + } |
0f6fb3c8 WD |
706 | + if (xalp->count > 1) |
707 | + qsort(xalp->items, xalp->count, sizeof (rsync_xa), rsync_xal_compare_names); | |
e5754c5f | 708 | + return 0; |
bbdff76a WD |
709 | +} |
710 | + | |
0f6fb3c8 WD |
711 | +/* Read the xattr(s) for this filename. */ |
712 | +int get_xattr(const char *fname, statx *sxp) | |
bbdff76a | 713 | +{ |
0f6fb3c8 WD |
714 | + sxp->xattr = new(item_list); |
715 | + *sxp->xattr = empty_xattr; | |
716 | + if (rsync_xal_get(fname, sxp->xattr) < 0) { | |
717 | + free_xattr(sxp); | |
718 | + return -1; | |
719 | + } | |
720 | + return 0; | |
bbdff76a WD |
721 | +} |
722 | + | |
0f6fb3c8 | 723 | +static int find_matching_xattr(item_list *xalp) |
bbdff76a | 724 | +{ |
0f6fb3c8 WD |
725 | + size_t i, j; |
726 | + item_list *lst = rsync_xal_l.items; | |
bbdff76a WD |
727 | + |
728 | + for (i = 0; i < rsync_xal_l.count; i++) { | |
0f6fb3c8 WD |
729 | + rsync_xa *rxas1 = lst[i].items; |
730 | + rsync_xa *rxas2 = xalp->items; | |
731 | + | |
bbdff76a | 732 | + /* Wrong number of elements? */ |
0f6fb3c8 | 733 | + if (lst[i].count != xalp->count) |
bbdff76a WD |
734 | + continue; |
735 | + /* any elements different? */ | |
0f6fb3c8 WD |
736 | + for (j = 0; j < xalp->count; j++) { |
737 | + if (rxas1[j].name_len != rxas2[j].name_len | |
738 | + || rxas1[j].datum_len != rxas2[j].datum_len | |
739 | + || strcmp(rxas1[j].name, rxas2[j].name) | |
740 | + || memcmp(rxas1[j].datum, rxas2[j].datum, rxas2[j].datum_len)) | |
bbdff76a WD |
741 | + break; |
742 | + } | |
743 | + /* no differences found. This is The One! */ | |
0f6fb3c8 WD |
744 | + if (j == xalp->count) |
745 | + return i; | |
bbdff76a | 746 | + } |
0f6fb3c8 WD |
747 | + |
748 | + return -1; | |
bbdff76a WD |
749 | +} |
750 | + | |
0f6fb3c8 WD |
751 | +/* Store *xalp on the end of rsync_xal_l */ |
752 | +static void rsync_xal_store(item_list *xalp) | |
bbdff76a | 753 | +{ |
0f6fb3c8 | 754 | + item_list *new_lst = EXPAND_ITEM_LIST(&rsync_xal_l, item_list, RSYNC_XAL_LIST_INITIAL); |
de565f59 WD |
755 | + /* Since the following call starts a new list, we know it will hold the |
756 | + * entire initial-count, not just enough space for one new item. */ | |
49de5440 WD |
757 | + *new_lst = empty_xattr; |
758 | + (void)EXPAND_ITEM_LIST(new_lst, rsync_xa, xalp->count); | |
759 | + memcpy(new_lst->items, xalp->items, xalp->count * sizeof (rsync_xa)); | |
0f6fb3c8 WD |
760 | + new_lst->count = xalp->count; |
761 | + xalp->count = 0; | |
bbdff76a WD |
762 | +} |
763 | + | |
0f6fb3c8 WD |
764 | +/* Send the make_xattr()-generated xattr list for this flist entry. */ |
765 | +void send_xattr(statx *sxp, int f) | |
bbdff76a | 766 | +{ |
0f6fb3c8 WD |
767 | + int ndx = find_matching_xattr(sxp->xattr); |
768 | + if (ndx != -1) { | |
bbdff76a | 769 | + write_byte(f, 'x'); |
0f6fb3c8 WD |
770 | + write_int(f, ndx); |
771 | + rsync_xal_free(sxp->xattr); | |
bbdff76a WD |
772 | + } else { |
773 | + rsync_xa *rxa; | |
0f6fb3c8 | 774 | + int count = sxp->xattr->count; |
bbdff76a WD |
775 | + write_byte(f, 'X'); |
776 | + write_int(f, count); | |
0f6fb3c8 | 777 | + for (rxa = sxp->xattr->items; count--; rxa++) { |
517cc92f WD |
778 | +#ifdef HAVE_OSX_XATTRS |
779 | + if (strncmp(rxa->name, "user.", 5) != 0 | |
780 | + && strncmp(rxa->name, "system.", 7) != 0) { | |
781 | + write_int(f, rxa->name_len + upre_len); | |
782 | + write_int(f, rxa->datum_len); | |
783 | + write_buf(f, unique_prefix, upre_len); | |
784 | + } else | |
785 | +#endif | |
786 | + { | |
787 | + write_int(f, rxa->name_len); | |
788 | + write_int(f, rxa->datum_len); | |
789 | + } | |
bbdff76a WD |
790 | + write_buf(f, rxa->name, rxa->name_len); |
791 | + write_buf(f, rxa->datum, rxa->datum_len); | |
792 | + } | |
49de5440 | 793 | + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */ |
bbdff76a | 794 | + } |
0f6fb3c8 | 795 | + free_xattr(sxp); |
bbdff76a WD |
796 | +} |
797 | + | |
bbdff76a | 798 | +/* ------------------------------------------------------------------------- */ |
bbdff76a | 799 | + |
0f6fb3c8 | 800 | +/* receive and build the rsync_xattr_lists */ |
bbdff76a WD |
801 | +void receive_xattr(struct file_struct *file, int f) |
802 | +{ | |
0f6fb3c8 WD |
803 | + static item_list temp_xattr = EMPTY_ITEM_LIST; |
804 | + int tag = read_byte(f); | |
805 | + char *ndx_ptr = (char*)file + file_struct_len; | |
806 | + int ndx; | |
bbdff76a | 807 | + |
bbdff76a | 808 | + if (tag == 'X') { |
0f6fb3c8 | 809 | + int i, count = read_int(f); |
bbdff76a | 810 | + for (i = 0; i < count; i++) { |
bbdff76a | 811 | + char *ptr; |
0f6fb3c8 WD |
812 | + rsync_xa *rxa; |
813 | + size_t name_len = read_int(f); | |
814 | + size_t datum_len = read_int(f); | |
3fcc541f WD |
815 | + if (name_len + datum_len < name_len) |
816 | + out_of_memory("receive_xattr"); /* overflow */ | |
0f6fb3c8 | 817 | + rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count); |
bbdff76a WD |
818 | + ptr = new_array(char, name_len + datum_len); |
819 | + if (!ptr) | |
820 | + out_of_memory("receive_xattr"); | |
821 | + read_buf(f, ptr, name_len); | |
822 | + read_buf(f, ptr + name_len, datum_len); | |
0f6fb3c8 WD |
823 | + rxa->name_len = name_len; |
824 | + rxa->datum_len = datum_len; | |
825 | + rxa->name = ptr; | |
826 | + rxa->datum = ptr + name_len; | |
517cc92f WD |
827 | +#ifdef HAVE_OSX_XATTRS |
828 | + if (strncmp(rxa->name, unique_prefix, upre_len) == 0) { | |
829 | + rxa->name_len -= upre_len; | |
830 | + memmove(rxa->name, rxa->name + upre_len, rxa->name_len); | |
831 | + } | |
832 | +#endif | |
bbdff76a | 833 | + } |
49de5440 WD |
834 | + ndx = rsync_xal_l.count; /* pre-incremented count */ |
835 | + rsync_xal_store(&temp_xattr); /* adds item to rsync_xal_l */ | |
0f6fb3c8 WD |
836 | + } else if (tag == 'x') { |
837 | + ndx = read_int(f); | |
838 | + if (ndx < 0 || (size_t)ndx >= rsync_xal_l.count) { | |
839 | + rprintf(FERROR, "%s: receive_xattr: xa index %d out of range\n", | |
840 | + f_name(file, NULL), ndx); | |
bbdff76a WD |
841 | + exit_cleanup(RERR_STREAMIO); |
842 | + } | |
0f6fb3c8 WD |
843 | + } else { |
844 | + rprintf(FERROR, | |
845 | + "%s: receive_xattr: unknown extended attribute type tag: %c\n", | |
846 | + f_name(file, NULL), tag); | |
847 | + exit_cleanup(RERR_STREAMIO); | |
848 | + ndx = 0; /* silence a compiler warning... */ | |
bbdff76a | 849 | + } |
bbdff76a | 850 | + |
0f6fb3c8 | 851 | + SIVAL(ndx_ptr, 0, ndx); |
bbdff76a WD |
852 | +} |
853 | + | |
0f6fb3c8 WD |
854 | +/* Turn the xattr data in statx into cached xattr data, setting the index |
855 | + * values in the file struct. */ | |
856 | +void cache_xattr(struct file_struct *file, statx *sxp) | |
bbdff76a | 857 | +{ |
0f6fb3c8 WD |
858 | + char *ndx_ptr = (char*)file + file_struct_len; |
859 | + int ndx; | |
bbdff76a | 860 | + |
0f6fb3c8 WD |
861 | + if (!sxp->xattr) |
862 | + return; | |
bbdff76a | 863 | + |
0f6fb3c8 WD |
864 | + ndx = find_matching_xattr(sxp->xattr); |
865 | + if (ndx == -1) | |
49de5440 | 866 | + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */ |
0f6fb3c8 | 867 | + free_xattr(sxp); |
bbdff76a | 868 | + |
0f6fb3c8 | 869 | + SIVAL(ndx_ptr, 0, ndx); |
bbdff76a WD |
870 | +} |
871 | + | |
0f6fb3c8 | 872 | +static int rsync_xal_set(const char *fname, item_list *xalp) |
bbdff76a | 873 | +{ |
0f6fb3c8 WD |
874 | + rsync_xa *rxas = xalp->items; |
875 | + size_t i; | |
876 | + int ret = 0; | |
bbdff76a | 877 | + |
0f6fb3c8 WD |
878 | + for (i = 0; i < xalp->count; i++) { |
879 | + int status = sys_lsetxattr(fname, rxas[i].name, rxas[i].datum, rxas[i].datum_len, 0); | |
880 | + if (status < 0) { | |
881 | + rsyserr(FERROR, errno, "%s: rsync_xal_set: lsetxattr %s failed", | |
882 | + fname, rxas[i].name); | |
883 | + ret = -1; | |
884 | + } | |
bbdff76a | 885 | + } |
0f6fb3c8 | 886 | + return ret; |
bbdff76a WD |
887 | +} |
888 | + | |
0f6fb3c8 WD |
889 | +/* Set extended attributes on indicated filename. */ |
890 | +int set_xattr(const char *fname, const struct file_struct *file, UNUSED(statx *sxp)) | |
bbdff76a | 891 | +{ |
0f6fb3c8 WD |
892 | + int ndx; |
893 | + char *ndx_ptr = (char*)file + file_struct_len; | |
894 | + item_list *lst = rsync_xal_l.items; | |
bbdff76a | 895 | + |
93d6ca6d WD |
896 | + if (dry_run) |
897 | + return 1; /* FIXME: --dry-run needs to compute this value */ | |
898 | + | |
0f6fb3c8 WD |
899 | + ndx = IVAL(ndx_ptr, 0); |
900 | + return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */ | |
bbdff76a WD |
901 | +} |
902 | + | |
903 | +#endif /* SUPPORT_XATTRS */ |