From 25fd68d0989254bdf921bcd118c4bae4d8afc419 Mon Sep 17 00:00:00 2001 From: Vojtech Bocek Date: Tue, 27 Aug 2013 03:10:10 +0200 Subject: libtar: store SELinux file context in tar archives * Using RedHat's "RHT.security.selinux=" tag in extended tar header (type 'x') Signed-off-by: Vojtech Bocek Change-Id: I102e492e4fa5b8a08fae4d34eb36386862509b4d --- libtar/extract.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libtar/extract.c') diff --git a/libtar/extract.c b/libtar/extract.c index 613e29fff..d19ba859d 100644 --- a/libtar/extract.c +++ b/libtar/extract.c @@ -154,6 +154,18 @@ tar_extract_file(TAR *t, char *realname, char *prefix) printf("FAILED SETTING PERMS: %d\n", i); return i; } + +#ifdef HAVE_SELINUX + if((t->options & TAR_STORE_SELINUX) && t->th_buf.selinux_context != NULL) + { +#ifdef DEBUG + printf(" Restoring SELinux context %s to file %s\n", t->th_buf.selinux_context, realname); +#endif + if(setfilecon(realname, t->th_buf.selinux_context) < 0) + fprintf(stderr, "Failed to restore SELinux context %s!\n", strerror(errno)); + } +#endif + /* pathname_len = strlen(th_get_pathname(t)) + 1; realname_len = strlen(realname) + 1; -- cgit v1.2.3