xref: /freebsd/contrib/pjdfstest/tests/open/06.t (revision 13ea0450a9c8742119d36f3bf8f47accdce46e54)
1#!/bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD: head/tools/regression/pjdfstest/tests/open/06.t 211352 2010-08-15 21:24:17Z pjd $
4
5desc="open returns EACCES when the required permissions (for reading and/or writing) are denied for the given flags"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10echo "1..144"
11
12n0=`namegen`
13n1=`namegen`
14
15expect 0 mkdir ${n0} 0755
16expect 0 chown ${n0} 65534 65534
17cdir=`pwd`
18cd ${n0}
19
20# Regular file.
21
22expect 0 -u 65534 -g 65534 create ${n1} 0644
23
24expect 0 -u 65534 -g 65534 chmod ${n1} 0600
25expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY,
26expect 0 -u 65534 -g 65534 open ${n1} O_WRONLY,
27expect 0 -u 65534 -g 65534 open ${n1} O_RDWR,
28expect 0 -u 65534 -g 65534 chmod ${n1} 0060
29expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY,
30expect 0 -u 65533 -g 65534 open ${n1} O_WRONLY,
31expect 0 -u 65533 -g 65534 open ${n1} O_RDWR,
32expect 0 -u 65534 -g 65534 chmod ${n1} 0006
33expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY,
34expect 0 -u 65533 -g 65533 open ${n1} O_WRONLY,
35expect 0 -u 65533 -g 65533 open ${n1} O_RDWR,
36
37expect 0 -u 65534 -g 65534 chmod ${n1} 0477
38expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY,
39expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY,
40expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR,
41expect 0 -u 65534 -g 65534 chmod ${n1} 0747
42expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY,
43expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY,
44expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR,
45expect 0 -u 65534 -g 65534 chmod ${n1} 0774
46expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY,
47expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY,
48expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR,
49
50expect 0 -u 65534 -g 65534 chmod ${n1} 0277
51expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY,
52expect 0 -u 65534 -g 65534 open ${n1} O_WRONLY,
53expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR,
54expect 0 -u 65534 -g 65534 chmod ${n1} 0727
55expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY,
56expect 0 -u 65533 -g 65534 open ${n1} O_WRONLY,
57expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR,
58expect 0 -u 65534 -g 65534 chmod ${n1} 0772
59expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY,
60expect 0 -u 65533 -g 65533 open ${n1} O_WRONLY,
61expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR,
62
63expect 0 -u 65534 -g 65534 chmod ${n1} 0177
64expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY,
65expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY,
66expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR,
67expect 0 -u 65534 -g 65534 chmod ${n1} 0717
68expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY,
69expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY,
70expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR,
71expect 0 -u 65534 -g 65534 chmod ${n1} 0771
72expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY,
73expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY,
74expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR,
75
76expect 0 -u 65534 -g 65534 chmod ${n1} 0077
77expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY,
78expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY,
79expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR,
80expect 0 -u 65534 -g 65534 chmod ${n1} 0707
81expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY,
82expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY,
83expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR,
84expect 0 -u 65534 -g 65534 chmod ${n1} 0770
85expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY,
86expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY,
87expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR,
88
89expect 0 -u 65534 -g 65534 unlink ${n1}
90
91# FIFO.
92
93expect 0 -u 65534 -g 65534 mkfifo ${n1} 0644
94
95expect 0 -u 65534 -g 65534 chmod ${n1} 0600
96expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY,O_NONBLOCK
97expect 0 -u 65534 -g 65534 open ${n1} O_RDWR,O_NONBLOCK
98expect 0 -u 65534 -g 65534 chmod ${n1} 0060
99expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY,O_NONBLOCK
100expect 0 -u 65533 -g 65534 open ${n1} O_RDWR,O_NONBLOCK
101expect 0 -u 65534 -g 65534 chmod ${n1} 0006
102expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY,O_NONBLOCK
103expect 0 -u 65533 -g 65533 open ${n1} O_RDWR,O_NONBLOCK
104
105expect 0 -u 65534 -g 65534 chmod ${n1} 0477
106expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY,O_NONBLOCK
107expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY
108expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR
109expect 0 -u 65534 -g 65534 chmod ${n1} 0747
110expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY,O_NONBLOCK
111expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY
112expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR
113expect 0 -u 65534 -g 65534 chmod ${n1} 0774
114expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY,O_NONBLOCK
115expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY
116expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR
117
118expect 0 -u 65534 -g 65534 chmod ${n1} 0177
119expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY
120expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY
121expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR
122expect 0 -u 65534 -g 65534 chmod ${n1} 0717
123expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY
124expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY
125expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR
126expect 0 -u 65534 -g 65534 chmod ${n1} 0771
127expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY
128expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY
129expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR
130
131expect 0 -u 65534 -g 65534 chmod ${n1} 0077
132expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY
133expect EACCES -u 65534 -g 65534 open ${n1} O_WRONLY
134expect EACCES -u 65534 -g 65534 open ${n1} O_RDWR
135expect 0 -u 65534 -g 65534 chmod ${n1} 0707
136expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY
137expect EACCES -u 65533 -g 65534 open ${n1} O_WRONLY
138expect EACCES -u 65533 -g 65534 open ${n1} O_RDWR
139expect 0 -u 65534 -g 65534 chmod ${n1} 0770
140expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY
141expect EACCES -u 65533 -g 65533 open ${n1} O_WRONLY
142expect EACCES -u 65533 -g 65533 open ${n1} O_RDWR
143
144expect 0 -u 65534 -g 65534 unlink ${n1}
145
146# Directory.
147
148expect 0 -u 65534 -g 65534 mkdir ${n1} 0755
149
150expect 0 -u 65534 -g 65534 chmod ${n1} 0600
151expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY
152expect 0 -u 65534 -g 65534 chmod ${n1} 0060
153expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY
154expect 0 -u 65534 -g 65534 chmod ${n1} 0006
155expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY
156
157expect 0 -u 65534 -g 65534 chmod ${n1} 0477
158expect 0 -u 65534 -g 65534 open ${n1} O_RDONLY
159expect 0 -u 65534 -g 65534 chmod ${n1} 0747
160expect 0 -u 65533 -g 65534 open ${n1} O_RDONLY
161expect 0 -u 65534 -g 65534 chmod ${n1} 0774
162expect 0 -u 65533 -g 65533 open ${n1} O_RDONLY
163
164expect 0 -u 65534 -g 65534 chmod ${n1} 0277
165expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY
166expect 0 -u 65534 -g 65534 chmod ${n1} 0727
167expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY
168expect 0 -u 65534 -g 65534 chmod ${n1} 0772
169expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY
170
171expect 0 -u 65534 -g 65534 chmod ${n1} 0177
172expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY
173expect 0 -u 65534 -g 65534 chmod ${n1} 0717
174expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY
175expect 0 -u 65534 -g 65534 chmod ${n1} 0771
176expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY
177
178expect 0 -u 65534 -g 65534 chmod ${n1} 0077
179expect EACCES -u 65534 -g 65534 open ${n1} O_RDONLY
180expect 0 -u 65534 -g 65534 chmod ${n1} 0707
181expect EACCES -u 65533 -g 65534 open ${n1} O_RDONLY
182expect 0 -u 65534 -g 65534 chmod ${n1} 0770
183expect EACCES -u 65533 -g 65533 open ${n1} O_RDONLY
184
185expect 0 -u 65534 -g 65534 rmdir ${n1}
186
187cd ${cdir}
188expect 0 rmdir ${n0}
189