xref: /freebsd/tools/regression/priv/priv_audit_setaudit.c (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
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  * $FreeBSD$
30  */
31 
32 /*
33  * Confirm privilege is required to set process audit properties; we first
34  * query current properties so that the attempted operation is a no-op.
35  */
36 
37 #include <sys/types.h>
38 
39 #include <bsm/audit.h>
40 
41 #include <err.h>
42 #include <errno.h>
43 #include <stdio.h>
44 
45 #include "main.h"
46 
47 static auditinfo_t ai;
48 static auditinfo_addr_t aia;
49 
50 int
51 priv_audit_setaudit_setup(int asroot, int injail, struct test *test)
52 {
53 
54 	if (getaudit(&ai) < 0) {
55 		warn("priv_audit_setaudit_setup: getaudit");
56 		return (-1);
57 	}
58 	if (getaudit_addr(&aia, sizeof(aia)) < 0) {
59 		warn("priv_audit_setaudit_setup: getaudit_addr");
60 		return (-1);
61 	}
62 
63 	return (0);
64 }
65 
66 void
67 priv_audit_setaudit(int asroot, int injail, struct test *test)
68 {
69 	int error;
70 
71 	error = setaudit(&ai);
72 	if (asroot && injail)
73 		expect("priv_audit_setaudit(asroot, injail)", error, -1,
74 		    ENOSYS);
75 	if (asroot && !injail)
76 		expect("priv_audit_setaudit(asroot, !injail)", error, 0, 0);
77 	if (!asroot && injail)
78 		expect("priv_audit_setaudit(!asroot, injail)", error, -1,
79 		    ENOSYS);
80 	if (!asroot && !injail)
81 		expect("priv_audit_setaudit(!asroot, !injail)", error, -1,
82 		    EPERM);
83 }
84 
85 void
86 priv_audit_setaudit_addr(int asroot, int injail, struct test *test)
87 {
88 	int error;
89 
90 	error = setaudit_addr(&aia, sizeof(aia));
91 	if (asroot && injail)
92 		expect("priv_audit_setaudit_addr(asroot, injail)", error, -1,
93 		    ENOSYS);
94 	if (asroot && !injail)
95 		expect("priv_audit_setaudit_addr(asroot, !injail)", error, 0,
96 		    0);
97 	if (!asroot && injail)
98 		expect("priv_audit_setaudit_addr(!asroot, injail)", error,
99 		    -1, ENOSYS);
100 	if (!asroot && !injail)
101 		expect("priv_audit_setaudit_addr(!asroot, !injail)", error,
102 		    -1, EPERM);
103 }
104 
105 void
106 priv_audit_setaudit_cleanup(int asroot, int injail, struct test *test)
107 {
108 
109 }
110