From be2f82f670b914e26ffcbbff0378a0452d432d1c Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Thu, 11 Feb 2016 15:07:52 +0100 Subject: tests: support non-MLS enabled SELinux systems When running "make check" on a Linux system running SELinux with a non-MLS policy, tests/mkdir/restorecon.sh test fails with: chcon: invalid context: root:object_r:tmp_t:s0: Invalid argument Indeed in such a configuration, contexts cannot have ":s0" suffix. * init.cfg (get_selinux_type): Refactor this function to here from various tests. Update to work with a non-MLS policy. (mls_enabled_): A new function to detect if MLS is enabled. (skip_if_mcstransd_is_running_): Update to not skip when MLS is not enabled. * tests/mkdir/restorecon.sh: Use a valid non-MLS context when needed. * tests/install/install-Z-selinux.sh: Likewise. * tests/cp/cp-a-selinux.sh: Likewise. * tests/misc/selinux.sh: Likewise. * tests/misc/chcon.sh: Skip if non-MLS as --range used throughout. Fixes http://bugs.gnu.org/22631 --- tests/cp/cp-a-selinux.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/cp/cp-a-selinux.sh') diff --git a/tests/cp/cp-a-selinux.sh b/tests/cp/cp-a-selinux.sh index 89735b65a..391595218 100755 --- a/tests/cp/cp-a-selinux.sh +++ b/tests/cp/cp-a-selinux.sh @@ -28,7 +28,8 @@ cwd=$(pwd) cleanup_() { cd /; umount "$cwd/mnt"; } # This context is special: it works even when mcstransd isn't running. -ctx=root:object_r:tmp_t:s0 +ctx='root:object_r:tmp_t' +mls_enabled_ && ctx="$ctx:s0" # Check basic functionality - before check on fixed context mount touch c || framework_failure_ @@ -62,7 +63,6 @@ grep $ctx ed_ctx && { ls -lZd restore/existing_dir; fail=1; } # Check restorecon (-Z) functionality for file and directory -get_selinux_type() { ls -Zd "$1" | sed -n 's/.*:\(.*_t\):.*/\1/p'; } # Also make a dir with our known context mkdir c_d || framework_failure_ chcon $ctx c_d || framework_failure_ -- cgit v1.2.3-70-g09d2