152267f74SRobert Watson /*-
2c0020399SRobert Watson * Copyright (c) 2004-2009 Apple Inc.
35e386598SRobert Watson * Copyright (c) 2016 Robert N. M. Watson
4ca0716f5SRobert Watson * All rights reserved.
5ca0716f5SRobert Watson *
65e386598SRobert Watson * Portions of this software were developed by BAE Systems, the University of
75e386598SRobert Watson * Cambridge Computer Laboratory, and Memorial University under DARPA/AFRL
85e386598SRobert Watson * contract FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent
95e386598SRobert Watson * Computing (TC) research program.
105e386598SRobert Watson *
11ca0716f5SRobert Watson * Redistribution and use in source and binary forms, with or without
12ca0716f5SRobert Watson * modification, are permitted provided that the following conditions
13ca0716f5SRobert Watson * are met:
14ca0716f5SRobert Watson * 1. Redistributions of source code must retain the above copyright
15ca0716f5SRobert Watson * notice, this list of conditions and the following disclaimer.
16ca0716f5SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright
17ca0716f5SRobert Watson * notice, this list of conditions and the following disclaimer in the
18ca0716f5SRobert Watson * documentation and/or other materials provided with the distribution.
1952267f74SRobert Watson * 3. Neither the name of Apple Inc. ("Apple") nor the names of
20ca0716f5SRobert Watson * its contributors may be used to endorse or promote products derived
21ca0716f5SRobert Watson * from this software without specific prior written permission.
22ca0716f5SRobert Watson *
23ca0716f5SRobert Watson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
24ca0716f5SRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ca0716f5SRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ca0716f5SRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
27ca0716f5SRobert Watson * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28ca0716f5SRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29ca0716f5SRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30ca0716f5SRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31ca0716f5SRobert Watson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32ca0716f5SRobert Watson * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33ca0716f5SRobert Watson * POSSIBILITY OF SUCH DAMAGE.
34ca0716f5SRobert Watson */
35ca0716f5SRobert Watson
36f4e380b0SRobert Watson #ifdef __APPLE__
37f4e380b0SRobert Watson #define _SYS_AUDIT_H /* Prevent include of sys/audit.h. */
38f4e380b0SRobert Watson #endif
39f4e380b0SRobert Watson
40ca0716f5SRobert Watson #include <sys/param.h>
41ca0716f5SRobert Watson #include <sys/stat.h>
423b97a967SRobert Watson
433b97a967SRobert Watson #ifdef __APPLE__
443b97a967SRobert Watson #include <sys/queue.h> /* Our bsm/audit.h doesn't include queue.h. */
453b97a967SRobert Watson #endif
463b97a967SRobert Watson
47ca0716f5SRobert Watson #include <sys/sysctl.h>
48ca0716f5SRobert Watson
49ca0716f5SRobert Watson #include <bsm/libbsm.h>
50ca0716f5SRobert Watson
51ca0716f5SRobert Watson #include <unistd.h>
52ca0716f5SRobert Watson #include <syslog.h>
53506764c6SRobert Watson #include <stdarg.h>
54ca0716f5SRobert Watson #include <string.h>
55ca0716f5SRobert Watson #include <errno.h>
56ca0716f5SRobert Watson
57ca0716f5SRobert Watson /* These are not advertised in libbsm.h */
58ca0716f5SRobert Watson int audit_set_terminal_port(dev_t *p);
59ca0716f5SRobert Watson int audit_set_terminal_host(uint32_t *m);
60ca0716f5SRobert Watson
61506764c6SRobert Watson /*
62506764c6SRobert Watson * General purpose audit submission mechanism for userspace.
63506764c6SRobert Watson */
64506764c6SRobert Watson int
audit_submit(short au_event,au_id_t auid,char status,int reterr,const char * fmt,...)65506764c6SRobert Watson audit_submit(short au_event, au_id_t auid, char status,
66506764c6SRobert Watson int reterr, const char *fmt, ...)
67506764c6SRobert Watson {
68506764c6SRobert Watson char text[MAX_AUDITSTRING_LEN];
69506764c6SRobert Watson token_t *token;
70c0020399SRobert Watson int acond;
71506764c6SRobert Watson va_list ap;
72506764c6SRobert Watson pid_t pid;
73bc168a6cSRobert Watson int error, afd, subj_ex;
74506764c6SRobert Watson struct auditinfo ai;
75bc168a6cSRobert Watson struct auditinfo_addr aia;
767a0a89d2SRobert Watson au_tid_t atid;
77506764c6SRobert Watson
78c0020399SRobert Watson if (audit_get_cond(&acond) != 0) {
79506764c6SRobert Watson /*
80506764c6SRobert Watson * If auditon(2) returns ENOSYS, then audit has not been
81506764c6SRobert Watson * compiled into the kernel, so just return.
82506764c6SRobert Watson */
83506764c6SRobert Watson if (errno == ENOSYS)
84506764c6SRobert Watson return (0);
85506764c6SRobert Watson error = errno;
86506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR, "audit: auditon failed: %s",
87506764c6SRobert Watson strerror(errno));
88506764c6SRobert Watson errno = error;
89506764c6SRobert Watson return (-1);
90506764c6SRobert Watson }
91506764c6SRobert Watson if (acond == AUC_NOAUDIT)
92506764c6SRobert Watson return (0);
93506764c6SRobert Watson afd = au_open();
94506764c6SRobert Watson if (afd < 0) {
95506764c6SRobert Watson error = errno;
96506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR, "audit: au_open failed: %s",
97506764c6SRobert Watson strerror(errno));
98506764c6SRobert Watson errno = error;
99506764c6SRobert Watson return (-1);
100506764c6SRobert Watson }
101bc168a6cSRobert Watson /*
1027a0a89d2SRobert Watson * Try to use getaudit_addr(2) first. If this kernel does not support
1037a0a89d2SRobert Watson * it, then fall back on to getaudit(2).
104bc168a6cSRobert Watson */
105bc168a6cSRobert Watson subj_ex = 0;
106bc168a6cSRobert Watson error = getaudit_addr(&aia, sizeof(aia));
1077a0a89d2SRobert Watson if (error < 0 && errno == ENOSYS) {
1087a0a89d2SRobert Watson error = getaudit(&ai);
109bc168a6cSRobert Watson if (error < 0) {
110506764c6SRobert Watson error = errno;
111506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR, "audit: getaudit failed: %s",
112506764c6SRobert Watson strerror(errno));
113506764c6SRobert Watson errno = error;
114506764c6SRobert Watson return (-1);
115506764c6SRobert Watson }
1167a0a89d2SRobert Watson /*
1177a0a89d2SRobert Watson * Convert this auditinfo_t to an auditinfo_addr_t to make the
1187a0a89d2SRobert Watson * following code less complicated wrt to preselection and
1197a0a89d2SRobert Watson * subject token generation.
1207a0a89d2SRobert Watson */
1217a0a89d2SRobert Watson aia.ai_auid = ai.ai_auid;
1227a0a89d2SRobert Watson aia.ai_mask = ai.ai_mask;
1237a0a89d2SRobert Watson aia.ai_asid = ai.ai_asid;
1247a0a89d2SRobert Watson aia.ai_termid.at_type = AU_IPv4;
1257a0a89d2SRobert Watson aia.ai_termid.at_addr[0] = ai.ai_termid.machine;
1267a0a89d2SRobert Watson aia.ai_termid.at_port = ai.ai_termid.port;
1277a0a89d2SRobert Watson } else if (error < 0) {
1287a0a89d2SRobert Watson error = errno;
1297a0a89d2SRobert Watson syslog(LOG_AUTH | LOG_ERR, "audit: getaudit_addr failed: %s",
1307a0a89d2SRobert Watson strerror(errno));
1317a0a89d2SRobert Watson errno = error;
1327a0a89d2SRobert Watson return (-1);
1337a0a89d2SRobert Watson }
1347a0a89d2SRobert Watson /*
1357a0a89d2SRobert Watson * NB: We should be performing pre-selection here now that we have the
1367a0a89d2SRobert Watson * masks for this process.
1377a0a89d2SRobert Watson */
1387a0a89d2SRobert Watson if (aia.ai_termid.at_type == AU_IPv6)
1397a0a89d2SRobert Watson subj_ex = 1;
140506764c6SRobert Watson pid = getpid();
1417a0a89d2SRobert Watson if (subj_ex == 0) {
1427a0a89d2SRobert Watson atid.port = aia.ai_termid.at_port;
1437a0a89d2SRobert Watson atid.machine = aia.ai_termid.at_addr[0];
144506764c6SRobert Watson token = au_to_subject32(auid, geteuid(), getegid(),
1457a0a89d2SRobert Watson getuid(), getgid(), pid, pid, &atid);
1467a0a89d2SRobert Watson } else
147bc168a6cSRobert Watson token = au_to_subject_ex(auid, geteuid(), getegid(),
148bc168a6cSRobert Watson getuid(), getgid(), pid, pid, &aia.ai_termid);
149506764c6SRobert Watson if (token == NULL) {
150506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR,
151506764c6SRobert Watson "audit: unable to build subject token");
152506764c6SRobert Watson (void) au_close(afd, AU_TO_NO_WRITE, au_event);
153506764c6SRobert Watson errno = EPERM;
154506764c6SRobert Watson return (-1);
155506764c6SRobert Watson }
156506764c6SRobert Watson if (au_write(afd, token) < 0) {
157506764c6SRobert Watson error = errno;
158506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR,
159506764c6SRobert Watson "audit: au_write failed: %s", strerror(errno));
160506764c6SRobert Watson (void) au_close(afd, AU_TO_NO_WRITE, au_event);
161506764c6SRobert Watson errno = error;
162506764c6SRobert Watson return (-1);
163506764c6SRobert Watson }
164506764c6SRobert Watson if (fmt != NULL) {
165506764c6SRobert Watson va_start(ap, fmt);
166506764c6SRobert Watson (void) vsnprintf(text, MAX_AUDITSTRING_LEN, fmt, ap);
167506764c6SRobert Watson va_end(ap);
168506764c6SRobert Watson token = au_to_text(text);
169506764c6SRobert Watson if (token == NULL) {
170506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR,
171506764c6SRobert Watson "audit: failed to generate text token");
172506764c6SRobert Watson (void) au_close(afd, AU_TO_NO_WRITE, au_event);
173506764c6SRobert Watson errno = EPERM;
174506764c6SRobert Watson return (-1);
175506764c6SRobert Watson }
176506764c6SRobert Watson if (au_write(afd, token) < 0) {
177506764c6SRobert Watson error = errno;
178506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR,
179506764c6SRobert Watson "audit: au_write failed: %s", strerror(errno));
180506764c6SRobert Watson (void) au_close(afd, AU_TO_NO_WRITE, au_event);
181506764c6SRobert Watson errno = error;
182506764c6SRobert Watson return (-1);
183506764c6SRobert Watson }
184506764c6SRobert Watson }
185c0020399SRobert Watson token = au_to_return32(au_errno_to_bsm(status), reterr);
186506764c6SRobert Watson if (token == NULL) {
187506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR,
188aa772005SRobert Watson "audit: unable to build return token");
189506764c6SRobert Watson (void) au_close(afd, AU_TO_NO_WRITE, au_event);
190506764c6SRobert Watson errno = EPERM;
191506764c6SRobert Watson return (-1);
192506764c6SRobert Watson }
193506764c6SRobert Watson if (au_write(afd, token) < 0) {
194506764c6SRobert Watson error = errno;
195506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR,
196506764c6SRobert Watson "audit: au_write failed: %s", strerror(errno));
197506764c6SRobert Watson (void) au_close(afd, AU_TO_NO_WRITE, au_event);
198506764c6SRobert Watson errno = error;
199506764c6SRobert Watson return (-1);
200506764c6SRobert Watson }
201506764c6SRobert Watson if (au_close(afd, AU_TO_WRITE, au_event) < 0) {
202506764c6SRobert Watson error = errno;
203506764c6SRobert Watson syslog(LOG_AUTH | LOG_ERR, "audit: record not committed");
204506764c6SRobert Watson errno = error;
205506764c6SRobert Watson return (-1);
206506764c6SRobert Watson }
207506764c6SRobert Watson return (0);
208506764c6SRobert Watson }
209506764c6SRobert Watson
210ca0716f5SRobert Watson int
audit_set_terminal_port(dev_t * p)211ca0716f5SRobert Watson audit_set_terminal_port(dev_t *p)
212ca0716f5SRobert Watson {
213ca0716f5SRobert Watson struct stat st;
214ca0716f5SRobert Watson
215ca0716f5SRobert Watson if (p == NULL)
216ca0716f5SRobert Watson return (kAUBadParamErr);
217ca0716f5SRobert Watson
2183b97a967SRobert Watson #ifdef NODEV
219ca0716f5SRobert Watson *p = NODEV;
2203b97a967SRobert Watson #else
2213b97a967SRobert Watson *p = -1;
2223b97a967SRobert Watson #endif
223ca0716f5SRobert Watson
224ca0716f5SRobert Watson /* for /usr/bin/login, try fstat() first */
225ca0716f5SRobert Watson if (fstat(STDIN_FILENO, &st) != 0) {
226ca0716f5SRobert Watson if (errno != EBADF) {
227ca0716f5SRobert Watson syslog(LOG_ERR, "fstat() failed (%s)",
228ca0716f5SRobert Watson strerror(errno));
229ca0716f5SRobert Watson return (kAUStatErr);
230ca0716f5SRobert Watson }
231ca0716f5SRobert Watson if (stat("/dev/console", &st) != 0) {
232ca0716f5SRobert Watson syslog(LOG_ERR, "stat() failed (%s)",
233ca0716f5SRobert Watson strerror(errno));
234ca0716f5SRobert Watson return (kAUStatErr);
235ca0716f5SRobert Watson }
236ca0716f5SRobert Watson }
237ca0716f5SRobert Watson *p = st.st_rdev;
238ca0716f5SRobert Watson return (kAUNoErr);
239ca0716f5SRobert Watson }
240ca0716f5SRobert Watson
241ca0716f5SRobert Watson int
audit_set_terminal_host(uint32_t * m)242ca0716f5SRobert Watson audit_set_terminal_host(uint32_t *m)
243ca0716f5SRobert Watson {
2443b97a967SRobert Watson
2453b97a967SRobert Watson #ifdef KERN_HOSTID
246ca0716f5SRobert Watson int name[2] = { CTL_KERN, KERN_HOSTID };
247ca0716f5SRobert Watson size_t len;
248ca0716f5SRobert Watson
249ca0716f5SRobert Watson if (m == NULL)
250ca0716f5SRobert Watson return (kAUBadParamErr);
251ca0716f5SRobert Watson *m = 0;
252ca0716f5SRobert Watson len = sizeof(*m);
253ca0716f5SRobert Watson if (sysctl(name, 2, m, &len, NULL, 0) != 0) {
254ca0716f5SRobert Watson syslog(LOG_ERR, "sysctl() failed (%s)", strerror(errno));
255ca0716f5SRobert Watson return (kAUSysctlErr);
256ca0716f5SRobert Watson }
257ca0716f5SRobert Watson return (kAUNoErr);
2583b97a967SRobert Watson #else
2593b97a967SRobert Watson *m = -1;
2603b97a967SRobert Watson return (kAUNoErr);
2613b97a967SRobert Watson #endif
262ca0716f5SRobert Watson }
263ca0716f5SRobert Watson
264ca0716f5SRobert Watson int
audit_set_terminal_id(au_tid_t * tid)265ca0716f5SRobert Watson audit_set_terminal_id(au_tid_t *tid)
266ca0716f5SRobert Watson {
267*69921123SKonstantin Belousov dev_t port;
268ca0716f5SRobert Watson int ret;
269ca0716f5SRobert Watson
270ca0716f5SRobert Watson if (tid == NULL)
271ca0716f5SRobert Watson return (kAUBadParamErr);
272*69921123SKonstantin Belousov if ((ret = audit_set_terminal_port(&port)) != kAUNoErr)
273ca0716f5SRobert Watson return (ret);
274*69921123SKonstantin Belousov tid->port = port;
275ca0716f5SRobert Watson return (audit_set_terminal_host(&tid->machine));
276ca0716f5SRobert Watson }
277ca0716f5SRobert Watson
278ca0716f5SRobert Watson /*
279ca0716f5SRobert Watson * This is OK for those callers who have only one token to write. If you have
280ca0716f5SRobert Watson * multiple tokens that logically form part of the same audit record, you need
281ca0716f5SRobert Watson * to use the existing au_open()/au_write()/au_close() API:
282ca0716f5SRobert Watson *
283ca0716f5SRobert Watson * aufd = au_open();
284ca0716f5SRobert Watson * tok = au_to_random_token_1(...);
285ca0716f5SRobert Watson * au_write(aufd, tok);
286ca0716f5SRobert Watson * tok = au_to_random_token_2(...);
287ca0716f5SRobert Watson * au_write(aufd, tok);
288ca0716f5SRobert Watson * ...
289506764c6SRobert Watson * au_close(aufd, AU_TO_WRITE, AUE_your_event_type);
290ca0716f5SRobert Watson *
291ca0716f5SRobert Watson * Assumes, like all wrapper calls, that the caller has previously checked
292ca0716f5SRobert Watson * that auditing is enabled via the audit_get_state() call.
293ca0716f5SRobert Watson *
294ca0716f5SRobert Watson * XXX: Should be more robust against bad arguments.
295ca0716f5SRobert Watson */
296ca0716f5SRobert Watson int
audit_write(short event_code,token_t * subject,token_t * misctok,char retval,int errcode)297ca0716f5SRobert Watson audit_write(short event_code, token_t *subject, token_t *misctok, char retval,
298ca0716f5SRobert Watson int errcode)
299ca0716f5SRobert Watson {
300ca0716f5SRobert Watson int aufd;
301ca0716f5SRobert Watson char *func = "audit_write()";
302ca0716f5SRobert Watson token_t *rettok;
303ca0716f5SRobert Watson
304ca0716f5SRobert Watson if ((aufd = au_open()) == -1) {
305ca0716f5SRobert Watson au_free_token(subject);
306ca0716f5SRobert Watson au_free_token(misctok);
307ca0716f5SRobert Watson syslog(LOG_ERR, "%s: au_open() failed", func);
308ca0716f5SRobert Watson return (kAUOpenErr);
309ca0716f5SRobert Watson }
310ca0716f5SRobert Watson
311ca0716f5SRobert Watson /* Save subject. */
312ca0716f5SRobert Watson if (subject && au_write(aufd, subject) == -1) {
313ca0716f5SRobert Watson au_free_token(subject);
314ca0716f5SRobert Watson au_free_token(misctok);
31552267f74SRobert Watson (void)au_close(aufd, AU_TO_NO_WRITE, event_code);
316ca0716f5SRobert Watson syslog(LOG_ERR, "%s: write of subject failed", func);
317ca0716f5SRobert Watson return (kAUWriteSubjectTokErr);
318ca0716f5SRobert Watson }
319ca0716f5SRobert Watson
320ca0716f5SRobert Watson /* Save the event-specific token. */
321ca0716f5SRobert Watson if (misctok && au_write(aufd, misctok) == -1) {
322ca0716f5SRobert Watson au_free_token(misctok);
323506764c6SRobert Watson (void)au_close(aufd, AU_TO_NO_WRITE, event_code);
324ca0716f5SRobert Watson syslog(LOG_ERR, "%s: write of caller token failed", func);
325ca0716f5SRobert Watson return (kAUWriteCallerTokErr);
326ca0716f5SRobert Watson }
327ca0716f5SRobert Watson
328ca0716f5SRobert Watson /* Tokenize and save the return value. */
329ca0716f5SRobert Watson if ((rettok = au_to_return32(retval, errcode)) == NULL) {
330506764c6SRobert Watson (void)au_close(aufd, AU_TO_NO_WRITE, event_code);
331ca0716f5SRobert Watson syslog(LOG_ERR, "%s: au_to_return32() failed", func);
332ca0716f5SRobert Watson return (kAUMakeReturnTokErr);
333ca0716f5SRobert Watson }
334ca0716f5SRobert Watson
335ca0716f5SRobert Watson if (au_write(aufd, rettok) == -1) {
336ca0716f5SRobert Watson au_free_token(rettok);
337506764c6SRobert Watson (void)au_close(aufd, AU_TO_NO_WRITE, event_code);
338ca0716f5SRobert Watson syslog(LOG_ERR, "%s: write of return code failed", func);
339ca0716f5SRobert Watson return (kAUWriteReturnTokErr);
340ca0716f5SRobert Watson }
341ca0716f5SRobert Watson
342ca0716f5SRobert Watson /*
343506764c6SRobert Watson * We assume the caller wouldn't have bothered with this
344ca0716f5SRobert Watson * function if it hadn't already decided to keep the record.
345ca0716f5SRobert Watson */
346506764c6SRobert Watson if (au_close(aufd, AU_TO_WRITE, event_code) < 0) {
347ca0716f5SRobert Watson syslog(LOG_ERR, "%s: au_close() failed", func);
348ca0716f5SRobert Watson return (kAUCloseErr);
349ca0716f5SRobert Watson }
350ca0716f5SRobert Watson
351ca0716f5SRobert Watson return (kAUNoErr);
352ca0716f5SRobert Watson }
353ca0716f5SRobert Watson
354ca0716f5SRobert Watson /*
355ca0716f5SRobert Watson * Same caveats as audit_write(). In addition, this function explicitly
356ca0716f5SRobert Watson * assumes success; use audit_write_failure() on error.
357ca0716f5SRobert Watson */
358ca0716f5SRobert Watson int
audit_write_success(short event_code,token_t * tok,au_id_t auid,uid_t euid,gid_t egid,uid_t ruid,gid_t rgid,pid_t pid,au_asid_t sid,au_tid_t * tid)359ca0716f5SRobert Watson audit_write_success(short event_code, token_t *tok, au_id_t auid, uid_t euid,
360ca0716f5SRobert Watson gid_t egid, uid_t ruid, gid_t rgid, pid_t pid, au_asid_t sid,
361ca0716f5SRobert Watson au_tid_t *tid)
362ca0716f5SRobert Watson {
363ca0716f5SRobert Watson char *func = "audit_write_success()";
364ca0716f5SRobert Watson token_t *subject = NULL;
365ca0716f5SRobert Watson
366ca0716f5SRobert Watson /* Tokenize and save subject. */
367ca0716f5SRobert Watson subject = au_to_subject32(auid, euid, egid, ruid, rgid, pid, sid,
368ca0716f5SRobert Watson tid);
369ca0716f5SRobert Watson if (subject == NULL) {
370ca0716f5SRobert Watson syslog(LOG_ERR, "%s: au_to_subject32() failed", func);
371ca0716f5SRobert Watson return kAUMakeSubjectTokErr;
372ca0716f5SRobert Watson }
373ca0716f5SRobert Watson
374ca0716f5SRobert Watson return (audit_write(event_code, subject, tok, 0, 0));
375ca0716f5SRobert Watson }
376ca0716f5SRobert Watson
377ca0716f5SRobert Watson /*
378ca0716f5SRobert Watson * Same caveats as audit_write(). In addition, this function explicitly
379ca0716f5SRobert Watson * assumes success; use audit_write_failure_self() on error.
380ca0716f5SRobert Watson */
381ca0716f5SRobert Watson int
audit_write_success_self(short event_code,token_t * tok)382ca0716f5SRobert Watson audit_write_success_self(short event_code, token_t *tok)
383ca0716f5SRobert Watson {
384ca0716f5SRobert Watson token_t *subject;
385ca0716f5SRobert Watson char *func = "audit_write_success_self()";
386ca0716f5SRobert Watson
387ca0716f5SRobert Watson if ((subject = au_to_me()) == NULL) {
388ca0716f5SRobert Watson syslog(LOG_ERR, "%s: au_to_me() failed", func);
389ca0716f5SRobert Watson return (kAUMakeSubjectTokErr);
390ca0716f5SRobert Watson }
391ca0716f5SRobert Watson
392ca0716f5SRobert Watson return (audit_write(event_code, subject, tok, 0, 0));
393ca0716f5SRobert Watson }
394ca0716f5SRobert Watson
395ca0716f5SRobert Watson /*
396ca0716f5SRobert Watson * Same caveats as audit_write(). In addition, this function explicitly
397ca0716f5SRobert Watson * assumes failure; use audit_write_success() otherwise.
398ca0716f5SRobert Watson *
399ca0716f5SRobert Watson * XXX This should let the caller pass an error return value rather than
400ca0716f5SRobert Watson * hard-coding -1.
401ca0716f5SRobert Watson */
402ca0716f5SRobert Watson int
audit_write_failure(short event_code,char * errmsg,int errcode,au_id_t auid,uid_t euid,gid_t egid,uid_t ruid,gid_t rgid,pid_t pid,au_asid_t sid,au_tid_t * tid)403ca0716f5SRobert Watson audit_write_failure(short event_code, char *errmsg, int errcode, au_id_t auid,
404ca0716f5SRobert Watson uid_t euid, gid_t egid, uid_t ruid, gid_t rgid, pid_t pid, au_asid_t sid,
405ca0716f5SRobert Watson au_tid_t *tid)
406ca0716f5SRobert Watson {
407ca0716f5SRobert Watson char *func = "audit_write_failure()";
408ca0716f5SRobert Watson token_t *subject, *errtok;
409ca0716f5SRobert Watson
410ca0716f5SRobert Watson subject = au_to_subject32(auid, euid, egid, ruid, rgid, pid, sid, tid);
411ca0716f5SRobert Watson if (subject == NULL) {
412ca0716f5SRobert Watson syslog(LOG_ERR, "%s: au_to_subject32() failed", func);
413ca0716f5SRobert Watson return (kAUMakeSubjectTokErr);
414ca0716f5SRobert Watson }
415ca0716f5SRobert Watson
416ca0716f5SRobert Watson /* tokenize and save the error message */
417ca0716f5SRobert Watson if ((errtok = au_to_text(errmsg)) == NULL) {
418ca0716f5SRobert Watson au_free_token(subject);
419ca0716f5SRobert Watson syslog(LOG_ERR, "%s: au_to_text() failed", func);
420ca0716f5SRobert Watson return (kAUMakeTextTokErr);
421ca0716f5SRobert Watson }
422ca0716f5SRobert Watson
423ca0716f5SRobert Watson return (audit_write(event_code, subject, errtok, -1, errcode));
424ca0716f5SRobert Watson }
425ca0716f5SRobert Watson
426ca0716f5SRobert Watson /*
427ca0716f5SRobert Watson * Same caveats as audit_write(). In addition, this function explicitly
428ca0716f5SRobert Watson * assumes failure; use audit_write_success_self() otherwise.
429ca0716f5SRobert Watson *
430ca0716f5SRobert Watson * XXX This should let the caller pass an error return value rather than
431ca0716f5SRobert Watson * hard-coding -1.
432ca0716f5SRobert Watson */
433ca0716f5SRobert Watson int
audit_write_failure_self(short event_code,char * errmsg,int errret)434ca0716f5SRobert Watson audit_write_failure_self(short event_code, char *errmsg, int errret)
435ca0716f5SRobert Watson {
436ca0716f5SRobert Watson char *func = "audit_write_failure_self()";
437ca0716f5SRobert Watson token_t *subject, *errtok;
438ca0716f5SRobert Watson
439ca0716f5SRobert Watson if ((subject = au_to_me()) == NULL) {
440ca0716f5SRobert Watson syslog(LOG_ERR, "%s: au_to_me() failed", func);
441ca0716f5SRobert Watson return (kAUMakeSubjectTokErr);
442ca0716f5SRobert Watson }
443ca0716f5SRobert Watson /* tokenize and save the error message */
444ca0716f5SRobert Watson if ((errtok = au_to_text(errmsg)) == NULL) {
445ca0716f5SRobert Watson au_free_token(subject);
446ca0716f5SRobert Watson syslog(LOG_ERR, "%s: au_to_text() failed", func);
447ca0716f5SRobert Watson return (kAUMakeTextTokErr);
448ca0716f5SRobert Watson }
449ca0716f5SRobert Watson return (audit_write(event_code, subject, errtok, -1, errret));
450ca0716f5SRobert Watson }
451ca0716f5SRobert Watson
452ca0716f5SRobert Watson /*
453ca0716f5SRobert Watson * For auditing errors during login. Such errors are implicitly
454ca0716f5SRobert Watson * non-attributable (i.e., not ascribable to any user).
455ca0716f5SRobert Watson *
456ca0716f5SRobert Watson * Assumes, like all wrapper calls, that the caller has previously checked
457ca0716f5SRobert Watson * that auditing is enabled via the audit_get_state() call.
458ca0716f5SRobert Watson */
459ca0716f5SRobert Watson int
audit_write_failure_na(short event_code,char * errmsg,int errret,uid_t euid,uid_t egid,pid_t pid,au_tid_t * tid)460ca0716f5SRobert Watson audit_write_failure_na(short event_code, char *errmsg, int errret, uid_t euid,
461ca0716f5SRobert Watson uid_t egid, pid_t pid, au_tid_t *tid)
462ca0716f5SRobert Watson {
463ca0716f5SRobert Watson
464ca0716f5SRobert Watson return (audit_write_failure(event_code, errmsg, errret, -1, euid,
465ca0716f5SRobert Watson egid, -1, -1, pid, -1, tid));
466ca0716f5SRobert Watson }
467ca0716f5SRobert Watson
468ca0716f5SRobert Watson /* END OF au_write() WRAPPERS */
469ca0716f5SRobert Watson
470ca0716f5SRobert Watson #ifdef __APPLE__
471ca0716f5SRobert Watson void
audit_token_to_au32(audit_token_t atoken,uid_t * auidp,uid_t * euidp,gid_t * egidp,uid_t * ruidp,gid_t * rgidp,pid_t * pidp,au_asid_t * asidp,au_tid_t * tidp)472ca0716f5SRobert Watson audit_token_to_au32(audit_token_t atoken, uid_t *auidp, uid_t *euidp,
473ca0716f5SRobert Watson gid_t *egidp, uid_t *ruidp, gid_t *rgidp, pid_t *pidp, au_asid_t *asidp,
474ca0716f5SRobert Watson au_tid_t *tidp)
475ca0716f5SRobert Watson {
476ca0716f5SRobert Watson
477ca0716f5SRobert Watson if (auidp != NULL)
478ca0716f5SRobert Watson *auidp = (uid_t)atoken.val[0];
479ca0716f5SRobert Watson if (euidp != NULL)
480ca0716f5SRobert Watson *euidp = (uid_t)atoken.val[1];
481ca0716f5SRobert Watson if (egidp != NULL)
482ca0716f5SRobert Watson *egidp = (gid_t)atoken.val[2];
483ca0716f5SRobert Watson if (ruidp != NULL)
484ca0716f5SRobert Watson *ruidp = (uid_t)atoken.val[3];
485ca0716f5SRobert Watson if (rgidp != NULL)
486ca0716f5SRobert Watson *rgidp = (gid_t)atoken.val[4];
487ca0716f5SRobert Watson if (pidp != NULL)
488ca0716f5SRobert Watson *pidp = (pid_t)atoken.val[5];
489ca0716f5SRobert Watson if (asidp != NULL)
490ca0716f5SRobert Watson *asidp = (au_asid_t)atoken.val[6];
491ca0716f5SRobert Watson if (tidp != NULL) {
492ca0716f5SRobert Watson audit_set_terminal_host(&tidp->machine);
493ca0716f5SRobert Watson tidp->port = (dev_t)atoken.val[7];
494ca0716f5SRobert Watson }
495ca0716f5SRobert Watson }
496ca0716f5SRobert Watson #endif /* !__APPLE__ */
497c0020399SRobert Watson
498c0020399SRobert Watson int
audit_get_cond(int * cond)499c0020399SRobert Watson audit_get_cond(int *cond)
500c0020399SRobert Watson {
501c0020399SRobert Watson int ret;
502c0020399SRobert Watson
503c0020399SRobert Watson ret = auditon(A_GETCOND, cond, sizeof(*cond));
504c0020399SRobert Watson #ifdef A_OLDGETCOND
505c0020399SRobert Watson if ((0 != ret) && EINVAL == errno) {
506c0020399SRobert Watson long lcond = *cond;
507c0020399SRobert Watson
508c0020399SRobert Watson ret = auditon(A_OLDGETCOND, &lcond, sizeof(lcond));
509c0020399SRobert Watson *cond = (int)lcond;
510c0020399SRobert Watson }
511c0020399SRobert Watson #endif
512c0020399SRobert Watson return (ret);
513c0020399SRobert Watson }
514c0020399SRobert Watson
515c0020399SRobert Watson int
audit_set_cond(int * cond)516c0020399SRobert Watson audit_set_cond(int *cond)
517c0020399SRobert Watson {
518c0020399SRobert Watson int ret;
519c0020399SRobert Watson
520c0020399SRobert Watson ret = auditon(A_SETCOND, cond, sizeof(*cond));
521c0020399SRobert Watson #ifdef A_OLDSETCOND
522c0020399SRobert Watson if ((0 != ret) && (EINVAL == errno)) {
523c0020399SRobert Watson long lcond = (long)*cond;
524c0020399SRobert Watson
525c0020399SRobert Watson ret = auditon(A_OLDSETCOND, &lcond, sizeof(lcond));
526c0020399SRobert Watson *cond = (int)lcond;
527c0020399SRobert Watson }
528c0020399SRobert Watson #endif
529c0020399SRobert Watson return (ret);
530c0020399SRobert Watson }
531c0020399SRobert Watson
532c0020399SRobert Watson int
audit_get_policy(int * policy)533c0020399SRobert Watson audit_get_policy(int *policy)
534c0020399SRobert Watson {
535c0020399SRobert Watson int ret;
536c0020399SRobert Watson
537c0020399SRobert Watson ret = auditon(A_GETPOLICY, policy, sizeof(*policy));
538c0020399SRobert Watson #ifdef A_OLDGETPOLICY
539c0020399SRobert Watson if ((0 != ret) && (EINVAL == errno)){
540c0020399SRobert Watson long lpolicy = (long)*policy;
541c0020399SRobert Watson
542c0020399SRobert Watson ret = auditon(A_OLDGETPOLICY, &lpolicy, sizeof(lpolicy));
543c0020399SRobert Watson *policy = (int)lpolicy;
544c0020399SRobert Watson }
545c0020399SRobert Watson #endif
546c0020399SRobert Watson return (ret);
547c0020399SRobert Watson }
548c0020399SRobert Watson
549c0020399SRobert Watson int
audit_set_policy(int * policy)550c0020399SRobert Watson audit_set_policy(int *policy)
551c0020399SRobert Watson {
552c0020399SRobert Watson int ret;
553c0020399SRobert Watson
554c0020399SRobert Watson ret = auditon(A_SETPOLICY, policy, sizeof(*policy));
555c0020399SRobert Watson #ifdef A_OLDSETPOLICY
556c0020399SRobert Watson if ((0 != ret) && (EINVAL == errno)){
557c0020399SRobert Watson long lpolicy = (long)*policy;
558c0020399SRobert Watson
559c0020399SRobert Watson ret = auditon(A_OLDSETPOLICY, &lpolicy, sizeof(lpolicy));
560c0020399SRobert Watson *policy = (int)lpolicy;
561c0020399SRobert Watson }
562c0020399SRobert Watson #endif
563c0020399SRobert Watson return (ret);
564c0020399SRobert Watson }
565c0020399SRobert Watson
566c0020399SRobert Watson int
audit_get_qctrl(au_qctrl_t * qctrl,size_t sz)567c0020399SRobert Watson audit_get_qctrl(au_qctrl_t *qctrl, size_t sz)
568c0020399SRobert Watson {
569c0020399SRobert Watson int ret;
570c0020399SRobert Watson
571c0020399SRobert Watson if (sizeof(*qctrl) != sz) {
572c0020399SRobert Watson errno = EINVAL;
573c0020399SRobert Watson return (-1);
574c0020399SRobert Watson }
575c0020399SRobert Watson
576c0020399SRobert Watson ret = auditon(A_GETQCTRL, qctrl, sizeof(*qctrl));
577c0020399SRobert Watson #ifdef A_OLDGETQCTRL
578c0020399SRobert Watson if ((0 != ret) && (EINVAL == errno)){
579c0020399SRobert Watson struct old_qctrl {
580c0020399SRobert Watson size_t oq_hiwater;
581c0020399SRobert Watson size_t oq_lowater;
582c0020399SRobert Watson size_t oq_bufsz;
583c0020399SRobert Watson clock_t oq_delay;
584c0020399SRobert Watson int oq_minfree;
585c0020399SRobert Watson } oq;
586c0020399SRobert Watson
587c0020399SRobert Watson oq.oq_hiwater = (size_t)qctrl->aq_hiwater;
588c0020399SRobert Watson oq.oq_lowater = (size_t)qctrl->aq_lowater;
589c0020399SRobert Watson oq.oq_bufsz = (size_t)qctrl->aq_bufsz;
590c0020399SRobert Watson oq.oq_delay = (clock_t)qctrl->aq_delay;
591c0020399SRobert Watson oq.oq_minfree = qctrl->aq_minfree;
592c0020399SRobert Watson
593c0020399SRobert Watson ret = auditon(A_OLDGETQCTRL, &oq, sizeof(oq));
594c0020399SRobert Watson
595c0020399SRobert Watson qctrl->aq_hiwater = (int)oq.oq_hiwater;
596c0020399SRobert Watson qctrl->aq_lowater = (int)oq.oq_lowater;
597c0020399SRobert Watson qctrl->aq_bufsz = (int)oq.oq_bufsz;
598c0020399SRobert Watson qctrl->aq_delay = (int)oq.oq_delay;
599c0020399SRobert Watson qctrl->aq_minfree = oq.oq_minfree;
600c0020399SRobert Watson }
601c0020399SRobert Watson #endif /* A_OLDGETQCTRL */
602c0020399SRobert Watson return (ret);
603c0020399SRobert Watson }
604c0020399SRobert Watson
605c0020399SRobert Watson int
audit_set_qctrl(au_qctrl_t * qctrl,size_t sz)606c0020399SRobert Watson audit_set_qctrl(au_qctrl_t *qctrl, size_t sz)
607c0020399SRobert Watson {
608c0020399SRobert Watson int ret;
609c0020399SRobert Watson
610c0020399SRobert Watson if (sizeof(*qctrl) != sz) {
611c0020399SRobert Watson errno = EINVAL;
612c0020399SRobert Watson return (-1);
613c0020399SRobert Watson }
614c0020399SRobert Watson
615c0020399SRobert Watson ret = auditon(A_SETQCTRL, qctrl, sz);
616c0020399SRobert Watson #ifdef A_OLDSETQCTRL
617c0020399SRobert Watson if ((0 != ret) && (EINVAL == errno)) {
618c0020399SRobert Watson struct old_qctrl {
619c0020399SRobert Watson size_t oq_hiwater;
620c0020399SRobert Watson size_t oq_lowater;
621c0020399SRobert Watson size_t oq_bufsz;
622c0020399SRobert Watson clock_t oq_delay;
623c0020399SRobert Watson int oq_minfree;
624c0020399SRobert Watson } oq;
625c0020399SRobert Watson
626c0020399SRobert Watson oq.oq_hiwater = (size_t)qctrl->aq_hiwater;
627c0020399SRobert Watson oq.oq_lowater = (size_t)qctrl->aq_lowater;
628c0020399SRobert Watson oq.oq_bufsz = (size_t)qctrl->aq_bufsz;
629c0020399SRobert Watson oq.oq_delay = (clock_t)qctrl->aq_delay;
630c0020399SRobert Watson oq.oq_minfree = qctrl->aq_minfree;
631c0020399SRobert Watson
632c0020399SRobert Watson ret = auditon(A_OLDSETQCTRL, &oq, sizeof(oq));
633c0020399SRobert Watson
634c0020399SRobert Watson qctrl->aq_hiwater = (int)oq.oq_hiwater;
635c0020399SRobert Watson qctrl->aq_lowater = (int)oq.oq_lowater;
636c0020399SRobert Watson qctrl->aq_bufsz = (int)oq.oq_bufsz;
637c0020399SRobert Watson qctrl->aq_delay = (int)oq.oq_delay;
638c0020399SRobert Watson qctrl->aq_minfree = oq.oq_minfree;
639c0020399SRobert Watson }
640c0020399SRobert Watson #endif /* A_OLDSETQCTRL */
641c0020399SRobert Watson return (ret);
642c0020399SRobert Watson }
643c0020399SRobert Watson
644c0020399SRobert Watson int
audit_send_trigger(int * trigger)645c0020399SRobert Watson audit_send_trigger(int *trigger)
646c0020399SRobert Watson {
647c0020399SRobert Watson
648c0020399SRobert Watson return (auditon(A_SENDTRIGGER, trigger, sizeof(*trigger)));
649c0020399SRobert Watson }
650c0020399SRobert Watson
651c0020399SRobert Watson int
audit_get_kaudit(auditinfo_addr_t * aia,size_t sz)652c0020399SRobert Watson audit_get_kaudit(auditinfo_addr_t *aia, size_t sz)
653c0020399SRobert Watson {
654c0020399SRobert Watson
655c0020399SRobert Watson if (sizeof(*aia) != sz) {
656c0020399SRobert Watson errno = EINVAL;
657c0020399SRobert Watson return (-1);
658c0020399SRobert Watson }
659c0020399SRobert Watson
660c0020399SRobert Watson return (auditon(A_GETKAUDIT, aia, sz));
661c0020399SRobert Watson }
662c0020399SRobert Watson
663c0020399SRobert Watson int
audit_set_kaudit(auditinfo_addr_t * aia,size_t sz)664c0020399SRobert Watson audit_set_kaudit(auditinfo_addr_t *aia, size_t sz)
665c0020399SRobert Watson {
666c0020399SRobert Watson
667c0020399SRobert Watson if (sizeof(*aia) != sz) {
668c0020399SRobert Watson errno = EINVAL;
669c0020399SRobert Watson return (-1);
670c0020399SRobert Watson }
671c0020399SRobert Watson
672c0020399SRobert Watson return (auditon(A_SETKAUDIT, aia, sz));
673c0020399SRobert Watson }
674c0020399SRobert Watson
675c0020399SRobert Watson int
audit_get_class(au_evclass_map_t * evc_map,size_t sz)676c0020399SRobert Watson audit_get_class(au_evclass_map_t *evc_map, size_t sz)
677c0020399SRobert Watson {
678c0020399SRobert Watson
679c0020399SRobert Watson if (sizeof(*evc_map) != sz) {
680c0020399SRobert Watson errno = EINVAL;
681c0020399SRobert Watson return (-1);
682c0020399SRobert Watson }
683c0020399SRobert Watson
684c0020399SRobert Watson return (auditon(A_GETCLASS, evc_map, sz));
685c0020399SRobert Watson }
686c0020399SRobert Watson
687c0020399SRobert Watson int
audit_set_class(au_evclass_map_t * evc_map,size_t sz)688c0020399SRobert Watson audit_set_class(au_evclass_map_t *evc_map, size_t sz)
689c0020399SRobert Watson {
690c0020399SRobert Watson
691c0020399SRobert Watson if (sizeof(*evc_map) != sz) {
692c0020399SRobert Watson errno = EINVAL;
693c0020399SRobert Watson return (-1);
694c0020399SRobert Watson }
695c0020399SRobert Watson
696c0020399SRobert Watson return (auditon(A_SETCLASS, evc_map, sz));
697c0020399SRobert Watson }
698c0020399SRobert Watson
699c0020399SRobert Watson int
audit_get_event(au_evname_map_t * evn_map,size_t sz)7005e386598SRobert Watson audit_get_event(au_evname_map_t *evn_map, size_t sz)
7015e386598SRobert Watson {
7025e386598SRobert Watson
7035e386598SRobert Watson if (sizeof(*evn_map) != sz) {
7045e386598SRobert Watson errno = EINVAL;
7055e386598SRobert Watson return (-1);
7065e386598SRobert Watson }
7075e386598SRobert Watson
7085e386598SRobert Watson return (auditon(A_GETEVENT, evn_map, sz));
7095e386598SRobert Watson }
7105e386598SRobert Watson
7115e386598SRobert Watson int
audit_set_event(au_evname_map_t * evn_map,size_t sz)7125e386598SRobert Watson audit_set_event(au_evname_map_t *evn_map, size_t sz)
7135e386598SRobert Watson {
7145e386598SRobert Watson
7155e386598SRobert Watson if (sizeof(*evn_map) != sz) {
7165e386598SRobert Watson errno = EINVAL;
7175e386598SRobert Watson return (-1);
7185e386598SRobert Watson }
7195e386598SRobert Watson
7205e386598SRobert Watson return (auditon(A_SETEVENT, evn_map, sz));
7215e386598SRobert Watson }
7225e386598SRobert Watson
7235e386598SRobert Watson int
audit_get_kmask(au_mask_t * kmask,size_t sz)724c0020399SRobert Watson audit_get_kmask(au_mask_t *kmask, size_t sz)
725c0020399SRobert Watson {
726c0020399SRobert Watson if (sizeof(*kmask) != sz) {
727c0020399SRobert Watson errno = EINVAL;
728c0020399SRobert Watson return (-1);
729c0020399SRobert Watson }
730c0020399SRobert Watson
731c0020399SRobert Watson return (auditon(A_GETKMASK, kmask, sz));
732c0020399SRobert Watson }
733c0020399SRobert Watson
734c0020399SRobert Watson int
audit_set_kmask(au_mask_t * kmask,size_t sz)735c0020399SRobert Watson audit_set_kmask(au_mask_t *kmask, size_t sz)
736c0020399SRobert Watson {
737c0020399SRobert Watson if (sizeof(*kmask) != sz) {
738c0020399SRobert Watson errno = EINVAL;
739c0020399SRobert Watson return (-1);
740c0020399SRobert Watson }
741c0020399SRobert Watson
742c0020399SRobert Watson return (auditon(A_SETKMASK, kmask, sz));
743c0020399SRobert Watson }
744c0020399SRobert Watson
745c0020399SRobert Watson int
audit_get_fsize(au_fstat_t * fstat,size_t sz)746c0020399SRobert Watson audit_get_fsize(au_fstat_t *fstat, size_t sz)
747c0020399SRobert Watson {
748c0020399SRobert Watson
749c0020399SRobert Watson if (sizeof(*fstat) != sz) {
750c0020399SRobert Watson errno = EINVAL;
751c0020399SRobert Watson return (-1);
752c0020399SRobert Watson }
753c0020399SRobert Watson
754c0020399SRobert Watson return (auditon(A_GETFSIZE, fstat, sz));
755c0020399SRobert Watson }
756c0020399SRobert Watson
757c0020399SRobert Watson int
audit_set_fsize(au_fstat_t * fstat,size_t sz)758c0020399SRobert Watson audit_set_fsize(au_fstat_t *fstat, size_t sz)
759c0020399SRobert Watson {
760c0020399SRobert Watson
761c0020399SRobert Watson if (sizeof(*fstat) != sz) {
762c0020399SRobert Watson errno = EINVAL;
763c0020399SRobert Watson return (-1);
764c0020399SRobert Watson }
765c0020399SRobert Watson
766c0020399SRobert Watson return (auditon(A_SETFSIZE, fstat, sz));
767c0020399SRobert Watson }
768c0020399SRobert Watson
769c0020399SRobert Watson int
audit_set_pmask(auditpinfo_t * api,size_t sz)770c0020399SRobert Watson audit_set_pmask(auditpinfo_t *api, size_t sz)
771c0020399SRobert Watson {
772c0020399SRobert Watson
773c0020399SRobert Watson if (sizeof(*api) != sz) {
774c0020399SRobert Watson errno = EINVAL;
775c0020399SRobert Watson return (-1);
776c0020399SRobert Watson }
777c0020399SRobert Watson
778c0020399SRobert Watson return (auditon(A_SETPMASK, api, sz));
779c0020399SRobert Watson }
780c0020399SRobert Watson
781c0020399SRobert Watson int
audit_get_pinfo(auditpinfo_t * api,size_t sz)782c0020399SRobert Watson audit_get_pinfo(auditpinfo_t *api, size_t sz)
783c0020399SRobert Watson {
784c0020399SRobert Watson
785c0020399SRobert Watson if (sizeof(*api) != sz) {
786c0020399SRobert Watson errno = EINVAL;
787c0020399SRobert Watson return (-1);
788c0020399SRobert Watson }
789c0020399SRobert Watson
790c0020399SRobert Watson return (auditon(A_GETPINFO, api, sz));
791c0020399SRobert Watson }
792c0020399SRobert Watson
793c0020399SRobert Watson int
audit_get_pinfo_addr(auditpinfo_addr_t * apia,size_t sz)794c0020399SRobert Watson audit_get_pinfo_addr(auditpinfo_addr_t *apia, size_t sz)
795c0020399SRobert Watson {
796c0020399SRobert Watson
797c0020399SRobert Watson if (sizeof(*apia) != sz) {
798c0020399SRobert Watson errno = EINVAL;
799c0020399SRobert Watson return (-1);
800c0020399SRobert Watson }
801c0020399SRobert Watson
802c0020399SRobert Watson return (auditon(A_GETPINFO_ADDR, apia, sz));
803c0020399SRobert Watson }
804c0020399SRobert Watson
805c0020399SRobert Watson int
audit_get_sinfo_addr(auditinfo_addr_t * aia,size_t sz)806c0020399SRobert Watson audit_get_sinfo_addr(auditinfo_addr_t *aia, size_t sz)
807c0020399SRobert Watson {
808c0020399SRobert Watson
809c0020399SRobert Watson if (sizeof(*aia) != sz) {
810c0020399SRobert Watson errno = EINVAL;
811c0020399SRobert Watson return (-1);
812c0020399SRobert Watson }
813c0020399SRobert Watson
814c0020399SRobert Watson return (auditon(A_GETSINFO_ADDR, aia, sz));
815c0020399SRobert Watson }
816c0020399SRobert Watson
817c0020399SRobert Watson int
audit_get_stat(au_stat_t * stats,size_t sz)818c0020399SRobert Watson audit_get_stat(au_stat_t *stats, size_t sz)
819c0020399SRobert Watson {
820c0020399SRobert Watson
821c0020399SRobert Watson if (sizeof(*stats) != sz) {
822c0020399SRobert Watson errno = EINVAL;
823c0020399SRobert Watson return (-1);
824c0020399SRobert Watson }
825c0020399SRobert Watson
826c0020399SRobert Watson return (auditon(A_GETSTAT, stats, sz));
827c0020399SRobert Watson }
828c0020399SRobert Watson
829c0020399SRobert Watson int
audit_set_stat(au_stat_t * stats,size_t sz)830c0020399SRobert Watson audit_set_stat(au_stat_t *stats, size_t sz)
831c0020399SRobert Watson {
832c0020399SRobert Watson
833c0020399SRobert Watson if (sizeof(*stats) != sz) {
834c0020399SRobert Watson errno = EINVAL;
835c0020399SRobert Watson return (-1);
836c0020399SRobert Watson }
837c0020399SRobert Watson
838c0020399SRobert Watson return (auditon(A_GETSTAT, stats, sz));
839c0020399SRobert Watson }
840c0020399SRobert Watson
841c0020399SRobert Watson int
audit_get_cwd(char * path,size_t sz)842c0020399SRobert Watson audit_get_cwd(char *path, size_t sz)
843c0020399SRobert Watson {
844c0020399SRobert Watson
845c0020399SRobert Watson return (auditon(A_GETCWD, path, sz));
846c0020399SRobert Watson }
847c0020399SRobert Watson
848c0020399SRobert Watson int
audit_get_car(char * path,size_t sz)849c0020399SRobert Watson audit_get_car(char *path, size_t sz)
850c0020399SRobert Watson {
851c0020399SRobert Watson
852c0020399SRobert Watson return (auditon(A_GETCAR, path, sz));
853c0020399SRobert Watson }
854