Debian Codegraph @

restore/xattr.c

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