]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - tools/regression/pjdfstest/tests/rename/09.t
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / tools / regression / pjdfstest / tests / rename / 09.t
1 #!/bin/sh
2 # $FreeBSD$
3
4 desc="rename returns EACCES or EPERM if the directory containing 'from' is marked sticky, and neither the containing directory nor 'from' are owned by the effective user ID"
5
6 dir=`dirname $0`
7 . ${dir}/../misc.sh
8
9 echo "1..2353"
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 chmod ${n0} 01777
23 expect 0 chown ${n0} 65534 65534
24
25 expect 0 mkdir ${n1} 0755
26 expect 0 chown ${n1} 65534 65534
27
28 for type in regular fifo block char socket symlink; do
29         # User owns both: the source sticky directory and the source file.
30         expect 0 chown ${n0} 65534 65534
31         create_file ${type} ${n0}/${n2} 65534 65534
32         inode=`${fstest} lstat ${n0}/${n2} inode`
33
34         for type in none regular fifo block char socket symlink; do
35                 create_file ${type} ${n1}/${n3} 65534 65534
36                 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
37                 expect ENOENT lstat ${n0}/${n2} inode
38                 expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
39                 expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2}
40                 expect ${inode} lstat ${n0}/${n2} inode
41                 expect ENOENT lstat ${n1}/${n3} inode
42         done
43
44         expect 0 unlink ${n0}/${n2}
45
46         # User owns the source sticky directory, but doesn't own the source file.
47         for id in 0 65533; do
48                 expect 0 chown ${n0} 65534 65534
49                 create_file ${type} ${n0}/${n2} ${id} ${id}
50                 inode=`${fstest} lstat ${n0}/${n2} inode`
51
52                 for type in none regular fifo block char socket symlink; do
53                         create_file ${type} ${n1}/${n3} 65534 65534
54                         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
55                         expect ENOENT lstat ${n0}/${n2} inode
56                         expect ${inode},${id},${id} lstat ${n1}/${n3} inode,uid,gid
57                         expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2}
58                         expect ${inode} lstat ${n0}/${n2} inode
59                         expect ENOENT lstat ${n1}/${n3} inode
60                 done
61
62                 expect 0 unlink ${n0}/${n2}
63         done
64
65         # User owns the source file, but doesn't own the source sticky directory.
66         for id in 0 65533; do
67                 expect 0 chown ${n0} ${id} ${id}
68                 create_file ${type} ${n0}/${n2} 65534 65534
69                 inode=`${fstest} lstat ${n0}/${n2} inode`
70
71                 for type in none regular fifo block char socket symlink; do
72                         create_file ${type} ${n1}/${n3} 65534 65534
73                         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
74                         expect ENOENT lstat ${n0}/${n2} inode
75                         expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
76                         expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2}
77                         expect ${inode} lstat ${n0}/${n2} inode
78                         expect ENOENT lstat ${n1}/${n3} inode
79                 done
80
81                 expect 0 unlink ${n0}/${n2}
82         done
83
84         # User doesn't own the source sticky directory nor the source file.
85         for id in 0 65533; do
86                 expect 0 chown ${n0} ${id} ${id}
87                 create_file ${type} ${n0}/${n2} ${id} ${id}
88                 inode=`${fstest} lstat ${n0}/${n2} inode`
89
90                 for type in none regular fifo block char socket symlink; do
91                         create_file ${type} ${n1}/${n3} 65534 65534
92                         expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
93                         expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
94                         if [ "${type}" != "none" ]; then
95                                 expect 65534,65534 lstat ${n1}/${n3} uid,gid
96                                 expect 0 unlink ${n1}/${n3}
97                         fi
98                 done
99
100                 expect 0 unlink ${n0}/${n2}
101         done
102 done
103
104 # User owns both: the source sticky directory and the source directory.
105 expect 0 chown ${n0} 65534 65534
106 create_file dir ${n0}/${n2} 65534 65534
107 inode=`${fstest} lstat ${n0}/${n2} inode`
108
109 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
110 expect ENOENT lstat ${n0}/${n2} type
111 expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
112 expect 0 rename ${n1}/${n3} ${n0}/${n2}
113
114 expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
115 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
116 expect ENOENT lstat ${n0}/${n2} type
117 expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
118 expect 0 rmdir ${n1}/${n3}
119
120 # User owns the source sticky directory, but doesn't own the source directory.
121 # This fails when changing parent directory, because this will modify
122 # source directory inode (the .. link in it), but we can still rename it
123 # without changing its parent directory.
124 for id in 0 65533; do
125         expect 0 chown ${n0} 65534 65534
126         create_file dir ${n0}/${n2} ${id} ${id}
127         inode=`${fstest} lstat ${n0}/${n2} inode`
128
129         expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
130         expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
131         expect ENOENT lstat ${n1}/${n3} type
132
133         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n0}/${n3}
134         expect ENOENT lstat ${n0}/${n2} type
135         expect ${inode},${id},${id} lstat ${n0}/${n3} inode,uid,gid
136         expect 0 rename ${n0}/${n3} ${n0}/${n2}
137
138         expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
139         expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
140         expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
141         expect dir,${id},${id} lstat ${n0}/${n2} type,uid,gid
142         expect 0 rmdir ${n1}/${n3}
143
144         expect 0 -u 65534 -g 65534 mkdir ${n0}/${n3} 0755
145         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n0}/${n3}
146         expect ENOENT lstat ${n0}/${n2} type
147         expect ${inode},${id},${id} lstat ${n0}/${n3} inode,uid,gid
148         expect 0 rmdir ${n0}/${n3}
149 done
150
151 # User owns the source directory, but doesn't own the source sticky directory.
152 for id in 0 65533; do
153         expect 0 chown ${n0} ${id} ${id}
154         create_file dir ${n0}/${n2} 65534 65534
155         inode=`${fstest} lstat ${n0}/${n2} inode`
156
157         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
158         expect ENOENT lstat ${n0}/${n2} type
159         expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
160         expect 0 rename ${n1}/${n3} ${n0}/${n2}
161
162         expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
163         expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
164         expect ENOENT lstat ${n0}/${n2} type
165         expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
166         expect 0 rmdir ${n1}/${n3}
167 done
168
169 # User doesn't own the source sticky directory nor the source directory.
170 for id in 0 65533; do
171         expect 0 chown ${n0} ${id} ${id}
172         create_file dir ${n0}/${n2} ${id} ${id}
173         inode=`${fstest} lstat ${n0}/${n2} inode`
174
175         expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
176         expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
177         expect ENOENT lstat ${n1}/${n3} type
178
179         expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
180         expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
181         expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
182         expect dir,65534,65534 lstat ${n1}/${n3} type,uid,gid
183         expect 0 rmdir ${n0}/${n2}
184         expect 0 rmdir ${n1}/${n3}
185 done
186
187 expect 0 rmdir ${n1}
188 expect 0 rmdir ${n0}
189
190 cd ${cdir}
191 expect 0 rmdir ${n4}