0e12a9f
diff -urNp star-1.5-orig/conf/configure.in star-1.5/conf/configure.in
0e12a9f
--- star-1.5-orig/conf/configure.in	2008-03-27 19:58:16.000000000 +0100
0e12a9f
+++ star-1.5/conf/configure.in	2008-12-18 16:11:49.000000000 +0100
0e12a9f
@@ -452,6 +452,15 @@ AC_CHECK_FUNCS(sched_yield)
0e12a9f
 AC_CHECK_FUNCS(nanosleep)
0e12a9f
 LIBS="$ac_save_LIBS"
0e12a9f
 
0e12a9f
+AC_CHECK_HEADERS(selinux/selinux.h)
0e12a9f
+if test "$ac_cv_header_selinux_selinux_h" = yes; then
0e12a9f
+  AC_CHECKING(for SELinux support)
0e12a9f
+  AC_CHECK_LIB(selinux, is_selinux_enabled, lib_selinux="-lselinux -lattr")
0e12a9f
+  ac_save_LIBS="$LIBS"
0e12a9f
+  LIBS="$LIBS $lib_selinux"
0e12a9f
+  AC_CHECK_FUNCS(is_selinux_enabled)
0e12a9f
+fi
0e12a9f
+
0e12a9f
 dnl Misc OS checks.
0e12a9f
 AC_MSG_CHECKING(for /dev/tty)
0e12a9f
 if test -r /dev/tty; then
0e12a9f
@@ -543,5 +552,6 @@ AC_SUBST(lib_secdb)
0e12a9f
 AC_SUBST(lib_gen)
0e12a9f
 AC_SUBST(lib_pthread)
0e12a9f
 AC_SUBST(lib_rt)
0e12a9f
+AC_SUBST(lib_selinux)
0e12a9f
 
0e12a9f
 AC_OUTPUT(rules.cnf)
0e12a9f
diff -urNp star-1.5-orig/conf/rules.cnf.in star-1.5/conf/rules.cnf.in
0e12a9f
--- star-1.5-orig/conf/rules.cnf.in	2008-02-20 18:52:09.000000000 +0100
0e12a9f
+++ star-1.5/conf/rules.cnf.in	2008-12-18 16:09:30.000000000 +0100
0e12a9f
@@ -21,3 +21,4 @@ LIB_SECDB = @lib_secdb@
0e12a9f
 LIB_GEN = @lib_gen@
0e12a9f
 LIB_PTHREAD = @lib_pthread@
0e12a9f
 LIB_RT = @lib_rt@
0e12a9f
+LIB_SELINUX = @lib_selinux@
0e12a9f
diff -urNp star-1.5-orig/star/cpio.mk star-1.5/star/cpio.mk
0e12a9f
--- star-1.5-orig/star/cpio.mk	2008-04-06 20:01:45.000000000 +0200
0e12a9f
+++ star-1.5/star/cpio.mk	2008-12-18 16:00:27.000000000 +0100
0e12a9f
@@ -19,6 +19,7 @@ CPPOPTS +=	-DUSE_FIND
d181987
 CPPOPTS +=	-DUSE_ACL
d181987
 CPPOPTS +=	-DUSE_XATTR
d181987
 CPPOPTS +=	-DUSE_FFLAGS
0e12a9f
+CPPOPTS +=	-DWITH_SELINUX
c7a6ac8
 CPPOPTS +=	-DSCHILY_PRINT
0e12a9f
 CFILES=		cpio.c header.c cpiohdr.c xheader.c xattr.c \
c7a6ac8
 		list.c extract.c create.c append.c diff.c restore.c \
0e12a9f
@@ -34,7 +35,7 @@ CFILES=		cpio.c header.c cpiohdr.c xhead
0e12a9f
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0e12a9f
 		movearch.h table.h props.h fifo.h diff.h \
d181987
 		checkerr.h dumpdate.h bitstring.h
0e12a9f
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL)
0e12a9f
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_SELINUX)
0e12a9f
 XMK_FILE=	scpioman.mk
0e2de46
 
0a28ddf
 ###########################################################################
0e12a9f
diff -urNp star-1.5-orig/star/extract.c star-1.5/star/extract.c
0e12a9f
--- star-1.5-orig/star/extract.c	2008-04-06 17:32:15.000000000 +0200
0e12a9f
+++ star-1.5/star/extract.c	2008-12-18 15:59:46.000000000 +0100
0e12a9f
@@ -253,6 +253,17 @@ extern	struct WALK walkstate;
c7a6ac8
 			continue;
c7a6ac8
 		}
c7a6ac8
 #endif
