09.t revision 166065
1#!/bin/sh
2# $FreeBSD: head/tools/regression/fstest/tests/rename/09.t 166065 2007-01-17 01:42:12Z 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
9echo "1..56"
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
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
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
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
51expect 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}
68
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}
72expect 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}
89
90expect 0 rmdir ${n1}
91expect 0 rmdir ${n0}
92
93cd ${cdir}
94expect 0 rmdir ${n4}
95