tests: Remove priv-check. Use new require_root_ function instead.
authorJim Meyering <meyering@redhat.com>
Sat, 8 Dec 2007 11:29:25 +0000 (12:29 +0100)
committerJim Meyering <meyering@redhat.com>
Sat, 9 Feb 2008 09:30:33 +0000 (10:30 +0100)
* tests/priv-check: Remove file.
* tests/Makefile.am (EXTRA_DIST): Remove priv-check.
* tests/test-lib.sh (require_root_): New function.
Use this function rather than sourcing the priv-check file.
* tests/sample-test: Use require_root_ rather than priv-check.
* tests/chown/basic: Likewise.
* tests/cp/cp-a-selinux: Likewise.
* tests/cp/preserve-gid: Likewise.
* tests/cp/special-bits: Likewise.
* tests/ls/nameless-uid: Likewise.
* tests/misc/chcon: Likewise.
* tests/mkdir/writable-under-readonly: Likewise.
* tests/mv/sticky-to-xpart: Likewise.
* tests/rm/fail-2eperm: Likewise.
* tests/rm/no-give-up: Likewise.
* tests/rm/one-file-system: Likewise.
* tests/tail-2/append-only: Likewise.
* tests/touch/now-owned-by-other: Likewise.
* tests/rm/fail-eperm: Use skip_if_root_ rather than priv-check.
* Makefile.maint (sc_root_tests): Reflect this change:
search for the new function name.

18 files changed:
Makefile.maint
tests/chown/basic
tests/cp/cp-a-selinux
tests/cp/preserve-gid
tests/cp/special-bits
tests/ls/nameless-uid
tests/misc/chcon
tests/mkdir/writable-under-readonly
tests/mv/sticky-to-xpart
tests/priv-check [deleted file]
tests/rm/fail-2eperm
tests/rm/fail-eperm
tests/rm/no-give-up
tests/rm/one-file-system
tests/sample-test
tests/tail-2/append-only
tests/test-lib.sh
tests/touch/now-owned-by-other

index ba3c55ebbded993175c59b544ba24ba73bc145a0..3fbfa422b6d9d30c62aabc198b9eab9027f08c89 100644 (file)
@@ -246,7 +246,7 @@ sc_root_tests:
        @if test -d tests \
              && grep check-root tests/Makefile.am>/dev/null 2>&1; then \
        t1=sc-root.expected; t2=sc-root.actual;                         \
-       grep -nl '^PRIV_CHECK_ARG=require-root'                         \
+       grep -nl '^require_root_$$'                                     \
          $$($(CVS_LIST) tests) |sed s,tests,., |sort > $$t1;           \
        sed -n 's,      cd \([^ ]*\) .*MAKE..check TESTS=\(.*\),./\1/\2,p' \
          $(srcdir)/tests/Makefile.am |sort > $$t2;                     \
index a4276b8dec950c59b982cab01efb90db49e331bc..e7e3f02b452f98487b2f45446095ef7addd7ce11 100755 (executable)
@@ -22,8 +22,8 @@ if test "$VERBOSE" = yes; then
 fi
 
 . $srcdir/../lang-default
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 
 touch f || framework_failure
 
index c0d98bdac8d609350ae079620e5a930e29a77e46..33b4c2246c49e269d557dd06269a5ea7cc9513d2 100755 (executable)
@@ -23,8 +23,8 @@ if test "$VERBOSE" = yes; then
 fi
 
 . $srcdir/../lang-default
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 require_selinux_
 
 cwd=`pwd`
index 516733f33ff8a1a9995561ea34ac328b5d8cbfac..da0005612af07a0615d6660906633f082a58e96e 100755 (executable)
@@ -17,8 +17,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 . "$srcdir/../lang-default"
-PRIV_CHECK_ARG=require-root . "$srcdir/../priv-check"
 . "$srcdir/../test-lib.sh"