c7a6ac8
+
c7a6ac8
+#ifdef WITH_SELINUX
c7a6ac8
+                if (!to_stdout && selinux_enabled) {
c7a6ac8
+                    if (setselinux(&finfo) == FALSE) {
c7a6ac8
+                    errmsgno(EX_BAD,
c7a6ac8
+                             "Can not setup security context for '%s'. Not created.\n",
c7a6ac8
+                              finfo.f_name);
c7a6ac8
+                    }
c7a6ac8
+                }
c7a6ac8
+#endif
c7a6ac8
+
c7a6ac8
 		if (finfo.f_flags & F_BAD_META) {
c7a6ac8
 			if (!void_bad(&finfo))
c7a6ac8
 				break;
0e12a9f
diff -urNp star-1.5-orig/star/gnutar.mk star-1.5/star/gnutar.mk
0e12a9f
--- star-1.5-orig/star/gnutar.mk	2008-04-06 20:01:45.000000000 +0200
0e12a9f
+++ star-1.5/star/gnutar.mk	2008-12-18 16:08:54.000000000 +0100
0e12a9f
@@ -19,6 +19,7 @@ CPPOPTS +=	-DUSE_FIND
c7a6ac8
 CPPOPTS +=	-DUSE_ACL
0e2de46
 CPPOPTS +=	-DUSE_XATTR
0e2de46
 CPPOPTS +=	-DUSE_FFLAGS
0e2de46
+CPPOPTS +=	-DWITH_SELINUX
c7a6ac8
 CPPOPTS +=	-DSCHILY_PRINT
0e12a9f
 CFILES=		gnutar.c header.c cpiohdr.c xheader.c xattr.c \
0e2de46
 		list.c extract.c create.c append.c diff.c restore.c \
0e12a9f
@@ -34,7 +35,7 @@ CFILES=		gnutar.c header.c cpiohdr.c xhe
0e12a9f
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0e12a9f
 		movearch.h table.h props.h fifo.h diff.h \
0e2de46
 		checkerr.h dumpdate.h bitstring.h
0e12a9f
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL)
0e12a9f
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_SELINUX)
0e12a9f
 XMK_FILE=	gnutarman.mk
0e2de46
 
0e2de46
 ###########################################################################
0e12a9f
diff -urNp star-1.5-orig/star/Makefile star-1.5/star/Makefile
0e12a9f
--- star-1.5-orig/star/Makefile	2008-04-06 20:02:25.000000000 +0200
0e12a9f
+++ star-1.5/star/Makefile	2008-12-18 16:02:39.000000000 +0100
0e12a9f
@@ -1,66 +1,19 @@
0e12a9f
-#ident @(#)star_fat.mk	1.23 08/04/06 
c7a6ac8
+#ident @(#)all.mk	1.1 05/02/16 
c7a6ac8
 ###########################################################################
c7a6ac8
-#include		$(MAKE_M_ARCH).def
c7a6ac8
 SRCROOT=	..
c7a6ac8
 RULESDIR=	RULES
c7a6ac8
 include		$(SRCROOT)/$(RULESDIR)/rules.top
c7a6ac8
 ###########################################################################
c7a6ac8
 
c7a6ac8
 #
c7a6ac8
-# This is star_fat.mk, it creates one "fat" binary for all functionality.
0e12a9f
+# This is all.mk, it creates sevral binaries, one for each function.
c7a6ac8
 #
c7a6ac8
-# If you like to create non "fat" binaries, remove Makefile
c7a6ac8
-# and copy all.mk to Makefile.
c7a6ac8
+# If you like to create one single "fat" binary, remove Makefile
c7a6ac8
+# and copy star_fat.mk to Makefile.
c7a6ac8
 #
