From 39137a5d05df940410261f4cad2e4a695faf0f7f Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 8 Dec 2007 12:29:25 +0100 Subject: tests: Remove priv-check. Use new require_root_ function instead. * 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. --- Makefile.maint | 2 +- tests/chown/basic | 2 +- tests/cp/cp-a-selinux | 2 +- tests/cp/preserve-gid | 2 +- tests/cp/special-bits | 2 +- tests/ls/nameless-uid | 2 +- tests/misc/chcon | 2 +- tests/mkdir/writable-under-readonly | 2 +- tests/mv/sticky-to-xpart | 2 +- tests/priv-check | 92 ------------------------------------- tests/rm/fail-2eperm | 2 +- tests/rm/fail-eperm | 3 +- tests/rm/no-give-up | 2 +- tests/rm/one-file-system | 2 +- tests/sample-test | 4 +- tests/tail-2/append-only | 2 +- tests/test-lib.sh | 1 + tests/touch/now-owned-by-other | 2 +- 18 files changed, 19 insertions(+), 109 deletions(-) delete mode 100644 tests/priv-check diff --git a/Makefile.maint b/Makefile.maint index ba3c55ebb..3fbfa422b 100644 --- a/Makefile.maint +++ b/Makefile.maint @@ -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; \ diff --git a/tests/chown/basic b/tests/chown/basic index a4276b8de..e7e3f02b4 100755 --- a/tests/chown/basic +++ b/tests/chown/basic @@ -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 diff --git a/tests/cp/cp-a-selinux b/tests/cp/cp-a-selinux index c0d98bdac..33b4c2246 100755 --- a/tests/cp/cp-a-selinux +++ b/tests/cp/cp-a-selinux @@ -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` diff --git a/tests/cp/preserve-gid b/tests/cp/preserve-gid index 516733f33..da0005612 100755 --- a/tests/cp/preserve-gid +++ b/tests/cp/preserve-gid @@ -17,8 +17,8 @@ # along with this program. If not, see . . "$srcdir/../lang-default" -PRIV_CHECK_ARG=require-root . "$srcdir/../priv-check" . "$srcdir/../test-lib.sh" +require_root_ create() { echo "$1" > "$1" || exit 1 diff --git a/tests/cp/special-bits b/tests/cp/special-bits index cce069cd4..be090fe2a 100755 --- a/tests/cp/special-bits +++ b/tests/cp/special-bits @@ -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 diff --git a/tests/ls/nameless-uid b/tests/ls/nameless-uid index a72438863..a2d3b9442 100755 --- a/tests/ls/nameless-uid +++ b/tests/ls/nameless-uid @@ -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 }'` diff --git a/tests/misc/chcon b/tests/misc/chcon index 3307bc970..9be450f29 100755 --- a/tests/misc/chcon +++ b/tests/misc/chcon @@ -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 diff --git a/tests/mkdir/writable-under-readonly b/tests/mkdir/writable-under-readonly index 0c30f3f70..bf2c2ad37 100755 --- a/tests/mkdir/writable-under-readonly +++ b/tests/mkdir/writable-under-readonly @@ -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 diff --git a/tests/mv/sticky-to-xpart b/tests/mv/sticky-to-xpart index 04690d75b..ac2e16193 100755 --- a/tests/mv/sticky-to-xpart +++ b/tests/mv/sticky-to-xpart @@ -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 index 7d7b1fead..000000000 --- a/tests/priv-check +++ /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 . - -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 <&2; (exit 1); exit 1; } framework_failure() { error_ 'failure in testing framework'; } diff --git a/tests/touch/now-owned-by-other b/tests/touch/now-owned-by-other index 0871ff7de..d4e01dd27 100755 --- a/tests/touch/now-owned-by-other +++ b/tests/touch/now-owned-by-other @@ -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) -- cgit v1.2.3-54-g00ecf