Blame SOURCES/star-1.5.3-selinux.patch

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