star/star-1.5-selinux.patch

281 lines
9.3 KiB
Diff
Raw Normal View History

2005-08-26 14:58:14 +00:00
diff --git a/conf/configure.in b/conf/configure.in
--- a/conf/configure.in
+++ b/conf/configure.in
@@ -312,6 +312,15 @@ if test "$ac_cv_header_attr_xattr_h" = y
LIBS="$ac_save_LIBS"
fi
+AC_CHECK_HEADERS(selinux/selinux.h)
+if test "$ac_cv_header_selinux_selinux_h" = yes; then
+ AC_CHECKING(for SELinux support)
+ AC_CHECK_LIB(selinux, is_selinux_enabled, lib_selinux="-lselinux -lattr")
+ ac_save_LIBS="$LIBS"
+ LIBS="$LIBS $lib_selinux"
+ AC_CHECK_FUNCS(is_selinux_enabled)
+fi
+
dnl Checks for OS madness.
AC_BROKEN_LINUX_EXT2_FS_H
AC_BROKEN_SRC_LINUX_EXT2_FS_H
@@ -327,5 +336,6 @@ AC_SUBST(scsi_lib)
AC_SUBST(lib_acl)
AC_SUBST(lib_acl_test)
AC_SUBST(lib_attr)
+AC_SUBST(lib_selinux)
AC_OUTPUT(rules.cnf)
diff --git a/conf/rules.cnf.in b/conf/rules.cnf.in
--- a/conf/rules.cnf.in
+++ b/conf/rules.cnf.in
@@ -9,3 +9,5 @@ LIB_CRYPT= @lib_crypt@
LIB_ACL= @lib_acl@
LIB_ACL_TEST= @lib_acl_test@
LIB_ATTR = @lib_attr@
+LIB_SELINUX = @lib_selinux@
+
diff --git a/star/Makefile b/star/Makefile
--- a/star/Makefile
+++ b/star/Makefile
@@ -24,6 +24,7 @@ CPPOPTS += -DSET_CTIME -DFIFO -DUSE_MMAP
2004-11-22 14:57:57 +00:00
CPPOPTS += -DUSE_LARGEFILES
CPPOPTS += -DUSE_ACL
CPPOPTS += -DUSE_XATTR
+CPPOPTS += -DWITH_SELINUX
CPPOPTS += -DUSE_FFLAGS
2005-08-26 14:58:14 +00:00
CPPOPTS += -DCOPY_LINKS_DELAYED
CPPOPTS += -DSTAR_FAT
@@ -43,7 +44,7 @@ HFILES= star.h starsubs.h dirtime.h xta
2004-11-22 14:57:57 +00:00
checkerr.h dumpdate.h bitstring.h
#LIBS= -lunos
#LIBS= -lschily -lc /usr/local/lib/gcc-gnulib
-LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET)
2005-08-15 12:21:48 +00:00
+LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_SELINUX)
2005-08-26 14:58:14 +00:00
XMK_FILE= Makefile.man starformatman.mk scpioman.mk gnutarman.mk \
spaxman.mk suntarman.mk Makefile.dfl
diff --git a/star/cpio.mk b/star/cpio.mk
--- a/star/cpio.mk
+++ b/star/cpio.mk
@@ -18,6 +18,7 @@ CPPOPTS += -DUSE_LARGEFILES
CPPOPTS += -DUSE_ACL
CPPOPTS += -DUSE_XATTR
CPPOPTS += -DUSE_FFLAGS
+CPPOPTS += -DWITH_SELINUX
CFILES= cpio.c header.c cpiohdr.c xheader.c xattr.c \
list.c extract.c create.c append.c diff.c restore.c \
remove.c star_unix.c acl_unix.c acltext.c fflags.c \
@@ -34,7 +35,7 @@ HFILES= star.h starsubs.h dirtime.h xta
checkerr.h dumpdate.h bitstring.h
#LIBS= -lunos
#LIBS= -lschily -lc /usr/local/lib/gcc-gnulib
-LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET)
+LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_SELINUX)
XMK_FILE= scpioman.mk
###########################################################################
diff --git a/star/extract.c b/star/extract.c
--- a/star/extract.c
+++ b/star/extract.c
@@ -209,6 +209,16 @@ extract(vhname)
if (prblockno)
(void) tblocks(); /* set curblockno */
+#ifdef WITH_SELINUX
+ if (!to_stdout && selinux_enabled) {
+ if (setselinux(&finfo) == FALSE) {
+ errmsgno(EX_BAD,
+ "Can not setup security context for '%s'. Not created.\n",
+ finfo.f_name);
+ }
+ }
+#endif
+
if (finfo.f_xflags & XF_BAD_META) {
if (!void_bad(&finfo))
break;
diff --git a/star/gnutar.mk b/star/gnutar.mk
--- a/star/gnutar.mk
+++ b/star/gnutar.mk
@@ -18,6 +18,7 @@ CPPOPTS += -DUSE_LARGEFILES
CPPOPTS += -DUSE_ACL
CPPOPTS += -DUSE_XATTR
CPPOPTS += -DUSE_FFLAGS
+CPPOPTS += -DWITH_SELINUX
CFILES= gnutar.c header.c cpiohdr.c xheader.c xattr.c \
list.c extract.c create.c append.c diff.c restore.c \
remove.c star_unix.c acl_unix.c acltext.c fflags.c \
@@ -34,7 +35,7 @@ HFILES= star.h starsubs.h dirtime.h xta
checkerr.h dumpdate.h bitstring.h
#LIBS= -lunos
#LIBS= -lschily -lc /usr/local/lib/gcc-gnulib
-LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET)
+LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_SELINUX)
XMK_FILE= gnutarman.mk
2004-11-22 14:57:57 +00:00
###########################################################################
2005-08-26 14:58:14 +00:00
diff --git a/star/pax.mk b/star/pax.mk
--- a/star/pax.mk
+++ b/star/pax.mk
@@ -17,6 +17,7 @@ CPPOPTS += -DSET_CTIME -DFIFO -DUSE_MMAP
2004-11-22 14:57:57 +00:00
CPPOPTS += -DUSE_LARGEFILES
CPPOPTS += -DUSE_ACL
CPPOPTS += -DUSE_XATTR
+CPPOPTS += -DWITH_SELINUX
CPPOPTS += -DUSE_FFLAGS
2005-08-26 14:58:14 +00:00
CPPOPTS += -DPAX
CFILES= pax.c header.c cpiohdr.c xheader.c xattr.c \
@@ -35,7 +36,7 @@ HFILES= star.h starsubs.h dirtime.h xta
2004-11-22 14:57:57 +00:00
checkerr.h dumpdate.h bitstring.h
#LIBS= -lunos
#LIBS= -lschily -lc /usr/local/lib/gcc-gnulib
-LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET)
2005-08-15 12:21:48 +00:00
+LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_SELINUX)
2005-08-26 14:58:14 +00:00
XMK_FILE= spaxman.mk
2004-11-22 14:57:57 +00:00
2005-08-26 14:58:14 +00:00
###########################################################################
diff --git a/star/star.c b/star/star.c
--- a/star/star.c
+++ b/star/star.c
@@ -40,6 +40,10 @@ static char sccsid[] =
2004-11-22 14:57:57 +00:00
#endif
#include "dumpdate.h"
+#ifdef WITH_SELINUX
+int selinux_enabled=0;
+#endif
+
EXPORT int main __PR((int ac, char **av));
LOCAL void star_create __PR((int ac, char *const *av));
LOCAL void checkdumptype __PR((GINFO *gp));
2005-08-26 14:58:14 +00:00
@@ -358,6 +362,11 @@ main(ac, av)
2004-11-22 14:57:57 +00:00
comerr("Panic cannot set back effective uid.\n");
}
2005-08-15 12:21:48 +00:00
my_uid = geteuid();
+
2004-11-22 14:57:57 +00:00
+#ifdef WITH_SELINUX
+ selinux_enabled=is_selinux_enabled()>0;
+#endif
+
/*
* WARNING: We now are no more able to open a new remote connection
* unless we have been called by root.
2005-08-26 14:58:14 +00:00
diff --git a/star/star.mk b/star/star.mk
--- a/star/star.mk
+++ b/star/star.mk
@@ -19,6 +19,7 @@ CPPOPTS += -DUSE_ACL
CPPOPTS += -DUSE_XATTR
CPPOPTS += -DUSE_FFLAGS
CPPOPTS += -DCOPY_LINKS_DELAYED
+CPPOPTS += -DWITH_SELINUX
CFILES= star.c header.c cpiohdr.c xheader.c xattr.c \
list.c extract.c create.c append.c diff.c restore.c \
remove.c star_unix.c acl_unix.c acltext.c fflags.c \
@@ -35,7 +36,7 @@ HFILES= star.h starsubs.h dirtime.h xta
checkerr.h dumpdate.h bitstring.h
#LIBS= -lunos
#LIBS= -lschily -lc /usr/local/lib/gcc-gnulib
-LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET)
+LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_SELINUX)
XMK_FILE= Makefile.man starformatman.mk
2004-11-22 14:57:57 +00:00
2005-08-26 14:58:14 +00:00
###########################################################################
diff --git a/star/star_fat.mk b/star/star_fat.mk
--- a/star/star_fat.mk
+++ b/star/star_fat.mk
@@ -27,6 +27,7 @@ CPPOPTS += -DUSE_XATTR
CPPOPTS += -DUSE_FFLAGS
CPPOPTS += -DCOPY_LINKS_DELAYED
CPPOPTS += -DSTAR_FAT
+CPPOPTS += -DWITH_SELINUX
CFILES= star_fat.c header.c cpiohdr.c xheader.c xattr.c \
list.c extract.c create.c append.c diff.c restore.c \
remove.c star_unix.c acl_unix.c acltext.c fflags.c \
@@ -43,7 +44,7 @@ HFILES= star.h starsubs.h dirtime.h xta
checkerr.h dumpdate.h bitstring.h
#LIBS= -lunos
#LIBS= -lschily -lc /usr/local/lib/gcc-gnulib
-LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET)
+LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_SELINUX)
XMK_FILE= Makefile.man starformatman.mk scpioman.mk gnutarman.mk \
spaxman.mk suntarman.mk Makefile.dfl
diff --git a/star/starsubs.h b/star/starsubs.h
--- a/star/starsubs.h
+++ b/star/starsubs.h
@@ -293,6 +293,11 @@ extern BOOL get_number __PR((char *keywo
2004-11-22 14:57:57 +00:00
extern BOOL get_xattr __PR((register FINFO *info));
extern BOOL set_xattr __PR((register FINFO *info));
extern void free_xattr __PR((star_xattr_t **xattr));
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
+extern BOOL setselinux __PR((register FINFO *info));
+extern int selinux_enabled;
+#endif
#endif
/*
2005-08-26 14:58:14 +00:00
diff --git a/star/suntar.mk b/star/suntar.mk
--- a/star/suntar.mk
+++ b/star/suntar.mk
@@ -18,6 +18,7 @@ CPPOPTS += -DUSE_LARGEFILES
CPPOPTS += -DUSE_ACL
CPPOPTS += -DUSE_XATTR
CPPOPTS += -DUSE_FFLAGS
+CPPOPTS += -DWITH_SELINUX
CFILES= suntar.c header.c cpiohdr.c xheader.c xattr.c \
list.c extract.c create.c append.c diff.c restore.c \
remove.c star_unix.c acl_unix.c acltext.c fflags.c \
@@ -34,7 +35,7 @@ HFILES= star.h starsubs.h dirtime.h xta
checkerr.h dumpdate.h bitstring.h
#LIBS= -lunos
#LIBS= -lschily -lc /usr/local/lib/gcc-gnulib
-LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET)
+LIBS= -ldeflt -lrmt -lschily $(LIB_ACL) $(LIB_ATTR) $(LIB_SOCKET) $(LIB_SELINUX)
XMK_FILE= suntarman.mk
###########################################################################
diff --git a/star/xattr.c b/star/xattr.c
--- a/star/xattr.c
+++ b/star/xattr.c
@@ -159,6 +159,29 @@ fail:
2004-11-22 14:57:57 +00:00
#endif /* USE_XATTR */
}
2005-08-15 12:21:48 +00:00
+
2004-11-22 14:57:57 +00:00
+#ifdef WITH_SELINUX
+EXPORT BOOL
+setselinux(info)
+ register FINFO *info;
+{
+#if defined(USE_XATTR) && defined(HAVE_SETXATTR) && defined(WITH_SELINUX)
+ if (info->f_xattr) {
+ star_xattr_t *xap;
+ for (xap = info->f_xattr; xap->name != NULL; xap++) {
+ if (strcmp(xap->name, "security.selinux") == 0) {
+ if (setfscreatecon(xap->value)) {
+ return FALSE;
+ }
+ }
+ }
+ }
+#endif /* USE_XATTR && WITH_SELINUX */
+ return TRUE;
+}
+#endif
2005-08-15 12:21:48 +00:00
+
2004-11-22 14:57:57 +00:00
+
/* ARGSUSED */
EXPORT BOOL
set_xattr(info)
2005-08-26 14:58:14 +00:00
@@ -171,6 +194,10 @@ set_xattr(info)
2004-11-22 14:57:57 +00:00
return (TRUE);
for (xap = info->f_xattr; xap->name != NULL; xap++) {
+#ifdef WITH_SELINUX
+ if (selinux_enabled && (strcmp(xap->name, "security.selinux") == 0))
+ continue;
+#endif
if (setxattr(info->f_name, xap->name, xap->value,
xap->value_len, 0) != 0) {
if (!errhidden(E_SETXATTR, info->f_name)) {