diff options
Diffstat (limited to '')
-rw-r--r-- | libtar/append.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/libtar/append.c b/libtar/append.c index 438829753..d8ba3cad5 100644 --- a/libtar/append.c +++ b/libtar/append.c @@ -22,6 +22,10 @@ #include <sys/types.h> #include <stdbool.h> +#include <sys/capability.h> +#include <sys/xattr.h> +#include <linux/xattr.h> + #ifdef STDC_HEADERS # include <stdlib.h> # include <string.h> @@ -31,9 +35,7 @@ # include <unistd.h> #endif -#ifdef HAVE_SELINUX -# include "selinux/selinux.h" -#endif +#include <selinux/selinux.h> #ifdef HAVE_EXT4_CRYPT # include "ext4crypt_tar.h" @@ -101,7 +103,6 @@ tar_append_file(TAR *t, const char *realname, const char *savename) #endif th_set_path(t, (savename ? savename : realname)); -#ifdef HAVE_SELINUX /* get selinux context */ if (t->options & TAR_STORE_SELINUX) { @@ -125,7 +126,6 @@ tar_append_file(TAR *t, const char *realname, const char *savename) #endif } } -#endif #ifdef HAVE_EXT4_CRYPT if (TH_ISDIR(t) && t->options & TAR_STORE_EXT4_POL) @@ -154,6 +154,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..."); |