7ee0e2a14761d4191ca7611c9d3cb8dcf6e7ce0d
[platform/upstream/coreutils.git] / tests / rm / fail-2eperm
1 #!/bin/sh
2 # Like fail-eperm, but the failure must be for a file encountered
3 # while trying to remove the containing directory with the sticky bit set.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   rm --version
8 fi
9
10 . $srcdir/../lang-default
11 PRIV_CHECK_ARG=require-root . $srcdir/../priv-check
12
13 pwd=`pwd`
14 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
15 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
16 trap '(exit $?); exit $?' 1 2 13 15
17
18 framework_failure=0
19 mkdir -p $tmp || framework_failure=1
20 cd $tmp || framework_failure=1
21
22 # The containing directory must be owned by the user who eventually runs rm.
23 chown $NON_ROOT_USERNAME .
24
25 mkdir a || framework_failure=1
26 chmod 1777 a || framework_failure=1
27 touch a/b || framework_failure=1
28
29 if test $framework_failure = 1; then
30   echo "$0: failure in testing framework" 1>&2
31   (exit 1); exit 1
32 fi
33
34 fail=0
35
36 # Try to ensure that $NON_ROOT_USERNAME can access
37 # the required version of rm.
38 rm_version=`setuidgid $NON_ROOT_USERNAME rm --version|sed -n '1s/.* //p'`
39 case $rm_version in
40   $PACKAGE_VERSION) ;;
41   *) echo "$0: cannot access required version ($PACKAGE_VERSION) of rm" 1>&2
42      fail=1 ;;
43 esac
44 setuidgid $NON_ROOT_USERNAME rm -rf a 2> out-t && fail=1
45
46 # On some systems, we get `Not owner'.  Convert it.
47 # On other systems (HPUX), we get `Permission denied'.  Convert it, too.
48 onp='Operation not permitted'
49 sed "s/Not owner/$onp/;s/Permission denied/$onp/" out-t > out
50
51 cat <<\EOF > exp
52 rm: cannot remove `a/b': Operation not permitted
53 EOF
54
55 cmp out exp || fail=1
56 test $fail = 1 && diff out exp 2> /dev/null
57
58 (exit $fail); exit $fail