]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - tools/regression/pjdfstest/tests/unlink/11.t
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / tools / regression / pjdfstest / tests / unlink / 11.t
1 #!/bin/sh
2 # $FreeBSD$
3
4 desc="unlink returns EACCES or EPERM if the directory containing the file is marked sticky, and neither the containing directory nor the file to be removed are owned by the effective user ID"
5
6 dir=`dirname $0`
7 . ${dir}/../misc.sh
8
9 echo "1..270"
10
11 n0=`namegen`
12 n1=`namegen`
13 n2=`namegen`
14
15 expect 0 mkdir ${n2} 0755
16 cdir=`pwd`
17 cd ${n2}
18
19 expect 0 mkdir ${n0} 0755
20 expect 0 chmod ${n0} 01777
21 expect 0 chown ${n0} 65534 65534
22
23 for type in regular fifo block char socket symlink; do
24         # User owns both: the sticky directory and the file.
25         expect 0 chown ${n0} 65534 65534
26         create_file ${type} ${n0}/${n1} 65534 65534
27         expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid
28         expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
29         expect ENOENT lstat ${n0}/${n1} type
30
31         # User owns the sticky directory, but doesn't own the file.
32         for id in 0 65533; do
33                 expect 0 chown ${n0} 65534 65534
34                 create_file ${type} ${n0}/${n1} ${id} ${id}
35                 expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
36                 expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
37                 expect ENOENT lstat ${n0}/${n1} type
38         done
39
40         # User owns the file, but doesn't own the sticky directory.
41         for id in 0 65533; do
42                 expect 0 chown ${n0} ${id} ${id}
43                 create_file ${type} ${n0}/${n1} 65534 65534
44                 expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid
45                 expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
46                 expect ENOENT lstat ${n0}/${n1} type
47         done
48
49         # User doesn't own the sticky directory nor the file.
50         for id in 0 65533; do
51                 expect 0 chown ${n0} ${id} ${id}
52                 create_file ${type} ${n0}/${n1} ${id} ${id}
53                 expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
54                 expect "EACCES|EPERM" -u 65534 -g 65534 unlink ${n0}/${n1}
55                 expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
56                 expect 0 unlink ${n0}/${n1}
57         done
58 done
59
60 expect 0 rmdir ${n0}
61
62 cd ${cdir}
63 expect 0 rmdir ${n2}