299
329
tempdir = getenv("TMPDIR");
300
330
if (tempdir == NULL)
301
331
tempdir = _PATH_TMP;
302
tempfile = tempnam(tempdir, "tar.md.");
332
archive_string_init(&tempfile);
333
archive_strcpy(&tempfile, tempdir);
334
archive_strcat(&tempfile, "tar.md.XXXXXX");
335
tempfd = mkstemp(tempfile.s);
337
archive_set_error(&a->archive, errno,
338
"Could not open extended attribute file");
342
__archive_ensure_cloexec_flag(tempfd);
304
344
/* XXX I wish copyfile() could pack directly to a memory
305
345
* buffer; that would avoid the temp file here. For that
306
346
* matter, it would be nice if fcopyfile() actually worked,
307
347
* that would reduce the many open/close races here. */
308
if (copyfile(name, tempfile, 0, copyfile_flags | COPYFILE_PACK)) {
348
if (copyfile(name, tempfile.s, 0, copyfile_flags | COPYFILE_PACK)) {
309
349
archive_set_error(&a->archive, errno,
310
350
"Could not pack extended attributes");
311
351
ret = ARCHIVE_WARN;
314
tempfd = open(tempfile, O_RDONLY);
316
archive_set_error(&a->archive, errno,
317
"Could not open extended attribute file");
321
354
if (fstat(tempfd, ©file_stat)) {
322
355
archive_set_error(&a->archive, errno,
323
356
"Could not check size of extended attributes");
418
* Translate POSIX.1e ACL into libarchive internal structure.
485
* Translate system ACL into libarchive internal structure.
421
setup_acl_posix1e(struct archive_read_disk *a,
422
struct archive_entry *entry, acl_t acl, int archive_entry_acl_type)
492
{ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE},
493
{ARCHIVE_ENTRY_ACL_WRITE, ACL_WRITE},
494
{ARCHIVE_ENTRY_ACL_READ, ACL_READ},
495
{ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA},
496
{ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY},
497
{ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA},
498
{ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE},
499
{ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA},
500
{ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY},
501
{ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_NAMED_ATTRS},
502
{ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_NAMED_ATTRS},
503
{ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD},
504
{ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES},
505
{ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES},
506
{ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE},
507
{ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_ACL},
508
{ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_ACL},
509
{ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_WRITE_OWNER},
510
{ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE}
515
int platform_inherit;
516
} acl_inherit_map[] = {
517
{ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT},
518
{ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT},
519
{ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_NO_PROPAGATE_INHERIT},
520
{ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_INHERIT_ONLY}
524
translate_acl(struct archive_read_disk *a,
525
struct archive_entry *entry, acl_t acl, int default_entry_acl_type)
424
527
acl_tag_t acl_tag;
528
acl_entry_type_t acl_type;
529
acl_flagset_t acl_flagset;
425
530
acl_entry_t acl_entry;
426
531
acl_permset_t acl_permset;
532
int brand, i, r, entry_acl_type;
427
533
int s, ae_id, ae_tag, ae_perm;
428
534
const char *ae_name;
537
// FreeBSD "brands" ACLs as POSIX.1e or NFSv4
538
// Make sure the "brand" on this ACL is consistent
539
// with the default_entry_acl_type bits provided.
540
acl_get_brand_np(acl, &brand);
542
case ACL_BRAND_POSIX:
543
switch (default_entry_acl_type) {
544
case ARCHIVE_ENTRY_ACL_TYPE_ACCESS:
545
case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT:
548
// XXX set warning message?
549
return ARCHIVE_FAILED;
553
if (default_entry_acl_type & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
554
// XXX set warning message?
555
return ARCHIVE_FAILED;
559
// XXX set warning message?
560
return ARCHIVE_FAILED;
430
565
s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry);
435
571
acl_get_tag_type(acl_entry, &acl_tag);
436
if (acl_tag == ACL_USER) {
437
574
ae_id = (int)*(uid_t *)acl_get_qualifier(acl_entry);
438
575
ae_name = archive_read_disk_uname(&a->archive, ae_id);
439
576
ae_tag = ARCHIVE_ENTRY_ACL_USER;
440
} else if (acl_tag == ACL_GROUP) {
441
579
ae_id = (int)*(gid_t *)acl_get_qualifier(acl_entry);
442
580
ae_name = archive_read_disk_gname(&a->archive, ae_id);
443
581
ae_tag = ARCHIVE_ENTRY_ACL_GROUP;
444
} else if (acl_tag == ACL_MASK) {
445
584
ae_tag = ARCHIVE_ENTRY_ACL_MASK;
446
} else if (acl_tag == ACL_USER_OBJ) {
447
587
ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
448
} else if (acl_tag == ACL_GROUP_OBJ) {
449
590
ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
450
} else if (acl_tag == ACL_OTHER) {
451
593
ae_tag = ARCHIVE_ENTRY_ACL_OTHER;
596
ae_tag = ARCHIVE_ENTRY_ACL_EVERYONE;
453
599
/* Skip types that libarchive can't support. */
600
s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
457
acl_get_permset(acl_entry, &acl_permset);
604
// XXX acl type maps to allow/deny/audit/YYYY bits
605
// XXX acl_get_entry_type_np on FreeBSD returns EINVAL for
607
entry_acl_type = default_entry_acl_type;
608
r = acl_get_entry_type_np(acl_entry, &acl_type);
611
case ACL_ENTRY_TYPE_ALLOW:
612
entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW;
614
case ACL_ENTRY_TYPE_DENY:
615
entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY;
617
case ACL_ENTRY_TYPE_AUDIT:
618
entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_AUDIT;
620
case ACL_ENTRY_TYPE_ALARM:
621
entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALARM;
460
* acl_get_perm() is spelled differently on different
461
* platforms; see above.
627
* Libarchive stores "flag" (NFSv4 inheritance bits)
628
* in the ae_perm bitmap.
463
if (ACL_GET_PERM(acl_permset, ACL_EXECUTE))
464
ae_perm |= ARCHIVE_ENTRY_ACL_EXECUTE;
465
if (ACL_GET_PERM(acl_permset, ACL_READ))
466
ae_perm |= ARCHIVE_ENTRY_ACL_READ;
467
if (ACL_GET_PERM(acl_permset, ACL_WRITE))
468
ae_perm |= ARCHIVE_ENTRY_ACL_WRITE;
470
archive_entry_acl_add_entry(entry,
471
archive_entry_acl_type, ae_perm, ae_tag,
630
acl_get_flagset_np(acl_entry, &acl_flagset);
631
for (i = 0; i < (int)(sizeof(acl_inherit_map) / sizeof(acl_inherit_map[0])); ++i) {
632
if (acl_get_flag_np(acl_flagset,
633
acl_inherit_map[i].platform_inherit))
634
ae_perm |= acl_inherit_map[i].archive_inherit;
638
acl_get_permset(acl_entry, &acl_permset);
639
for (i = 0; i < (int)(sizeof(acl_perm_map) / sizeof(acl_perm_map[0])); ++i) {
641
* acl_get_perm() is spelled differently on different
642
* platforms; see above.
644
if (ACL_GET_PERM(acl_permset, acl_perm_map[i].platform_perm))
645
ae_perm |= acl_perm_map[i].archive_perm;
648
archive_entry_acl_add_entry(entry, entry_acl_type,
474
652
s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
479
setup_acls_posix1e(struct archive_read_disk *a,
480
struct archive_entry *entry, int fd)
658
setup_acls(struct archive_read_disk *a,
659
struct archive_entry *entry, int *fd)
482
661
(void)a; /* UNUSED */
483
662
(void)entry; /* UNUSED */
859
r = ioctl(fd, FS_IOC_FIEMAP, fm);
1073
r = ioctl(*fd, FS_IOC_FIEMAP, fm);
861
/* When errno is ENOTTY, it is better we should
862
* return ARCHIVE_OK because an earlier version
863
*(<2.6.28) cannot perfom FS_IOC_FIEMAP.
864
* We should also check if errno is EOPNOTSUPP,
865
* it means "Operation not supported". */
866
if (errno != ENOTTY && errno != EOPNOTSUPP) {
867
archive_set_error(&a->archive, errno,
869
exit_sts = ARCHIVE_FAILED;
1075
/* When something error happens, it is better we
1076
* should return ARCHIVE_OK because an earlier
1077
* version(<2.6.28) cannot perfom FS_IOC_FIEMAP. */
871
1078
goto exit_setup_sparse;
873
1080
if (fm->fm_mapped_extents == 0)
875
1082
fe = fm->fm_extents;
876
for (i = 0; i < fm->fm_mapped_extents; i++, fe++) {
1083
for (i = 0; i < (int)fm->fm_mapped_extents; i++, fe++) {
877
1084
if (!(fe->fe_flags & FIEMAP_EXTENT_UNWRITTEN)) {
878
1085
/* The fe_length of the last block does not
879
1086
* adjust itself to its size files. */
880
1087
int64_t length = fe->fe_length;
881
if (fe->fe_logical + length > size)
1088
if (fe->fe_logical + length > (uint64_t)size)
882
1089
length -= fe->fe_logical + length - size;
883
1090
if (fe->fe_logical == 0 && length == size) {
884
1091
/* This is not sparse. */
926
1130
return (ARCHIVE_OK);
928
1132
/* Does filesystem support the reporting of hole ? */
930
if (fpathconf(fd, _PC_MIN_HOLE_SIZE) <= 0)
1133
if (*fd < 0 && a->tree != NULL) {
1136
path = archive_entry_sourcepath(entry);
1138
path = archive_entry_pathname(entry);
1139
*fd = a->open_on_current_dir(a->tree, path,
1140
O_RDONLY | O_NONBLOCK);
1142
archive_set_error(&a->archive, errno,
1143
"Can't open `%s'", path);
1144
return (ARCHIVE_FAILED);
1149
if (fpathconf(*fd, _PC_MIN_HOLE_SIZE) <= 0)
931
1150
return (ARCHIVE_OK);
932
initial_off = lseek(fd, 0, SEEK_CUR);
1151
initial_off = lseek(*fd, 0, SEEK_CUR);
933
1152
if (initial_off != 0)
934
lseek(fd, 0, SEEK_SET);
1153
lseek(*fd, 0, SEEK_SET);
936
1155
const char *path;
938
1157
path = archive_entry_sourcepath(entry);
939
1158
if (path == NULL)
940
1159
path = archive_entry_pathname(entry);
941
1161
if (pathconf(path, _PC_MIN_HOLE_SIZE) <= 0)
942
1162
return (ARCHIVE_OK);
943
fd = open(path, O_RDONLY | O_NONBLOCK);
1163
*fd = open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
945
1165
archive_set_error(&a->archive, errno,
946
1166
"Can't open `%s'", path);
947
1167
return (ARCHIVE_FAILED);
1169
__archive_ensure_cloexec_flag(*fd);
949
1170
initial_off = 0;
953
1174
size = archive_entry_size(entry);
954
1175
while (off_s < size) {
955
off_s = lseek(fd, off_s, SEEK_DATA);
1176
off_s = lseek(*fd, off_s, SEEK_DATA);
956
1177
if (off_s == (off_t)-1) {
957
1178
if (errno == ENXIO)
958
1179
break;/* no more hole */