Blame SOURCES/star-1.5.3-selinux.patch

0ad3e7
diff --git a/autoconf/configure.in b/autoconf/configure.in
0ad3e7
index fc9f880..30383e4 100644
0ad3e7
--- a/autoconf/configure.in
0ad3e7
+++ b/autoconf/configure.in
0ad3e7
@@ -906,6 +906,15 @@ LIBS="$LIBS $lib_cap"
0ad3e7
 AC_CHECK_FUNCS(cap_get_proc cap_set_proc cap_set_flag cap_clear_flag)
0ad3e7
 LIBS="$ac_save_LIBS"
0ad3e7
 
0ad3e7
+AC_CHECK_HEADERS(selinux/selinux.h)
0ad3e7
+if test "$ac_cv_header_selinux_selinux_h" = yes; then
0ad3e7
+  AC_CHECKING(for SELinux support)
0ad3e7
+  AC_CHECK_LIB(selinux, is_selinux_enabled, lib_selinux="-lselinux -lattr")
0ad3e7
+  ac_save_LIBS="$LIBS"
0ad3e7
+  LIBS="$LIBS $lib_selinux"
0ad3e7
+  AC_CHECK_FUNCS(is_selinux_enabled)
0ad3e7
+fi
0ad3e7
+
0ad3e7
 dnl Misc OS checks.
0ad3e7
 AC_CHECK_FILES(/dev/tty /dev/null /dev/zero)
0ad3e7
 AC_CHECK_FILES(/dev/stdin /dev/stdout /dev/stderr)
0ad3e7
@@ -992,6 +1001,7 @@ AC_SUBST(lib_secdb)
0ad3e7
 AC_SUBST(lib_gen)
0ad3e7
 AC_SUBST(lib_pthread)
0ad3e7
 AC_SUBST(lib_rt)
0ad3e7
+AC_SUBST(lib_selinux)
0ad3e7
 AC_SUBST(lib_dl)
0ad3e7
 AC_SUBST(lib_dir)
0ad3e7
 AC_SUBST(lib_cap)
0ad3e7
diff --git a/autoconf/rules.cnf.in b/autoconf/rules.cnf.in
0ad3e7
index affcb5c..2b7bff2 100644
0ad3e7
--- a/autoconf/rules.cnf.in
0ad3e7
+++ b/autoconf/rules.cnf.in
0ad3e7
@@ -34,6 +34,7 @@ LIB_SECDB = @lib_secdb@
0ad3e7
 LIB_GEN = @lib_gen@
0ad3e7
 LIB_PTHREAD = @lib_pthread@
0ad3e7
 LIB_RT = @lib_rt@
0ad3e7
+LIB_SELINUX = @lib_selinux@
0ad3e7
 LIB_DL= @lib_dl@
0ad3e7
 LIB_DIR= @lib_dir@
0ad3e7
 LIB_CAP= @lib_cap@
0ad3e7
diff --git a/star/cpio.mk b/star/cpio.mk
0ad3e7
index 37a6dd2..8bfc3bd 100644
0ad3e7
--- a/star/cpio.mk
0ad3e7
+++ b/star/cpio.mk
0ad3e7
@@ -19,6 +19,7 @@ CPPOPTS +=	-DUSE_FIND
0ad3e7
 CPPOPTS +=	-DUSE_ACL
0ad3e7
 CPPOPTS +=	-DUSE_XATTR
0ad3e7
 CPPOPTS +=	-DUSE_FFLAGS
0ad3e7
+CPPOPTS +=	-DWITH_SELINUX
0ad3e7
 CPPOPTS +=	-DSCHILY_PRINT
0ad3e7
 CFILES=		cpio.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 		list.c extract.c create.c append.c diff.c restore.c \
0ad3e7
@@ -34,7 +35,7 @@ CFILES=		cpio.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0ad3e7
 		movearch.h table.h props.h fifo.h diff.h \
0ad3e7
 		checkerr.h dumpdate.h bitstring.h pathname.h
0ad3e7
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_CAP)
0ad3e7
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_CAP) $(LIB_SELINUX)
0ad3e7
 XMK_FILE=	scpioman.mk
0ad3e7
 
