[sheepdog] [PATCH 04/14] tests: check root privilege

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Apr 30 10:29:59 CEST 2013


This prevents non-root users from running tests which need root
privilege.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 tests/011       |  2 ++
 tests/035       |  2 ++
 tests/042       |  2 ++
 tests/050       |  2 ++
 tests/common.rc | 11 +++++++++++
 5 files changed, 19 insertions(+)

diff --git a/tests/011 b/tests/011
index de70a64..b575cce 100755
--- a/tests/011
+++ b/tests/011
@@ -13,6 +13,8 @@ status=1        # failure is the default!
 . ./common.rc
 . ./common.filter
 
+_need_to_be_root
+
 _cleanup
 
 _make_device 0 $((2 * 1024 ** 3))
diff --git a/tests/035 b/tests/035
index ed492fb..5b948c9 100755
--- a/tests/035
+++ b/tests/035
@@ -15,6 +15,8 @@ trap "_uninit; exit \$status" 0 1 2 3 15
 . ./common.rc
 . ./common.filter
 
+_need_to_be_root
+
 _uninit()
 {
 	for i in `seq 1 7`; do
diff --git a/tests/042 b/tests/042
index b6aa54d..9290ab6 100755
--- a/tests/042
+++ b/tests/042
@@ -13,6 +13,8 @@ status=1        # failure is the default!
 . ./common.rc
 . ./common.filter
 
+_need_to_be_root
+
 _cleanup
 
 _make_device 0 $((1024 ** 3))
diff --git a/tests/050 b/tests/050
index 6837446..76eccdd 100755
--- a/tests/050
+++ b/tests/050
@@ -15,6 +15,8 @@ trap "_uninit; exit \$status" 0 1 2 3 15
 . ./common.rc
 . ./common.filter
 
+_need_to_be_root
+
 _uninit()
 {
 	iptables -D INPUT -p tcp --sport 8001 -j DROP
diff --git a/tests/common.rc b/tests/common.rc
index e59b5f0..7d34bdb 100644
--- a/tests/common.rc
+++ b/tests/common.rc
@@ -30,6 +30,17 @@ fi
 # make sure we have a standard umask
 umask 022
 
+# check if run as root
+#
+_need_to_be_root()
+{
+    id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
+    if [ "$id" -ne 0 ]
+    then
+	_notrun "you need to be root (not uid=$id) to run this test"
+    fi
+}
+
 # Do a command, log it to $seq.full, optionally test return status
 # and die if command fails. If called with one argument _do executes the
 # command, logs it, and returns its exit status. With two arguments _do
-- 
1.8.1.3.566.gaa39828




More information about the sheepdog mailing list