Debian Codegraph @

restore/xattr.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Copyright (c) 1999-2004
3 * Stelian Pop <[email protected]>, 1999-2004
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #include "config.h" // IWYU pragma: keep
31 #include "xattr.h"
32
33 #include "compat/include/compaterr.h" // IWYU pragma: keep
34 #include <sys/types.h>
35 #include <sys/xattr.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <errno.h>
40 #include <ctype.h>
41 #include <endian.h>
42 #ifdef HAVE_EXT2FS_EXT2_FS_H
43 #include <ext2fs/ext2_fs.h>
44 #else
45 #include <linux/ext2_fs.h>
46 #endif
47 #include <ext2fs/ext2_types.h>
48 #include "compat/include/bsdcompat.h"
49 #include "compat/include/protocols/dumprestore.h"
50 #ifdef TRANSSELINUX /*GAN6May06 SELinux MLS */
51 # include <selinux/selinux.h>
52 #endif
53 #include "restore.h"
54 #include "restore_globals.h"
55
•56 #if BYTE_ORDER == BIG_ENDIAN
57 #include "tape.h"
58 #endif
59
60 /*
61 * Data structures below taken from the kernel
62 */
63
64 /* Maximum number of references to one attribute block */
65 #define EXT2_XATTR_REFCOUNT_MAX 1024
66
67 /* Name indexes */
68 #define EXT2_XATTR_INDEX_MAX 10
69 #define EXT2_XATTR_INDEX_USER 1
70 #define EXT2_XATTR_INDEX_POSIX_ACL_ACCESS 2
71 #define EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT 3
72 #define EXT2_XATTR_INDEX_TRUSTED 4
73 #define EXT2_XATTR_INDEX_LUSTRE 5
74 #define EXT2_XATTR_INDEX_SECURITY 6
75 #define EXT2_XATTR_INDEX_SYSTEM 7
76
77 struct ext2_xattr_header {
78 u_int32_t h_magic; /* magic number for identification */
79 u_int32_t h_refcount; /* reference count */
80 u_int32_t h_blocks; /* number of disk blocks used */
81 u_int32_t h_hash; /* hash value of all attributes */
82 u_int32_t h_reserved[4]; /* zero right now */
83 };
84
85 struct ext3_xattr_ibody_header {
86 u_int32_t h_magic; /* magic number for identification */
87 };
88
89 struct ext2_xattr_entry {
90 u_char e_name_len; /* length of name */
91 u_char e_name_index; /* attribute name index */
92 u_int16_t e_value_offs; /* offset in disk block of value */
93 u_int32_t e_value_block; /* disk block attribute is stored on (n/i) */
94 u_int32_t e_value_size; /* size of attribute value */
95 u_int32_t e_hash; /* hash value of name and value */
96 char e_name[0]; /* attribute name */
97 };
98
99 #define EXT2_XATTR_PAD_BITS 2
100 #define EXT2_XATTR_PAD (1<<EXT2_XATTR_PAD_BITS)
101 #define EXT2_XATTR_ROUND (EXT2_XATTR_PAD-1)
102 #ifndef EXT2_XATTR_LEN
103 #define EXT2_XATTR_LEN(name_len) \
104 (((name_len) + EXT2_XATTR_ROUND + \
105 sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
106 #endif
107 #define EXT2_XATTR_NEXT(entry) \
108 ( (struct ext2_xattr_entry *)( \
109 (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
110 #define EXT3_XATTR_SIZE(size) \
111 (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
112
113 #define HDR(buffer) ((struct ext2_xattr_header *)(buffer))
114 #define ENTRY(ptr) ((struct ext2_xattr_entry *)(ptr))
115 #define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
116
117 #define BFIRST(buffer) ENTRY(HDR(buffer)+1)
118 #define IFIRST(buffer) ENTRY(((struct ext3_xattr_ibody_header *)(buffer))+1)
119
120 #define FIRST_ENTRY(buffer) \
121 ((HDR(buffer)->h_magic == EXT2_XATTR_MAGIC2) ? \
122 IFIRST(buffer) : \
123 BFIRST(buffer))
124
125 /*
126 * On-block xattr value offsets start at the beginning of the block, but
127 * on-inode xattr value offsets start after the initial header
128 * (ext3_xattr_ibody_header).
129 */
130 #define VALUE_OFFSET(buffer, entry) \
131 (((HDR(buffer)->h_magic == EXT2_XATTR_MAGIC2) ? \
132 (entry)->e_value_offs + sizeof(struct ext3_xattr_ibody_header) : \
133 (entry)->e_value_offs))
134
135 static int xattr_cb_list (char *, char *, int, int, void *);
136 static int xattr_cb_set (char *, char *, int, int, void *);
137 static int xattr_cb_compare (char *, char *, int, int, void *);
138 static int xattr_verify (char *);
139 static int xattr_walk (char *, int (*)(char *, char *, int, int, void *), void *);
140
141 #define POSIX_ACL_XATTR_VERSION 0x0002
142
143 #define ACL_UNDEFINED_ID (-1)
144
145 #define ACL_USER_OBJ (0x01)
146 #define ACL_USER (0x02)
147 #define ACL_GROUP_OBJ (0x04)
148 #define ACL_GROUP (0x08)
149 #define ACL_MASK (0x10)
150 #define ACL_OTHER (0x20)
151
152 typedef struct {
153 u_int16_t e_tag;
154 u_int16_t e_perm;
155 u_int32_t e_id;
156 } posix_acl_xattr_entry;
157
158 typedef struct {
159 u_int32_t a_version;
160 posix_acl_xattr_entry a_entries[0];
161 } posix_acl_xattr_header;
162
163 static inline size_t
164 posix_acl_xattr_size(int count)
165 {
166 return (sizeof(posix_acl_xattr_header) +
167 (count * sizeof(posix_acl_xattr_entry)));
168 }
169
170 struct posix_acl_entry {
171 short e_tag;
172 unsigned short e_perm;
173 unsigned int e_id;
174 };
175
176 struct posix_acl {
177 unsigned int a_count;
178 struct posix_acl_entry a_entries[0];
179 };
180
181 #define EXT3_ACL_VERSION 0x0001
182
183 typedef struct {
184 u_int16_t e_tag;
185 u_int16_t e_perm;
186 u_int32_t e_id;
187 } ext3_acl_entry;
188
189 typedef struct {
190 u_int16_t e_tag;
191 u_int16_t e_perm;
192 } ext3_acl_entry_short;
193
194 typedef struct {
195 u_int32_t a_version;
196 } ext3_acl_header;
197
198 static inline int ext3_acl_count(size_t size)
199 {
200 ssize_t s;
201 size -= sizeof(ext3_acl_header);
202 s = size - 4 * sizeof(ext3_acl_entry_short);
203 if (s < 0) {
204 if (size % sizeof(ext3_acl_entry_short))
205 return -1;
206 return size / sizeof(ext3_acl_entry_short);
207 } else {
208 if (s % sizeof(ext3_acl_entry))
209 return -1;
210 return s / sizeof(ext3_acl_entry) + 4;
211 }
212 }
213
214 static int
215 posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size) {
216 posix_acl_xattr_header *ext_acl = (posix_acl_xattr_header *)buffer;
217 posix_acl_xattr_entry *ext_entry = ext_acl->a_entries;
218 int real_size;
219
220 real_size = posix_acl_xattr_size(acl->a_count);
221 if (!buffer)
222 return real_size;
223 if (real_size > (ssize_t)size) {
224 fprintf(stderr, "ACL: not enough space to convert (%d %d)\n", real_size, (int)size);
225 return -1;
226 }
227
228 ext_acl->a_version = POSIX_ACL_XATTR_VERSION;
229 #if BYTE_ORDER == BIG_ENDIAN
230 swabst("1i", (u_char *)ext_acl);
231 #endif
232
233 for (unsigned int n=0; n < acl->a_count; n++, ext_entry++) {
234 ext_entry->e_tag = acl->a_entries[n].e_tag;
235 ext_entry->e_perm = acl->a_entries[n].e_perm;
236 ext_entry->e_id = acl->a_entries[n].e_id;
237 #if BYTE_ORDER == BIG_ENDIAN
238 swabst("2s1i", (u_char *)ext_entry);
239 #endif
240 }
241 return real_size;
242 }
243
244 // Avoid [-Werror=free-nonheap-object]
245 __attribute__((noinline, used))
246 static void cleanup_ptr(char**p) {
247 free(*p);
248 }
249
250 static struct posix_acl *
251 ext3_acl_from_disk(const void *value_, size_t size)
252 {
253 #if BYTE_ORDER == BIG_ENDIAN
254 char* value __attribute__((cleanup(cleanup_ptr))) = malloc(size);
255 if (!value) {
256 fprintf(stderr, "ACL malloc failed\n");
257 return NULL;
258 }
259 memcpy(value, value_, size);
260 #else
261 const char *value = value_;
262 #endif
263 const char *end = value + size;
264 int n, count;
265 struct posix_acl *acl;
266
267 if (!value)
268 return NULL;
269 if (size < sizeof(ext3_acl_header)) {
270 fprintf(stderr, "ACL size too little\n");
271 return NULL;
272 }
273 #if BYTE_ORDER == BIG_ENDIAN
274 swabst("1i", (u_char *)value);
275 #endif
276 if (((const ext3_acl_header *)value)->a_version != EXT3_ACL_VERSION) {
277 fprintf(stderr, "ACL version unknown\n");
278 return NULL;
279 }
280 value = value + sizeof(ext3_acl_header);
281 count = ext3_acl_count(size);
282 if (count < 0) {
283 fprintf(stderr, "ACL bad count\n");
284 return NULL;
285 }
286 if (count == 0)
287 return NULL;
288 acl = malloc(sizeof(struct posix_acl) + count * sizeof(struct posix_acl_entry));
289 if (!acl) {
290 fprintf(stderr, "ACL malloc failed\n");
291 return NULL;
292 }
293 acl->a_count = count;
294
295 for (n=0; n < count; n++) {
296 #if BYTE_ORDER == BIG_ENDIAN
297 ext3_acl_entry *entry = (ext3_acl_entry *)value;
298 swabst("2s", (u_char *)entry);
299 #else
300 const ext3_acl_entry *entry = (const ext3_acl_entry *)value;
301 #endif
302 if (value + sizeof(ext3_acl_entry_short) > end)
303 goto fail;
304 acl->a_entries[n].e_tag = entry->e_tag;
305 acl->a_entries[n].e_perm = entry->e_perm;
306 switch(acl->a_entries[n].e_tag) {
307 case ACL_USER_OBJ:
308 case ACL_GROUP_OBJ:
309 case ACL_MASK:
310 case ACL_OTHER:
311 value = value + sizeof(ext3_acl_entry_short);
312 acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
313 break;
314
315 case ACL_USER:
316 case ACL_GROUP:
317 #if BYTE_ORDER == BIG_ENDIAN
318 swabst("4b1i", (u_char *)entry);
319 #endif
320 value = value + sizeof(ext3_acl_entry);
321 if ((const char*)value > end)
322 goto fail;
323 acl->a_entries[n].e_id = entry->e_id;
324 break;
325
326 default:
327 goto fail;
328 }
329 }
330 if (value != end)
331 goto fail;
332 return acl;
333
334 fail:
335 fprintf(stderr, "ACL bad entry\n");
336 free(acl);
337 return NULL;
338 }
339
340 /*
341 * Dump code starts here :)
342 */
343
344 static int
345 xattr_cb_list(char *name, char *value, int valuelen, int isSELinux, UNUSED(void *private))
346 {
347 if (strcmp(name, "system.data") == 0) {
348 return GOOD;
349 }
350 (void)isSELinux;
351 value[valuelen] = '\0';
352 Dmsg(DEFAULT_DEBUG, "EA: %s:%s\n", name, value);
353
354 return GOOD;
355 }
356
357 static int
358 xattr_cb_set(char *name, char *value, int valuelen, int isSELinux, void *private)
359 {
360 char *path = (char *)private;
361 int err;
362
363 if (strcmp(name, "system.data") == 0) {
364 memcpy(inline_data + INLINE_DATA_MAX_INODE_SIZE, value, valuelen);
365 return GOOD;
366 }
367 if (Nflag)
368 return GOOD;
369
370 (void)isSELinux;
371 #ifdef TRANSSELINUX /*GAN6May06 SELinux MLS */
372 if (isSELinux)
373 err = lsetfilecon(path, value);
374 else
375 #endif
376 err = lsetxattr(path, name, value, valuelen, 0);
377
378 if (err) {
379 warn("%s: EA set %s:%s failed", path, name, value);
380 return FAIL;
381 }
382
383 return GOOD;
384 }
385
386 /* if value is a printable string then we return it as a NUL-terminated string in buffer, otherwise return a hex representation */
387 static void xattr_print(char *buffer, int bufsz, const char *value, int valuelen)
388 {
389 int ascii = 1;
390 int i;
391 int dst;
392 for (i=0; ascii && i < valuelen && i < bufsz-1; ++i) {
393 buffer[i] = value[i];
394 if(!isprint((unsigned char)value[i]))
395 ascii = 0;
396 }
397 if (ascii) {
398 buffer[i] = 0;
399 return;
400 }
401 i = 0;
402 dst = 0;
403 while (i < valuelen) {
404 if (dst == bufsz-1) {
405 buffer[dst] = 0;
406 return;
407 }
408 if (dst+(i>0?4:3) > bufsz) {
409 return;
410 }
411 sprintf(buffer+dst, "%s%02x", i>0?" ":"", (unsigned char)value[i]);
412 dst += (i>0?3:2);
413 ++i;
414 }
415 }
416
417 static int
418 xattr_cb_compare(char *name, char *value, int valuelen, int isSELinux, void *private)
419 {
420 char *path = (char *)private;
421 char valuef[XATTR_MAXSIZE];
422 int valuesz;
423
424 if (strcmp(name, "system.data") == 0) {
425 memcpy(inline_data + INLINE_DATA_MAX_INODE_SIZE, value, valuelen);
426 return GOOD;
427 }
428 (void)isSELinux;
429 #ifdef TRANSSELINUX /*GAN6May06 SELinux MLS */
430 if (isSELinux)
431 {
432 char *con = NULL;
433
434 if (lgetfilecon(path, &con) < 0) {
435 warn("%s: EA compare lgetfilecon failed\n", path);
436 return FAIL;
437 }
438
439 valuesz = strlen(con) + 1;
440 valuef[0] = 0;
441 strncat(valuef, con, sizeof(valuef) - 1);
442 freecon(con);
443 }
444 else {
445 #endif
446 valuesz = lgetxattr(path, name, valuef, XATTR_MAXSIZE);
447 if (valuesz < 0) {
448 if(errno == ENODATA) {
449 valuef[0] = 0;
450 } else {
451 warn("%s: EA compare lgetxattr for %s failed\n", path, name);
452 return FAIL;
453 }
454 }
455 #ifdef TRANSSELINUX /*GAN6May06 SELinux MLS */
456 }
457 #endif
458
459 if (valuesz != valuelen || memcmp(value, valuef, valuelen)) {
460 /* GAN24May06: show name and new value for user to compare */
461 char tvalue[49];
462 xattr_print(tvalue, 49, value, valuelen);
463 if (valuesz < 0) {
464 fprintf(stderr, "%s: EA %s with value %s on tape does not exist on disk\n", path, name, tvalue);
465 } else {
466 char fvalue[49];
467 xattr_print(fvalue, 49, valuef, valuesz);
468 fprintf(stderr, "%s: EA %s value changed from %s on tape to %s on disk\n", path, name, tvalue, fvalue);
469 }
470 return FAIL;
471 }
472
473 return GOOD;
474 }
475
476 static int
477 xattr_verify(char *buffer)
478 {
479 struct ext2_xattr_entry *entry;
480 char *end;
481
482 end = buffer + XATTR_MAXSIZE;
483
484 #if BYTE_ORDER == BIG_ENDIAN
485 swabst("4i", (u_char *)buffer);
486 #endif
487
488 if (HDR(buffer)->h_magic != EXT2_XATTR_MAGIC &&
489 HDR(buffer)->h_magic != EXT2_XATTR_MAGIC2) {
490 fprintf(stderr, "error in EA block\n");
491 fprintf(stderr, "magic = %x\n", HDR(buffer)->h_magic);
492
493 return FAIL;
494 }
495
496 /* check the on-disk data structure */
497 entry = FIRST_ENTRY(buffer);
498 #if BYTE_ORDER == BIG_ENDIAN
499 swabst("2b1s3i", (u_char *)entry);
500 #endif
501 while (!IS_LAST_ENTRY(entry)) {
502 struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(entry);
503
504 if ((char *)next >= end) {
505 fprintf(stderr, "error in EA block\n");
506 return FAIL;
507 }
508 entry = next;
509 #if BYTE_ORDER == BIG_ENDIAN
510 swabst("2b1s3i", (u_char *)entry);
511 #endif
512 }
513 return GOOD;
514 }
515
516 int
517 xattr_count(char *buffer, int *count)
518 {
519 struct ext2_xattr_entry *entry;
520 int result = 0;
521
522 /* list the attribute names */
523 for (entry = FIRST_ENTRY(buffer); !IS_LAST_ENTRY(entry);
524 entry = EXT2_XATTR_NEXT(entry))
525 switch (entry->e_name_index) {
526 case EXT2_XATTR_INDEX_SYSTEM:
527 if (entry->e_name_len == 4 && strncmp(entry->e_name, "data", 4)==0)
528 break;
529 /* FALLTHROUGH */
530 default:
531 result++;
532 break;
533 }
534 *count = result;
535 return GOOD;
536 }
537
538 /* We do not want to return early from this function as even if one attribute fails to apply for some reason, we want to try the rest. */
539 static int
540 xattr_walk(char *buffer, int (*xattr_cb)(char *, char *, int, int, void *), void *private)
541 {
542 struct ext2_xattr_entry *entry;
543 int rcode = GOOD;
544
545 /* list the attribute names */
546 for (entry = FIRST_ENTRY(buffer); !IS_LAST_ENTRY(entry);
547 entry = EXT2_XATTR_NEXT(entry)) {
548 char name[XATTR_MAXSIZE], value[XATTR_MAXSIZE];
549 int size;
550 int off;
551 int convertacl = 0;
552 int convertcon = 0;
553
554 switch (entry->e_name_index) {
555 case EXT2_XATTR_INDEX_USER:
556 strcpy(name, "user.");
557 break;
558 case EXT2_XATTR_INDEX_POSIX_ACL_ACCESS:
559 strcpy(name, "system.posix_acl_access");
560 convertacl = 1;
561 break;
562 case EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT:
563 strcpy(name, "system.posix_acl_default");
564 convertacl = 1;
565 break;
566 case EXT2_XATTR_INDEX_TRUSTED:
567 strcpy(name, "trusted.");
568 break;
569 case EXT2_XATTR_INDEX_LUSTRE:
570 strcpy(name, "lustre.");
571 break;
572 case EXT2_XATTR_INDEX_SYSTEM:
573 strcpy(name, "system.");
574 break;
575 case EXT2_XATTR_INDEX_SECURITY:
576 strcpy(name, "security.");
577 #ifdef TRANSSELINUX /*GAN6May06 SELinux MLS */
578 convertcon = transselinuxflag;
579 #endif
580 break;
581 default:
582 fprintf(stderr, "Unknown EA index\n");
583 rcode = FAIL;
584 continue;
585 }
586
587 off = strlen(name);
588 memcpy(name + off, entry->e_name, entry->e_name_len);
589 name[off + entry->e_name_len] = '\0';
590 size = entry->e_value_size;
591
592 memcpy(value, buffer + VALUE_OFFSET(buffer, entry), size);
593 value[size]='\0';
594
595 if (convertacl) {
596 struct posix_acl *acl;
597
598 acl = ext3_acl_from_disk(value, size);
599 if (!acl) {
600 rcode = FAIL;
601 continue;
602 }
603 size = posix_acl_to_xattr(acl, value, XATTR_MAXSIZE);
604 if (size < 0) {
605 rcode = FAIL;
606 continue;
607 }
608 free(acl);
609 }
610
611 #ifdef TRANSSELINUX /*GAN6May06 SELinux MLS */
612 if (convertcon && strcmp(name, "security.selinux"))
613 convertcon = 0; /*GAN24May06 only for selinux */
614
615 if (convertcon) {
616 char *con = NULL;
617 int err;
618
619 if (!transselinuxarg)
620 err = security_canonicalize_context(value, &con);
621 else {
622 strncat(value, transselinuxarg, sizeof(value) - 1);
623 err = security_canonicalize_context_raw(value, &con);
624 }
625
626 if (err < 0) {
627 warn("%s: EA canonicalize failed\n", value);
628 rcode = FAIL;
629 continue;
630 }
631
632 size = strlen(con) + 1;
633 value[0] = 0;
634 strncat(value, con, sizeof(value) - 1);
635 freecon(con);
636 }
637 #endif
638
639 if (xattr_cb(name, value, size, convertcon, private) != GOOD)
640 rcode = FAIL;
641 }
642
643 return rcode;
644 }
645
646 /* return count of the xattrs on the given file or FAIL if failed */
647 int xattr_count_file(char *path)
648 {
649 int size, count = 0;
650 char *names = NULL, *end_names, *name;
651
652 /* return number of bytes a/v */
653 size = llistxattr(path, NULL, 0);
654 if (size < 0) {
655 warn("%s: llistxattr failed", path);
656 return FAIL;
657 }
658
659 names = malloc(size + 1);
660 if (!names)
661 {
662 warn("%s: malloc failed", path);
663 return FAIL;
664 }
665
666 /* return nr of bytes and park data in names array */
667 size = llistxattr(path, names, size);
668 if (size < 0)
669 {
670 warn("%s: llistxattr failed", path);
671 free(names);
672 return FAIL;
673 }
674
675 names[size] = '\0';
676 end_names = names + size;
677
678 for (name = names; name != end_names; name = strchr(name, '\0') + 1)
679 {
680 if (!*name)
681 continue;
682 count++;
683 }
684 free(names);
685
686 return count;
687 }
688
689 int
690 xattr_compare(char *path, char *buffer)
691 {
692 /* with ext4 there may be two tape blocks for attrs: one from the actual inode, plus
693 one extra filesystem block. So we cannot check attribute counts here
694 but defer it to the caller. */
695
696 if (buffer) {
697 if (xattr_verify(buffer) == FAIL)
698 return FAIL;
699 }
700
701 return xattr_walk(buffer, xattr_cb_compare, path);
702 }
703
704 int
705 xattr_extract(char *path, char *buffer)
706 {
707 if (dflag) {
708 Dmsg(DEFAULT_DEBUG, "xattr_extract(%s)\n", path);
709 xattr_walk(buffer, xattr_cb_list, NULL);
710 }
711
712 if (xattr_verify(buffer) == FAIL)
713 return FAIL;
714
715 return xattr_walk(buffer, xattr_cb_set, path);
716 }