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