17836SJohn.Forte@Sun.COM#!/bin/sh
27836SJohn.Forte@Sun.COM# $FreeBSD: head/tools/regression/pjdfstest/tests/unlink/11.t 211352 2010-08-15 21:24:17Z pjd $
37836SJohn.Forte@Sun.COM
47836SJohn.Forte@Sun.COMdesc="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"
57836SJohn.Forte@Sun.COM
67836SJohn.Forte@Sun.COMdir=`dirname $0`
77836SJohn.Forte@Sun.COM. ${dir}/../misc.sh
87836SJohn.Forte@Sun.COM
97836SJohn.Forte@Sun.COMecho "1..270"
107836SJohn.Forte@Sun.COM
117836SJohn.Forte@Sun.COMn0=`namegen`
127836SJohn.Forte@Sun.COMn1=`namegen`
137836SJohn.Forte@Sun.COMn2=`namegen`
147836SJohn.Forte@Sun.COM
157836SJohn.Forte@Sun.COMexpect 0 mkdir ${n2} 0755
167836SJohn.Forte@Sun.COMcdir=`pwd`
177836SJohn.Forte@Sun.COMcd ${n2}
187836SJohn.Forte@Sun.COM
197836SJohn.Forte@Sun.COMexpect 0 mkdir ${n0} 0755
207836SJohn.Forte@Sun.COMexpect 0 chmod ${n0} 01777
217836SJohn.Forte@Sun.COMexpect 0 chown ${n0} 65534 65534
227836SJohn.Forte@Sun.COM
237836SJohn.Forte@Sun.COMfor type in regular fifo block char socket symlink; do
247836SJohn.Forte@Sun.COM	# User owns both: the sticky directory and the file.
257836SJohn.Forte@Sun.COM	expect 0 chown ${n0} 65534 65534
267836SJohn.Forte@Sun.COM	create_file ${type} ${n0}/${n1} 65534 65534
277836SJohn.Forte@Sun.COM	expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid
287836SJohn.Forte@Sun.COM	expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
297836SJohn.Forte@Sun.COM	expect ENOENT lstat ${n0}/${n1} type
307836SJohn.Forte@Sun.COM
317836SJohn.Forte@Sun.COM	# User owns the sticky directory, but doesn't own the file.
327836SJohn.Forte@Sun.COM	for id in 0 65533; do
337836SJohn.Forte@Sun.COM		expect 0 chown ${n0} 65534 65534
347836SJohn.Forte@Sun.COM		create_file ${type} ${n0}/${n1} ${id} ${id}
357836SJohn.Forte@Sun.COM		expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
367836SJohn.Forte@Sun.COM		expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
377836SJohn.Forte@Sun.COM		expect ENOENT lstat ${n0}/${n1} type
387836SJohn.Forte@Sun.COM	done
397836SJohn.Forte@Sun.COM
407836SJohn.Forte@Sun.COM	# User owns the file, but doesn't own the sticky directory.
417836SJohn.Forte@Sun.COM	for id in 0 65533; do
427836SJohn.Forte@Sun.COM		expect 0 chown ${n0} ${id} ${id}
437836SJohn.Forte@Sun.COM		create_file ${type} ${n0}/${n1} 65534 65534
447836SJohn.Forte@Sun.COM		expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid
457836SJohn.Forte@Sun.COM		expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
467836SJohn.Forte@Sun.COM		expect ENOENT lstat ${n0}/${n1} type
477836SJohn.Forte@Sun.COM	done
487836SJohn.Forte@Sun.COM
497836SJohn.Forte@Sun.COM	# User doesn't own the sticky directory nor the file.
507836SJohn.Forte@Sun.COM	for id in 0 65533; do
517836SJohn.Forte@Sun.COM		expect 0 chown ${n0} ${id} ${id}
527836SJohn.Forte@Sun.COM		create_file ${type} ${n0}/${n1} ${id} ${id}
537836SJohn.Forte@Sun.COM		expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
547836SJohn.Forte@Sun.COM		expect "EACCES|EPERM" -u 65534 -g 65534 unlink ${n0}/${n1}
557836SJohn.Forte@Sun.COM		expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid
567836SJohn.Forte@Sun.COM		expect 0 unlink ${n0}/${n1}
577836SJohn.Forte@Sun.COM	done
587836SJohn.Forte@Sun.COMdone
597836SJohn.Forte@Sun.COM
607836SJohn.Forte@Sun.COMexpect 0 rmdir ${n0}
617836SJohn.Forte@Sun.COM
627836SJohn.Forte@Sun.COMcd ${cdir}
637836SJohn.Forte@Sun.COMexpect 0 rmdir ${n2}
647836SJohn.Forte@Sun.COM