+require_root_
 
 create() {
   echo "$1" > "$1" || exit 1
index cce069cd4af8e55c88f1e8cc5bf150fd7c43b61c..be090fe2a29860907affbc3d7bcc7730612bb1fb 100755 (executable)
@@ -25,8 +25,8 @@ if test "$VERBOSE" = yes; then
   cp --version
 fi
 
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 
 touch a b c || framework_failure
 chmod u+sx,go= a || framework_failure
index a72438863d8b6c1e0831f6d5476128c32557212d..a2d3b94421497bcc1589fdc5e9f7674e692e46b7 100755 (executable)
@@ -25,8 +25,8 @@ fi
 . $srcdir/../require-perl
 
 . $srcdir/../lang-default
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 
 nameless_uid=`$PERL -e 'foreach my $i (1000..16*1024) { getpwuid $i or (print "$i\n"), exit }'`
 
index 3307bc970939ab83d938097dcd601ab5d40ca87e..9be450f29848452ad6d552dd187e53b88dcdf187 100755 (executable)
@@ -7,8 +7,8 @@ if test "$VERBOSE" = yes; then
 fi
 
 . $srcdir/../lang-default
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 require_selinux_
 
 mkdir -p d/sub/s2 || framework_failure
index 0c30f3f70257021350a66352f9283b5aeee93fef..bf2c2ad375d1b9c45bbe817ed081a795e478bca3 100755 (executable)
@@ -29,8 +29,8 @@ if test "$VERBOSE" = yes; then
   mkdir --version
 fi
 
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 
 # FIXME: for now, skip it unconditionally
 skip_test_ temporarily disabled
index 04690d75b2447226e45c47fa69d566a940768166..ac2e16193fa89832932e2374542523cb508ae524 100755 (executable)
@@ -26,8 +26,8 @@ fi
 
 . $srcdir/../envvar-check
 . $srcdir/../lang-default
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 
 cleanup_() { rm -rf "$other_partition_tmpdir"; }
 . "$abs_top_srcdir/tests/other-fs-tmpdir"
diff --git a/tests/priv-check b/tests/priv-check
deleted file mode 100644 (file)
index 7d7b1fe..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-# -*- sh -*-
-# Source this file at the beginning of a test that works
-# only when run as root or as non-root.
-
-# Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-case "$PRIV_CHECK_ARG" in
-  require-root) who='as root';;
-  require-non-root) who='by an unprivileged user';;
-  *) echo "Usage: PRIV_CHECK_ARG={require-root|require-non-root} . priv-check"\
-     1>&2; exit 1;;
-esac
-
-# Make sure id -u succeeds.
-my_uid=`id -u`
-test $? = 0 || {
-  echo "$0: cannot run \`id -u'" 1>&2
-  (exit 1); exit 1
-}
-
-# Make sure it gives valid output.
-case $my_uid in
-  *[!0-9]*)
-    echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2
-    (exit 1); exit 1
-    ;;
-  *) ;;
-esac
-
-test $my_uid = 0 && \
-{
-  # When running as root, always ensure that we have a valid non-root username.
-  # As non-root, don't do anything, since we won't be running setuidgid.
-  : ${NON_ROOT_USERNAME=nobody}
-
-  # Ensure that the supplied username is valid and with UID != 0.
-  coreutils_non_root_uid=`id -u $NON_ROOT_USERNAME`
-  test $? = 0 || \
-    {
-      echo "$0: This command failed: \`id -u $NON_ROOT_USERNAME'" 1>&2
-      echo "$0: Skipping this test.  To enable it, set the envvar" 1>&2
-      echo "$0: NON_ROOT_USERNAME to a non-root user name." 1>&2
-      (exit 77); exit 77
-    }
-  test "$coreutils_non_root_uid" = 0 && \
-    {
-      echo "$0: The specified NON_ROOT_USERNAME ($NON_ROOT_USERNAME)" 1>&2
-      echo "$0: is invalid because its UID is 0." 1>&2
-      (exit 1); exit 1
-    }
-}
-
-give_msg=no
-case $PRIV_CHECK_ARG:$my_uid in
-  require-root:0) ;;
-  require-root:*) give_msg=yes ;;
-  require-non-root:0)
-    # `.' must be writable by $NON_ROOT_USERNAME
-    setuidgid $NON_ROOT_USERNAME test -w . ||
-      {
-       echo "$0: `pwd`: not writable by user \`$NON_ROOT_USERNAME'" 1>&2
-       echo "$0: skipping this test" 1>&2
-       (exit 77); exit 77
-      }
-    exec setuidgid $NON_ROOT_USERNAME env PATH="$PATH" $0
-    ;;
-  require-non-root:*) ;;
-esac
-
-test $give_msg = yes && {
-  cat <<EOF
-***************************
-NOTICE:
-$0: This test is being skipped, since it works only
-when run $who.
-***************************
-EOF
-  (exit 77); exit 77
-}
index bafd5bfcc255c1a3c9f226be984497dbdbfc1222..66efbce291721e9153c960781b2a89e9adff6b7b 100755 (executable)
@@ -23,8 +23,8 @@ if test "$VERBOSE" = yes; then
 fi
 
 . $srcdir/../lang-default
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 
 # The containing directory must be owned by the user who eventually runs rm.
 chown $NON_ROOT_USERNAME .
