[augeas-devel] [PATCH] tests: extract SELinux context more portably
Jim Meyering
jim at meyering.net
Tue Jul 21 13:43:31 UTC 2009
Hi David,
I found that test-preserve.sh would fail on an F11 system
with SELinux in enforcing mode.
That happened because ls -lZ would print this:
-rw-r--r--. root root system_u:object_r:net_conf_t:s0 /etc/hosts
And in that case, the context string is the 4th space-delimited token,
and not the 5th. Perhaps you have disabled SELinux and have a space
in place of the "."? Then the cut...-f 5 would work. You might also
have to have a slightly outdated version of ls.
In any case, if ls accepts -lZ, then stat --format=%C should also work,
yet be independent of whether SELinux is in enforcing mode.
Its result also requires less parsing:
(alternatively, you could use sed 's/ */ /' like you
did for act_group= just above)
>From c3df3f9ed0be573658d36873b8a2b047f1cee915 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Tue, 21 Jul 2009 09:22:45 -0400
Subject: [PATCH] tests: extract SELinux context more portably
* test-preserve.sh: Use stat --format=%C $hosts ... rather than
ls -lZ $hosts | cut -d ' ' -f 5. The latter fails with some
combinations of ls and SELinux.
---
tests/test-preserve.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tests/test-preserve.sh b/tests/test-preserve.sh
index 301b0c1..eb6bb7a 100755
--- a/tests/test-preserve.sh
+++ b/tests/test-preserve.sh
@@ -42,7 +42,7 @@ fi
act_group=$(ls -l $hosts | sed -e 's/ */ /g' | cut -d ' ' -f 4)
act_mode=$(ls -l $hosts | cut -b 1-10)
if [ $selinux = yes ] ; then
- act_con=$(ls -lZ $hosts | cut -d ' ' -f 5 | cut -d ':' -f 3)
+ act_con=$(stat --format=%C $hosts | cut -d ':' -f 3)
fi
if [ "x$group" != "x$act_group" ] ; then
echo "Expected group $group but got $act_group"
--
1.6.2.5
More information about the augeas-devel
mailing list