archive_disk_acl_darwin.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /*-
  2. * Copyright (c) 2017 Martin Matuska
  3. * All rights reserved.
  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. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "archive_platform.h"
  26. #if ARCHIVE_ACL_DARWIN
  27. #ifdef HAVE_FCNTL_H
  28. #include <fcntl.h>
  29. #endif
  30. #if HAVE_ERRNO_H
  31. #include <errno.h>
  32. #endif
  33. #if HAVE_MEMBERSHIP_H
  34. #include <membership.h>
  35. #endif
  36. #ifdef HAVE_SYS_TYPES_H
  37. #include <sys/types.h>
  38. #endif
  39. #ifdef HAVE_SYS_ACL_H
  40. #define _ACL_PRIVATE /* For debugging */
  41. #include <sys/acl.h>
  42. #endif
  43. #include "archive_entry.h"
  44. #include "archive_private.h"
  45. #include "archive_read_disk_private.h"
  46. #include "archive_write_disk_private.h"
  47. typedef struct {
  48. const int a_perm; /* Libarchive permission or flag */
  49. const int p_perm; /* Platform permission or flag */
  50. } acl_perm_map_t;
  51. static const acl_perm_map_t acl_nfs4_perm_map[] = {
  52. {ARCHIVE_ENTRY_ACL_READ_DATA, ACL_READ_DATA},
  53. {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACL_LIST_DIRECTORY},
  54. {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACL_WRITE_DATA},
  55. {ARCHIVE_ENTRY_ACL_ADD_FILE, ACL_ADD_FILE},
  56. {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE},
  57. {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE},
  58. {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA},
  59. {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY},
  60. {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACL_DELETE_CHILD},
  61. {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACL_READ_ATTRIBUTES},
  62. {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACL_WRITE_ATTRIBUTES},
  63. {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACL_READ_EXTATTRIBUTES},
  64. {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_EXTATTRIBUTES},
  65. {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_SECURITY},
  66. {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_SECURITY},
  67. {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_CHANGE_OWNER},
  68. #if HAVE_DECL_ACL_SYNCHRONIZE
  69. {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE}
  70. #endif
  71. };
  72. static const int acl_nfs4_perm_map_size =
  73. (int)(sizeof(acl_nfs4_perm_map)/sizeof(acl_nfs4_perm_map[0]));
  74. static const acl_perm_map_t acl_nfs4_flag_map[] = {
  75. {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED},
  76. {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACL_ENTRY_FILE_INHERIT},
  77. {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACL_ENTRY_DIRECTORY_INHERIT},
  78. {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACL_ENTRY_LIMIT_INHERIT},
  79. {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_ONLY_INHERIT}
  80. };
  81. static const int acl_nfs4_flag_map_size =
  82. (int)(sizeof(acl_nfs4_flag_map)/sizeof(acl_nfs4_flag_map[0]));
  83. static int translate_guid(struct archive *a, acl_entry_t acl_entry,
  84. int *ae_id, int *ae_tag, const char **ae_name)
  85. {
  86. void *q;
  87. uid_t ugid;
  88. int r, idtype;
  89. q = acl_get_qualifier(acl_entry);
  90. if (q == NULL)
  91. return (1);
  92. r = mbr_uuid_to_id((const unsigned char *)q, &ugid, &idtype);
  93. if (r != 0) {
  94. acl_free(q);
  95. return (1);
  96. }
  97. if (idtype == ID_TYPE_UID) {
  98. *ae_tag = ARCHIVE_ENTRY_ACL_USER;
  99. *ae_id = ugid;
  100. *ae_name = archive_read_disk_uname(a, *ae_id);
  101. } else if (idtype == ID_TYPE_GID) {
  102. *ae_tag = ARCHIVE_ENTRY_ACL_GROUP;
  103. *ae_id = ugid;
  104. *ae_name = archive_read_disk_gname(a, *ae_id);
  105. } else
  106. r = 1;
  107. acl_free(q);
  108. return (r);
  109. }
  110. static void
  111. add_trivial_nfs4_acl(struct archive_entry *entry)
  112. {
  113. mode_t mode;
  114. int i;
  115. const int rperm = ARCHIVE_ENTRY_ACL_READ_DATA;
  116. const int wperm = ARCHIVE_ENTRY_ACL_WRITE_DATA |
  117. ARCHIVE_ENTRY_ACL_APPEND_DATA;
  118. const int eperm = ARCHIVE_ENTRY_ACL_EXECUTE;
  119. const int pubset = ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES |
  120. ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS |
  121. ARCHIVE_ENTRY_ACL_READ_ACL |
  122. ARCHIVE_ENTRY_ACL_SYNCHRONIZE;
  123. const int ownset = pubset | ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES |
  124. ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS |
  125. ARCHIVE_ENTRY_ACL_WRITE_ACL |
  126. ARCHIVE_ENTRY_ACL_WRITE_OWNER;
  127. struct {
  128. const int type;
  129. const int tag;
  130. int permset;
  131. } tacl_entry[] = {
  132. {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_USER_OBJ, 0},
  133. {ARCHIVE_ENTRY_ACL_TYPE_DENY, ARCHIVE_ENTRY_ACL_USER_OBJ, 0},
  134. {ARCHIVE_ENTRY_ACL_TYPE_DENY, ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0},
  135. {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_USER_OBJ, ownset},
  136. {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_GROUP_OBJ, pubset},
  137. {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_EVERYONE, pubset}
  138. };
  139. mode = archive_entry_mode(entry);
  140. /* Permissions for everyone@ */
  141. if (mode & 0004)
  142. tacl_entry[5].permset |= rperm;
  143. if (mode & 0002)
  144. tacl_entry[5].permset |= wperm;
  145. if (mode & 0001)
  146. tacl_entry[5].permset |= eperm;
  147. /* Permissions for group@ */
  148. if (mode & 0040)
  149. tacl_entry[4].permset |= rperm;
  150. else if (mode & 0004)
  151. tacl_entry[2].permset |= rperm;
  152. if (mode & 0020)
  153. tacl_entry[4].permset |= wperm;
  154. else if (mode & 0002)
  155. tacl_entry[2].permset |= wperm;
  156. if (mode & 0010)
  157. tacl_entry[4].permset |= eperm;
  158. else if (mode & 0001)
  159. tacl_entry[2].permset |= eperm;
  160. /* Permissions for owner@ */
  161. if (mode & 0400) {
  162. tacl_entry[3].permset |= rperm;
  163. if (!(mode & 0040) && (mode & 0004))
  164. tacl_entry[0].permset |= rperm;
  165. } else if ((mode & 0040) || (mode & 0004))
  166. tacl_entry[1].permset |= rperm;
  167. if (mode & 0200) {
  168. tacl_entry[3].permset |= wperm;
  169. if (!(mode & 0020) && (mode & 0002))
  170. tacl_entry[0].permset |= wperm;
  171. } else if ((mode & 0020) || (mode & 0002))
  172. tacl_entry[1].permset |= wperm;
  173. if (mode & 0100) {
  174. tacl_entry[3].permset |= eperm;
  175. if (!(mode & 0010) && (mode & 0001))
  176. tacl_entry[0].permset |= eperm;
  177. } else if ((mode & 0010) || (mode & 0001))
  178. tacl_entry[1].permset |= eperm;
  179. for (i = 0; i < 6; i++) {
  180. if (tacl_entry[i].permset != 0) {
  181. archive_entry_acl_add_entry(entry,
  182. tacl_entry[i].type, tacl_entry[i].permset,
  183. tacl_entry[i].tag, -1, NULL);
  184. }
  185. }
  186. return;
  187. }
  188. static int
  189. translate_acl(struct archive_read_disk *a,
  190. struct archive_entry *entry, acl_t acl)
  191. {
  192. acl_tag_t acl_tag;
  193. acl_flagset_t acl_flagset;
  194. acl_entry_t acl_entry;
  195. acl_permset_t acl_permset;
  196. int i, entry_acl_type;
  197. int r, s, ae_id, ae_tag, ae_perm;
  198. const char *ae_name;
  199. s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry);
  200. if (s == -1) {
  201. archive_set_error(&a->archive, errno,
  202. "Failed to get first ACL entry");
  203. return (ARCHIVE_WARN);
  204. }
  205. while (s == 0) {
  206. ae_id = -1;
  207. ae_name = NULL;
  208. ae_perm = 0;
  209. if (acl_get_tag_type(acl_entry, &acl_tag) != 0) {
  210. archive_set_error(&a->archive, errno,
  211. "Failed to get ACL tag type");
  212. return (ARCHIVE_WARN);
  213. }
  214. switch (acl_tag) {
  215. case ACL_EXTENDED_ALLOW:
  216. entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW;
  217. r = translate_guid(&a->archive, acl_entry,
  218. &ae_id, &ae_tag, &ae_name);
  219. break;
  220. case ACL_EXTENDED_DENY:
  221. entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY;
  222. r = translate_guid(&a->archive, acl_entry,
  223. &ae_id, &ae_tag, &ae_name);
  224. break;
  225. default:
  226. /* Skip types that libarchive can't support. */
  227. s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
  228. continue;
  229. }
  230. /* Skip if translate_guid() above failed */
  231. if (r != 0) {
  232. s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
  233. continue;
  234. }
  235. /*
  236. * Libarchive stores "flag" (NFSv4 inheritance bits)
  237. * in the ae_perm bitmap.
  238. *
  239. * acl_get_flagset_np() fails with non-NFSv4 ACLs
  240. */
  241. if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) {
  242. archive_set_error(&a->archive, errno,
  243. "Failed to get flagset from a NFSv4 ACL entry");
  244. return (ARCHIVE_WARN);
  245. }
  246. for (i = 0; i < acl_nfs4_flag_map_size; ++i) {
  247. r = acl_get_flag_np(acl_flagset,
  248. acl_nfs4_flag_map[i].p_perm);
  249. if (r == -1) {
  250. archive_set_error(&a->archive, errno,
  251. "Failed to check flag in a NFSv4 "
  252. "ACL flagset");
  253. return (ARCHIVE_WARN);
  254. } else if (r)
  255. ae_perm |= acl_nfs4_flag_map[i].a_perm;
  256. }
  257. if (acl_get_permset(acl_entry, &acl_permset) != 0) {
  258. archive_set_error(&a->archive, errno,
  259. "Failed to get ACL permission set");
  260. return (ARCHIVE_WARN);
  261. }
  262. for (i = 0; i < acl_nfs4_perm_map_size; ++i) {
  263. /*
  264. * acl_get_perm() is spelled differently on different
  265. * platforms; see above.
  266. */
  267. r = acl_get_perm_np(acl_permset,
  268. acl_nfs4_perm_map[i].p_perm);
  269. if (r == -1) {
  270. archive_set_error(&a->archive, errno,
  271. "Failed to check permission in an ACL "
  272. "permission set");
  273. return (ARCHIVE_WARN);
  274. } else if (r)
  275. ae_perm |= acl_nfs4_perm_map[i].a_perm;
  276. }
  277. #if !HAVE_DECL_ACL_SYNCHRONIZE
  278. /* On Mac OS X without ACL_SYNCHRONIZE assume it is set */
  279. ae_perm |= ARCHIVE_ENTRY_ACL_SYNCHRONIZE;
  280. #endif
  281. archive_entry_acl_add_entry(entry, entry_acl_type,
  282. ae_perm, ae_tag,
  283. ae_id, ae_name);
  284. s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
  285. }
  286. return (ARCHIVE_OK);
  287. }
  288. static int
  289. set_acl(struct archive *a, int fd, const char *name,
  290. struct archive_acl *abstract_acl,
  291. int ae_requested_type, const char *tname)
  292. {
  293. acl_t acl;
  294. acl_entry_t acl_entry;
  295. acl_permset_t acl_permset;
  296. acl_flagset_t acl_flagset;
  297. int ret;
  298. int ae_type, ae_permset, ae_tag, ae_id;
  299. uuid_t ae_uuid;
  300. uid_t ae_uid;
  301. gid_t ae_gid;
  302. const char *ae_name;
  303. int entries;
  304. int i;
  305. ret = ARCHIVE_OK;
  306. entries = archive_acl_reset(abstract_acl, ae_requested_type);
  307. if (entries == 0)
  308. return (ARCHIVE_OK);
  309. if (ae_requested_type != ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
  310. errno = ENOENT;
  311. archive_set_error(a, errno, "Unsupported ACL type");
  312. return (ARCHIVE_FAILED);
  313. }
  314. acl = acl_init(entries);
  315. if (acl == (acl_t)NULL) {
  316. archive_set_error(a, errno,
  317. "Failed to initialize ACL working storage");
  318. return (ARCHIVE_FAILED);
  319. }
  320. while (archive_acl_next(a, abstract_acl, ae_requested_type, &ae_type,
  321. &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) {
  322. /*
  323. * Mac OS doesn't support NFSv4 ACLs for
  324. * owner@, group@ and everyone@.
  325. * We skip any of these ACLs found.
  326. */
  327. if (ae_tag == ARCHIVE_ENTRY_ACL_USER_OBJ ||
  328. ae_tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ ||
  329. ae_tag == ARCHIVE_ENTRY_ACL_EVERYONE)
  330. continue;
  331. if (acl_create_entry(&acl, &acl_entry) != 0) {
  332. archive_set_error(a, errno,
  333. "Failed to create a new ACL entry");
  334. ret = ARCHIVE_FAILED;
  335. goto exit_free;
  336. }
  337. switch (ae_type) {
  338. case ARCHIVE_ENTRY_ACL_TYPE_ALLOW:
  339. acl_set_tag_type(acl_entry, ACL_EXTENDED_ALLOW);
  340. break;
  341. case ARCHIVE_ENTRY_ACL_TYPE_DENY:
  342. acl_set_tag_type(acl_entry, ACL_EXTENDED_DENY);
  343. break;
  344. default:
  345. /* We don't support any other types on MacOS */
  346. continue;
  347. }
  348. switch (ae_tag) {
  349. case ARCHIVE_ENTRY_ACL_USER:
  350. ae_uid = archive_write_disk_uid(a, ae_name, ae_id);
  351. if (mbr_uid_to_uuid(ae_uid, ae_uuid) != 0)
  352. continue;
  353. if (acl_set_qualifier(acl_entry, &ae_uuid) != 0)
  354. continue;
  355. break;
  356. case ARCHIVE_ENTRY_ACL_GROUP:
  357. ae_gid = archive_write_disk_gid(a, ae_name, ae_id);
  358. if (mbr_gid_to_uuid(ae_gid, ae_uuid) != 0)
  359. continue;
  360. if (acl_set_qualifier(acl_entry, &ae_uuid) != 0)
  361. continue;
  362. break;
  363. default:
  364. archive_set_error(a, ARCHIVE_ERRNO_MISC,
  365. "Unsupported ACL tag");
  366. ret = ARCHIVE_FAILED;
  367. goto exit_free;
  368. }
  369. if (acl_get_permset(acl_entry, &acl_permset) != 0) {
  370. archive_set_error(a, errno,
  371. "Failed to get ACL permission set");
  372. ret = ARCHIVE_FAILED;
  373. goto exit_free;
  374. }
  375. if (acl_clear_perms(acl_permset) != 0) {
  376. archive_set_error(a, errno,
  377. "Failed to clear ACL permissions");
  378. ret = ARCHIVE_FAILED;
  379. goto exit_free;
  380. }
  381. for (i = 0; i < acl_nfs4_perm_map_size; ++i) {
  382. if (ae_permset & acl_nfs4_perm_map[i].a_perm) {
  383. if (acl_add_perm(acl_permset,
  384. acl_nfs4_perm_map[i].p_perm) != 0) {
  385. archive_set_error(a, errno,
  386. "Failed to add ACL permission");
  387. ret = ARCHIVE_FAILED;
  388. goto exit_free;
  389. }
  390. }
  391. }
  392. /*
  393. * acl_get_flagset_np() fails with non-NFSv4 ACLs
  394. */
  395. if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) {
  396. archive_set_error(a, errno,
  397. "Failed to get flagset from an NFSv4 ACL entry");
  398. ret = ARCHIVE_FAILED;
  399. goto exit_free;
  400. }
  401. if (acl_clear_flags_np(acl_flagset) != 0) {
  402. archive_set_error(a, errno,
  403. "Failed to clear flags from an NFSv4 ACL flagset");
  404. ret = ARCHIVE_FAILED;
  405. goto exit_free;
  406. }
  407. for (i = 0; i < acl_nfs4_flag_map_size; ++i) {
  408. if (ae_permset & acl_nfs4_flag_map[i].a_perm) {
  409. if (acl_add_flag_np(acl_flagset,
  410. acl_nfs4_flag_map[i].p_perm) != 0) {
  411. archive_set_error(a, errno,
  412. "Failed to add flag to "
  413. "NFSv4 ACL flagset");
  414. ret = ARCHIVE_FAILED;
  415. goto exit_free;
  416. }
  417. }
  418. }
  419. }
  420. if (fd >= 0) {
  421. if (acl_set_fd_np(fd, acl, ACL_TYPE_EXTENDED) == 0)
  422. ret = ARCHIVE_OK;
  423. else {
  424. if (errno == EOPNOTSUPP) {
  425. /* Filesystem doesn't support ACLs */
  426. ret = ARCHIVE_OK;
  427. } else {
  428. archive_set_error(a, errno,
  429. "Failed to set acl on fd: %s", tname);
  430. ret = ARCHIVE_WARN;
  431. }
  432. }
  433. } else if (acl_set_link_np(name, ACL_TYPE_EXTENDED, acl) != 0) {
  434. if (errno == EOPNOTSUPP) {
  435. /* Filesystem doesn't support ACLs */
  436. ret = ARCHIVE_OK;
  437. } else {
  438. archive_set_error(a, errno, "Failed to set acl: %s",
  439. tname);
  440. ret = ARCHIVE_WARN;
  441. }
  442. }
  443. exit_free:
  444. acl_free(acl);
  445. return (ret);
  446. }
  447. int
  448. archive_read_disk_entry_setup_acls(struct archive_read_disk *a,
  449. struct archive_entry *entry, int *fd)
  450. {
  451. const char *accpath;
  452. acl_t acl;
  453. int r;
  454. accpath = NULL;
  455. if (*fd < 0) {
  456. accpath = archive_read_disk_entry_setup_path(a, entry, fd);
  457. if (accpath == NULL)
  458. return (ARCHIVE_WARN);
  459. }
  460. archive_entry_acl_clear(entry);
  461. acl = NULL;
  462. if (*fd >= 0)
  463. acl = acl_get_fd_np(*fd, ACL_TYPE_EXTENDED);
  464. else if (!a->follow_symlinks)
  465. acl = acl_get_link_np(accpath, ACL_TYPE_EXTENDED);
  466. else
  467. acl = acl_get_file(accpath, ACL_TYPE_EXTENDED);
  468. if (acl != NULL) {
  469. r = translate_acl(a, entry, acl);
  470. acl_free(acl);
  471. acl = NULL;
  472. if (r != ARCHIVE_OK) {
  473. archive_set_error(&a->archive, errno,
  474. "Couldn't translate NFSv4 ACLs");
  475. }
  476. /*
  477. * Because Mac OS doesn't support owner@, group@ and everyone@
  478. * ACLs we need to add NFSv4 ACLs mirroring the file mode to
  479. * the archive entry. Otherwise extraction on non-Mac platforms
  480. * would lead to an invalid file mode.
  481. */
  482. if ((archive_entry_acl_types(entry) &
  483. ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0)
  484. add_trivial_nfs4_acl(entry);
  485. return (r);
  486. }
  487. return (ARCHIVE_OK);
  488. }
  489. int
  490. archive_write_disk_set_acls(struct archive *a, int fd, const char *name,
  491. struct archive_acl *abstract_acl, __LA_MODE_T mode)
  492. {
  493. int ret = ARCHIVE_OK;
  494. (void)mode; /* UNUSED */
  495. if ((archive_acl_types(abstract_acl) &
  496. ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) {
  497. ret = set_acl(a, fd, name, abstract_acl,
  498. ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4");
  499. }
  500. return (ret);
  501. }
  502. #endif /* ARCHIVE_ACL_DARWIN */