xref: /openbsd/regress/sys/ffs/tests/unlink/11.t (revision d89ec533)
1#!/bin/sh
2# $FreeBSD: src/tools/regression/fstest/tests/unlink/11.t,v 1.1 2007/01/17 01:42:12 pjd Exp $
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
6n0=`namegen`
7n1=`namegen`
8n2=`namegen`
9
10expect 0 mkdir ${n2} 0755
11cdir=`pwd`
12cd ${n2}
13
14expect 0 mkdir ${n0} 0755
15expect 0 chown ${n0} 65534 65534
16expect 0 chmod ${n0} 01777
17
18# User owns both: the sticky directory and the file to be removed.
19expect 0 -u 65534 -g 65534 create ${n0}/${n1} 0644
20expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
21# User owns the file to be removed, but doesn't own the sticky directory.
22expect 0 -u 65533 -g 65533 create ${n0}/${n1} 0644
23expect 0 -u 65533 -g 65533 unlink ${n0}/${n1}
24# User owns the sticky directory, but doesn't own the file to be removed.
25expect 0 -u 65533 -g 65533 create ${n0}/${n1} 0644
26expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
27# User doesn't own the sticky directory nor the file to be removed.
28expect 0 -u 65534 -g 65534 create ${n0}/${n1} 0644
29expect "EACCES|EPERM" -u 65533 -g 65533 unlink ${n0}/${n1}
30expect 0 unlink ${n0}/${n1}
31
32# User owns both: the sticky directory and the fifo to be removed.
33expect 0 -u 65534 -g 65534 mkfifo ${n0}/${n1} 0644
34expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
35# User owns the fifo to be removed, but doesn't own the sticky directory.
36expect 0 -u 65533 -g 65533 mkfifo ${n0}/${n1} 0644
37expect 0 -u 65533 -g 65533 unlink ${n0}/${n1}
38# User owns the sticky directory, but doesn't own the fifo to be removed.
39expect 0 -u 65533 -g 65533 mkfifo ${n0}/${n1} 0644
40expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
41# User doesn't own the sticky directory nor the fifo to be removed.
42expect 0 -u 65534 -g 65534 mkfifo ${n0}/${n1} 0644
43expect "EACCES|EPERM" -u 65533 -g 65533 unlink ${n0}/${n1}
44expect 0 unlink ${n0}/${n1}
45
46# User owns both: the sticky directory and the symlink to be removed.
47expect 0 -u 65534 -g 65534 symlink test ${n0}/${n1}
48expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
49# User owns the symlink to be removed, but doesn't own the sticky directory.
50expect 0 -u 65533 -g 65533 symlink test ${n0}/${n1}
51expect 0 -u 65533 -g 65533 unlink ${n0}/${n1}
52# User owns the sticky directory, but doesn't own the symlink to be removed.
53expect 0 -u 65533 -g 65533 symlink test ${n0}/${n1}
54expect 0 -u 65534 -g 65534 unlink ${n0}/${n1}
55# User doesn't own the sticky directory nor the symlink to be removed.
56expect 0 -u 65534 -g 65534 symlink test ${n0}/${n1}
57expect "EACCES|EPERM" -u 65533 -g 65533 unlink ${n0}/${n1}
58expect 0 unlink ${n0}/${n1}
59
60expect 0 rmdir ${n0}
61
62cd ${cdir}
63expect 0 rmdir ${n2}
64