Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / cp / fail-perm
1 #!/bin/sh
2
3 # Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006 Free Software
4 # Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   cp --version
24 fi
25
26 . $srcdir/../lang-default
27 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
28
29 pwd=`pwd`
30 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
31 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
32 trap '(exit $?); exit' 1 2 13 15
33
34 framework_failure=0
35 mkdir -p $tmp || framework_failure=1
36 cd $tmp || framework_failure=1
37
38 mkdir D D/D || framework_failure=1
39 touch D/a || framework_failure=1
40 chmod 0 D/a || framework_failure=1
41 chmod u=rx,go=,-st D || framework_failure=1
42
43 if test $framework_failure = 1; then
44   echo 'failure in testing framework'
45   exit 1
46 fi
47
48 fail=0
49
50 # This is expected to exit non-zero, because it can't read D/a.
51 cp -pR D DD > /dev/null 2>&1 && fail=1
52
53 # Permissions on DD must be `dr-x------'
54
55 set X `ls -ld DD`
56 shift
57 test "$1" = dr-x------ || fail=1
58
59 chmod 0 D
60 ln -s D/D symlink
61 touch F
62 cat > exp <<\EOF
63 cp: accessing `symlink': Permission denied
64 EOF
65
66 cp F symlink 2> out && fail=1
67 # HPUX appears to fail with EACCES rather than EPERM.
68 # Transform their diagnostic
69 #   ...: The file access permissions do not allow the specified action.
70 # to the expected one:
71 sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
72 cmp out exp || { (diff -c out exp) 2> /dev/null; fail=1; }
73
74 cp --target-directory=symlink F 2> out && fail=1
75 sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out
76 cmp out exp || { (diff -c out exp) 2> /dev/null; fail=1; }
77
78 chmod 700 D
79
80 (exit $fail); exit $fail