From b5a8fa324d089323f0af02f4eb7c8bfdc86b4337 Mon Sep 17 00:00:00 2001 From: Ondrej Oprala 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 | 6 ++++++ tests/init.cfg | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/NEWS b/NEWS index 46d0a41..173f861 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,12 @@ GNU coreutils NEWS -*- outline -*- certain options like -a, -l, -t and -x. [This bug was present in "the beginning".] +** 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. + * Noteworthy changes in release 8.18 (2012-08-12) [stable] diff --git a/tests/init.cfg b/tests/init.cfg index 4ff5ad4..2d0fe10 100644 --- a/tests/init.cfg +++ b/tests/init.cfg @@ -341,11 +341,30 @@ or use the shortcut target of the toplevel Makefile, fi } +setuidgid_has_perm_() +{ + local rm_version=$( + setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm --version | + sed -n 'ls/.* //p' + ) + case "_${rm_version}_" in + _$PACKAGE_VERSION}_) ;; + *) return 1;; + esac +} + 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 execute permissions" + fi } skip_if_root_() { uid_is_privileged_ && skip_ "must be run as non-root"; } -- 1.7.11.2