]>
Commit | Line | Data |
---|---|---|
2fc1e207 A |
1 | /* |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * "Portions Copyright (c) 2004 Apple Computer, Inc. All Rights | |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.0 (the 'License'). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
13 | * | |
14 | * The Original Code and all software distributed under the License are | |
15 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License." | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | ||
25 | #include <sys/types.h> | |
26 | #include <unistd.h> | |
27 | #include <stdio.h> | |
34d340d7 | 28 | #include <stdlib.h> |
2fc1e207 A |
29 | |
30 | #include <auditd.h> | |
31 | ||
32 | /* Write to the audit log. */ | |
33 | static int auditwarnlog(char *args[]) | |
34 | { | |
35 | char *loc_args[9]; | |
36 | int i; | |
37 | pid_t pid; | |
38 | loc_args[0] = AUDITWARN_SCRIPT; | |
39 | for (i = 0; args[i] != NULL && i < 8; i++) { | |
40 | loc_args[i+1] = args[i]; | |
41 | } | |
42 | loc_args[i+1] = NULL; | |
43 | ||
44 | pid = fork(); | |
45 | if (pid == 0) { | |
46 | return execv(AUDITWARN_SCRIPT, loc_args); | |
47 | /* not reached */ | |
48 | exit(1); | |
49 | } else if (pid == -1) { | |
50 | return -1; | |
51 | } else { | |
52 | return 0; | |
53 | } | |
54 | } | |
55 | ||
56 | /* | |
57 | * Indicates that the hard limit for all filesystems | |
58 | * has been exceeded count times | |
59 | */ | |
60 | int audit_warn_allhard(int count) | |
61 | { | |
62 | char intstr[12]; | |
63 | char *args[3]; | |
64 | ||
65 | snprintf(intstr, 12, "%d", count); | |
66 | ||
67 | args[0] = HARDLIM_ALL_WARN; | |
68 | args[1] = intstr; | |
69 | args[2] = NULL; | |
70 | ||
71 | return auditwarnlog(args); | |
72 | } | |
73 | ||
74 | /* | |
75 | * Indicates that the soft limit for all filesystems | |
76 | * has been exceeded | |
77 | */ | |
78 | int audit_warn_allsoft() | |
79 | { | |
80 | char *args[2]; | |
81 | ||
82 | args[0] = SOFTLIM_ALL_WARN; | |
83 | args[1] = NULL; | |
84 | ||
85 | return auditwarnlog(args); | |
86 | } | |
87 | ||
88 | /* | |
89 | * Indicates that someone other than the audit daemon | |
90 | * turned off auditing | |
91 | * XXX Its not clear at this point how this function will | |
92 | * XXX be invoked | |
93 | */ | |
94 | int audit_warn_auditoff() | |
95 | { | |
96 | char *args[2]; | |
97 | ||
98 | args[0] = AUDITOFF_WARN; | |
99 | args[1] = NULL; | |
100 | ||
101 | return auditwarnlog(args); | |
102 | } | |
103 | ||
104 | /* | |
105 | * Indicates that the audit deammn is already running | |
106 | */ | |
107 | int audit_warn_ebusy() | |
108 | { | |
109 | char *args[2]; | |
110 | ||
111 | args[0] = EBUSY_WARN; | |
112 | args[1] = NULL; | |
113 | ||
114 | return auditwarnlog(args); | |
115 | ||
116 | } | |
117 | ||
118 | /* | |
119 | * Indicates that there is a problem getting the directory | |
120 | * from audit_control | |
121 | * | |
122 | * XXX Note that we take the filename instead of a count | |
123 | * XXX as the argument here (different from BSM) | |
124 | */ | |
125 | int audit_warn_getacdir(char *filename) | |
126 | { | |
127 | char *args[3]; | |
128 | ||
129 | args[0] = GETACDIR_WARN; | |
130 | args[1] = filename; | |
131 | args[2] = NULL; | |
132 | ||
133 | return auditwarnlog(args); | |
134 | } | |
135 | ||
136 | ||
137 | /* | |
138 | * Indicates that the hard limit for this file has been | |
139 | * exceeded | |
140 | */ | |
141 | int audit_warn_hard(char *filename) | |
142 | { | |
143 | char *args[3]; | |
144 | ||
145 | args[0] = HARDLIM_WARN; | |
146 | args[1] = filename; | |
147 | args[2] = NULL; | |
148 | ||
149 | return auditwarnlog(args); | |
150 | ||
151 | } | |
152 | ||
153 | /* | |
154 | * Indicates that auditing could not be started | |
155 | */ | |
156 | int audit_warn_nostart() | |
157 | { | |
158 | char *args[2]; | |
159 | ||
160 | args[0] = NOSTART_WARN; | |
161 | args[1] = NULL; | |
162 | ||
163 | return auditwarnlog(args); | |
164 | } | |
165 | ||
166 | /* | |
167 | * Indicaes that an error occrred during the orderly shutdown | |
168 | * of the audit daemon | |
169 | */ | |
170 | int audit_warn_postsigterm() | |
171 | { | |
172 | char *args[2]; | |
173 | ||
174 | args[0] = POSTSIGTERM_WARN; | |
175 | args[1] = NULL; | |
176 | ||
177 | return auditwarnlog(args); | |
178 | } | |
179 | ||
180 | /* | |
181 | * Indicates that the soft limit for this file has been | |
182 | * exceeded | |
183 | */ | |
184 | int audit_warn_soft(char *filename) | |
185 | { | |
186 | char *args[3]; | |
187 | ||
188 | args[0] = SOFTLIM_WARN; | |
189 | args[1] = filename; | |
190 | args[2] = NULL; | |
191 | ||
192 | return auditwarnlog(args); | |
193 | ||
194 | } | |
195 | ||
196 | /* | |
197 | * Indicates that the temporary audit file already exists | |
198 | * indicating a fatal error | |
199 | */ | |
200 | int audit_warn_tmpfile() | |
201 | { | |
202 | char *args[2]; | |
203 | ||
204 | args[0] = TMPFILE_WARN; | |
205 | args[1] = NULL; | |
206 | ||
207 | return auditwarnlog(args); | |
208 | } |