xref: /freebsd/tools/regression/priv/priv_audit_control.c (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1 /*-
2  * Copyright (c) 2007 Robert M. M. Watson
3  * All rights reserved.
4  *
5  * This software was developed by Robert N. M. Watson for the TrustedBSD
6  * Project.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY,
21  * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * Confirm that privilege is required to issue an audit control command via
32  * auditon().  We do a simple policy retrieve.
33  *
34  * XXXRW: It would be a good idea to also test auditctl(), which also tests
35  * PRIV_AUDIT_CONTROL.
36  */
37 
38 #include <sys/types.h>
39 
40 #include <bsm/audit.h>
41 
42 #include <err.h>
43 #include <errno.h>
44 #include <stdio.h>
45 
46 #include "main.h"
47 
48 int
49 priv_audit_control_setup(int asroot, int injail, struct test *test)
50 {
51 
52 	/*
53 	 * XXXRW: It would be nice if we checked for audit being configured
54 	 * here.
55 	 */
56 	return (0);
57 }
58 
59 void
60 priv_audit_control(int asroot, int injail, struct test *test)
61 {
62 	long policy;
63 	int error;
64 
65 	error = auditon(A_GETPOLICY, &policy, sizeof(policy));
66 	if (asroot && injail)
67 		expect("priv_audit_control(asroot, injail)", error, -1,
68 		    ENOSYS);
69 	if (asroot && !injail)
70 		expect("priv_audit_control(asroot, !injail)", error, 0, 0);
71 	if (!asroot && injail)
72 		expect("priv_audit_control(!asroot, injail)", error, -1,
73 		    ENOSYS);
74 	if (!asroot && !injail)
75 		expect("priv_audit_control(!asroot, !injail)", error, -1,
76 		    EPERM);
77 }
78 
79 void
80 priv_audit_control_cleanup(int asroot, int injail, struct test *test)
81 {
82 
83 }
84