Deleted Added
full compact
09.t (166065) 09.t (211180)
1#!/bin/sh
1#!/bin/sh
2# $FreeBSD: head/tools/regression/fstest/tests/rename/09.t 166065 2007-01-17 01:42:12Z pjd $
2# $FreeBSD: head/tools/regression/fstest/tests/rename/09.t 211180 2010-08-11 16:34:44Z pjd $
3
4desc="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
6dir=`dirname $0`
7. ${dir}/../misc.sh
8
3
4desc="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
6dir=`dirname $0`
7. ${dir}/../misc.sh
8
9echo "1..56"
9echo "1..2353"
10
11n0=`namegen`
12n1=`namegen`
13n2=`namegen`
14n3=`namegen`
15n4=`namegen`
16
17expect 0 mkdir ${n4} 0755
18cdir=`pwd`
19cd ${n4}
20
21expect 0 mkdir ${n0} 0755
10
11n0=`namegen`
12n1=`namegen`
13n2=`namegen`
14n3=`namegen`
15n4=`namegen`
16
17expect 0 mkdir ${n4} 0755
18cdir=`pwd`
19cd ${n4}
20
21expect 0 mkdir ${n0} 0755
22expect 0 chown ${n0} 65534 65534
23expect 0 chmod ${n0} 01777
22expect 0 chmod ${n0} 01777
23expect 0 chown ${n0} 65534 65534
24
25expect 0 mkdir ${n1} 0755
24
25expect 0 mkdir ${n1} 0755
26
27# User owns both: the sticky directory and the file to be renamed.
28expect 0 chown ${n1} 65534 65534
26expect 0 chown ${n1} 65534 65534
29expect 0 -u 65534 -g 65534 create ${n0}/${n2} 0644
30expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
31expect 0 unlink ${n1}/${n3}
32# User owns the file to be renamed, but doesn't own the sticky directory.
33expect 0 chown ${n1} 65533 65533
34expect 0 -u 65533 -g 65533 create ${n0}/${n2} 0644
35expect 0 -u 65533 -g 65533 rename ${n0}/${n2} ${n1}/${n3}
36expect 0 unlink ${n1}/${n3}
37# User owns the sticky directory, but doesn't own the file to be renamed.
38expect 0 chown ${n1} 65534 65534
39expect 0 -u 65533 -g 65533 create ${n0}/${n2} 0644
40expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
41expect 0 unlink ${n1}/${n3}
42# User doesn't own the sticky directory nor the file to be renamed.
43expect 0 chown ${n1} 65533 65533
44expect 0 -u 65534 -g 65534 create ${n0}/${n2} 0644
45expect "EACCES|EPERM" -u 65533 -g 65533 rename ${n0}/${n2} ${n1}/${n3}
46expect 0 unlink ${n0}/${n2}
47
27
48# User owns both: the sticky directory and the fifo to be renamed.
49expect 0 chown ${n1} 65534 65534
50expect 0 -u 65534 -g 65534 mkfifo ${n0}/${n2} 0644
28for 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
102done
103
104# User owns both: the source sticky directory and the source directory.
105expect 0 chown ${n0} 65534 65534
106create_file dir ${n0}/${n2} 65534 65534
107inode=`${fstest} lstat ${n0}/${n2} inode`
108
51expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
109expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
52expect 0 unlink ${n1}/${n3}
53# User owns the fifo to be renamed, but doesn't own the sticky directory.
54expect 0 chown ${n1} 65533 65533
55expect 0 -u 65533 -g 65533 mkfifo ${n0}/${n2} 0644
56expect 0 -u 65533 -g 65533 rename ${n0}/${n2} ${n1}/${n3}
57expect 0 unlink ${n1}/${n3}
58# User owns the sticky directory, but doesn't own the fifo to be renamed.
59expect 0 chown ${n1} 65534 65534
60expect 0 -u 65533 -g 65533 mkfifo ${n0}/${n2} 0644
61expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
62expect 0 unlink ${n1}/${n3}
63# User doesn't own the sticky directory nor the fifo to be renamed.
64expect 0 chown ${n1} 65533 65533
65expect 0 -u 65534 -g 65534 mkfifo ${n0}/${n2} 0644
66expect "EACCES|EPERM" -u 65533 -g 65533 rename ${n0}/${n2} ${n1}/${n3}
67expect 0 unlink ${n0}/${n2}
110expect ENOENT lstat ${n0}/${n2} type
111expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
112expect 0 rename ${n1}/${n3} ${n0}/${n2}
68
113
69# User owns both: the sticky directory and the symlink to be renamed.
70expect 0 chown ${n1} 65534 65534
71expect 0 -u 65534 -g 65534 symlink test ${n0}/${n2}
114expect 0 -u 65534 -g 65534 mkdir ${n1}/${n3} 0755
72expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
115expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
73expect 0 unlink ${n1}/${n3}
74# User owns the symlink to be renamed, but doesn't own the sticky directory.
75expect 0 chown ${n1} 65533 65533
76expect 0 -u 65533 -g 65533 symlink test ${n0}/${n2}
77expect 0 -u 65533 -g 65533 rename ${n0}/${n2} ${n1}/${n3}
78expect 0 unlink ${n1}/${n3}
79# User owns the sticky directory, but doesn't own the symlink to be renamed.
80expect 0 chown ${n1} 65534 65534
81expect 0 -u 65533 -g 65533 symlink test ${n0}/${n2}
82expect 0 -u 65534 -g 65534 rename ${n0}/${n2} ${n1}/${n3}
83expect 0 unlink ${n1}/${n3}
84# User doesn't own the sticky directory nor the symlink to be renamed.
85expect 0 chown ${n1} 65533 65533
86expect 0 -u 65534 -g 65534 symlink test ${n0}/${n2}
87expect "EACCES|EPERM" -u 65533 -g 65533 rename ${n0}/${n2} ${n1}/${n3}
88expect 0 unlink ${n0}/${n2}
116expect ENOENT lstat ${n0}/${n2} type
117expect ${inode},65534,65534 lstat ${n1}/${n3} inode,uid,gid
118expect 0 rmdir ${n1}/${n3}
89
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.
124for 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}
149done
150
151# User owns the source directory, but doesn't own the source sticky directory.
152for 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}
167done
168
169# User doesn't own the source sticky directory nor the source directory.
170for 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}
185done
186
90expect 0 rmdir ${n1}
91expect 0 rmdir ${n0}
92
93cd ${cdir}
94expect 0 rmdir ${n4}
187expect 0 rmdir ${n1}
188expect 0 rmdir ${n0}
189
190cd ${cdir}
191expect 0 rmdir ${n4}