xref: /freebsd/contrib/openbsm/bin/auditd/audit_warn.c (revision ca0716f5714781ac39461f60647d795321921363)
1ca0716f5SRobert Watson /*
2ca0716f5SRobert Watson  * Copyright (c) 2005 Apple Computer, Inc.
3ca0716f5SRobert Watson  * All rights reserved.
4ca0716f5SRobert Watson  *
5ca0716f5SRobert Watson  * @APPLE_BSD_LICENSE_HEADER_START@
6ca0716f5SRobert Watson  *
7ca0716f5SRobert Watson  * Redistribution and use in source and binary forms, with or without
8ca0716f5SRobert Watson  * modification, are permitted provided that the following conditions
9ca0716f5SRobert Watson  * are met:
10ca0716f5SRobert Watson  *
11ca0716f5SRobert Watson  * 1.  Redistributions of source code must retain the above copyright
12ca0716f5SRobert Watson  *     notice, this list of conditions and the following disclaimer.
13ca0716f5SRobert Watson  * 2.  Redistributions in binary form must reproduce the above copyright
14ca0716f5SRobert Watson  *     notice, this list of conditions and the following disclaimer in the
15ca0716f5SRobert Watson  *     documentation and/or other materials provided with the distribution.
16ca0716f5SRobert Watson  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
17ca0716f5SRobert Watson  *     its contributors may be used to endorse or promote products derived
18ca0716f5SRobert Watson  *     from this software without specific prior written permission.
19ca0716f5SRobert Watson  *
20ca0716f5SRobert Watson  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21ca0716f5SRobert Watson  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22ca0716f5SRobert Watson  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23ca0716f5SRobert Watson  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24ca0716f5SRobert Watson  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25ca0716f5SRobert Watson  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26ca0716f5SRobert Watson  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27ca0716f5SRobert Watson  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28ca0716f5SRobert Watson  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29ca0716f5SRobert Watson  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30ca0716f5SRobert Watson  *
31ca0716f5SRobert Watson  * @APPLE_BSD_LICENSE_HEADER_END@
32ca0716f5SRobert Watson  *
33ca0716f5SRobert Watson  * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/audit_warn.c#5 $
34ca0716f5SRobert Watson  */
35ca0716f5SRobert Watson 
36ca0716f5SRobert Watson #include <sys/types.h>
37ca0716f5SRobert Watson #include <unistd.h>
38ca0716f5SRobert Watson #include <stdio.h>
39ca0716f5SRobert Watson 
40ca0716f5SRobert Watson #include "auditd.h"
41ca0716f5SRobert Watson 
42ca0716f5SRobert Watson /*
43ca0716f5SRobert Watson  * Write an audit-related error to the system log via syslog(3).
44ca0716f5SRobert Watson  */
45ca0716f5SRobert Watson static int
46ca0716f5SRobert Watson auditwarnlog(char *args[])
47ca0716f5SRobert Watson {
48ca0716f5SRobert Watson 	char *loc_args[9];
49ca0716f5SRobert Watson 	pid_t pid;
50ca0716f5SRobert Watson 	int i;
51ca0716f5SRobert Watson 
52ca0716f5SRobert Watson 	loc_args[0] = AUDITWARN_SCRIPT;
53ca0716f5SRobert Watson 	for (i = 0; args[i] != NULL && i < 8; i++)
54ca0716f5SRobert Watson 		loc_args[i+1] = args[i];
55ca0716f5SRobert Watson 	loc_args[i+1] = NULL;
56ca0716f5SRobert Watson 
57ca0716f5SRobert Watson 	pid = fork();
58ca0716f5SRobert Watson 	if (pid == -1)
59ca0716f5SRobert Watson 		return (-1);
60ca0716f5SRobert Watson 	if (pid == 0) {
61ca0716f5SRobert Watson 		/*
62ca0716f5SRobert Watson 		 * Child.
63ca0716f5SRobert Watson 		 */
64ca0716f5SRobert Watson 		execv(AUDITWARN_SCRIPT, loc_args);
65ca0716f5SRobert Watson 		syslog(LOG_ERR, "Could not exec %s (%m)\n",
66ca0716f5SRobert Watson 		    AUDITWARN_SCRIPT);
67ca0716f5SRobert Watson 		exit(1);
68ca0716f5SRobert Watson 	}
69ca0716f5SRobert Watson 	/*
70ca0716f5SRobert Watson 	 * Parent.
71ca0716f5SRobert Watson 	 */
72ca0716f5SRobert Watson 	return (0);
73ca0716f5SRobert Watson }
74ca0716f5SRobert Watson 
75ca0716f5SRobert Watson /*
76ca0716f5SRobert Watson  * Indicates that the hard limit for all filesystems has been exceeded count
77ca0716f5SRobert Watson  * times.
78ca0716f5SRobert Watson  */
79ca0716f5SRobert Watson int
80ca0716f5SRobert Watson audit_warn_allhard(int count)
81ca0716f5SRobert Watson {
82ca0716f5SRobert Watson 	char intstr[12];
83ca0716f5SRobert Watson 	char *args[3];
84ca0716f5SRobert Watson 
85ca0716f5SRobert Watson 	snprintf(intstr, 12, "%d", count);
86ca0716f5SRobert Watson 
87ca0716f5SRobert Watson 	args[0] = HARDLIM_ALL_WARN;
88ca0716f5SRobert Watson 	args[1] = intstr;
89ca0716f5SRobert Watson 	args[2] = NULL;
90ca0716f5SRobert Watson 
91ca0716f5SRobert Watson 	return (auditwarnlog(args));
92ca0716f5SRobert Watson }
93ca0716f5SRobert Watson 
94ca0716f5SRobert Watson /*
95ca0716f5SRobert Watson  * Indicates that the soft limit for all filesystems has been exceeded.
96ca0716f5SRobert Watson  */
97ca0716f5SRobert Watson int
98ca0716f5SRobert Watson audit_warn_allsoft(void)
99ca0716f5SRobert Watson {
100ca0716f5SRobert Watson 	char *args[2];
101ca0716f5SRobert Watson 
102ca0716f5SRobert Watson 	args[0] = SOFTLIM_ALL_WARN;
103ca0716f5SRobert Watson 	args[1] = NULL;
104ca0716f5SRobert Watson 
105ca0716f5SRobert Watson 	return (auditwarnlog(args));
106ca0716f5SRobert Watson }
107ca0716f5SRobert Watson 
108ca0716f5SRobert Watson /*
109ca0716f5SRobert Watson  * Indicates that someone other than the audit daemon turned off auditing.
110ca0716f5SRobert Watson  * XXX Its not clear at this point how this function will be invoked.
111ca0716f5SRobert Watson  *
112ca0716f5SRobert Watson  * XXXRW: This function is not used.
113ca0716f5SRobert Watson  */
114ca0716f5SRobert Watson int
115ca0716f5SRobert Watson audit_warn_auditoff(void)
116ca0716f5SRobert Watson {
117ca0716f5SRobert Watson 	char *args[2];
118ca0716f5SRobert Watson 
119ca0716f5SRobert Watson 	args[0] = AUDITOFF_WARN;
120ca0716f5SRobert Watson 	args[1] = NULL;
121ca0716f5SRobert Watson 
122ca0716f5SRobert Watson 	return (auditwarnlog(args));
123ca0716f5SRobert Watson }
124ca0716f5SRobert Watson 
125ca0716f5SRobert Watson /*
126ca0716f5SRobert Watson  * Indicates that the audit deammn is already running
127ca0716f5SRobert Watson  */
128ca0716f5SRobert Watson int
129ca0716f5SRobert Watson audit_warn_ebusy(void)
130ca0716f5SRobert Watson {
131ca0716f5SRobert Watson 	char *args[2];
132ca0716f5SRobert Watson 
133ca0716f5SRobert Watson 	args[0] = EBUSY_WARN;
134ca0716f5SRobert Watson 	args[1] = NULL;
135ca0716f5SRobert Watson 
136ca0716f5SRobert Watson 	return (auditwarnlog(args));
137ca0716f5SRobert Watson }
138ca0716f5SRobert Watson 
139ca0716f5SRobert Watson /*
140ca0716f5SRobert Watson  * Indicates that there is a problem getting the directory from
141ca0716f5SRobert Watson  * audit_control.
142ca0716f5SRobert Watson  *
143ca0716f5SRobert Watson  * XXX Note that we take the filename instead of a count as the argument here
144ca0716f5SRobert Watson  * (different from BSM).
145ca0716f5SRobert Watson  */
146ca0716f5SRobert Watson int
147ca0716f5SRobert Watson audit_warn_getacdir(char *filename)
148ca0716f5SRobert Watson {
149ca0716f5SRobert Watson 	char *args[3];
150ca0716f5SRobert Watson 
151ca0716f5SRobert Watson 	args[0] = GETACDIR_WARN;
152ca0716f5SRobert Watson 	args[1] = filename;
153ca0716f5SRobert Watson 	args[2] = NULL;
154ca0716f5SRobert Watson 
155ca0716f5SRobert Watson 	return (auditwarnlog(args));
156ca0716f5SRobert Watson }
157ca0716f5SRobert Watson 
158ca0716f5SRobert Watson /*
159ca0716f5SRobert Watson  * Indicates that the hard limit for this file has been exceeded.
160ca0716f5SRobert Watson  */
161ca0716f5SRobert Watson int
162ca0716f5SRobert Watson audit_warn_hard(char *filename)
163ca0716f5SRobert Watson {
164ca0716f5SRobert Watson 	char *args[3];
165ca0716f5SRobert Watson 
166ca0716f5SRobert Watson 	args[0] = HARDLIM_WARN;
167ca0716f5SRobert Watson 	args[1] = filename;
168ca0716f5SRobert Watson 	args[2] = NULL;
169ca0716f5SRobert Watson 
170ca0716f5SRobert Watson 	return (auditwarnlog(args));
171ca0716f5SRobert Watson }
172ca0716f5SRobert Watson 
173ca0716f5SRobert Watson /*
174ca0716f5SRobert Watson  * Indicates that auditing could not be started.
175ca0716f5SRobert Watson  */
176ca0716f5SRobert Watson int
177ca0716f5SRobert Watson audit_warn_nostart(void)
178ca0716f5SRobert Watson {
179ca0716f5SRobert Watson 	char *args[2];
180ca0716f5SRobert Watson 
181ca0716f5SRobert Watson 	args[0] = NOSTART_WARN;
182ca0716f5SRobert Watson 	args[1] = NULL;
183ca0716f5SRobert Watson 
184ca0716f5SRobert Watson 	return (auditwarnlog(args));
185ca0716f5SRobert Watson }
186ca0716f5SRobert Watson 
187ca0716f5SRobert Watson /*
188ca0716f5SRobert Watson  * Indicaes that an error occrred during the orderly shutdown of the audit
189ca0716f5SRobert Watson  * daemon.
190ca0716f5SRobert Watson  */
191ca0716f5SRobert Watson int
192ca0716f5SRobert Watson audit_warn_postsigterm(void)
193ca0716f5SRobert Watson {
194ca0716f5SRobert Watson 	char *args[2];
195ca0716f5SRobert Watson 
196ca0716f5SRobert Watson 	args[0] = POSTSIGTERM_WARN;
197ca0716f5SRobert Watson 	args[1] = NULL;
198ca0716f5SRobert Watson 
199ca0716f5SRobert Watson 	return (auditwarnlog(args));
200ca0716f5SRobert Watson }
201ca0716f5SRobert Watson 
202ca0716f5SRobert Watson /*
203ca0716f5SRobert Watson  * Indicates that the soft limit for this file has been exceeded.
204ca0716f5SRobert Watson  */
205ca0716f5SRobert Watson int
206ca0716f5SRobert Watson audit_warn_soft(char *filename)
207ca0716f5SRobert Watson {
208ca0716f5SRobert Watson 	char *args[3];
209ca0716f5SRobert Watson 
210ca0716f5SRobert Watson 	args[0] = SOFTLIM_WARN;
211ca0716f5SRobert Watson 	args[1] = filename;
212ca0716f5SRobert Watson 	args[2] = NULL;
213ca0716f5SRobert Watson 
214ca0716f5SRobert Watson 	return (auditwarnlog(args));
215ca0716f5SRobert Watson }
216ca0716f5SRobert Watson 
217ca0716f5SRobert Watson /*
218ca0716f5SRobert Watson  * Indicates that the temporary audit file already exists indicating a fatal
219ca0716f5SRobert Watson  * error.
220ca0716f5SRobert Watson  */
221ca0716f5SRobert Watson int
222ca0716f5SRobert Watson audit_warn_tmpfile(void)
223ca0716f5SRobert Watson {
224ca0716f5SRobert Watson 	char *args[2];
225ca0716f5SRobert Watson 
226ca0716f5SRobert Watson 	args[0] = TMPFILE_WARN;
227ca0716f5SRobert Watson 	args[1] = NULL;
228ca0716f5SRobert Watson 
229ca0716f5SRobert Watson 	return (auditwarnlog(args));
230ca0716f5SRobert Watson }
231