xattrs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /* Support for extended attributes.
  2. Copyright (C) 2006-2020 Free Software Foundation, Inc.
  3. This file is part of GNU tar.
  4. GNU tar is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. GNU tar is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. Written by James Antill, on 2006-07-27. */
  15. #include <config.h>
  16. #include <system.h>
  17. #include <fnmatch.h>
  18. #include <quotearg.h>
  19. #include "common.h"
  20. #include "xattr-at.h"
  21. #include "selinux-at.h"
  22. struct xattrs_mask_map
  23. {
  24. const char **masks;
  25. size_t size;
  26. size_t used;
  27. };
  28. /* list of fnmatch patterns */
  29. static struct
  30. {
  31. /* lists of fnmatch patterns */
  32. struct xattrs_mask_map incl;
  33. struct xattrs_mask_map excl;
  34. } xattrs_setup;
  35. /* disable posix acls when problem found in gnulib script m4/acl.m4 */
  36. #if ! USE_ACL
  37. # undef HAVE_POSIX_ACLS
  38. #endif
  39. #ifdef HAVE_POSIX_ACLS
  40. # include "acl.h"
  41. # include <sys/acl.h>
  42. #endif
  43. #ifdef HAVE_POSIX_ACLS
  44. /* acl-at wrappers, TODO: move to gnulib in future? */
  45. static acl_t acl_get_file_at (int, const char *, acl_type_t);
  46. static int acl_set_file_at (int, const char *, acl_type_t, acl_t);
  47. static int file_has_acl_at (int, char const *, struct stat const *);
  48. static int acl_delete_def_file_at (int, char const *);
  49. /* acl_get_file_at */
  50. #define AT_FUNC_NAME acl_get_file_at
  51. #define AT_FUNC_RESULT acl_t
  52. #define AT_FUNC_FAIL (acl_t)NULL
  53. #define AT_FUNC_F1 acl_get_file
  54. #define AT_FUNC_POST_FILE_PARAM_DECLS , acl_type_t type
  55. #define AT_FUNC_POST_FILE_ARGS , type
  56. #include "at-func.c"
  57. #undef AT_FUNC_NAME
  58. #undef AT_FUNC_F1
  59. #undef AT_FUNC_RESULT
  60. #undef AT_FUNC_FAIL
  61. #undef AT_FUNC_POST_FILE_PARAM_DECLS
  62. #undef AT_FUNC_POST_FILE_ARGS
  63. /* acl_set_file_at */
  64. #define AT_FUNC_NAME acl_set_file_at
  65. #define AT_FUNC_F1 acl_set_file
  66. #define AT_FUNC_POST_FILE_PARAM_DECLS , acl_type_t type, acl_t acl
  67. #define AT_FUNC_POST_FILE_ARGS , type, acl
  68. #include "at-func.c"
  69. #undef AT_FUNC_NAME
  70. #undef AT_FUNC_F1
  71. #undef AT_FUNC_POST_FILE_PARAM_DECLS
  72. #undef AT_FUNC_POST_FILE_ARGS
  73. /* acl_delete_def_file_at */
  74. #define AT_FUNC_NAME acl_delete_def_file_at
  75. #define AT_FUNC_F1 acl_delete_def_file
  76. #define AT_FUNC_POST_FILE_PARAM_DECLS
  77. #define AT_FUNC_POST_FILE_ARGS
  78. #include "at-func.c"
  79. #undef AT_FUNC_NAME
  80. #undef AT_FUNC_F1
  81. #undef AT_FUNC_POST_FILE_PARAM_DECLS
  82. #undef AT_FUNC_POST_FILE_ARGS
  83. /* gnulib file_has_acl_at */
  84. #define AT_FUNC_NAME file_has_acl_at
  85. #define AT_FUNC_F1 file_has_acl
  86. #define AT_FUNC_POST_FILE_PARAM_DECLS , struct stat const *st
  87. #define AT_FUNC_POST_FILE_ARGS , st
  88. #include "at-func.c"
  89. #undef AT_FUNC_NAME
  90. #undef AT_FUNC_F1
  91. #undef AT_FUNC_POST_FILE_PARAM_DECLS
  92. #undef AT_FUNC_POST_FILE_ARGS
  93. /* convert unix permissions into an ACL ... needed due to "default" ACLs */
  94. static acl_t
  95. perms2acl (int perms)
  96. {
  97. char val[] = "user::---,group::---,other::---";
  98. /* 0123456789 123456789 123456789 123456789 */
  99. /* user */
  100. if (perms & 0400)
  101. val[6] = 'r';
  102. if (perms & 0200)
  103. val[7] = 'w';
  104. if (perms & 0100)
  105. val[8] = 'x';
  106. /* group */
  107. if (perms & 0040)
  108. val[17] = 'r';
  109. if (perms & 0020)
  110. val[18] = 'w';
  111. if (perms & 0010)
  112. val[19] = 'x';
  113. /* other */
  114. if (perms & 0004)
  115. val[28] = 'r';
  116. if (perms & 0002)
  117. val[29] = 'w';
  118. if (perms & 0001)
  119. val[30] = 'x';
  120. return acl_from_text (val);
  121. }
  122. static char *
  123. skip_to_ext_fields (char *ptr)
  124. {
  125. /* skip tag name (user/group/default/mask) */
  126. ptr += strcspn (ptr, ":,\n");
  127. if (*ptr != ':')
  128. return ptr;
  129. ++ptr;
  130. ptr += strcspn (ptr, ":,\n"); /* skip user/group name */
  131. if (*ptr != ':')
  132. return ptr;
  133. ++ptr;
  134. ptr += strcspn (ptr, ":,\n"); /* skip perms */
  135. return ptr;
  136. }
  137. /* The POSIX draft allows extra fields after the three main ones. Star
  138. uses this to add a fourth field for user/group which is the numeric ID.
  139. This function removes such extra fields by overwriting them with the
  140. characters that follow. */
  141. static char *
  142. fixup_extra_acl_fields (char *ptr)
  143. {
  144. char *src = ptr;
  145. char *dst = ptr;
  146. while (*src)
  147. {
  148. const char *old = src;
  149. size_t len = 0;
  150. src = skip_to_ext_fields (src);
  151. len = src - old;
  152. if (old != dst)
  153. memmove (dst, old, len);
  154. dst += len;
  155. if (*src == ':') /* We have extra fields, skip them all */
  156. src += strcspn (src, "\n,");
  157. if ((*src == '\n') || (*src == ','))
  158. *dst++ = *src++; /* also done when dst == src, but that's ok */
  159. }
  160. if (src != dst)
  161. *dst = 0;
  162. return ptr;
  163. }
  164. /* Set the "system.posix_acl_access/system.posix_acl_default" extended
  165. attribute. Called only when acls_option > 0. */
  166. static void
  167. xattrs__acls_set (struct tar_stat_info const *st,
  168. char const *file_name, int type,
  169. char *ptr, size_t len, bool def)
  170. {
  171. acl_t acl;
  172. if (ptr)
  173. {
  174. /* assert (strlen (ptr) == len); */
  175. ptr = fixup_extra_acl_fields (ptr);
  176. acl = acl_from_text (ptr);
  177. }
  178. else if (def)
  179. {
  180. /* No "default" IEEE 1003.1e ACL set for directory. At this moment,
  181. FILE_NAME may already have inherited default acls from parent
  182. directory; clean them up. */
  183. if (acl_delete_def_file_at (chdir_fd, file_name))
  184. WARNOPT (WARN_XATTR_WRITE,
  185. (0, errno,
  186. _("acl_delete_def_file_at: Cannot drop default POSIX ACLs "
  187. "for file '%s'"),
  188. file_name));
  189. return;
  190. }
  191. else
  192. acl = perms2acl (st->stat.st_mode);
  193. if (!acl)
  194. {
  195. call_arg_warn ("acl_from_text", file_name);
  196. return;
  197. }
  198. if (acl_set_file_at (chdir_fd, file_name, type, acl) == -1)
  199. /* warn even if filesystem does not support acls */
  200. WARNOPT (WARN_XATTR_WRITE,
  201. (0, errno,
  202. _ ("acl_set_file_at: Cannot set POSIX ACLs for file '%s'"),
  203. file_name));
  204. acl_free (acl);
  205. }
  206. /* Cleanup textual representation of the ACL in VAL by eliminating tab
  207. characters and comments */
  208. static void
  209. xattrs_acls_cleanup (char *val, size_t *plen)
  210. {
  211. char *p, *q;
  212. p = q = val + strcspn (val, "#\t");
  213. while (*q)
  214. {
  215. if (*q == '\t')
  216. q++;
  217. else if (*q == '#')
  218. {
  219. while (*q != '\n')
  220. q++;
  221. }
  222. else
  223. *p++ = *q++;
  224. }
  225. *plen = p - val;
  226. *p++ = 0;
  227. }
  228. static void
  229. xattrs__acls_get_a (int parentfd, const char *file_name,
  230. struct tar_stat_info *st,
  231. char **ret_ptr, size_t * ret_len)
  232. {
  233. char *val = NULL;
  234. acl_t acl;
  235. if (!(acl = acl_get_file_at (parentfd, file_name, ACL_TYPE_ACCESS)))
  236. {
  237. if (errno != ENOTSUP)
  238. call_arg_warn ("acl_get_file_at", file_name);
  239. return;
  240. }
  241. val = acl_to_text (acl, NULL);
  242. acl_free (acl);
  243. if (!val)
  244. {
  245. call_arg_warn ("acl_to_text", file_name);
  246. return;
  247. }
  248. *ret_ptr = xstrdup (val);
  249. xattrs_acls_cleanup (*ret_ptr, ret_len);
  250. acl_free (val);
  251. }
  252. /* "system.posix_acl_default" */
  253. static void
  254. xattrs__acls_get_d (int parentfd, char const *file_name,
  255. struct tar_stat_info *st,
  256. char **ret_ptr, size_t * ret_len)
  257. {
  258. char *val = NULL;
  259. acl_t acl;
  260. if (!(acl = acl_get_file_at (parentfd, file_name, ACL_TYPE_DEFAULT)))
  261. {
  262. if (errno != ENOTSUP)
  263. call_arg_warn ("acl_get_file_at", file_name);
  264. return;
  265. }
  266. val = acl_to_text (acl, NULL);
  267. acl_free (acl);
  268. if (!val)
  269. {
  270. call_arg_warn ("acl_to_text", file_name);
  271. return;
  272. }
  273. *ret_ptr = xstrdup (val);
  274. xattrs_acls_cleanup (*ret_ptr, ret_len);
  275. acl_free (val);
  276. }
  277. #endif /* HAVE_POSIX_ACLS */
  278. static void
  279. acls_one_line (const char *prefix, char delim,
  280. const char *aclstring, size_t len)
  281. {
  282. /* support both long and short text representation of posix acls */
  283. struct obstack stk;
  284. int pref_len = strlen (prefix);
  285. const char *oldstring = aclstring;
  286. int pos = 0;
  287. if (!aclstring || !len)
  288. return;
  289. obstack_init (&stk);
  290. while (pos <= len)
  291. {
  292. int move = strcspn (aclstring, ",\n");
  293. if (!move)
  294. break;
  295. if (oldstring != aclstring)
  296. obstack_1grow (&stk, delim);
  297. obstack_grow (&stk, prefix, pref_len);
  298. obstack_grow (&stk, aclstring, move);
  299. pos += move + 1;
  300. aclstring += move + 1;
  301. }
  302. obstack_1grow (&stk, '\0');
  303. fprintf (stdlis, "%s", (char *) obstack_finish (&stk));
  304. obstack_free (&stk, NULL);
  305. }
  306. void
  307. xattrs_acls_get (int parentfd, char const *file_name,
  308. struct tar_stat_info *st, int fd, int xisfile)
  309. {
  310. if (acls_option > 0)
  311. {
  312. #ifndef HAVE_POSIX_ACLS
  313. static int done = 0;
  314. if (!done)
  315. WARN ((0, 0, _("POSIX ACL support is not available")));
  316. done = 1;
  317. #else
  318. int err = file_has_acl_at (parentfd, file_name, &st->stat);
  319. if (err == 0)
  320. return;
  321. if (err == -1)
  322. {
  323. call_arg_warn ("file_has_acl_at", file_name);
  324. return;
  325. }
  326. xattrs__acls_get_a (parentfd, file_name, st,
  327. &st->acls_a_ptr, &st->acls_a_len);
  328. if (!xisfile)
  329. xattrs__acls_get_d (parentfd, file_name, st,
  330. &st->acls_d_ptr, &st->acls_d_len);
  331. #endif
  332. }
  333. }
  334. void
  335. xattrs_acls_set (struct tar_stat_info const *st,
  336. char const *file_name, char typeflag)
  337. {
  338. if (acls_option > 0 && typeflag != SYMTYPE)
  339. {
  340. #ifndef HAVE_POSIX_ACLS
  341. static int done = 0;
  342. if (!done)
  343. WARN ((0, 0, _("POSIX ACL support is not available")));
  344. done = 1;
  345. #else
  346. xattrs__acls_set (st, file_name, ACL_TYPE_ACCESS,
  347. st->acls_a_ptr, st->acls_a_len, false);
  348. if (typeflag == DIRTYPE || typeflag == GNUTYPE_DUMPDIR)
  349. xattrs__acls_set (st, file_name, ACL_TYPE_DEFAULT,
  350. st->acls_d_ptr, st->acls_d_len, true);
  351. #endif
  352. }
  353. }
  354. static void
  355. mask_map_realloc (struct xattrs_mask_map *map)
  356. {
  357. if (map->used == map->size)
  358. {
  359. if (map->size == 0)
  360. map->size = 4;
  361. map->masks = x2nrealloc (map->masks, &map->size, sizeof (map->masks[0]));
  362. }
  363. }
  364. void
  365. xattrs_mask_add (const char *mask, bool incl)
  366. {
  367. struct xattrs_mask_map *mask_map =
  368. incl ? &xattrs_setup.incl : &xattrs_setup.excl;
  369. /* ensure there is enough space */
  370. mask_map_realloc (mask_map);
  371. /* just assign pointers -- we silently expect that pointer "mask" is valid
  372. through the whole program (pointer to argv array) */
  373. mask_map->masks[mask_map->used++] = mask;
  374. }
  375. static void
  376. clear_mask_map (struct xattrs_mask_map *mask_map)
  377. {
  378. if (mask_map->size)
  379. free (mask_map->masks);
  380. }
  381. void
  382. xattrs_clear_setup (void)
  383. {
  384. clear_mask_map (&xattrs_setup.incl);
  385. clear_mask_map (&xattrs_setup.excl);
  386. }
  387. static bool xattrs_masked_out (const char *kw, bool archiving);
  388. /* get xattrs from file given by FILE_NAME or FD (when non-zero)
  389. xattrs are checked against the user supplied include/exclude mask
  390. if no mask is given this includes all the user.*, security.*, system.*,
  391. etc. available domains */
  392. void
  393. xattrs_xattrs_get (int parentfd, char const *file_name,
  394. struct tar_stat_info *st, int fd)
  395. {
  396. if (xattrs_option > 0)
  397. {
  398. #ifndef HAVE_XATTRS
  399. static int done = 0;
  400. if (!done)
  401. WARN ((0, 0, _("XATTR support is not available")));
  402. done = 1;
  403. #else
  404. static size_t xsz = 1024;
  405. static char *xatrs = NULL;
  406. ssize_t xret = -1;
  407. if (!xatrs)
  408. xatrs = x2nrealloc (xatrs, &xsz, 1);
  409. while (((fd == 0) ?
  410. ((xret =
  411. llistxattrat (parentfd, file_name, xatrs, xsz)) == -1) :
  412. ((xret = flistxattr (fd, xatrs, xsz)) == -1))
  413. && (errno == ERANGE))
  414. {
  415. xatrs = x2nrealloc (xatrs, &xsz, 1);
  416. }
  417. if (xret == -1)
  418. call_arg_warn ((fd == 0) ? "llistxattrat" : "flistxattr", file_name);
  419. else
  420. {
  421. const char *attr = xatrs;
  422. static size_t asz = 1024;
  423. static char *val = NULL;
  424. if (!val)
  425. val = x2nrealloc (val, &asz, 1);
  426. while (xret > 0)
  427. {
  428. size_t len = strlen (attr);
  429. ssize_t aret = 0;
  430. while (((fd == 0)
  431. ? ((aret = lgetxattrat (parentfd, file_name, attr,
  432. val, asz)) == -1)
  433. : ((aret = fgetxattr (fd, attr, val, asz)) == -1))
  434. && (errno == ERANGE))
  435. {
  436. val = x2nrealloc (val, &asz, 1);
  437. }
  438. if (aret != -1)
  439. {
  440. if (!xattrs_masked_out (attr, true))
  441. xheader_xattr_add (st, attr, val, aret);
  442. }
  443. else if (errno != ENOATTR)
  444. call_arg_warn ((fd == 0) ? "lgetxattrat"
  445. : "fgetxattr", file_name);
  446. attr += len + 1;
  447. xret -= len + 1;
  448. }
  449. }
  450. #endif
  451. }
  452. }
  453. #ifdef HAVE_XATTRS
  454. static void
  455. xattrs__fd_set (struct tar_stat_info const *st,
  456. char const *file_name, char typeflag,
  457. const char *attr, const char *ptr, size_t len)
  458. {
  459. if (ptr)
  460. {
  461. const char *sysname = "setxattrat";
  462. int ret = -1;
  463. if (typeflag != SYMTYPE)
  464. ret = setxattrat (chdir_fd, file_name, attr, ptr, len, 0);
  465. else
  466. {
  467. sysname = "lsetxattr";
  468. ret = lsetxattrat (chdir_fd, file_name, attr, ptr, len, 0);
  469. }
  470. if (ret == -1)
  471. WARNOPT (WARN_XATTR_WRITE,
  472. (0, errno,
  473. _("%s: Cannot set '%s' extended attribute for file '%s'"),
  474. sysname, attr, file_name));
  475. }
  476. }
  477. #endif
  478. /* lgetfileconat is called against FILE_NAME iff the FD parameter is set to
  479. zero, otherwise the fgetfileconat is used against correct file descriptor */
  480. void
  481. xattrs_selinux_get (int parentfd, char const *file_name,
  482. struct tar_stat_info *st, int fd)
  483. {
  484. if (selinux_context_option > 0)
  485. {
  486. #if HAVE_SELINUX_SELINUX_H != 1
  487. static int done = 0;
  488. if (!done)
  489. WARN ((0, 0, _("SELinux support is not available")));
  490. done = 1;
  491. #else
  492. int result = fd ?
  493. fgetfilecon (fd, &st->cntx_name)
  494. : lgetfileconat (parentfd, file_name, &st->cntx_name);
  495. if (result == -1 && errno != ENODATA && errno != ENOTSUP)
  496. call_arg_warn (fd ? "fgetfilecon" : "lgetfileconat", file_name);
  497. #endif
  498. }
  499. }
  500. void
  501. xattrs_selinux_set (struct tar_stat_info const *st,
  502. char const *file_name, char typeflag)
  503. {
  504. if (selinux_context_option > 0)
  505. {
  506. #if HAVE_SELINUX_SELINUX_H != 1
  507. static int done = 0;
  508. if (!done)
  509. WARN ((0, 0, _("SELinux support is not available")));
  510. done = 1;
  511. #else
  512. const char *sysname = "setfilecon";
  513. int ret;
  514. if (!st->cntx_name)
  515. return;
  516. if (typeflag != SYMTYPE)
  517. {
  518. ret = setfileconat (chdir_fd, file_name, st->cntx_name);
  519. sysname = "setfileconat";
  520. }
  521. else
  522. {
  523. ret = lsetfileconat (chdir_fd, file_name, st->cntx_name);
  524. sysname = "lsetfileconat";
  525. }
  526. if (ret == -1)
  527. WARNOPT (WARN_XATTR_WRITE,
  528. (0, errno,
  529. _("%s: Cannot set SELinux context for file '%s'"),
  530. sysname, file_name));
  531. #endif
  532. }
  533. }
  534. static bool
  535. xattrs_matches_mask (const char *kw, struct xattrs_mask_map *mm)
  536. {
  537. int i;
  538. if (!mm->size)
  539. return false;
  540. for (i = 0; i < mm->used; i++)
  541. if (fnmatch (mm->masks[i], kw, 0) == 0)
  542. return true;
  543. return false;
  544. }
  545. #define USER_DOT_PFX "user."
  546. static bool
  547. xattrs_kw_included (const char *kw, bool archiving)
  548. {
  549. if (xattrs_setup.incl.size)
  550. return xattrs_matches_mask (kw, &xattrs_setup.incl);
  551. else if (archiving)
  552. return true;
  553. else
  554. return strncmp (kw, USER_DOT_PFX, sizeof (USER_DOT_PFX) - 1) == 0;
  555. }
  556. static bool
  557. xattrs_kw_excluded (const char *kw, bool archiving)
  558. {
  559. return xattrs_setup.excl.size ?
  560. xattrs_matches_mask (kw, &xattrs_setup.excl) : false;
  561. }
  562. /* Check whether the xattr with keyword KW should be discarded from list of
  563. attributes that are going to be archived/excluded (set ARCHIVING=true for
  564. archiving, false for excluding) */
  565. static bool
  566. xattrs_masked_out (const char *kw, bool archiving)
  567. {
  568. return xattrs_kw_included (kw, archiving) ?
  569. xattrs_kw_excluded (kw, archiving) : true;
  570. }
  571. void
  572. xattrs_xattrs_set (struct tar_stat_info const *st,
  573. char const *file_name, char typeflag, int later_run)
  574. {
  575. if (xattrs_option > 0)
  576. {
  577. #ifndef HAVE_XATTRS
  578. static int done = 0;
  579. if (!done)
  580. WARN ((0, 0, _("XATTR support is not available")));
  581. done = 1;
  582. #else
  583. size_t scan = 0;
  584. if (!st->xattr_map_size)
  585. return;
  586. for (; scan < st->xattr_map_size; ++scan)
  587. {
  588. char *keyword = st->xattr_map[scan].xkey;
  589. keyword += strlen ("SCHILY.xattr.");
  590. /* TODO: this 'later_run' workaround is temporary solution -> once
  591. capabilities should become fully supported by it's API and there
  592. should exist something like xattrs_capabilities_set() call.
  593. For a regular files: all extended attributes are restored during
  594. the first run except 'security.capability' which is restored in
  595. 'later_run == 1'. */
  596. if (typeflag == REGTYPE
  597. && later_run == !!strcmp (keyword, "security.capability"))
  598. continue;
  599. if (xattrs_masked_out (keyword, false /* extracting */ ))
  600. /* we don't want to restore this keyword */
  601. continue;
  602. xattrs__fd_set (st, file_name, typeflag, keyword,
  603. st->xattr_map[scan].xval_ptr,
  604. st->xattr_map[scan].xval_len);
  605. }
  606. #endif
  607. }
  608. }
  609. void
  610. xattrs_print_char (struct tar_stat_info const *st, char *output)
  611. {
  612. int i;
  613. if (verbose_option < 2)
  614. {
  615. *output = 0;
  616. return;
  617. }
  618. if (xattrs_option > 0 || selinux_context_option > 0 || acls_option > 0)
  619. {
  620. /* placeholders */
  621. *output = ' ';
  622. output[1] = 0;
  623. }
  624. if (xattrs_option > 0 && st->xattr_map_size)
  625. for (i = 0; i < st->xattr_map_size; ++i)
  626. {
  627. char *keyword = st->xattr_map[i].xkey + strlen ("SCHILY.xattr.");
  628. if (!xattrs_masked_out (keyword, false /* like extracting */ ))
  629. {
  630. *output = '*';
  631. break;
  632. }
  633. }
  634. if (selinux_context_option > 0 && st->cntx_name)
  635. *output = '.';
  636. if (acls_option > 0 && (st->acls_a_len || st->acls_d_len))
  637. *output = '+';
  638. }
  639. void
  640. xattrs_print (struct tar_stat_info const *st)
  641. {
  642. if (verbose_option < 3)
  643. return;
  644. /* selinux */
  645. if (selinux_context_option > 0 && st->cntx_name)
  646. fprintf (stdlis, " s: %s\n", st->cntx_name);
  647. /* acls */
  648. if (acls_option > 0 && (st->acls_a_len || st->acls_d_len))
  649. {
  650. fprintf (stdlis, " a: ");
  651. acls_one_line ("", ',', st->acls_a_ptr, st->acls_a_len);
  652. if (st->acls_a_len && st->acls_d_len)
  653. fprintf (stdlis, ",");
  654. acls_one_line ("default:", ',', st->acls_d_ptr, st->acls_d_len);
  655. fprintf (stdlis, "\n");
  656. }
  657. /* xattrs */
  658. if (xattrs_option > 0 && st->xattr_map_size)
  659. {
  660. int i;
  661. for (i = 0; i < st->xattr_map_size; ++i)
  662. {
  663. char *keyword = st->xattr_map[i].xkey + strlen ("SCHILY.xattr.");
  664. if (!xattrs_masked_out (keyword, false /* like extracting */ ))
  665. fprintf (stdlis, " x: %lu %s\n",
  666. (unsigned long) st->xattr_map[i].xval_len, keyword);
  667. }
  668. }
  669. }