2 # vim: filetype=sh noexpandtab ts=8 sw=8
3 # $FreeBSD: head/tools/regression/pjdfstest/tests/rename/10.t 211352 2010-08-15 21:24:17Z pjd $
5 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"
18 expect 0 mkdir ${n4} 0755
22 expect 0 mkdir ${n0} 0755
23 expect 0 chown ${n0} 65534 65534
25 expect 0 mkdir ${n1} 0755
26 expect 0 chmod ${n1} 01777
28 for type in regular fifo block char socket symlink; do
29 # User owns both: the sticky directory and the destination file.
30 expect 0 chown ${n1} 65534 65534
31 create_file ${type} ${n0}/${n2} 65534 65534
32 inode=`${fstest} lstat ${n0}/${n2} inode`
34 for type in 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} lstat ${n1}/${n3} inode
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 sticky directory, but doesn't own the destination file.
48 expect 0 chown ${n1} 65534 65534
49 create_file ${type} ${n0}/${n2} 65534 65534
50 inode=`${fstest} lstat ${n0}/${n2} inode`
52 for type in regular fifo block char socket symlink; do
53 create_file ${type} ${n1}/${n3} ${id} ${id}
54 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
55 expect ENOENT lstat ${n0}/${n2} inode
56 expect ${inode} lstat ${n1}/${n3} inode
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 destination file, but doesn't own the sticky directory.
67 expect 0 chown ${n1} ${id} ${id}
68 create_file ${type} ${n0}/${n2} 65534 65534
69 inode=`${fstest} lstat ${n0}/${n2} inode`
71 for type in 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} lstat ${n1}/${n3} inode
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 sticky directory nor the destination file.
86 expect 0 chown ${n1} ${id} ${id}
87 create_file ${type} ${n0}/${n2} 65534 65534
88 inode=`${fstest} lstat ${n0}/${n2} inode`
90 for type in regular fifo block char socket symlink; do
91 create_file ${type} ${n1}/${n3} ${id} ${id}
92 expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
93 expect ${inode} lstat ${n0}/${n2} inode
94 expect ${id},${id} lstat ${n1}/${n3} uid,gid
95 expect 0 unlink ${n1}/${n3}
98 expect 0 unlink ${n0}/${n2}
102 # User owns both: the sticky directory and the destination directory.
103 expect 0 chown ${n1} 65534 65534
104 expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755
105 inode=`${fstest} lstat ${n0}/${n2} inode`
107 expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
108 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
109 expect ENOENT lstat ${n0}/${n2} type
110 expect ${inode} lstat ${n1}/${n3} inode
111 expect 0 rmdir ${n1}/${n3}
113 # User owns the sticky directory, but doesn't own the destination directory.
114 for id in 0 65533; do
115 expect 0 chown ${n1} 65534 65534
116 expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755
117 inode=`${fstest} lstat ${n0}/${n2} inode`
119 expect 0 -u ${id} -g ${id} mkdir ${n1}/${n3} 0755
120 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
121 expect ENOENT lstat ${n0}/${n2} type
122 expect ${inode} lstat ${n1}/${n3} inode
123 expect 0 rmdir ${n1}/${n3}
126 # User owns the destination directory, but doesn't own the sticky directory.
127 for id in 0 65533; do
128 expect 0 chown ${n1} ${id} ${id}
129 expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755
130 inode=`${fstest} lstat ${n0}/${n2} inode`
132 expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
133 expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
134 expect ENOENT lstat ${n0}/${n2} type
135 expect ${inode} lstat ${n1}/${n3} inode
136 expect 0 rmdir ${n1}/${n3}
139 # User doesn't own the sticky directory nor the destination directory.
140 for id in 0 65533; do
141 expect 0 chown ${n1} ${id} ${id}
142 expect 0 -u 65534 -g 65534 mkdir ${n0}/${n2} 0755
143 inode=`${fstest} lstat ${n0}/${n2} inode`
145 expect 0 -u ${id} -g ${id} mkdir ${n1}/${n3} 0755
146 expect "EACCES|EPERM" -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
147 expect ${inode} lstat ${n0}/${n2} inode
148 expect ${id},${id} lstat ${n1}/${n3} uid,gid
149 expect 0 rmdir ${n0}/${n2}
150 expect 0 rmdir ${n1}/${n3}