1166065Spjd#!/bin/sh 2166065Spjd# $FreeBSD$ 3166065Spjd 4166065Spjddesc="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" 5166065Spjd 6166065Spjddir=`dirname $0` 7166065Spjd. ${dir}/../misc.sh 8166065Spjd 9211242Spjdecho "1..270" 10166065Spjd 11166065Spjdn0=`namegen` 12166065Spjdn1=`namegen` 13166065Spjdn2=`namegen` 14166065Spjd 15166065Spjdexpect 0 mkdir ${n2} 0755 16166065Spjdcdir=`pwd` 17166065Spjdcd ${n2} 18166065Spjd 19166065Spjdexpect 0 mkdir ${n0} 0755 20211242Spjdexpect 0 chmod ${n0} 01777 21166065Spjdexpect 0 chown ${n0} 65534 65534 22166065Spjd 23211242Spjdfor type in regular fifo block char socket symlink; do 24211242Spjd # User owns both: the sticky directory and the file. 25211242Spjd expect 0 chown ${n0} 65534 65534 26211242Spjd create_file ${type} ${n0}/${n1} 65534 65534 27211242Spjd expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid 28211242Spjd expect 0 -u 65534 -g 65534 unlink ${n0}/${n1} 29211242Spjd expect ENOENT lstat ${n0}/${n1} type 30166065Spjd 31211242Spjd # User owns the sticky directory, but doesn't own the file. 32211242Spjd for id in 0 65533; do 33211242Spjd expect 0 chown ${n0} 65534 65534 34211242Spjd create_file ${type} ${n0}/${n1} ${id} ${id} 35211242Spjd expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid 36211242Spjd expect 0 -u 65534 -g 65534 unlink ${n0}/${n1} 37211242Spjd expect ENOENT lstat ${n0}/${n1} type 38211242Spjd done 39166065Spjd 40211242Spjd # User owns the file, but doesn't own the sticky directory. 41211242Spjd for id in 0 65533; do 42211242Spjd expect 0 chown ${n0} ${id} ${id} 43211242Spjd create_file ${type} ${n0}/${n1} 65534 65534 44211242Spjd expect ${type},65534,65534 lstat ${n0}/${n1} type,uid,gid 45211242Spjd expect 0 -u 65534 -g 65534 unlink ${n0}/${n1} 46211242Spjd expect ENOENT lstat ${n0}/${n1} type 47211242Spjd done 48211156Spjd 49211242Spjd # User doesn't own the sticky directory nor the file. 50211242Spjd for id in 0 65533; do 51211242Spjd expect 0 chown ${n0} ${id} ${id} 52211242Spjd create_file ${type} ${n0}/${n1} ${id} ${id} 53211242Spjd expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid 54211242Spjd expect "EACCES|EPERM" -u 65534 -g 65534 unlink ${n0}/${n1} 55211242Spjd expect ${type},${id},${id} lstat ${n0}/${n1} type,uid,gid 56211242Spjd expect 0 unlink ${n0}/${n1} 57211242Spjd done 58211242Spjddone 59211156Spjd 60166065Spjdexpect 0 rmdir ${n0} 61166065Spjd 62166065Spjdcd ${cdir} 63166065Spjdexpect 0 rmdir ${n2} 64