index 4abc9dec6722b47af541ea4add902bf0a5a9a8d8..7bc89da158c83eb2f5e079afd16320ca59426e47 100755 (executable)
@@ -27,7 +27,8 @@ fi
 # searching below.  root can simply create the required
 # dir/files and run the test as someone else.
 
-PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
+. $srcdir/../test-lib.sh
+skip_if_root_
 
 : ${srcdir=.}
 . $srcdir/../require-perl
index 14d2a4694ca0f282ceb36c1a480955597fe836da..8a1ecdc757c58b898ba3cea23722880b86c053bf 100755 (executable)
@@ -22,8 +22,8 @@ if test "$VERBOSE" = yes; then
   rm --version
 fi
 
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 
 mkdir d || framework_failure
 touch d/f || framework_failure
index 471216c2caa339b002ae954069f02681bfa08143..15d32796568cd2577d38b9cb79d6c6b7f5b14f53 100755 (executable)
@@ -21,9 +21,9 @@ if test "$VERBOSE" = yes; then
   rm --version
 fi
 
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../lang-default
 . $srcdir/../test-lib.sh
+require_root_
 
 # If used, these must *follow* test-lib.sh.
 cleanup_() { rm -rf "$other_partition_tmpdir"; }
index e1d0d939f5230ce38519da23c6f231e263706afc..0da0bca95273cdee2ac77f617e9374a5c69699f6 100644 (file)
@@ -23,9 +23,9 @@ fi
 
 # FIXME: . $srcdir/../envvar-check
 # FIXME: . $srcdir/../lang-default
-# FIXME: PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
-# FIXME skip_if_root_
+# FIXME: skip_if_root_
+# FIXME: require_root_
 
 # If used, these must *follow* test-lib.sh.
 # FIXME: cleanup_() { rm -rf "$other_partition_tmpdir"; }
index 606ed339a18dd8d91dc97c2e4fdfc6e23cb55a46..615401874b569c41d9ff0ad47cc66ec9f51096fa 100755 (executable)
@@ -22,8 +22,8 @@ if test "$VERBOSE" = yes; then
   tail --version
 fi
 
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 
 chattr_a_works=1
 touch f
index 3b8d2ce988e33cfe0d3aaa62b8d6b642bd80ad40..b273f1a81d6ae44da8a3663d0afe2e6baa5df6ff 100644 (file)
@@ -100,6 +100,7 @@ environment variable set to yes.  E.g.,
   fi
 }
 
+require_root_() { uid_is_privileged_ || skip_test_ "must be run as root"; }
 skip_if_root_() { uid_is_privileged_ && skip_test_ "must be run as non-root"; }
 error_() { echo "$0: $@" 1>&2; (exit 1); exit 1; }
 framework_failure() { error_ 'failure in testing framework'; }
index 0871ff7de1c80010f99dbc1c4e4e940e798c9218..d4e01dd27a23156c5cca4214f18634df2e2d3709 100755 (executable)
@@ -22,8 +22,8 @@ if test "$VERBOSE" = yes; then
 fi
 
 . $srcdir/../envvar-check
-PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
 . $srcdir/../test-lib.sh
+require_root_
 
 group_num=$(id -g $NON_ROOT_USERNAME)