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/append.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'libtar/append.c') diff --git a/libtar/append.c b/libtar/append.c index 05024b926..3a8bfc690 100644 --- a/libtar/append.c +++ b/libtar/append.c @@ -90,6 +90,31 @@ tar_append_file(TAR *t, char *realname, char *savename) #endif th_set_path(t, (savename ? savename : realname)); +#ifdef HAVE_SELINUX + /* get selinux context */ + if(t->options & TAR_STORE_SELINUX) + { + if(t->th_buf.selinux_context != NULL) + { + free(t->th_buf.selinux_context); + t->th_buf.selinux_context = NULL; + } + + security_context_t selinux_context = NULL; + if(getfilecon(realname, &selinux_context) >= 0) + { + t->th_buf.selinux_context = strdup(selinux_context); + freecon(selinux_context); + } + else + { +#ifdef DEBUG + perror("Failed to get selinux context"); +#endif + } + } +#endif + /* check if it's a hardlink */ #ifdef DEBUG puts(" tar_append_file(): checking inode cache for hardlink..."); -- cgit v1.2.3