2 # vim: filetype=sh noexpandtab ts=8 sw=8
3 # $FreeBSD: head/tools/regression/pjdfstest/tests/rename/09.t 211352 2010-08-15 21:24:17Z pjd $
5 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"
18 expect 0 mkdir ${n4} 0755
22 expect 0 mkdir ${n0} 0755
23 expect 0 chmod ${n0} 01777
24 expect 0 chown ${n0} 65534 65534
26 expect 0 mkdir ${n1} 0755
27 expect 0 chown ${n1} 65534 65534
29 for type in regular fifo block char socket symlink; do
30 # User owns both: the source sticky directory and the source file.
31 expect 0 chown ${n0} 65534 65534
32 create_file ${type} ${n0}/${n2} 65534 65534
33 inode=`${fstest} lstat ${n0}/${n2} inode`
35 for type in none regular fifo block char socket symlink; do
36 create_file ${type} ${n1}/${n3} 65534 65534
37 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
38 expect ENOENT lstat ${n0}/${n2} inode
39 expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
40 expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2}
41 expect ${inode} lstat ${n0}/${n2} inode
42 expect ENOENT lstat ${n1}/${n3} inode
45 expect 0 unlink ${n0}/${n2}
47 # User owns the source sticky directory, but doesn't own the source file.
49 expect 0 chown ${n0} 65534 65534
50 create_file ${type} ${n0}/${n2} ${id} ${id}
51 inode=`${fstest} lstat ${n0}/${n2} inode`
53 for type in none regular fifo block char socket symlink; do
54 create_file ${type} ${n1}/${n3} 65534 65534
55 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
56 expect ENOENT lstat ${n0}/${n2} inode
57 expect ${inode},${id},${id} lstat ${n1}/${n3} inode,uid,gid
58 expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2}
59 expect ${inode} lstat ${n0}/${n2} inode
60 expect ENOENT lstat ${n1}/${n3} inode
63 expect 0 unlink ${n0}/${n2}
66 # User owns the source file, but doesn't own the source sticky directory.
68 expect 0 chown ${n0} ${id} ${id}
69 create_file ${type} ${n0}/${n2} 65534 65534
70 inode=`${fstest} lstat ${n0}/${n2} inode`
72 for type in none regular fifo block char socket symlink; do
73 create_file ${type} ${n1}/${n3} 65534 65534
74 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
75 expect ENOENT lstat ${n0}/${n2} inode
76 expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
77 expect 0 -u 65534 -g 65534 rename ${n1}/${n3} ${n0}/${n2}
78 expect ${inode} lstat ${n0}/${n2} inode
79 expect ENOENT lstat ${n1}/${n3} inode
82 expect 0 unlink ${n0}/${n2}
85 # User doesn't own the source sticky directory nor the source file.
87 expect 0 chown ${n0} ${id} ${id}
88 create_file ${type} ${n0}/${n2} ${id} ${id}
89 inode=`${fstest} lstat ${n0}/${n2} inode`
91 for type in none regular fifo block char socket symlink; do
92 create_file ${type} ${n1}/${n3} 65534 65534
93 expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
94 expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
95 if [ "${type}" != "none" ]; then
96 expect 65534,65534 lstat ${n1}/${n3} uid,gid
97 expect 0 unlink ${n1}/${n3}
101 expect 0 unlink ${n0}/${n2}
105 # User owns both: the source sticky directory and the source directory.
106 expect 0 chown ${n0} 65534 65534
107 create_file dir ${n0}/${n2} 65534 65534
108 inode=`${fstest} lstat ${n0}/${n2} inode`
110 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
111 expect ENOENT lstat ${n0}/${n2} type
112 expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
113 expect 0 rename ${n1}/${n3} ${n0}/${n2}
115 expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
116 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
117 expect ENOENT lstat ${n0}/${n2} type
118 expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
119 expect 0 rmdir ${n1}/${n3}
121 # User owns the source sticky directory, but doesn't own the source directory.
122 # This fails when changing parent directory, because this will modify
123 # source directory inode (the .. link in it), but we can still rename it
124 # without changing its parent directory.
125 for id in 0 65533; do
126 expect 0 chown ${n0} 65534 65534
127 create_file dir ${n0}/${n2} ${id} ${id}
128 inode=`${fstest} lstat ${n0}/${n2} inode`
130 expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
131 expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
132 expect ENOENT lstat ${n1}/${n3} type
134 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n0}/${n3}
135 expect ENOENT lstat ${n0}/${n2} type
136 expect ${inode},${id},${id} lstat ${n0}/${n3} inode,uid,gid
137 expect 0 rename ${n0}/${n3} ${n0}/${n2}
139 expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
140 expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
141 expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
142 expect dir,${id},${id} lstat ${n0}/${n2} type,uid,gid
143 expect 0 rmdir ${n1}/${n3}
145 expect 0 -u 65534 -g 65534 mkdir ${n0}/${n3} 0755
146 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n0}/${n3}
147 expect ENOENT lstat ${n0}/${n2} type
148 expect ${inode},${id},${id} lstat ${n0}/${n3} inode,uid,gid
149 expect 0 rmdir ${n0}/${n3}
152 # User owns the source directory, but doesn't own the source sticky directory.
153 for id in 0 65533; do
154 expect 0 chown ${n0} ${id} ${id}
155 create_file dir ${n0}/${n2} 65534 65534
156 inode=`${fstest} lstat ${n0}/${n2} inode`
158 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
159 expect ENOENT lstat ${n0}/${n2} type
160 expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
161 expect 0 rename ${n1}/${n3} ${n0}/${n2}
163 expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
164 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
165 expect ENOENT lstat ${n0}/${n2} type
166 expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
167 expect 0 rmdir ${n1}/${n3}
170 # User doesn't own the source sticky directory nor the source directory.
171 for id in 0 65533; do
172 expect 0 chown ${n0} ${id} ${id}
173 create_file dir ${n0}/${n2} ${id} ${id}
174 inode=`${fstest} lstat ${n0}/${n2} inode`
176 expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
177 expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
178 expect ENOENT lstat ${n1}/${n3} type
180 expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
181 expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
182 expect ${inode},${id},${id} lstat ${n0}/${n2} inode,uid,gid
183 expect dir,65534,65534 lstat ${n1}/${n3} type,uid,gid
184 expect 0 rmdir ${n0}/${n2}
185 expect 0 rmdir ${n1}/${n3}