2 # $FreeBSD: head/tools/regression/pjdfstest/tests/rename/09.t 211352 2010-08-15 21:24:17Z pjd $
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"
17 expect 0 mkdir ${n4} 0755
21 expect 0 mkdir ${n0} 0755
22 expect 0 chmod ${n0} 01777
23 expect 0 chown ${n0} 65534 65534
25 expect 0 mkdir ${n1} 0755
26 expect 0 chown ${n1} 65534 65534
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`
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
44 expect 0 unlink ${n0}/${n2}
46 # User owns the source sticky directory, but doesn't own the source file.
48 expect 0 chown ${n0} 65534 65534
49 create_file ${type} ${n0}/${n2} ${id} ${id}
50 inode=`${fstest} lstat ${n0}/${n2} inode`
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
62 expect 0 unlink ${n0}/${n2}
65 # User owns the source file, but doesn't own the source sticky directory.
67 expect 0 chown ${n0} ${id} ${id}
68 create_file ${type} ${n0}/${n2} 65534 65534
69 inode=`${fstest} lstat ${n0}/${n2} inode`
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
81 expect 0 unlink ${n0}/${n2}
84 # User doesn't own the source sticky directory nor the source file.
86 expect 0 chown ${n0} ${id} ${id}
87 create_file ${type} ${n0}/${n2} ${id} ${id}
88 inode=`${fstest} lstat ${n0}/${n2} inode`
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}
100 expect 0 unlink ${n0}/${n2}
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`
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}
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}
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`
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
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}
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}
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}
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`
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}
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}
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`
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
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}