0ad3e7
 ###########################################################################
0ad3e7
diff --git a/star/extract.c b/star/extract.c
0ad3e7
index cf60154..98842e1 100644
0ad3e7
--- a/star/extract.c
0ad3e7
+++ b/star/extract.c
0ad3e7
@@ -256,6 +256,17 @@ extern	struct WALK walkstate;
0ad3e7
 			continue;
0ad3e7
 		}
0ad3e7
 #endif
0ad3e7
+
0ad3e7
+#ifdef WITH_SELINUX
0ad3e7
+                if (!to_stdout && selinux_enabled) {
0ad3e7
+                    if (setselinux(&finfo) == FALSE) {
0ad3e7
+                    errmsgno(EX_BAD,
0ad3e7
+                             "Can not setup security context for '%s'. Not created.\n",
0ad3e7
+                              finfo.f_name);
0ad3e7
+                    }
0ad3e7
+                }
0ad3e7
+#endif
0ad3e7
+
0ad3e7
 		if (finfo.f_flags & F_BAD_META) {
0ad3e7
 			if (!void_bad(&finfo))
0ad3e7
 				break;
0ad3e7
diff --git a/star/gnutar.mk b/star/gnutar.mk
0ad3e7
index 1a296e1..6595aa2 100644
0ad3e7
--- a/star/gnutar.mk
0ad3e7
+++ b/star/gnutar.mk
0ad3e7
@@ -19,6 +19,7 @@ CPPOPTS +=	-DUSE_FIND
0ad3e7
 CPPOPTS +=	-DUSE_ACL
0ad3e7
 CPPOPTS +=	-DUSE_XATTR
0ad3e7
 CPPOPTS +=	-DUSE_FFLAGS
0ad3e7
+CPPOPTS +=	-DWITH_SELINUX
0ad3e7
 CPPOPTS +=	-DSCHILY_PRINT
0ad3e7
 CFILES=		gnutar.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 		list.c extract.c create.c append.c diff.c restore.c \
0ad3e7
@@ -34,7 +35,7 @@ CFILES=		gnutar.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0ad3e7
 		movearch.h table.h props.h fifo.h diff.h \
0ad3e7
 		checkerr.h dumpdate.h bitstring.h pathname.h
0ad3e7
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_CAP)
0ad3e7
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_CAP) $(LIB_SELINUX)
0ad3e7
 XMK_FILE=	gnutarman.mk
0ad3e7
 
0ad3e7
 ###########################################################################
0ad3e7
diff --git a/star/pax.mk b/star/pax.mk
0ad3e7
index 73c6bc1..d2a52a9 100644
0ad3e7
--- a/star/pax.mk
0ad3e7
+++ b/star/pax.mk
0ad3e7
@@ -19,6 +19,7 @@ CPPOPTS +=	-DUSE_FIND
0ad3e7
 CPPOPTS +=	-DUSE_ACL
0ad3e7
 CPPOPTS +=	-DUSE_XATTR
0ad3e7
 CPPOPTS +=	-DUSE_FFLAGS
0ad3e7
+CPPOPTS +=	-DWITH_SELINUX
0ad3e7
 CPPOPTS +=	-DPAX
0ad3e7
 CPPOPTS +=	-DSCHILY_PRINT
0ad3e7
 CFILES=		pax.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
@@ -35,7 +36,7 @@ CFILES=		pax.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0ad3e7
 		movearch.h table.h props.h fifo.h diff.h \
0ad3e7
 		checkerr.h dumpdate.h bitstring.h pathname.h
0ad3e7
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_CAP)
0ad3e7
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_CAP) $(LIB_SELINUX)
0ad3e7
 XMK_FILE=	spaxman.mk
0ad3e7
 
0ad3e7
 ###########################################################################
0ad3e7
diff --git a/star/star.c b/star/star.c
0ad3e7
index 9dfcef7..464c751 100644
0ad3e7
--- a/star/star.c
0ad3e7
+++ b/star/star.c
0ad3e7
@@ -48,6 +48,10 @@ static	UConst char sccsid[] =
0ad3e7
 #include "starsubs.h"
0ad3e7
 #include "checkerr.h"
