]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - tools/regression/pjdfstest/tests/rename/10.t
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / tools / regression / pjdfstest / tests / rename / 10.t
1 #!/bin/sh
2 # $FreeBSD$
3
4 desc="rename returns EACCES or EPERM if the file pointed at by the 'to' argument exists, the directory containing 'to' is marked sticky, and neither the containing directory nor 'to' are owned by the effective user ID"
5
6 dir=`dirname $0`
7 . ${dir}/../misc.sh
8
9 echo "1..2099"
10
11 n0=`namegen`
12 n1=`namegen`
13 n2=`namegen`
14 n3=`namegen`
15 n4=`namegen`
16
17 expect 0 mkdir ${n4} 0755
18 cdir=`pwd`
19 cd ${n4}
20
21 expect 0 mkdir ${n0} 0755
22 expect 0 chown ${n0} 65534 65534
23
24 expect 0 mkdir ${n1} 0755
25 expect 0 chmod ${n1} 01777
26
27 for type in regular fifo block char socket symlink; do
28         # User owns both: the sticky directory and the destination file.
29         expect 0 chown ${n1} 65534 65534
30         create_file ${type} ${n0}/${n2} 65534 65534
31         inode=`${fstest} lstat ${n0}/${n2} inode`
32
33         for type in regular fifo block char socket symlink; do
34                 create_file ${type} ${n1}/${n3} 65534 65534
35                 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
36                 expect ENOENT lstat ${n0}/${n2} inode
37                 expect ${inode} lstat ${n1}/${n3} inode
38                 expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2}
39                 expect ${inode} lstat ${n0}/${n2} inode
40                 expect ENOENT lstat ${n1}/${n3} inode
41         done
42
43         expect 0 unlink ${n0}/${n2}
44
45         # User owns the sticky directory, but doesn't own the destination file.
46         for id in 0 65533; do
47                 expect 0 chown ${n1} 65534 65534
48                 create_file ${type} ${n0}/${n2} 65534 65534
49                 inode=`${fstest} lstat ${n0}/${n2} inode`
50
51                 for type in regular fifo block char socket symlink; do
52                         create_file ${type} ${n1}/${n3} ${id} ${id}
53                         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
54                         expect ENOENT lstat ${n0}/${n2} inode
55                         expect ${inode} lstat ${n1}/${n3} inode
56                         expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2}
57                         expect ${inode} lstat ${n0}/${n2} inode
58                         expect ENOENT lstat ${n1}/${n3} inode
59                 done
60
61                 expect 0 unlink ${n0}/${n2}
62         done
63
64         # User owns the destination file, but doesn't own the sticky directory.
65         for id in 0 65533; do
66                 expect 0 chown ${n1} ${id} ${id}
67                 create_file ${type} ${n0}/${n2} 65534 65534
68                 inode=`${fstest} lstat ${n0}/${n2} inode`
69
70                 for type in regular fifo block char socket symlink; do
71                         create_file ${type} ${n1}/${n3} 65534 65534
72                         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
73                         expect ENOENT lstat ${n0}/${n2} inode
74                         expect ${inode} lstat ${n1}/${n3} inode
75                         expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2}
76                         expect ${inode} lstat ${n0}/${n2} inode
77                         expect ENOENT lstat ${n1}/${n3} inode
78                 done
79
80                 expect 0 unlink ${n0}/${n2}
81         done
82
83         # User doesn't own the sticky directory nor the destination file.
84         for id in 0 65533; do
85                 expect 0 chown ${n1} ${id} ${id}
86                 create_file ${type} ${n0}/${n2} 65534 65534
87                 inode=`${fstest} lstat ${n0}/${n2} inode`
88
89                 for type in regular fifo block char socket symlink; do
90                         create_file ${type} ${n1}/${n3} ${id} ${id}
91                         expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
92                         expect ${inode} lstat ${n0}/${n2} inode
93                         expect ${id},${id} lstat ${n1}/${n3} uid,gid
94                         expect 0 unlink ${n1}/${n3}
95                 done
96
97                 expect 0 unlink ${n0}/${n2}
98         done
99 done
100
101 # User owns both: the sticky directory and the destination directory.
102 expect 0 chown ${n1} 65534 65534
103 expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755
104 inode=`${fstest} lstat ${n0}/${n2} inode`
105
106 expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
107 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
108 expect ENOENT lstat ${n0}/${n2} type
109 expect ${inode} lstat ${n1}/${n3} inode
110 expect 0 rmdir ${n1}/${n3}
111
112 # User owns the sticky directory, but doesn't own the destination directory.
113 for id in 0 65533; do
114         expect 0 chown ${n1} 65534 65534
115         expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755
116         inode=`${fstest} lstat ${n0}/${n2} inode`
117
118         expect 0 -u ${id} -g ${id} mkdir ${n1}/${n3} 0755
119         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
120         expect ENOENT lstat ${n0}/${n2} type
121         expect ${inode} lstat ${n1}/${n3} inode
122         expect 0 rmdir ${n1}/${n3}
123 done
124
125 # User owns the destination directory, but doesn't own the sticky directory.
126 for id in 0 65533; do
127         expect 0 chown ${n1} ${id} ${id}
128         expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755
129         inode=`${fstest} lstat ${n0}/${n2} inode`
130
131         expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
132         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
133         expect ENOENT lstat ${n0}/${n2} type
134         expect ${inode} lstat ${n1}/${n3} inode
135         expect 0 rmdir ${n1}/${n3}
136 done
137
138 # User doesn't own the sticky directory nor the destination directory.
139 for id in 0 65533; do
140         expect 0 chown ${n1} ${id} ${id}
141         expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755
142         inode=`${fstest} lstat ${n0}/${n2} inode`
143
144         expect 0 -u ${id} -g ${id} mkdir ${n1}/${n3} 0755
145         expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
146         expect ${inode} lstat ${n0}/${n2} inode
147         expect ${id},${id} lstat ${n1}/${n3} uid,gid
148         expect 0 rmdir ${n0}/${n2}
149         expect 0 rmdir ${n1}/${n3}
150 done
151
152 expect 0 rmdir ${n1}
153 expect 0 rmdir ${n0}
154
155 cd ${cdir}
156 expect 0 rmdir ${n4}