1/*-
2 * Copyright (c) 2006 nCircle Network Security, Inc.
3 * Copyright (c) 2007 Robert N. M. Watson
4 * All rights reserved.
5 *
6 * This software was developed by Robert N. M. Watson for the TrustedBSD
7 * Project under contract to nCircle Network Security, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY,
22 * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#define	UID_ROOT	0
32#define	UID_OWNER	100
33#define	UID_OTHER	200
34#define	UID_THIRD	300
35
36#define	GID_WHEEL	0
37#define	GID_OWNER	100
38#define	GID_OTHER	200
39
40#define	KENV_VAR_NAME	"test"
41#define	KENV_VAR_VALUE	"test"
42#define	KENV_VAR_LEN	sizeof(KENV_VAR_VALUE)
43
44/*
45 * Library routines used by many tests.
46 */
47void	setup_dir(const char *test, char *dpathp, uid_t uid, gid_t gid,
48	    mode_t mode);
49void	setup_file(const char *test, char *fpathp, uid_t uid, gid_t gid,
50	    mode_t mode);
51void	expect(const char *test, int error, int expected_error,
52	    int expected_errno);
53
54/*
55 * Definition for a particular test, both used to manage the test list in
56 * main.c, and passed to tests so they can be aware of which specific test is
57 * running if particular method implementations are shared across tests.
58 */
59struct test {
60	const char	*t_name;
61	int		(*t_setup_func)(int asroot, int injail,
62			    struct test *test);
63	void		(*t_test_func)(int asroot, int injail,
64			    struct test *test);
65	void		(*t_cleanup_func)(int asroot, int injail,
66			    struct test *test);
67};
68
69/*
70 * Prototypes for test functions that will be hooked up to the test vector in
71 * main.c.  It's possible to imagine more dynamic (convenient?) ways to do
72 * this.
73 */
74int	priv_acct_setup(int, int, struct test *);
75void	priv_acct_enable(int, int, struct test *);
76void	priv_acct_disable(int, int, struct test *);
77void	priv_acct_rotate(int, int, struct test *);
78void	priv_acct_noopdisable(int, int, struct test *);
79void	priv_acct_cleanup(int, int, struct test *);
80
81int	priv_adjtime_setup(int, int, struct test *);
82void	priv_adjtime_set(int, int, struct test *);
83void	priv_adjtime_cleanup(int, int, struct test *);
84
85int	priv_audit_submit_setup(int, int, struct test *);
86void	priv_audit_submit(int, int, struct test *);
87void	priv_audit_submit_cleanup(int, int, struct test *);
88
89int	priv_audit_control_setup(int, int, struct test *);
90void	priv_audit_control(int, int, struct test *);
91void	priv_audit_control_cleanup(int, int, struct test *);
92
93int	priv_audit_getaudit_setup(int, int, struct test *);
94void	priv_audit_getaudit(int, int, struct test *);
95void	priv_audit_getaudit_addr(int, int, struct test *);
96void	priv_audit_getaudit_cleanup(int, int, struct test *);
97
98int	priv_audit_setaudit_setup(int, int, struct test *);
99void	priv_audit_setaudit(int, int, struct test *);
100void	priv_audit_setaudit_addr(int, int, struct test *);
101void	priv_audit_setaudit_cleanup(int, int, struct test *);
102
103int	priv_clock_settime_setup(int, int, struct test *);
104void	priv_clock_settime(int, int, struct test *);
105void	priv_clock_settime_cleanup(int, int, struct test *);
106
107int	priv_cred_setup(int, int, struct test *);
108void	priv_cred_setuid(int, int, struct test *);
109void	priv_cred_seteuid(int, int, struct test *);
110void	priv_cred_setgid(int, int, struct test *);
111void	priv_cred_setegid(int, int, struct test *);
112void	priv_cred_setgroups(int, int, struct test *);
113void	priv_cred_setreuid(int, int, struct test *);
114void	priv_cred_setregid(int, int, struct test *);
115void	priv_cred_setresuid(int, int, struct test *);
116void	priv_cred_setresgid(int, int, struct test *);
117void	priv_cred_cleanup(int, int, struct test *);
118
119int	priv_io_setup(int, int, struct test *);
120void	priv_io(int, int, struct test *);
121void	priv_io_cleanup(int, int, struct test *);
122
123int	priv_kenv_set_setup(int, int, struct test *);
124void	priv_kenv_set(int, int, struct test *);
125void	priv_kenv_set_cleanup(int, int, struct test *);
126
127int	priv_kenv_unset_setup(int, int, struct test *);
128void	priv_kenv_unset(int, int, struct test *);
129void	priv_kenv_unset_cleanup(int, int, struct test *);
130
131int	priv_msgbuf_privonly_setup(int, int, struct test *);
132void	priv_msgbuf_privonly(int, int, struct test *);
133
134int	priv_msgbuf_unprivok_setup(int, int, struct test *);
135void	priv_msgbuf_unprivok(int, int, struct test *);
136
137void	priv_msgbuf_cleanup(int, int, struct test *);
138
139void	priv_netinet_ipsec_pfkey(int, int, struct test *);
140int	priv_netinet_ipsec_policy4_bypass_setup(int, int, struct test *);
141void	priv_netinet_ipsec_policy4_bypass(int, int, struct test *);
142int	priv_netinet_ipsec_policy6_bypass_setup(int, int, struct test *);
143void	priv_netinet_ipsec_policy6_bypass(int, int, struct test *);
144void	priv_netinet_ipsec_policy_bypass_cleanup(int, int, struct test *);
145int	priv_netinet_ipsec_policy4_entrust_setup(int, int, struct test *);
146void	priv_netinet_ipsec_policy4_entrust(int, int, struct test *);
147int	priv_netinet_ipsec_policy6_entrust_setup(int, int, struct test *);
148void	priv_netinet_ipsec_policy6_entrust(int, int, struct test *);
149void	priv_netinet_ipsec_policy_entrust_cleanup(int, int, struct test *);
150
151int	priv_netinet_raw_setup(int, int, struct test *);
152void	priv_netinet_raw(int, int, struct test *);
153void	priv_netinet_raw_cleanup(int, int, struct test *);
154
155int	priv_proc_setlogin_setup(int, int, struct test *);
156void	priv_proc_setlogin(int, int, struct test *);
157void	priv_proc_setlogin_cleanup(int, int, struct test *);
158
159int	priv_proc_setrlimit_setup(int, int, struct test *);
160void	priv_proc_setrlimit_raisemax(int, int, struct test *);
161void	priv_proc_setrlimit_raisecur(int, int, struct test *);
162void	priv_proc_setrlimit_raisecur_nopriv(int, int, struct test *);
163void	priv_proc_setrlimit_cleanup(int, int, struct test *);
164
165int	priv_sched_rtprio_setup(int, int, struct test *);
166void	priv_sched_rtprio_curproc_normal(int, int, struct test *);
167void	priv_sched_rtprio_curproc_idle(int, int, struct test *);
168void	priv_sched_rtprio_curproc_realtime(int, int, struct test *);
169
170void	priv_sched_rtprio_myproc_normal(int, int, struct test *);
171void	priv_sched_rtprio_myproc_idle(int, int, struct test *);
172void	priv_sched_rtprio_myproc_realtime(int, int, struct test *);
173
174void	priv_sched_rtprio_aproc_normal(int, int, struct test *);
175void	priv_sched_rtprio_aproc_idle(int, int, struct test *);
176void	priv_sched_rtprio_aproc_realtime(int, int, struct test *);
177void	priv_sched_rtprio_cleanup(int, int, struct test *);
178
179int	priv_sched_setpriority_setup(int, int, struct test *);
180void	priv_sched_setpriority_curproc(int, int, struct test *);
181void	priv_sched_setpriority_myproc(int, int, struct test *);
182void	priv_sched_setpriority_aproc(int, int, struct test *);
183void	priv_sched_setpriority_cleanup(int, int, struct test *);
184
185int	priv_settimeofday_setup(int, int, struct test *);
186void	priv_settimeofday(int, int, struct test *);
187void	priv_settimeofday_cleanup(int, int, struct test *);
188
189int	priv_sysctl_write_setup(int, int, struct test *);
190void	priv_sysctl_write(int, int, struct test *);
191void	priv_sysctl_writejail(int, int, struct test *);
192void	priv_sysctl_write_cleanup(int, int, struct test *);
193
194int	priv_vfs_chflags_froot_setup(int, int, struct test *);
195void	priv_vfs_chflags_froot_uflags(int, int, struct test *);
196void	priv_vfs_chflags_froot_sflags(int, int, struct test *);
197
198int	priv_vfs_chflags_fowner_setup(int, int, struct test *);
199void	priv_vfs_chflags_fowner_uflags(int, int, struct test *);
200void	priv_vfs_chflags_fowner_sflags(int, int, struct test *);
201
202int	priv_vfs_chflags_fother_setup(int, int, struct test *);
203void	priv_vfs_chflags_fother_uflags(int, int, struct test *);
204void	priv_vfs_chflags_fother_sflags(int, int, struct test *);
205
206void	priv_vfs_chflags_cleanup(int, int, struct test *);
207
208int	priv_vfs_chmod_froot_setup(int, int, struct test *);
209void	priv_vfs_chmod_froot(int, int, struct test *);
210
211int	priv_vfs_chmod_fowner_setup(int, int, struct test *);
212void	priv_vfs_chmod_fowner(int, int, struct test *);
213
214int	priv_vfs_chmod_fother_setup(int, int, struct test *);
215void	priv_vfs_chmod_fother(int, int, struct test *);
216
217void	priv_vfs_chmod_cleanup(int, int, struct test *);
218
219int	priv_vfs_chown_uid_setup(int, int, struct test *);
220void	priv_vfs_chown_uid(int, int, struct test *);
221
222int	priv_vfs_chown_mygid_setup(int, int, struct test *);
223void	priv_vfs_chown_mygid(int, int, struct test *);
224
225int	priv_vfs_chown_othergid_setup(int, int, struct test *);
226void	priv_vfs_chown_othergid(int, int, struct test *);
227
228void	priv_vfs_chown_cleanup(int, int, struct test *);
229
230int	priv_vfs_chroot_setup(int, int, struct test *);
231void	priv_vfs_chroot(int, int, struct test *);
232void	priv_vfs_chroot_cleanup(int, int, struct test *);
233
234int	priv_vfs_clearsugid_setup(int, int, struct test *);
235void	priv_vfs_clearsugid_chgrp(int, int, struct test *);
236void	priv_vfs_clearsugid_extattr(int, int, struct test *);
237void	priv_vfs_clearsugid_write(int, int, struct test *);
238void	priv_vfs_clearsugid_cleanup(int, int, struct test *);
239
240int	priv_vfs_extattr_system_setup(int, int, struct test *);
241void	priv_vfs_extattr_system(int, int, struct test *);
242void	priv_vfs_extattr_system_cleanup(int, int, struct test *);
243
244int	priv_vfs_fhopen_setup(int, int, struct test *);
245void	priv_vfs_fhopen(int, int, struct test *);
246void	priv_vfs_fhopen_cleanup(int, int, struct test *);
247
248int	priv_vfs_fhstat_setup(int, int, struct test *);
249void	priv_vfs_fhstat(int, int, struct test *);
250void	priv_vfs_fhstat_cleanup(int, int, struct test *);
251
252int	priv_vfs_fhstatfs_setup(int, int, struct test *);
253void	priv_vfs_fhstatfs(int, int, struct test *);
254void	priv_vfs_fhstatfs_cleanup(int, int, struct test *);
255
256int	priv_vfs_generation_setup(int, int, struct test *);
257void	priv_vfs_generation(int, int, struct test *);
258void	priv_vfs_generation_cleanup(int, int, struct test *);
259
260int	priv_vfs_getfh_setup(int, int, struct test *);
261void	priv_vfs_getfh(int, int, struct test *);
262void	priv_vfs_getfh_cleanup(int, int, struct test *);
263
264int	priv_vfs_readwrite_fowner_setup(int, int, struct test *);
265void	priv_vfs_readwrite_fowner(int, int, struct test *);
266
267int	priv_vfs_readwrite_fgroup_setup(int, int, struct test *);
268void	priv_vfs_readwrite_fgroup(int, int, struct test *);
269
270int	priv_vfs_readwrite_fother_setup(int, int, struct test *);
271void	priv_vfs_readwrite_fother(int, int, struct test *);
272
273void	priv_vfs_readwrite_cleanup(int, int, struct test *);
274
275int	priv_vfs_setgid_fowner_setup(int, int, struct test *);
276void	priv_vfs_setgid_fowner(int, int, struct test *);
277
278int	priv_vfs_setgid_fother_setup(int, int, struct test *);
279void	priv_vfs_setgid_fother(int, int, struct test *);
280
281void	priv_vfs_setgid_cleanup(int, int, struct test *);
282
283int	priv_vfs_stickyfile_dir_fowner_setup(int, int, struct test *);
284
285void	priv_vfs_stickyfile_dir_fowner(int, int, struct test *);
286int	priv_vfs_stickyfile_dir_fother_setup(int, int, struct test *);
287void	priv_vfs_stickyfile_dir_fother(int, int, struct test *);
288
289void	priv_vfs_stickyfile_dir_cleanup(int, int, struct test *);
290
291int	priv_vfs_stickyfile_file_fowner_setup(int, int, struct test *);
292void	priv_vfs_stickyfile_file_fowner(int, int, struct test *);
293
294int	priv_vfs_stickyfile_file_fother_setup(int, int, struct test *);
295void	priv_vfs_stickyfile_file_fother(int, int, struct test *);
296
297void	priv_vfs_stickyfile_file_cleanup(int, int, struct test *);
298
299int	priv_vfs_utimes_froot_setup(int, int, struct test *);
300void	priv_vfs_utimes_froot(int, int, struct test *);
301void	priv_vfs_utimes_froot_null(int, int, struct test *);
302
303int	priv_vfs_utimes_fowner_setup(int, int, struct test *);
304void	priv_vfs_utimes_fowner(int, int, struct test *);
305void	priv_vfs_utimes_fowner_null(int, int, struct test *);
306
307int	priv_vfs_utimes_fother_setup(int, int, struct test *);
308void	priv_vfs_utimes_fother(int, int, struct test *);
309void	priv_vfs_utimes_fother_null(int, int, struct test *);
310
311void	priv_vfs_utimes_cleanup(int, int, struct test *);
312
313int	priv_vm_madv_protect_setup(int, int, struct test *);
314void	priv_vm_madv_protect(int, int, struct test *);
315void	priv_vm_madv_protect_cleanup(int, int, struct test *);
316
317int	priv_vm_mlock_setup(int, int, struct test *);
318void	priv_vm_mlock(int, int, struct test *);
319void	priv_vm_mlock_cleanup(int, int, struct test *);
320
321int	priv_vm_munlock_setup(int, int, struct test *);
322void	priv_vm_munlock(int, int, struct test *);
323void	priv_vm_munlock_cleanup(int, int, struct test *);
324