0ad3e7
 
0ad3e7
+#ifdef WITH_SELINUX
0ad3e7
+int selinux_enabled=0;
0ad3e7
+#endif
0ad3e7
+
0ad3e7
 EXPORT	int	main		__PR((int ac, char **av));
0ad3e7
 LOCAL	void	star_create	__PR((int ac, char *const *av));
0ad3e7
 LOCAL	void	checkdumptype	__PR((GINFO *gp));
0ad3e7
@@ -402,6 +406,10 @@ main(ac, av)
0ad3e7
 			comerr("Panic cannot set back effective uid.\n");
0ad3e7
 	}
0ad3e7
 	my_uid = geteuid();
0ad3e7
+
0ad3e7
+#ifdef WITH_SELINUX
0ad3e7
+	selinux_enabled=is_selinux_enabled()>0;
0ad3e7
+#endif
0ad3e7
 	/*
0ad3e7
 	 * WARNING: We now are no more able to open a new remote connection
0ad3e7
 	 * unless we have been called by root.
0ad3e7
diff --git a/star/star.mk b/star/star.mk
0ad3e7
index a6f6cff..68d3482 100644
0ad3e7
--- a/star/star.mk
0ad3e7
+++ b/star/star.mk
0ad3e7
@@ -21,6 +21,7 @@ CPPOPTS +=	-DUSE_XATTR
0ad3e7
 CPPOPTS +=	-DUSE_FFLAGS
0ad3e7
 CPPOPTS +=	-DCOPY_LINKS_DELAYED
0ad3e7
 CPPOPTS +=	-DSCHILY_PRINT
0ad3e7
+CPPOPTS +=	-DWITH_SELINUX
0ad3e7
 CFILES=		star.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 		list.c extract.c create.c append.c diff.c restore.c \
0ad3e7
 		remove.c star_unix.c acl_unix.c acltext.c fflags.c \
0ad3e7
@@ -35,7 +36,7 @@ CFILES=		star.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0ad3e7
 		movearch.h table.h props.h fifo.h diff.h restore.h \
0ad3e7
 		checkerr.h dumpdate.h bitstring.h
0ad3e7
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL)
0ad3e7
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_SELINUX)
0ad3e7
 XMK_FILE=	Makefile.man starformatman.mk
0ad3e7
 
0ad3e7
 ###########################################################################
0ad3e7
diff --git a/star/star_fat.mk b/star/star_fat.mk
0ad3e7
index 1975c94..507fbee 100644
0ad3e7
--- a/star/star_fat.mk
0ad3e7
+++ b/star/star_fat.mk
0ad3e7
@@ -29,6 +29,7 @@ CPPOPTS +=	-DUSE_FFLAGS
0ad3e7
 CPPOPTS +=	-DCOPY_LINKS_DELAYED
0ad3e7
 CPPOPTS +=	-DSTAR_FAT
0ad3e7
 CPPOPTS +=	-DSCHILY_PRINT
0ad3e7
+CPPOPTS +=	-DWITH_SELINUX
0ad3e7
 CFILES=		star_fat.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 		list.c extract.c create.c append.c diff.c restore.c \
0ad3e7
 		remove.c star_unix.c acl_unix.c acltext.c fflags.c \
0ad3e7
@@ -48,7 +49,7 @@ HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0ad3e7
 
0ad3e7
 #LIBS=		-lunos
0ad3e7
 #LIBS=		-lschily -lc /usr/local/lib/gcc-gnulib
0ad3e7
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL)
0ad3e7
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_SELINUX)
0ad3e7
 #
0ad3e7
 #	Wenn -lfind, dann auch  $(LIB_INTL)
0ad3e7
 #
0ad3e7
diff --git a/star/starsubs.h b/star/starsubs.h
0ad3e7
index a914ade..1e2a233 100644
0ad3e7
--- a/star/starsubs.h
0ad3e7
+++ b/star/starsubs.h
0ad3e7
@@ -317,6 +317,11 @@ extern	void	opt_xattr	__PR((void));
0ad3e7
 extern	BOOL	get_xattr	__PR((register FINFO *info));
0ad3e7
 extern	BOOL	set_xattr	__PR((register FINFO *info));
0ad3e7
 extern	void	free_xattr	__PR((star_xattr_t **xattr));
0ad3e7
+# ifdef WITH_SELINUX
0ad3e7
+#include <selinux/selinux.h>
0ad3e7
+extern BOOL    setselinux __PR((register FINFO *info));
0ad3e7
+extern int selinux_enabled;
0ad3e7
+# endif
0ad3e7
 #endif
0ad3e7
 
0ad3e7
 /*
0ad3e7
diff --git a/star/suntar.mk b/star/suntar.mk
0ad3e7
index 9b76a23..1842917 100644
0ad3e7
--- a/star/suntar.mk
0ad3e7
+++ b/star/suntar.mk
0ad3e7
@@ -19,6 +19,7 @@ CPPOPTS +=	-DUSE_FIND
0ad3e7
 CPPOPTS +=	-DUSE_ACL
0ad3e7
 CPPOPTS +=	-DUSE_XATTR
0ad3e7
 CPPOPTS +=	-DUSE_FFLAGS
0ad3e7
+CPPOPTS +=	-DWITH_SELINUX
0ad3e7
 CPPOPTS +=	-DSCHILY_PRINT
0ad3e7
 CFILES=		suntar.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 		list.c extract.c create.c append.c diff.c restore.c \
0ad3e7
@@ -34,7 +35,7 @@ CFILES=		suntar.c header.c cpiohdr.c xheader.c xattr.c \
0ad3e7
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0ad3e7
 		movearch.h table.h props.h fifo.h diff.h \
0ad3e7
 		checkerr.h dumpdate.h bitstring.h pathname.h
0ad3e7
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_CAP)
0ad3e7
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_CAP) $(LIB_SELINUX)
0ad3e7
 XMK_FILE=	suntarman.mk
0ad3e7
 
0ad3e7
 ###########################################################################
0ad3e7
diff --git a/star/xattr.c b/star/xattr.c
0ad3e7
index 2e262ef..08fc42e 100644
0ad3e7
--- a/star/xattr.c
0ad3e7
+++ b/star/xattr.c
0ad3e7
@@ -198,6 +198,27 @@ fail:
0ad3e7
 #endif  /* USE_XATTR */
