1271294Sngie#!/bin/sh
2271294Sngie# $FreeBSD: head/tools/regression/pjdfstest/tests/rmdir/11.t 211352 2010-08-15 21:24:17Z pjd $
3271294Sngie
4271294Sngiedesc="rmdir returns EACCES or EPERM if the directory containing the directory to be removed is marked sticky, and neither the containing directory nor the directory to be removed are owned by the effective user ID"
5271294Sngie
6271294Sngiedir=`dirname $0`
7271294Sngie. ${dir}/../misc.sh
8271294Sngie
9271294Sngieecho "1..47"
10271294Sngie
11271294Sngien0=`namegen`
12271294Sngien1=`namegen`
13271294Sngien2=`namegen`
14271294Sngie
15271294Sngieexpect 0 mkdir ${n2} 0755
16271294Sngiecdir=`pwd`
17271294Sngiecd ${n2}
18271294Sngie
19271294Sngieexpect 0 mkdir ${n0} 0755
20271294Sngieexpect 0 chown ${n0} 65534 65534
21271294Sngieexpect 0 chmod ${n0} 01777
22271294Sngie
23271294Sngie# User owns both: the sticky directory and the directory to be removed.
24271294Sngieexpect 0 -u 65534 -g 65534 mkdir ${n0}/${n1} 0755
25271294Sngieexpect dir,65534,65534 lstat ${n0}/${n1} type,uid,gid
26271294Sngieexpect 0 -u 65534 -g 65534 rmdir ${n0}/${n1}
27271294Sngieexpect ENOENT lstat ${n0}/${n1} type
28271294Sngie# User owns the directory to be removed, but doesn't own the sticky directory.
29271294Sngiefor id in 0 65533; do
30271294Sngie	expect 0 chown ${n0} ${id} ${id}
31271294Sngie	create_file dir ${n0}/${n1} 65534 65534
32271294Sngie	expect dir,65534,65534 lstat ${n0}/${n1} type,uid,gid
33271294Sngie	expect 0 -u 65534 -g 65534 rmdir ${n0}/${n1}
34271294Sngie	expect ENOENT lstat ${n0}/${n1} type
35271294Sngiedone
36271294Sngie# User owns the sticky directory, but doesn't own the directory to be removed.
37271294Sngieexpect 0 chown ${n0} 65534 65534
38271294Sngiefor id in 0 65533; do
39271294Sngie	create_file dir ${n0}/${n1} ${id} ${id}
40271294Sngie	expect dir,${id},${id} lstat ${n0}/${n1} type,uid,gid
41271294Sngie	expect 0 -u 65534 -g 65534 rmdir ${n0}/${n1}
42271294Sngie	expect ENOENT lstat ${n0}/${n1} type
43271294Sngiedone
44271294Sngie# User doesn't own the sticky directory nor the directory to be removed.
45271294Sngiefor id in 0 65533; do
46271294Sngie	expect 0 chown ${n0} ${id} ${id}
47271294Sngie	create_file dir ${n0}/${n1} ${id} ${id}
48271294Sngie	expect dir,${id},${id} lstat ${n0}/${n1} type,uid,gid
49271294Sngie	expect "EACCES|EPERM" -u 65534 -g 65534 rmdir ${n0}/${n1}
50271294Sngie	expect dir,${id},${id} lstat ${n0}/${n1} type,uid,gid
51271294Sngie	expect 0 rmdir ${n0}/${n1}
52271294Sngiedone
53271294Sngie
54271294Sngieexpect 0 rmdir ${n0}
55271294Sngie
56271294Sngiecd ${cdir}
57271294Sngieexpect 0 rmdir ${n2}
58