Hi, I think I got a fix for this bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=556358. I added a bit of permission checking to require_root_ so no tests have to be rewriten.
Have a nice day :) ,
 Ondrej
>From 4c3dad461c638a710bb8c36c54d4ac4f64aa747e Mon Sep 17 00:00:00 2001
From: Ondrej Oprala <[email protected]>
Date: Thu, 9 Aug 2012 15:40:39 +0200
Subject: [PATCH] tests: Add error checking for root-only tests running
 setuidgid

NEWS: Mention the fix.
tests/init.cfg: Modify the require_root_ function to check
for setuidgid calls and proper permissions.
---
 NEWS           |  4 ++++
 tests/init.cfg | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/NEWS b/NEWS
index ca4568a..43c3a8e 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@ GNU coreutils NEWS                                    -*- 
outline -*-
 
 ** Bug fixes
 
+  root-only tests now properly check for permissions of dummy
+  user $NON_ROOT_USERNAME before trying to run binaries from the
+  src dir.
+
   cksum now prints checksums atomically so that concurrent
   processes will not intersperse their output.
   [the bug dates back to the initial implementation]
diff --git a/tests/init.cfg b/tests/init.cfg
index 4ff5ad4..00679e8 100644
--- a/tests/init.cfg
+++ b/tests/init.cfg
@@ -341,11 +341,36 @@ or use the shortcut target of the toplevel Makefile,
   fi
 }
 
+setuidgid_has_perm_()
+{
+
+  cat << \EOF > cmds.tmp
+  IFS=:
+  for DIR in $PATH; do
+    test -x $DIR || exit 1
+  done
+  exit 0
+EOF
+
+  su -s /bin/sh $NON_ROOT_USERNAME < cmds.tmp
+
+  RET=$?
+  return $RET
+}
+
 require_root_()
 {
   uid_is_privileged_ || skip_ "must be run as root"
+
   NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
   NON_ROOT_GROUP=${NON_ROOT_GROUP=$(id -g $NON_ROOT_USERNAME)}
+
+  #if test contains a setuidgid call...
+  grep '^[ ]*setuidgid' "../$0"
+  if [ "$?" = "0" ]; then
+    setuidgid_has_perm_ || skip_ "user $NON_ROOT_USERNAME lacks permissions"
+  fi
+
 }
 
 skip_if_root_() { uid_is_privileged_ && skip_ "must be run as non-root"; }
-- 
1.7.11.2

Reply via email to