c7a6ac8
-INSDIR=		bin
c7a6ac8
-TARGET=		star
c7a6ac8
-#SYMLINKS=	ustar tar
c7a6ac8
-SYMLINKS=	ustar tar gnutar suntar scpio spax
c7a6ac8
-CPPOPTS +=	-D__STAR__
c7a6ac8
-CPPOPTS +=	-DSET_CTIME -DFIFO -DUSE_MMAP -DUSE_REMOTE -DUSE_RCMD_RSH
c7a6ac8
-#CPPOPTS +=	-DSET_CTIME -DFIFO -DUSE_MMAP
c7a6ac8
-#CPPOPTS +=	-DSET_CTIME -DUSE_MMAP
c7a6ac8
-#CPPOPTS +=	-DFIFO -DUSE_MMAP
c7a6ac8
-CPPOPTS +=	-DUSE_LARGEFILES
c7a6ac8
-CPPOPTS +=	-DUSE_FIND
c7a6ac8
-CPPOPTS +=	-DUSE_ACL
c7a6ac8
-CPPOPTS +=	-DUSE_XATTR
c7a6ac8
-CPPOPTS +=	-DUSE_FFLAGS
c7a6ac8
-CPPOPTS +=	-DCOPY_LINKS_DELAYED
c7a6ac8
-CPPOPTS +=	-DSTAR_FAT
c7a6ac8
-CPPOPTS +=	-DSCHILY_PRINT
c7a6ac8
-CFILES=		star_fat.c header.c cpiohdr.c xheader.c xattr.c \
c7a6ac8
-		list.c extract.c create.c append.c diff.c restore.c \
c7a6ac8
-		remove.c star_unix.c acl_unix.c acltext.c fflags.c \
c7a6ac8
-		buffer.c dirtime.c lhash.c \
0e12a9f
-		hole.c longnames.c \
c7a6ac8
-		movearch.c table.c props.c \
c7a6ac8
-		unicode.c \
c7a6ac8
-		subst.c volhdr.c \
c7a6ac8
-		chdir.c match.c defaults.c dumpdate.c \
c7a6ac8
-		fifo.c device.c checkerr.c \
c7a6ac8
-		\
0e12a9f
-		findinfo.c
0e12a9f
 
c7a6ac8
-HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
c7a6ac8
-		movearch.h table.h props.h fifo.h diff.h restore.h \
0e12a9f
-		checkerr.h dumpdate.h bitstring.h
0e12a9f
-
c7a6ac8
-#LIBS=		-lunos
c7a6ac8
-#LIBS=		-lschily -lc /usr/local/lib/gcc-gnulib
0e12a9f
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL)
aaca4ca
-#
aaca4ca
-#	Wenn -lfind, dann auch  $(LIB_INTL)
aaca4ca
-#
c7a6ac8
-XMK_FILE=	Makefile.man starformatman.mk scpioman.mk gnutarman.mk \
c7a6ac8
-		spaxman.mk suntarman.mk Makefile.dfl Makefile.doc
0e12a9f
-
c7a6ac8
-star_fat.c: star.c
c7a6ac8
-	$(RM) $(RM_FORCE) $@; cp star.c $@
c7a6ac8
+MK_FILES= star.mk pax.mk suntar.mk gnutar.mk cpio.mk 
c7a6ac8
 
c7a6ac8
 ###########################################################################
c7a6ac8
-include		$(SRCROOT)/$(RULESDIR)/rules.cmd
c7a6ac8
+include		$(SRCROOT)/$(RULESDIR)/rules.mks
c7a6ac8
 ###########################################################################
c7a6ac8
-count:	$(CFILES) $(HFILES)
c7a6ac8
-	count $r1
c7a6ac8
-
0e12a9f
diff -urNp star-1.5-orig/star/pax.mk star-1.5/star/pax.mk
0e12a9f
--- star-1.5-orig/star/pax.mk	2008-04-06 20:01:45.000000000 +0200
0e12a9f
+++ star-1.5/star/pax.mk	2008-12-18 16:03:42.000000000 +0100
0e12a9f
@@ -19,6 +19,7 @@ CPPOPTS +=	-DUSE_FIND
c7a6ac8
 CPPOPTS +=	-DUSE_ACL
c7a6ac8
 CPPOPTS +=	-DUSE_XATTR
c7a6ac8
 CPPOPTS +=	-DUSE_FFLAGS
0e12a9f
+CPPOPTS +=	-DWITH_SELINUX
c7a6ac8
 CPPOPTS +=	-DPAX
774908b
 CPPOPTS +=	-DSCHILY_PRINT
c7a6ac8
 CFILES=		pax.c header.c cpiohdr.c xheader.c xattr.c \
0e12a9f
@@ -35,7 +36,7 @@ CFILES=		pax.c header.c cpiohdr.c xheade
0e12a9f
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0e12a9f
 		movearch.h table.h props.h fifo.h diff.h \
c7a6ac8
 		checkerr.h dumpdate.h bitstring.h
0e12a9f
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL)
0e12a9f
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_SELINUX)
c7a6ac8
 XMK_FILE=	spaxman.mk
d181987
 
c7a6ac8
 ###########################################################################
0e12a9f
diff -urNp star-1.5-orig/star/star.c star-1.5/star/star.c
0e12a9f
--- star-1.5-orig/star/star.c	2008-04-13 15:01:30.000000000 +0200
0e12a9f
+++ star-1.5/star/star.c	2008-12-18 16:05:31.000000000 +0100
0e12a9f
@@ -46,6 +46,10 @@ static	char sccsid[] =
0a28ddf
 #include "starsubs.h"