0ad3e7
 }
0ad3e7
 
0ad3e7
+#ifdef WITH_SELINUX
0ad3e7
+EXPORT BOOL
0ad3e7
+setselinux(info)
0ad3e7
+       register FINFO *info;
0ad3e7
+{
0ad3e7
+#if defined(USE_XATTR) && defined(HAVE_SETXATTR) && defined(WITH_SELINUX)
0ad3e7
+       if (info->f_xattr) {
0ad3e7
+               star_xattr_t    *xap;
0ad3e7
+               for (xap = info->f_xattr; xap->name != NULL; xap++) {
0ad3e7
+                 if (strcmp(xap->name, "security.selinux") == 0) {
0ad3e7
+                   if (setfscreatecon(xap->value)) {
0ad3e7
+                     return FALSE;
0ad3e7
+                   }
0ad3e7
+                 }
0ad3e7
+               }
0ad3e7
+       }
0ad3e7
+#endif  /* USE_XATTR && WITH_SELINUX */
0ad3e7
+       return TRUE;
0ad3e7
+}
0ad3e7
+#endif
0ad3e7
+
0ad3e7
 /* ARGSUSED */
0ad3e7
 EXPORT BOOL
0ad3e7
 set_xattr(info)
0ad3e7
@@ -211,6 +232,10 @@ set_xattr(info)
0ad3e7
 		return (TRUE);
0ad3e7
 
0ad3e7
 	for (xap = info->f_xattr; xap->name != NULL; xap++) {
0ad3e7
+#ifdef WITH_SELINUX
0ad3e7
+		if (selinux_enabled && (strcmp(xap->name, "security.selinux") == 0))
0ad3e7
+			continue;
0ad3e7
+#endif
0ad3e7
 		if (lsetxattr(info->f_name, xap->name, xap->value,
0ad3e7
 		    xap->value_len, 0) != 0) {
0ad3e7
 			if (!errhidden(E_SETXATTR, info->f_name)) {