4
0

xattrs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /* Support for extended attributes.
  2. Copyright (C) 2006-2014, 2016 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. static void
  207. xattrs__acls_get_a (int parentfd, const char *file_name,
  208. struct tar_stat_info *st,
  209. char **ret_ptr, size_t * ret_len)
  210. {
  211. char *val = NULL;
  212. ssize_t len;
  213. acl_t acl;
  214. if (!(acl = acl_get_file_at (parentfd, file_name, ACL_TYPE_ACCESS)))
  215. {
  216. if (errno != ENOTSUP)
  217. call_arg_warn ("acl_get_file_at", file_name);
  218. return;
  219. }
  220. val = acl_to_text (acl, &len);
  221. acl_free (acl);
  222. if (!val)
  223. {
  224. call_arg_warn ("acl_to_text", file_name);
  225. return;
  226. }
  227. *ret_ptr = xstrdup (val);
  228. *ret_len = len;
  229. acl_free (val);
  230. }
  231. /* "system.posix_acl_default" */
  232. static void
  233. xattrs__acls_get_d (int parentfd, char const *file_name,
  234. struct tar_stat_info *st,
  235. char **ret_ptr, size_t * ret_len)
  236. {
  237. char *val = NULL;
  238. ssize_t len;
  239. acl_t acl;
  240. if (!(acl = acl_get_file_at (parentfd, file_name, ACL_TYPE_DEFAULT)))
  241. {
  242. if (errno != ENOTSUP)
  243. call_arg_warn ("acl_get_file_at", file_name);
  244. return;
  245. }
  246. val = acl_to_text (acl, &len);
  247. acl_free (acl);
  248. if (!val)
  249. {
  250. call_arg_warn ("acl_to_text", file_name);
  251. return;
  252. }
  253. *ret_ptr = xstrdup (val);
  254. *ret_len = len;
  255. acl_free (val);
  256. }
  257. #endif /* HAVE_POSIX_ACLS */
  258. static void
  259. acls_one_line (const char *prefix, char delim,
  260. const char *aclstring, size_t len)
  261. {
  262. /* support both long and short text representation of posix acls */
  263. struct obstack stk;
  264. int pref_len = strlen (prefix);
  265. const char *oldstring = aclstring;
  266. int pos = 0;
  267. if (!aclstring || !len)
  268. return;
  269. obstack_init (&stk);
  270. while (pos <= len)
  271. {
  272. int move = strcspn (aclstring, ",\n");
  273. if (!move)
  274. break;
  275. if (oldstring != aclstring)
  276. obstack_1grow (&stk, delim);
  277. obstack_grow (&stk, prefix, pref_len);
  278. obstack_grow (&stk, aclstring, move);
  279. aclstring += move + 1;
  280. }
  281. obstack_1grow (&stk, '\0');
  282. fprintf (stdlis, "%s", (char *) obstack_finish (&stk));
  283. obstack_free (&stk, NULL);
  284. }
  285. void
  286. xattrs_acls_get (int parentfd, char const *file_name,
  287. struct tar_stat_info *st, int fd, int xisfile)
  288. {
  289. if (acls_option > 0)
  290. {
  291. #ifndef HAVE_POSIX_ACLS
  292. static int done = 0;
  293. if (!done)
  294. WARN ((0, 0, _("POSIX ACL support is not available")));
  295. done = 1;
  296. #else
  297. int err = file_has_acl_at (parentfd, file_name, &st->stat);
  298. if (err == 0)
  299. return;
  300. if (err == -1)
  301. {
  302. call_arg_warn ("file_has_acl_at", file_name);
  303. return;
  304. }
  305. xattrs__acls_get_a (parentfd, file_name, st,
  306. &st->acls_a_ptr, &st->acls_a_len);
  307. if (!xisfile)
  308. xattrs__acls_get_d (parentfd, file_name, st,
  309. &st->acls_d_ptr, &st->acls_d_len);
  310. #endif
  311. }
  312. }
  313. void
  314. xattrs_acls_set (struct tar_stat_info const *st,
  315. char const *file_name, char typeflag)
  316. {
  317. if (acls_option > 0 && typeflag != SYMTYPE)
  318. {
  319. #ifndef HAVE_POSIX_ACLS
  320. static int done = 0;
  321. if (!done)
  322. WARN ((0, 0, _("POSIX ACL support is not available")));
  323. done = 1;
  324. #else
  325. xattrs__acls_set (st, file_name, ACL_TYPE_ACCESS,
  326. st->acls_a_ptr, st->acls_a_len, false);
  327. if (typeflag == DIRTYPE || typeflag == GNUTYPE_DUMPDIR)
  328. xattrs__acls_set (st, file_name, ACL_TYPE_DEFAULT,
  329. st->acls_d_ptr, st->acls_d_len, true);
  330. #endif
  331. }
  332. }
  333. static void
  334. mask_map_realloc (struct xattrs_mask_map *map)
  335. {
  336. if (map->used == map->size)
  337. {
  338. if (map->size == 0)
  339. map->size = 4;
  340. map->masks = x2nrealloc (map->masks, &map->size, sizeof (map->masks[0]));
  341. }
  342. }
  343. void
  344. xattrs_mask_add (const char *mask, bool incl)
  345. {
  346. struct xattrs_mask_map *mask_map =
  347. incl ? &xattrs_setup.incl : &xattrs_setup.excl;
  348. /* ensure there is enough space */
  349. mask_map_realloc (mask_map);
  350. /* just assign pointers -- we silently expect that pointer "mask" is valid
  351. through the whole program (pointer to argv array) */
  352. mask_map->masks[mask_map->used++] = mask;
  353. }
  354. static void
  355. clear_mask_map (struct xattrs_mask_map *mask_map)
  356. {
  357. if (mask_map->size)
  358. free (mask_map->masks);
  359. }
  360. void
  361. xattrs_clear_setup (void)
  362. {
  363. clear_mask_map (&xattrs_setup.incl);
  364. clear_mask_map (&xattrs_setup.excl);
  365. }
  366. /* get all xattrs from file given by FILE_NAME or FD (when non-zero). This
  367. includes all the user.*, security.*, system.*, etc. available domains */
  368. void
  369. xattrs_xattrs_get (int parentfd, char const *file_name,
  370. struct tar_stat_info *st, int fd)
  371. {
  372. if (xattrs_option > 0)
  373. {
  374. #ifndef HAVE_XATTRS
  375. static int done = 0;
  376. if (!done)
  377. WARN ((0, 0, _("XATTR support is not available")));
  378. done = 1;
  379. #else
  380. static size_t xsz = 1024;
  381. static char *xatrs = NULL;
  382. ssize_t xret = -1;
  383. if (!xatrs)
  384. xatrs = x2nrealloc (xatrs, &xsz, 1);
  385. while (((fd == 0) ?
  386. ((xret =
  387. llistxattrat (parentfd, file_name, xatrs, xsz)) == -1) :
  388. ((xret = flistxattr (fd, xatrs, xsz)) == -1))
  389. && (errno == ERANGE))
  390. {
  391. xatrs = x2nrealloc (xatrs, &xsz, 1);
  392. }
  393. if (xret == -1)
  394. call_arg_warn ((fd == 0) ? "llistxattrat" : "flistxattr", file_name);
  395. else
  396. {
  397. const char *attr = xatrs;
  398. static size_t asz = 1024;
  399. static char *val = NULL;
  400. if (!val)
  401. val = x2nrealloc (val, &asz, 1);
  402. while (xret > 0)
  403. {
  404. size_t len = strlen (attr);
  405. ssize_t aret = 0;
  406. /* Archive all xattrs during creation, decide at extraction time
  407. * which ones are of interest/use for the target filesystem. */
  408. while (((fd == 0)
  409. ? ((aret = lgetxattrat (parentfd, file_name, attr,
  410. val, asz)) == -1)
  411. : ((aret = fgetxattr (fd, attr, val, asz)) == -1))
  412. && (errno == ERANGE))
  413. {
  414. val = x2nrealloc (val, &asz, 1);
  415. }
  416. if (aret != -1)
  417. xheader_xattr_add (st, attr, val, aret);
  418. else if (errno != ENOATTR)
  419. call_arg_warn ((fd == 0) ? "lgetxattrat"
  420. : "fgetxattr", file_name);
  421. attr += len + 1;
  422. xret -= len + 1;
  423. }
  424. }
  425. #endif
  426. }
  427. }
  428. #ifdef HAVE_XATTRS
  429. static void
  430. xattrs__fd_set (struct tar_stat_info const *st,
  431. char const *file_name, char typeflag,
  432. const char *attr, const char *ptr, size_t len)
  433. {
  434. if (ptr)
  435. {
  436. const char *sysname = "setxattrat";
  437. int ret = -1;
  438. if (typeflag != SYMTYPE)
  439. ret = setxattrat (chdir_fd, file_name, attr, ptr, len, 0);
  440. else
  441. {
  442. sysname = "lsetxattr";
  443. ret = lsetxattrat (chdir_fd, file_name, attr, ptr, len, 0);
  444. }
  445. if (ret == -1)
  446. WARNOPT (WARN_XATTR_WRITE,
  447. (0, errno,
  448. _("%s: Cannot set '%s' extended attribute for file '%s'"),
  449. sysname, attr, file_name));
  450. }
  451. }
  452. #endif
  453. /* lgetfileconat is called against FILE_NAME iff the FD parameter is set to
  454. zero, otherwise the fgetfileconat is used against correct file descriptor */
  455. void
  456. xattrs_selinux_get (int parentfd, char const *file_name,
  457. struct tar_stat_info *st, int fd)
  458. {
  459. if (selinux_context_option > 0)
  460. {
  461. #if HAVE_SELINUX_SELINUX_H != 1
  462. static int done = 0;
  463. if (!done)
  464. WARN ((0, 0, _("SELinux support is not available")));
  465. done = 1;
  466. #else
  467. int result = fd ?
  468. fgetfilecon (fd, &st->cntx_name)
  469. : lgetfileconat (parentfd, file_name, &st->cntx_name);
  470. if (result == -1 && errno != ENODATA && errno != ENOTSUP)
  471. call_arg_warn (fd ? "fgetfilecon" : "lgetfileconat", file_name);
  472. #endif
  473. }
  474. }
  475. void
  476. xattrs_selinux_set (struct tar_stat_info const *st,
  477. char const *file_name, char typeflag)
  478. {
  479. if (selinux_context_option > 0)
  480. {
  481. #if HAVE_SELINUX_SELINUX_H != 1
  482. static int done = 0;
  483. if (!done)
  484. WARN ((0, 0, _("SELinux support is not available")));
  485. done = 1;
  486. #else
  487. const char *sysname = "setfilecon";
  488. int ret;
  489. if (!st->cntx_name)
  490. return;
  491. if (typeflag != SYMTYPE)
  492. {
  493. ret = setfileconat (chdir_fd, file_name, st->cntx_name);
  494. sysname = "setfileconat";
  495. }
  496. else
  497. {
  498. ret = lsetfileconat (chdir_fd, file_name, st->cntx_name);
  499. sysname = "lsetfileconat";
  500. }
  501. if (ret == -1)
  502. WARNOPT (WARN_XATTR_WRITE,
  503. (0, errno,
  504. _("%s: Cannot set SELinux context for file '%s'"),
  505. sysname, file_name));
  506. #endif
  507. }
  508. }
  509. static bool
  510. xattrs_matches_mask (const char *kw, struct xattrs_mask_map *mm)
  511. {
  512. int i;
  513. if (!mm->size)
  514. return false;
  515. for (i = 0; i < mm->used; i++)
  516. if (fnmatch (mm->masks[i], kw, 0) == 0)
  517. return true;
  518. return false;
  519. }
  520. #define USER_DOT_PFX "user."
  521. static bool
  522. xattrs_kw_included (const char *kw, bool archiving)
  523. {
  524. if (xattrs_setup.incl.size)
  525. return xattrs_matches_mask (kw, &xattrs_setup.incl);
  526. else if (archiving)
  527. return true;
  528. else
  529. return strncmp (kw, USER_DOT_PFX, sizeof (USER_DOT_PFX) - 1) == 0;
  530. }
  531. static bool
  532. xattrs_kw_excluded (const char *kw, bool archiving)
  533. {
  534. return xattrs_setup.excl.size ?
  535. xattrs_matches_mask (kw, &xattrs_setup.excl) : false;
  536. }
  537. /* Check whether the xattr with keyword KW should be discarded from list of
  538. attributes that are going to be archived/excluded (set ARCHIVING=true for
  539. archiving, false for excluding) */
  540. static bool
  541. xattrs_masked_out (const char *kw, bool archiving)
  542. {
  543. return xattrs_kw_included (kw, archiving) ?
  544. xattrs_kw_excluded (kw, archiving) : true;
  545. }
  546. void
  547. xattrs_xattrs_set (struct tar_stat_info const *st,
  548. char const *file_name, char typeflag, int later_run)
  549. {
  550. if (xattrs_option > 0)
  551. {
  552. #ifndef HAVE_XATTRS
  553. static int done = 0;
  554. if (!done)
  555. WARN ((0, 0, _("XATTR support is not available")));
  556. done = 1;
  557. #else
  558. size_t scan = 0;
  559. if (!st->xattr_map_size)
  560. return;
  561. for (; scan < st->xattr_map_size; ++scan)
  562. {
  563. char *keyword = st->xattr_map[scan].xkey;
  564. keyword += strlen ("SCHILY.xattr.");
  565. /* TODO: this 'later_run' workaround is temporary solution -> once
  566. capabilities should become fully supported by it's API and there
  567. should exist something like xattrs_capabilities_set() call.
  568. For a regular files: all extended attributes are restored during
  569. the first run except 'security.capability' which is restored in
  570. 'later_run == 1'. */
  571. if (typeflag == REGTYPE
  572. && later_run == !!strcmp (keyword, "security.capability"))
  573. continue;
  574. if (xattrs_masked_out (keyword, false /* extracting */ ))
  575. /* we don't want to restore this keyword */
  576. continue;
  577. xattrs__fd_set (st, file_name, typeflag, keyword,
  578. st->xattr_map[scan].xval_ptr,
  579. st->xattr_map[scan].xval_len);
  580. }
  581. #endif
  582. }
  583. }
  584. void
  585. xattrs_print_char (struct tar_stat_info const *st, char *output)
  586. {
  587. int i;
  588. if (verbose_option < 2)
  589. {
  590. *output = 0;
  591. return;
  592. }
  593. if (xattrs_option > 0 || selinux_context_option > 0 || acls_option > 0)
  594. {
  595. /* placeholders */
  596. *output = ' ';
  597. output[1] = 0;
  598. }
  599. if (xattrs_option > 0 && st->xattr_map_size)
  600. for (i = 0; i < st->xattr_map_size; ++i)
  601. {
  602. char *keyword = st->xattr_map[i].xkey + strlen ("SCHILY.xattr.");
  603. if (!xattrs_masked_out (keyword, false /* like extracting */ ))
  604. {
  605. *output = '*';
  606. break;
  607. }
  608. }
  609. if (selinux_context_option > 0 && st->cntx_name)
  610. *output = '.';
  611. if (acls_option > 0 && (st->acls_a_len || st->acls_d_len))
  612. *output = '+';
  613. }
  614. void
  615. xattrs_print (struct tar_stat_info const *st)
  616. {
  617. if (verbose_option < 3)
  618. return;
  619. /* selinux */
  620. if (selinux_context_option > 0 && st->cntx_name)
  621. fprintf (stdlis, " s: %s\n", st->cntx_name);
  622. /* acls */
  623. if (acls_option > 0 && (st->acls_a_len || st->acls_d_len))
  624. {
  625. fprintf (stdlis, " a: ");
  626. acls_one_line ("", ',', st->acls_a_ptr, st->acls_a_len);
  627. acls_one_line ("default:", ',', st->acls_d_ptr, st->acls_d_len);
  628. fprintf (stdlis, "\n");
  629. }
  630. /* xattrs */
  631. if (xattrs_option > 0 && st->xattr_map_size)
  632. {
  633. int i;
  634. for (i = 0; i < st->xattr_map_size; ++i)
  635. {
  636. char *keyword = st->xattr_map[i].xkey + strlen ("SCHILY.xattr.");
  637. if (!xattrs_masked_out (keyword, false /* like extracting */ ))
  638. fprintf (stdlis, " x: %lu %s\n",
  639. (unsigned long) st->xattr_map[i].xval_len, keyword);
  640. }
  641. }
  642. }