0a28ddf
 #include "checkerr.h"
d181987
 
d181987
+#ifdef WITH_SELINUX
d181987
+int selinux_enabled=0;
d181987
+#endif
d181987
+
d181987
 EXPORT	int	main		__PR((int ac, char **av));
d181987
 LOCAL	void	star_create	__PR((int ac, char *const *av));
d181987
 LOCAL	void	checkdumptype	__PR((GINFO *gp));
0e12a9f
@@ -388,6 +392,10 @@ main(ac, av)
d181987
 			comerr("Panic cannot set back effective uid.\n");
d181987
 	}
3ac25fc
 	my_uid = geteuid();
3ac25fc
+
d181987
+#ifdef WITH_SELINUX
0e12a9f
+	selinux_enabled=is_selinux_enabled()>0;
d181987
+#endif
d181987
 	/*
d181987
 	 * WARNING: We now are no more able to open a new remote connection
d181987
 	 * unless we have been called by root.
0e12a9f
diff -urNp star-1.5-orig/star/star_fat.mk star-1.5/star/star_fat.mk
0e12a9f
--- star-1.5-orig/star/star_fat.mk	2008-04-06 20:02:25.000000000 +0200
0e12a9f
+++ star-1.5/star/star_fat.mk	2008-12-18 16:04:20.000000000 +0100
0e12a9f
@@ -29,6 +29,7 @@ CPPOPTS +=	-DUSE_FFLAGS
0e12a9f
 CPPOPTS +=	-DCOPY_LINKS_DELAYED
0e12a9f
 CPPOPTS +=	-DSTAR_FAT
0e12a9f
 CPPOPTS +=	-DSCHILY_PRINT
0e12a9f
+CPPOPTS +=	-DWITH_SELINUX
0e12a9f
 CFILES=		star_fat.c header.c cpiohdr.c xheader.c xattr.c \
0e12a9f
 		list.c extract.c create.c append.c diff.c restore.c \
0e12a9f
 		remove.c star_unix.c acl_unix.c acltext.c fflags.c \
0e12a9f
@@ -48,7 +49,7 @@ HFILES=		star.h starsubs.h dirtime.h xta
0e12a9f
 
0e12a9f
 #LIBS=		-lunos
0e12a9f
 #LIBS=		-lschily -lc /usr/local/lib/gcc-gnulib
0e12a9f
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL)
0e12a9f
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_SELINUX)
0e12a9f
 #
0e12a9f
 #	Wenn -lfind, dann auch  $(LIB_INTL)
0e12a9f
 #
0e12a9f
diff -urNp star-1.5-orig/star/star.mk star-1.5/star/star.mk
0e12a9f
--- star-1.5-orig/star/star.mk	2008-04-06 20:01:45.000000000 +0200
0e12a9f
+++ star-1.5/star/star.mk	2008-12-18 16:06:07.000000000 +0100
0e12a9f
@@ -21,6 +21,7 @@ CPPOPTS +=	-DUSE_XATTR
0e2de46
 CPPOPTS +=	-DUSE_FFLAGS
c7a6ac8
 CPPOPTS +=	-DCOPY_LINKS_DELAYED
c7a6ac8
 CPPOPTS +=	-DSCHILY_PRINT
0e12a9f
+CPPOPTS +=	-DWITH_SELINUX
c7a6ac8
 CFILES=		star.c header.c cpiohdr.c xheader.c xattr.c \
0e2de46
 		list.c extract.c create.c append.c diff.c restore.c \
0e12a9f
 		remove.c star_unix.c acl_unix.c acltext.c fflags.c \
0e12a9f
@@ -35,7 +36,7 @@ CFILES=		star.c header.c cpiohdr.c xhead
0e12a9f
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0e12a9f
 		movearch.h table.h props.h fifo.h diff.h restore.h \
0e2de46
 		checkerr.h dumpdate.h bitstring.h
0e12a9f
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL)
0e12a9f
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_SELINUX)
c7a6ac8
 XMK_FILE=	Makefile.man starformatman.mk
0e2de46
 
0e2de46
 ###########################################################################
0e12a9f
diff -urNp star-1.5-orig/star/starsubs.h star-1.5/star/starsubs.h
0e12a9f
--- star-1.5-orig/star/starsubs.h	2008-04-06 17:32:15.000000000 +0200
0e12a9f
+++ star-1.5/star/starsubs.h	2008-12-18 16:01:15.000000000 +0100
0e12a9f
@@ -304,6 +304,11 @@ extern	void	opt_xattr	__PR((void));
0e12a9f
 extern	BOOL	get_xattr	__PR((register FINFO *info));
0e12a9f
 extern	BOOL	set_xattr	__PR((register FINFO *info));
0e12a9f
 extern	void	free_xattr	__PR((star_xattr_t **xattr));
0e12a9f
+# ifdef WITH_SELINUX
0e12a9f
+#include <selinux/selinux.h>
0e12a9f
+extern BOOL    setselinux __PR((register FINFO *info));
0e12a9f
+extern int selinux_enabled;
0e12a9f
+# endif
0e12a9f
 #endif
0e12a9f
 
0e12a9f
 /*
0e12a9f
diff -urNp star-1.5-orig/star/suntar.mk star-1.5/star/suntar.mk
0e12a9f
--- star-1.5-orig/star/suntar.mk	2008-04-06 20:01:45.000000000 +0200
0e12a9f
+++ star-1.5/star/suntar.mk	2008-12-18 15:58:44.000000000 +0100
0e12a9f
@@ -19,6 +19,7 @@ CPPOPTS +=	-DUSE_FIND
0e12a9f
 CPPOPTS +=	-DUSE_ACL
0e12a9f
 CPPOPTS +=	-DUSE_XATTR
0e12a9f
 CPPOPTS +=	-DUSE_FFLAGS
0e12a9f
+CPPOPTS +=	-DWITH_SELINUX
0e12a9f
 CPPOPTS +=	-DSCHILY_PRINT
0e12a9f
 CFILES=		suntar.c header.c cpiohdr.c xheader.c xattr.c \
0e12a9f
 		list.c extract.c create.c append.c diff.c restore.c \
0e12a9f
@@ -34,7 +35,7 @@ CFILES=		suntar.c header.c cpiohdr.c xhe
0e12a9f
 HFILES=		star.h starsubs.h dirtime.h xtab.h xutimes.h \
0e12a9f
 		movearch.h table.h props.h fifo.h diff.h \
0e12a9f
 		checkerr.h dumpdate.h bitstring.h
0e12a9f
-LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL)
0e12a9f
+LIBS=		-ldeflt -lrmt -lfind -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_INTL) $(LIB_SELINUX)
0e12a9f
 XMK_FILE=	suntarman.mk
0e12a9f
 
0e12a9f
 ###########################################################################
0e12a9f
diff -urNp star-1.5-orig/star/xattr.c star-1.5/star/xattr.c
0e12a9f
--- star-1.5-orig/star/xattr.c	2008-03-16 16:40:41.000000000 +0100
0e12a9f
+++ star-1.5/star/xattr.c	2008-12-18 16:08:15.000000000 +0100
0e12a9f
@@ -196,6 +196,27 @@ fail:
d181987
 #endif  /* USE_XATTR */
