1#!/bin/sh
2# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/11.t 211352 2010-08-15 21:24:17Z pjd $
3
4desc="unlink returns EACCES or EPERM if the directory containing the file is marked sticky, and neither the containing directory nor the file to be removed are owned by the effective user ID"
5
6dir=`dirname $0`
7. ${dir}/../misc.sh
8
9echo "1..270"
10
11n0=`namegen`
12n1=`namegen`
13n2=`namegen`
14
15expect 0 mkdir ${n2} 0755
16cdir=`pwd`
17cd ${n2}
18
19expect 0 mkdir ${n0} 0755
20expect 0 chmod ${n0} 01777
21expect 0 chown ${n0} 65534 65534
22
23for type in regular fifo block char socket symlink; do
24	# User owns both: the sticky directory and the file.
25	expect 0 chown ${n0} 65534 65534
26	create_file ${type} ${n0}/${n1} 65534 65534
27	expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid
28	expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
29	expect ENOENT lstat ${n0}/${n1} type
30
31	# User owns the sticky directory, but doesn't own the file.
32	for id in 0 65533; do
33		expect 0 chown ${n0} 65534 65534
34		create_file ${type} ${n0}/${n1} ${id} ${id}
35		expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
36		expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
37		expect ENOENT lstat ${n0}/${n1} type
38	done
39
40	# User owns the file, but doesn't own the sticky directory.
41	for id in 0 65533; do
42		expect 0 chown ${n0} ${id} ${id}
43		create_file ${type} ${n0}/${n1} 65534 65534
44		expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid
45		expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
46		expect ENOENT lstat ${n0}/${n1} type
47	done
48
49	# User doesn't own the sticky directory nor the file.
50	for id in 0 65533; do
51		expect 0 chown ${n0} ${id} ${id}
52		create_file ${type} ${n0}/${n1} ${id} ${id}
53		expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
54		expect "EACCES|EPERM" -u 65534 -g 65534 unlink ${n0}/${n1}
55		expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
56		expect 0 unlink ${n0}/${n1}
57	done
58done
59
60expect 0 rmdir ${n0}
61
62cd ${cdir}
63expect 0 rmdir ${n2}
64