From 7118774ec94bb1a2e8ef7a5f8cbcb6b781ccfdd8 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Fri, 13 Jan 2017 13:30:10 -0600 Subject: libtar: backup and restore posix capabilities This patch also allows libtar to combine data from multiple extended tar headers into a single header. Change-Id: I82d13e89a3622ea665b60062b1904ddbedfa41b3 --- libtar/append.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libtar/append.c') diff --git a/libtar/append.c b/libtar/append.c index 438829753..7c679f66d 100644 --- a/libtar/append.c +++ b/libtar/append.c @@ -22,6 +22,10 @@ #include #include +#include +#include +#include + #ifdef STDC_HEADERS # include # include @@ -154,6 +158,24 @@ tar_append_file(TAR *t, const char *realname, const char *savename) } #endif + /* get posix file capabilities */ + if (TH_ISREG(t) && t->options & TAR_STORE_POSIX_CAP) + { + if (t->th_buf.has_cap_data) + { + memset(&t->th_buf.cap_data, 0, sizeof(struct vfs_cap_data)); + t->th_buf.has_cap_data = 0; + } + + if (getxattr(realname, XATTR_NAME_CAPS, &t->th_buf.cap_data, sizeof(struct vfs_cap_data)) >= 0) + { + t->th_buf.has_cap_data = 1; +#if 1 //def DEBUG + print_caps(&t->th_buf.cap_data); +#endif + } + } + /* check if it's a hardlink */ #ifdef DEBUG puts("tar_append_file(): checking inode cache for hardlink..."); -- cgit v1.2.3