d181987
 }
d181987
 
d181987
+#ifdef WITH_SELINUX
d181987
+EXPORT BOOL
d181987
+setselinux(info)
d181987
+       register FINFO *info;
d181987
+{
d181987
+#if defined(USE_XATTR) && defined(HAVE_SETXATTR) && defined(WITH_SELINUX)
d181987
+       if (info->f_xattr) {
d181987
+               star_xattr_t    *xap;
d181987
+               for (xap = info->f_xattr; xap->name != NULL; xap++) {
d181987
+                 if (strcmp(xap->name, "security.selinux") == 0) {
d181987
+                   if (setfscreatecon(xap->value)) {
d181987
+                     return FALSE;
d181987
+                   }
d181987
+                 }
d181987
+               }
d181987
+       }
d181987
+#endif  /* USE_XATTR && WITH_SELINUX */
d181987
+       return TRUE;
d181987
+}
d181987
+#endif
d181987
+
d181987
 /* ARGSUSED */
d181987
 EXPORT BOOL
d181987
 set_xattr(info)
0e12a9f
@@ -209,6 +230,10 @@ set_xattr(info)
d181987
 		return (TRUE);
d181987
 
d181987
 	for (xap = info->f_xattr; xap->name != NULL; xap++) {
d181987
+#ifdef WITH_SELINUX
0e12a9f
+		if (selinux_enabled && (strcmp(xap->name, "security.selinux") == 0))
0e12a9f
+			continue;
d181987
+#endif
94c16cb
 		if (lsetxattr(info->f_name, xap->name, xap->value,
d181987
 		    xap->value_len, 0) != 0) {
d181987
 			if (!errhidden(E_SETXATTR, info->f_name)) {