summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-07-10 15:47:36 +0000
committerJim Meyering <jim@meyering.net>2003-07-10 15:47:36 +0000
commitaacb015d414a07a2312cf684e05807fb0132a269 (patch)
treeb59c10e47dc18eadf69bfd8e5b373320bdb1fe96 /tests
parent0dca45f31054406685719e4a1989c658003609c4 (diff)
downloadcoreutils-aacb015d414a07a2312cf684e05807fb0132a269.tar.xz
Now that we have setuidgid, use it in place of the kludge in this test.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/rm/fail-2eperm26
1 files changed, 17 insertions, 9 deletions
diff --git a/tests/rm/fail-2eperm b/tests/rm/fail-2eperm
index 18662e3f5..7a675d3c7 100755
--- a/tests/rm/fail-2eperm
+++ b/tests/rm/fail-2eperm
@@ -19,16 +19,24 @@ framework_failure=0
mkdir -p $tmp || framework_failure=1
cd $tmp || framework_failure=1
-# Find a username with UID != 0, and a valid shell.
-non_root_username=
-names=`grep -v '[^:]*:[^:]*:0:' /etc/passwd| sed 's/:.*//'`
-for name in $names; do
- su -c ':' $name && { non_root_username=$name; break; }
-done
-test "x$non_root_username" = x && framework_failure=1
+: ${NON_ROOT_USERNAME=nobody}
+
+# Ensure that the supplied username is valid and with UID != 0.
+setuidgid $NON_ROOT_USERNAME id -u > id || \
+ {
+ 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 `cat id` = 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
+ }
# The containing directory must be owned by the user who eventually runs rm.
-chown $non_root_username .
+chown $NON_ROOT_USERNAME .
mkdir a || framework_failure=1
chmod 1777 a || framework_failure=1
@@ -41,7 +49,7 @@ fi
fail=0
-su -c 'rm -rf a' $non_root_username 2> out && fail=1
+setuidgid $NON_ROOT_USERNAME rm -rf a 2> out && fail=1
cat <<\EOF > exp
rm: cannot remove `a/b': Operation not permitted
EOF