411173a7cad064b583d8ffbe45eec7aeb38aa78c
[platform/upstream/coreutils.git] / tests / cp / fail-perm
1 #!/bin/sh
2
3 if test "$VERBOSE" = yes; then
4   set -x
5   cp --version
6 fi
7
8 . $srcdir/../lang-default
9 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
10
11 pwd=`pwd`
12 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
13 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
14 trap '(exit $?); exit' 1 2 13 15
15
16 framework_failure=0
17 mkdir -p $tmp || framework_failure=1
18 cd $tmp || framework_failure=1
19
20 mkdir D D/D || framework_failure=1
21 touch D/a || framework_failure=1
22 chmod 0 D/a || framework_failure=1
23 chmod u=rx,go=,-st D || framework_failure=1
24
25 if test $framework_failure = 1; then
26   echo 'failure in testing framework'
27   exit 1
28 fi
29
30 fail=0
31
32 # This is expected to exit non-zero, because it can't read D/a.
33 cp -pR D DD > /dev/null 2>&1 && fail=1
34
35 # Permissions on DD must be `dr-x------'
36
37 set X `ls -ld DD`
38 shift
39 test "$1" = dr-x------ || fail=1
40
41 chmod 0 D
42 ln -s D/D symlink
43 touch F
44 cat > exp <<\EOF
45 cp: accessing `symlink': Permission denied
46 EOF
47
48 cp F symlink 2> out && fail=1
49 # HPUX appears to fail with EACCES rather than EPERM.
50 # Transform their diagnostic
51 #   ...: The file access permissions do not allow the specified action.
52 # to the expected one:
53 sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
54 cmp out exp || { (diff -c out exp) 2> /dev/null; fail=1; }
55
56 cp --target-directory=symlink F 2> out && fail=1
57 sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
58 cmp out exp || { (diff -c out exp) 2> /dev/null; fail=1; }
59
60 chmod 700 D
61
62 (exit $fail); exit $fail