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