xref: /freebsd/contrib/pjdfstest/tests/unlink/11.t (revision 3416500aef140042c64bc149cb1ec6620483bc44)
140a8ac8fSEnji Cooper#!/bin/sh
2*3416500aSEnji Cooper# vim: filetype=sh noexpandtab ts=8 sw=8
340a8ac8fSEnji Cooper# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/11.t 211352 2010-08-15 21:24:17Z pjd $
440a8ac8fSEnji Cooper
540a8ac8fSEnji Cooperdesc="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"
640a8ac8fSEnji Cooper
740a8ac8fSEnji Cooperdir=`dirname $0`
840a8ac8fSEnji Cooper. ${dir}/../misc.sh
940a8ac8fSEnji Cooper
1040a8ac8fSEnji Cooperecho "1..270"
1140a8ac8fSEnji Cooper
1240a8ac8fSEnji Coopern0=`namegen`
1340a8ac8fSEnji Coopern1=`namegen`
1440a8ac8fSEnji Coopern2=`namegen`
1540a8ac8fSEnji Cooper
1640a8ac8fSEnji Cooperexpect 0 mkdir ${n2} 0755
1740a8ac8fSEnji Coopercdir=`pwd`
1840a8ac8fSEnji Coopercd ${n2}
1940a8ac8fSEnji Cooper
2040a8ac8fSEnji Cooperexpect 0 mkdir ${n0} 0755
2140a8ac8fSEnji Cooperexpect 0 chmod ${n0} 01777
2240a8ac8fSEnji Cooperexpect 0 chown ${n0} 65534 65534
2340a8ac8fSEnji Cooper
2440a8ac8fSEnji Cooperfor type in regular fifo block char socket symlink; do
2540a8ac8fSEnji Cooper	# User owns both: the sticky directory and the file.
2640a8ac8fSEnji Cooper	expect 0 chown ${n0} 65534 65534
2740a8ac8fSEnji Cooper	create_file ${type} ${n0}/${n1} 65534 65534
2840a8ac8fSEnji Cooper	expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid
2940a8ac8fSEnji Cooper	expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
3040a8ac8fSEnji Cooper	expect ENOENT lstat ${n0}/${n1} type
3140a8ac8fSEnji Cooper
3240a8ac8fSEnji Cooper	# User owns the sticky directory, but doesn't own the file.
3340a8ac8fSEnji Cooper	for id in 0 65533; do
3440a8ac8fSEnji Cooper		expect 0 chown ${n0} 65534 65534
3540a8ac8fSEnji Cooper		create_file ${type} ${n0}/${n1} ${id} ${id}
3640a8ac8fSEnji Cooper		expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
3740a8ac8fSEnji Cooper		expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
3840a8ac8fSEnji Cooper		expect ENOENT lstat ${n0}/${n1} type
3940a8ac8fSEnji Cooper	done
4040a8ac8fSEnji Cooper
4140a8ac8fSEnji Cooper	# User owns the file, but doesn't own the sticky directory.
4240a8ac8fSEnji Cooper	for id in 0 65533; do
4340a8ac8fSEnji Cooper		expect 0 chown ${n0} ${id} ${id}
4440a8ac8fSEnji Cooper		create_file ${type} ${n0}/${n1} 65534 65534
4540a8ac8fSEnji Cooper		expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid
4640a8ac8fSEnji Cooper		expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
4740a8ac8fSEnji Cooper		expect ENOENT lstat ${n0}/${n1} type
4840a8ac8fSEnji Cooper	done
4940a8ac8fSEnji Cooper
5040a8ac8fSEnji Cooper	# User doesn't own the sticky directory nor the file.
5140a8ac8fSEnji Cooper	for id in 0 65533; do
5240a8ac8fSEnji Cooper		expect 0 chown ${n0} ${id} ${id}
5340a8ac8fSEnji Cooper		create_file ${type} ${n0}/${n1} ${id} ${id}
5440a8ac8fSEnji Cooper		expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
5540a8ac8fSEnji Cooper		expect "EACCES|EPERM" -u 65534 -g 65534 unlink ${n0}/${n1}
5640a8ac8fSEnji Cooper		expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
5740a8ac8fSEnji Cooper		expect 0 unlink ${n0}/${n1}
5840a8ac8fSEnji Cooper	done
5940a8ac8fSEnji Cooperdone
6040a8ac8fSEnji Cooper
6140a8ac8fSEnji Cooperexpect 0 rmdir ${n0}
6240a8ac8fSEnji Cooper
6340a8ac8fSEnji Coopercd ${cdir}
6440a8ac8fSEnji Cooperexpect 0 rmdir ${n2}
65