2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <sys/types.h>
29 #include <sys/vnode_internal.h>
32 #include <sys/socketvar.h>
33 #include <sys/socket.h>
34 #include <sys/queue.h>
35 #include <sys/fcntl.h>
39 #include <bsm/audit.h>
40 #include <bsm/audit_record.h>
41 #include <bsm/audit_kernel.h>
42 #include <bsm/audit_kevents.h>
43 #include <bsm/audit_klib.h>
45 #include <netinet/in_systm.h>
46 #include <netinet/in.h>
47 #include <netinet/ip.h>
49 #include <kern/lock.h>
50 #include <kern/kalloc.h>
52 /* The number of BSM records allocated. */
53 static int bsm_rec_count
= 0;
56 * Records that can be recycled are maintained in the list given below
57 * The maximum number of elements that can be present in this list is
58 * bounded by MAX_AUDIT_RECORDS. Memory allocated for these records are never
61 LIST_HEAD(, au_record
) bsm_free_q
;
64 * Lock for serializing access to the list of audit records.
66 static mutex_t
*bsm_audit_mutex
;
68 static void audit_sys_auditon(struct audit_record
*ar
, struct au_record
*rec
);
71 * Initialize the BSM auditing subsystem.
76 printf("BSM auditing present\n");
77 LIST_INIT(&bsm_free_q
);
78 bsm_audit_mutex
= mutex_alloc(0);
83 * This call reserves memory for the audit record.
84 * Memory must be guaranteed before any auditable event can be
86 * The au_record structure maintains a reference to the
87 * memory allocated above and also the list of tokens associated
93 struct au_record
*rec
= NULL
;
96 * Find an unused record, remove it from the free list, mark as used
98 mutex_lock(bsm_audit_mutex
);
99 if (!LIST_EMPTY(&bsm_free_q
)) {
100 rec
= LIST_FIRST(&bsm_free_q
);
101 LIST_REMOVE(rec
, au_rec_q
);
103 mutex_unlock(bsm_audit_mutex
);
106 mutex_lock(bsm_audit_mutex
);
107 if (bsm_rec_count
>= MAX_AUDIT_RECORDS
) {
108 /* XXX We need to increase size of MAX_AUDIT_RECORDS */
109 mutex_unlock(bsm_audit_mutex
);
112 mutex_unlock(bsm_audit_mutex
);
115 * Create a new BSM kernel record.
117 rec
= (struct au_record
*)kalloc(sizeof(*rec
));
121 rec
->data
= (u_char
*)kalloc(MAX_AUDIT_RECORD_SIZE
* sizeof(u_char
));
122 if((rec
->data
) == NULL
) {
123 kfree(rec
, sizeof(*rec
));
126 mutex_lock(bsm_audit_mutex
);
128 mutex_unlock(bsm_audit_mutex
);
130 memset(rec
->data
, 0, MAX_AUDIT_RECORD_SIZE
);
132 TAILQ_INIT(&rec
->token_q
);
140 * Store the token with the record descriptor
143 int kau_write(struct au_record
*rec
, struct au_token
*tok
)
146 return -1; /* Invalid Token */
149 /* Add the token to the tail */
151 * XXX Not locking here -- we should not be writing to
152 * XXX the same audit record from different threads
154 TAILQ_INSERT_TAIL(&rec
->token_q
, tok
, tokens
);
156 rec
->len
+= tok
->len
; /* grow record length by token size bytes */
162 * Close out the audit record by adding the header token, identifying
163 * any missing tokens. Write out the tokens to the record memory.
166 kau_close(struct au_record
*rec
, struct timespec
*ctime
, short event
)
170 token_t
*cur
, *hdr
, *trail
;
173 tot_rec_size
= rec
->len
+ HEADER_SIZE
+ TRAILER_SIZE
;
174 if(tot_rec_size
<= MAX_AUDIT_RECORD_SIZE
) {
175 /* Create the header token */
176 hdr
= kau_to_header32(ctime
, tot_rec_size
, event
, 0);
179 /* Add to head of list */
180 TAILQ_INSERT_HEAD(&rec
->token_q
, hdr
, tokens
);
182 trail
= au_to_trailer(tot_rec_size
);
184 TAILQ_INSERT_TAIL(&rec
->token_q
, trail
, tokens
);
187 /* Serialize token data to the record */
189 rec
->len
= tot_rec_size
;
191 TAILQ_FOREACH(cur
, &rec
->token_q
, tokens
) {
192 memcpy(dptr
, cur
->t_data
, cur
->len
);
201 * Free a BSM audit record by releasing all the tokens and clearing the
202 * audit record information.
204 void kau_free(struct au_record
*rec
)
206 struct au_token
*tok
;
208 /* Free the token list */
209 while ((tok
= TAILQ_FIRST(&rec
->token_q
))) {
210 TAILQ_REMOVE(&rec
->token_q
, tok
, tokens
);
211 kfree(tok
, sizeof(*tok
) + tok
->len
);
217 mutex_lock(bsm_audit_mutex
);
219 /* Add the record to the freelist */
220 LIST_INSERT_HEAD(&bsm_free_q
, rec
, au_rec_q
);
222 mutex_unlock(bsm_audit_mutex
);
227 * XXX May want turn some (or all) of these macros into functions in order
228 * to reduce the generated code sized.
230 #define UPATH1_TOKENS \
232 if (ar->ar_valid_arg & ARG_UPATH1) { \
233 tok = au_to_path(ar->ar_arg_upath1); \
234 kau_write(rec, tok); \
238 #define UPATH2_TOKENS \
240 if (ar->ar_valid_arg & ARG_UPATH2) { \
241 tok = au_to_path(ar->ar_arg_upath2); \
242 kau_write(rec, tok); \
246 #define UPATH1_KPATH1_VNODE1_TOKENS \
248 if (ar->ar_valid_arg & ARG_UPATH1) { \
249 tok = au_to_path(ar->ar_arg_upath1); \
250 kau_write(rec, tok); \
252 if (ar->ar_valid_arg & ARG_KPATH1) { \
253 tok = au_to_path(ar->ar_arg_kpath1); \
254 kau_write(rec, tok); \
256 if (ar->ar_valid_arg & ARG_VNODE1) { \
257 tok = kau_to_attr32(&ar->ar_arg_vnode1);\
258 kau_write(rec, tok); \
262 #define KPATH1_VNODE1_TOKENS \
264 if (ar->ar_valid_arg & ARG_KPATH1) { \
265 tok = au_to_path(ar->ar_arg_kpath1); \
266 kau_write(rec, tok); \
268 if (ar->ar_valid_arg & ARG_VNODE1) { \
269 tok = kau_to_attr32(&ar->ar_arg_vnode1);\
270 kau_write(rec, tok); \
274 #define KPATH2_VNODE2_TOKENS \
276 if (ar->ar_valid_arg & ARG_KPATH2) { \
277 tok = au_to_path(ar->ar_arg_kpath2); \
278 kau_write(rec, tok); \
280 if (ar->ar_valid_arg & ARG_VNODE2) { \
281 tok = kau_to_attr32(&ar->ar_arg_vnode1);\
282 kau_write(rec, tok); \
286 #define FD_KPATH1_VNODE1_TOKENS \
288 if (ar->ar_valid_arg & ARG_KPATH1) { \
289 tok = au_to_path(ar->ar_arg_kpath1); \
290 kau_write(rec, tok); \
291 if (ar->ar_valid_arg & ARG_VNODE1) { \
292 tok = kau_to_attr32(&ar->ar_arg_vnode1);\
293 kau_write(rec, tok); \
296 tok = au_to_arg32(1, "no path: fd", ar->ar_arg_fd); \
297 kau_write(rec, tok); \
301 #define PROCESS_PID_TOKENS(argn) \
303 if ((ar->ar_arg_pid > 0) /* Kill a single process */ \
304 && (ar->ar_valid_arg & ARG_PROCESS)) { \
305 tok = au_to_process(ar->ar_arg_auid, ar->ar_arg_euid, \
306 ar->ar_arg_egid, ar->ar_arg_ruid, \
307 ar->ar_arg_rgid, ar->ar_arg_pid, \
308 ar->ar_arg_asid, &ar->ar_arg_termid); \
309 kau_write(rec, tok); \
311 tok = au_to_arg32(argn, "process", ar->ar_arg_pid);\
312 kau_write(rec, tok); \
317 * Implement auditing for the auditon() system call. The audit tokens
318 * that are generated depend on the command that was sent into the
319 * auditon() system call.
323 audit_sys_auditon(struct audit_record
*ar
, struct au_record
*rec
)
325 struct au_token
*tok
;
327 switch (ar
->ar_arg_cmd
) {
329 if (sizeof(ar
->ar_arg_auditon
.au_flags
) > 4)
330 tok
= au_to_arg64(1, "policy",
331 ar
->ar_arg_auditon
.au_flags
);
333 tok
= au_to_arg32(1, "policy",
334 ar
->ar_arg_auditon
.au_flags
);
338 tok
= au_to_arg32(2, "setkmask:as_success",
339 ar
->ar_arg_auditon
.au_mask
.am_success
);
341 tok
= au_to_arg32(2, "setkmask:as_failure",
342 ar
->ar_arg_auditon
.au_mask
.am_failure
);
346 tok
= au_to_arg32(3, "setqctrl:aq_hiwater",
347 ar
->ar_arg_auditon
.au_qctrl
.aq_hiwater
);
349 tok
= au_to_arg32(3, "setqctrl:aq_lowater",
350 ar
->ar_arg_auditon
.au_qctrl
.aq_lowater
);
352 tok
= au_to_arg32(3, "setqctrl:aq_bufsz",
353 ar
->ar_arg_auditon
.au_qctrl
.aq_bufsz
);
355 tok
= au_to_arg32(3, "setqctrl:aq_delay",
356 ar
->ar_arg_auditon
.au_qctrl
.aq_delay
);
358 tok
= au_to_arg32(3, "setqctrl:aq_minfree",
359 ar
->ar_arg_auditon
.au_qctrl
.aq_minfree
);
363 tok
= au_to_arg32(3, "setumask:as_success",
364 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_success
);
366 tok
= au_to_arg32(3, "setumask:as_failure",
367 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_failure
);
371 tok
= au_to_arg32(3, "setsmask:as_success",
372 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_success
);
374 tok
= au_to_arg32(3, "setsmask:as_failure",
375 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_failure
);
379 if (sizeof(ar
->ar_arg_auditon
.au_cond
) > 4)
380 tok
= au_to_arg64(3, "setcond",
381 ar
->ar_arg_auditon
.au_cond
);
383 tok
= au_to_arg32(3, "setcond",
384 ar
->ar_arg_auditon
.au_cond
);
388 tok
= au_to_arg32(2, "setclass:ec_event",
389 ar
->ar_arg_auditon
.au_evclass
.ec_number
);
391 tok
= au_to_arg32(3, "setclass:ec_class",
392 ar
->ar_arg_auditon
.au_evclass
.ec_class
);
396 tok
= au_to_arg32(2, "setpmask:as_success",
397 ar
->ar_arg_auditon
.au_aupinfo
.ap_mask
.am_success
);
399 tok
= au_to_arg32(2, "setpmask:as_failure",
400 ar
->ar_arg_auditon
.au_aupinfo
.ap_mask
.am_failure
);
404 tok
= au_to_arg32(2, "setfsize:filesize",
405 ar
->ar_arg_auditon
.au_fstat
.af_filesz
);
414 * Convert an internal kernel audit record to a BSM record and return
415 * a success/failure indicator. The BSM record is passed as an out
416 * parameter to this function.
418 * BSM_SUCCESS: The BSM record is valid
419 * BSM_FAILURE: Failure; the BSM record is NULL.
420 * BSM_NOAUDIT: The event is not auditable for BSM; the BSM record is NULL.
423 kaudit_to_bsm(struct kaudit_record
*kar
, struct au_record
**pau
)
425 struct au_token
*tok
, *subj_tok
;
426 struct au_record
*rec
;
428 struct audit_record
*ar
;
433 return (BSM_FAILURE
);
439 return (BSM_FAILURE
);
441 /* Create the subject token */
442 tid
.port
= ar
->ar_subj_term
.port
;
443 tid
.machine
= ar
->ar_subj_term
.machine
;
444 subj_tok
= au_to_subject32(ar
->ar_subj_auid
, /* audit ID */
445 ar
->ar_subj_cred
.cr_uid
, /* eff uid */
446 ar
->ar_subj_egid
, /* eff group id */
447 ar
->ar_subj_ruid
, /* real uid */
448 ar
->ar_subj_rgid
, /* real group id */
449 ar
->ar_subj_pid
, /* process id */
450 ar
->ar_subj_asid
, /* session ID */
453 /* The logic inside each case fills in the tokens required for the
454 * event, except for the header, trailer, and return tokens. The
455 * header and trailer tokens are added by the kau_close() function.
456 * The return token is added outside of the switch statement.
458 switch(ar
->ar_event
) {
461 * Socket-related events.
470 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
472 if (ar
->ar_valid_arg
& ARG_SADDRINET
) {
473 tok
= au_to_sock_inet(
474 (struct sockaddr_in
*)&ar
->ar_arg_sockaddr
);
477 if (ar
->ar_valid_arg
& ARG_SADDRUNIX
) {
478 tok
= au_to_sock_unix(
479 (struct sockaddr_un
*)&ar
->ar_arg_sockaddr
);
483 /* XXX Need to handle ARG_SADDRINET6 */
488 tok
= au_to_arg32(1,"domain", ar
->ar_arg_sockinfo
.so_domain
);
490 tok
= au_to_arg32(2,"type", ar
->ar_arg_sockinfo
.so_type
);
492 tok
= au_to_arg32(3,"protocol",ar
->ar_arg_sockinfo
.so_protocol
);
498 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
503 if (ar
->ar_valid_arg
& (ARG_KPATH1
| ARG_UPATH1
)) {
504 UPATH1_KPATH1_VNODE1_TOKENS
;
506 tok
= au_to_arg32(1, "accounting off", 0);
512 tok
= au_to_arg32(2, "setauid", ar
->ar_arg_auid
);
517 if (ar
->ar_valid_arg
& ARG_AUID
) {
518 tok
= au_to_arg32(1, "setaudit:auid", ar
->ar_arg_auid
);
520 tok
= au_to_arg32(1, "setaudit:port",
521 ar
->ar_arg_termid
.port
);
523 tok
= au_to_arg32(1, "setaudit:machine",
524 ar
->ar_arg_termid
.machine
);
526 tok
= au_to_arg32(1, "setaudit:as_success",
527 ar
->ar_arg_amask
.am_success
);
529 tok
= au_to_arg32(1, "setaudit:as_failure",
530 ar
->ar_arg_amask
.am_failure
);
532 tok
= au_to_arg32(1, "setaudit:asid", ar
->ar_arg_asid
);
537 case AUE_SETAUDIT_ADDR
:
538 break; /* XXX need to add arguments */
541 /* For AUDITON commands without own event, audit the cmd */
542 tok
= au_to_arg32(1, "cmd", ar
->ar_arg_cmd
);
546 case AUE_AUDITON_GETCAR
:
547 case AUE_AUDITON_GETCLASS
:
548 case AUE_AUDITON_GETCOND
:
549 case AUE_AUDITON_GETCWD
:
550 case AUE_AUDITON_GETKMASK
:
551 case AUE_AUDITON_GETSTAT
:
552 case AUE_AUDITON_GPOLICY
:
553 case AUE_AUDITON_GQCTRL
:
554 case AUE_AUDITON_SETCLASS
:
555 case AUE_AUDITON_SETCOND
:
556 case AUE_AUDITON_SETKMASK
:
557 case AUE_AUDITON_SETSMASK
:
558 case AUE_AUDITON_SETSTAT
:
559 case AUE_AUDITON_SETUMASK
:
560 case AUE_AUDITON_SPOLICY
:
561 case AUE_AUDITON_SQCTRL
:
562 if (ar
->ar_valid_arg
& ARG_AUDITON
) {
563 audit_sys_auditon(ar
, rec
);
568 UPATH1_KPATH1_VNODE1_TOKENS
;
575 case AUE_GETAUDIT_ADDR
:
582 case AUE_SETTIMEOFDAY
:
583 case AUE_NEWSYSTEMSHREG
:
584 /* Header, subject, and return tokens added at end */
591 case AUE_GETATTRLIST
:
600 case AUE_SETATTRLIST
:
607 UPATH1_KPATH1_VNODE1_TOKENS
;
611 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
613 UPATH1_KPATH1_VNODE1_TOKENS
;
617 tok
= au_to_arg32(2, "new file mode", ar
->ar_arg_mode
);
619 UPATH1_KPATH1_VNODE1_TOKENS
;
624 tok
= au_to_arg32(2, "new file uid", ar
->ar_arg_uid
);
626 tok
= au_to_arg32(3, "new file gid", ar
->ar_arg_gid
);
628 UPATH1_KPATH1_VNODE1_TOKENS
;
631 case AUE_EXCHANGEDATA
:
632 UPATH1_KPATH1_VNODE1_TOKENS
;
633 KPATH2_VNODE2_TOKENS
;
637 tok
= au_to_arg32(2, "fd", ar
->ar_arg_fd
);
639 UPATH1_KPATH1_VNODE1_TOKENS
;
643 tok
= au_to_arg32(2, "new file mode", ar
->ar_arg_mode
);
645 FD_KPATH1_VNODE1_TOKENS
;
649 tok
= au_to_arg32(1, "request", ar
->ar_arg_cmd
);
651 if (ar
->ar_valid_arg
& (ARG_KPATH1
| ARG_UPATH1
)) {
652 UPATH1_KPATH1_VNODE1_TOKENS
;
658 case AUE_FSTAT
: /* XXX Need to handle sockets and shm */
662 case AUE_GETDIRENTRIES
:
663 case AUE_GETDIRENTRIESATTR
:
664 FD_KPATH1_VNODE1_TOKENS
;
668 tok
= au_to_arg32(2, "new file uid", ar
->ar_arg_uid
);
670 tok
= au_to_arg32(3, "new file gid", ar
->ar_arg_gid
);
672 FD_KPATH1_VNODE1_TOKENS
;
676 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
678 if (ar
->ar_valid_arg
& ARG_VNODE1
) {
679 FD_KPATH1_VNODE1_TOKENS
;
684 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
686 FD_KPATH1_VNODE1_TOKENS
;
690 tok
= au_to_arg32(2, "operation", ar
->ar_arg_cmd
);
692 FD_KPATH1_VNODE1_TOKENS
;
697 tok
= au_to_arg32(0, "child PID", ar
->ar_arg_pid
);
702 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
704 tok
= au_to_arg32(1, "arg", (u_int32_t
)ar
->ar_arg_addr
);
706 if (ar
->ar_valid_arg
& ARG_VNODE1
) {
707 FD_KPATH1_VNODE1_TOKENS
;
709 if (ar
->ar_valid_arg
& ARG_SOCKINFO
) {
710 tok
= kau_to_socket(&ar
->ar_arg_sockinfo
);
713 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
720 tok
= au_to_arg32(2, "signal", ar
->ar_arg_signum
);
722 PROCESS_PID_TOKENS(1);
726 tok
= au_to_arg32(2, "ops", ar
->ar_arg_cmd
);
728 tok
= au_to_arg32(3, "trpoints", ar
->ar_arg_value
);
730 PROCESS_PID_TOKENS(4);
731 UPATH1_KPATH1_VNODE1_TOKENS
;
736 UPATH1_KPATH1_VNODE1_TOKENS
;
741 tok
= au_to_arg32(4, "base addr", (u_int32_t
)ar
->ar_arg_addr
);
743 UPATH1_KPATH1_VNODE1_TOKENS
;
747 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
749 UPATH1_KPATH1_VNODE1_TOKENS
;
753 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
755 tok
= au_to_arg32(3, "dev", ar
->ar_arg_dev
);
757 UPATH1_KPATH1_VNODE1_TOKENS
;
766 tok
= au_to_arg32(1, "addr", (u_int32_t
)ar
->ar_arg_addr
); /* LP64todo */
768 tok
= au_to_arg32(2, "len", ar
->ar_arg_len
); /* LP64todo */
770 if (ar
->ar_event
== AUE_MMAP
)
771 FD_KPATH1_VNODE1_TOKENS
;
772 if (ar
->ar_event
== AUE_MPROTECT
) {
773 tok
= au_to_arg32(3, "protection", ar
->ar_arg_value
);
776 if (ar
->ar_event
== AUE_MINHERIT
) {
777 tok
= au_to_arg32(3, "inherit", ar
->ar_arg_value
);
783 /* XXX Need to handle NFS mounts */
784 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
786 if (ar
->ar_valid_arg
& ARG_TEXT
) {
787 tok
= au_to_text(ar
->ar_arg_text
);
792 UPATH1_KPATH1_VNODE1_TOKENS
;
796 ar
->ar_event
= msgctl_to_event(ar
->ar_arg_svipc_cmd
);
800 tok
= au_to_arg32(1, "msg ID", ar
->ar_arg_svipc_id
);
802 if (ar
->ar_errno
!= EINVAL
) {
803 tok
= au_to_ipc(AT_IPC_MSG
, ar
->ar_arg_svipc_id
);
809 if (ar
->ar_errno
== 0) {
810 tok
= au_to_ipc(AT_IPC_MSG
, ar
->ar_arg_svipc_id
);
815 case AUE_RESETSHFILE
:
816 tok
= au_to_arg32(1, "base addr", (u_int32_t
)ar
->ar_arg_addr
);
826 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
837 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
839 UPATH1_KPATH1_VNODE1_TOKENS
;
843 tok
= au_to_arg32(1, "request", ar
->ar_arg_cmd
);
845 tok
= au_to_arg32(3, "addr", (u_int32_t
)ar
->ar_arg_addr
); /* LP64todo */
847 tok
= au_to_arg32(4, "data", ar
->ar_arg_value
);
849 PROCESS_PID_TOKENS(2);
853 tok
= au_to_arg32(2, "command", ar
->ar_arg_cmd
);
855 tok
= au_to_arg32(3, "uid", ar
->ar_arg_uid
);
857 UPATH1_KPATH1_VNODE1_TOKENS
;
861 tok
= au_to_arg32(1, "howto", ar
->ar_arg_cmd
);
866 ar
->ar_event
= semctl_to_event(ar
->ar_arg_svipc_cmd
);
869 tok
= au_to_arg32(1, "sem ID", ar
->ar_arg_svipc_id
);
871 if (ar
->ar_errno
!= EINVAL
) {
872 tok
= au_to_ipc(AT_IPC_SEM
, ar
->ar_arg_svipc_id
);
877 if (ar
->ar_errno
== 0) {
878 tok
= au_to_ipc(AT_IPC_SEM
, ar
->ar_arg_svipc_id
);
883 tok
= au_to_arg32(1, "gid", ar
->ar_arg_egid
);
887 tok
= au_to_arg32(1, "uid", ar
->ar_arg_euid
);
891 tok
= au_to_arg32(1, "gid", ar
->ar_arg_gid
);
895 tok
= au_to_arg32(1, "uid", ar
->ar_arg_uid
);
899 if (ar
->ar_valid_arg
& ARG_GROUPSET
) {
900 for(ctr
= 0; ctr
< ar
->ar_arg_groups
.gidset_size
; ctr
++)
902 tok
= au_to_arg32(1, "setgroups", ar
->ar_arg_groups
.gidset
[ctr
]);
909 if (ar
->ar_valid_arg
& ARG_TEXT
) {
910 tok
= au_to_text(ar
->ar_arg_text
);
915 case AUE_SETPRIORITY
:
916 tok
= au_to_arg32(1, "which", ar
->ar_arg_cmd
);
918 tok
= au_to_arg32(2, "who", ar
->ar_arg_uid
);
920 tok
= au_to_arg32(2, "priority", ar
->ar_arg_value
);
924 case AUE_SETPRIVEXEC
:
925 tok
= au_to_arg32(1, "flag", ar
->ar_arg_value
);
929 /* AUE_SHMAT, AUE_SHMCTL, AUE_SHMDT and AUE_SHMGET are SysV IPC */
931 tok
= au_to_arg32(1, "shmid", ar
->ar_arg_svipc_id
);
933 tok
= au_to_arg32(2, "shmaddr", (int)ar
->ar_arg_svipc_addr
);
935 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
936 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
938 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
944 tok
= au_to_arg32(1, "shmid", ar
->ar_arg_svipc_id
);
946 switch (ar
->ar_arg_svipc_cmd
) {
948 ar
->ar_event
= AUE_SHMCTL_STAT
;
949 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
950 tok
= au_to_ipc(AT_IPC_SHM
,
951 ar
->ar_arg_svipc_id
);
956 ar
->ar_event
= AUE_SHMCTL_RMID
;
957 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
958 tok
= au_to_ipc(AT_IPC_SHM
,
959 ar
->ar_arg_svipc_id
);
964 ar
->ar_event
= AUE_SHMCTL_SET
;
965 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
966 tok
= au_to_ipc(AT_IPC_SHM
,
967 ar
->ar_arg_svipc_id
);
969 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
974 break; /* We will audit a bad command */
979 tok
= au_to_arg32(1, "shmaddr", (int)ar
->ar_arg_svipc_addr
);
984 /* This is unusual; the return value is in an argument token */
985 tok
= au_to_arg32(0, "shmid", ar
->ar_arg_svipc_id
);
987 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
988 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
990 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
995 /* AUE_SHMOPEN, AUE_SHMUNLINK, AUE_SEMOPEN, AUE_SEMCLOSE
996 * and AUE_SEMUNLINK are Posix IPC */
998 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1000 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1001 kau_write(rec
, tok
);
1003 if (ar
->ar_valid_arg
& ARG_TEXT
) {
1004 tok
= au_to_text(ar
->ar_arg_text
);
1005 kau_write(rec
, tok
);
1007 if (ar
->ar_valid_arg
& ARG_POSIX_IPC_PERM
) {
1008 /* Create an ipc_perm token */
1009 struct ipc_perm perm
;
1010 perm
.uid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1011 perm
.gid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1012 perm
.cuid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1013 perm
.cgid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1014 perm
.mode
= ar
->ar_arg_pipc_perm
.pipc_mode
;
1017 tok
= au_to_ipc_perm(&perm
);
1018 kau_write(rec
, tok
);
1023 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1024 kau_write(rec
, tok
);
1025 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1026 kau_write(rec
, tok
);
1027 tok
= au_to_arg32(4, "value", ar
->ar_arg_value
);
1028 kau_write(rec
, tok
);
1031 if (ar
->ar_valid_arg
& ARG_TEXT
) {
1032 tok
= au_to_text(ar
->ar_arg_text
);
1033 kau_write(rec
, tok
);
1035 if (ar
->ar_valid_arg
& ARG_POSIX_IPC_PERM
) {
1036 /* Create an ipc_perm token */
1037 struct ipc_perm perm
;
1038 perm
.uid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1039 perm
.gid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1040 perm
.cuid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1041 perm
.cgid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1042 perm
.mode
= ar
->ar_arg_pipc_perm
.pipc_mode
;
1045 tok
= au_to_ipc_perm(&perm
);
1046 kau_write(rec
, tok
);
1051 tok
= au_to_arg32(1, "sem", ar
->ar_arg_fd
);
1052 kau_write(rec
, tok
);
1056 if (ar
->ar_valid_arg
& ARG_TEXT
) {
1057 tok
= au_to_text(ar
->ar_arg_text
);
1058 kau_write(rec
, tok
);
1060 UPATH1_KPATH1_VNODE1_TOKENS
;
1064 case AUE_SYSCTL_NONADMIN
:
1065 if (ar
->ar_valid_arg
& (ARG_CTLNAME
| ARG_LEN
)) {
1066 for (ctr
= 0; ctr
< ar
->ar_arg_len
; ctr
++) {
1067 tok
= au_to_arg32(1, "name", ar
->ar_arg_ctlname
[ctr
]);
1068 kau_write(rec
, tok
);
1071 if (ar
->ar_valid_arg
& ARG_VALUE
) {
1072 tok
= au_to_arg32(5, "newval", ar
->ar_arg_value
);
1073 kau_write(rec
, tok
);
1075 if (ar
->ar_valid_arg
& ARG_TEXT
) {
1076 tok
= au_to_text(ar
->ar_arg_text
);
1077 kau_write(rec
, tok
);
1082 tok
= au_to_arg32(1, "new mask", ar
->ar_arg_mask
);
1083 kau_write(rec
, tok
);
1084 tok
= au_to_arg32(0, "prev mask", ar
->ar_retval
);
1085 kau_write(rec
, tok
);
1088 /************************
1089 * Mach system calls *
1090 ************************/
1091 case AUE_INITPROCESS
:
1094 case AUE_PIDFORTASK
:
1095 tok
= au_to_arg32(1, "port", (u_int32_t
)ar
->ar_arg_mach_port1
);
1096 kau_write(rec
, tok
);
1097 if (ar
->ar_valid_arg
& ARG_PID
) {
1098 tok
= au_to_arg32(2, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1099 kau_write(rec
, tok
);
1103 case AUE_TASKFORPID
:
1104 tok
= au_to_arg32(1, "target port",
1105 (u_int32_t
)ar
->ar_arg_mach_port1
);
1106 kau_write(rec
, tok
);
1107 if (ar
->ar_valid_arg
& ARG_MACHPORT2
) {
1108 tok
= au_to_arg32(3, "task port",
1109 (u_int32_t
)ar
->ar_arg_mach_port2
);
1110 kau_write(rec
, tok
);
1112 PROCESS_PID_TOKENS(2);
1116 tok
= au_to_arg32(4, "priority",
1117 (u_int32_t
)ar
->ar_arg_value
);
1118 kau_write(rec
, tok
);
1119 UPATH1_KPATH1_VNODE1_TOKENS
;
1123 UPATH1_KPATH1_VNODE1_TOKENS
;
1127 tok
= au_to_arg32(3, "va", (u_int32_t
)ar
->ar_arg_addr
);
1128 kau_write(rec
, tok
);
1129 FD_KPATH1_VNODE1_TOKENS
;
1132 default: /* We shouldn't fall through to here. */
1133 printf("BSM conversion requested for unknown event %d\n",
1139 kau_write(rec
, subj_tok
);
1140 tok
= au_to_return32((char)ar
->ar_errno
, ar
->ar_retval
);
1141 kau_write(rec
, tok
); /* Every record gets a return token */
1143 kau_close(rec
, &ar
->ar_endtime
, ar
->ar_event
);
1150 * Verify that a record is a valid BSM record. This verification is
1151 * simple now, but may be expanded on sometime in the future.
1152 * Return 1 if the record is good, 0 otherwise.
1156 bsm_rec_verify(void* rec
)
1158 char c
= *(char *)rec
;
1160 * Check the token ID of the first token; it has to be a header
1163 /* XXXAUDIT There needs to be a token structure to map a token.
1164 * XXXAUDIT 'Shouldn't be simply looking at the first char.
1166 if ( (c
!= AU_HEADER_32_TOKEN
) &&
1167 (c
!= AU_HEADER_EX_32_TOKEN
) &&
1168 (c
!= AU_HEADER_64_TOKEN
) &&
1169 (c
!= AU_HEADER_EX_64_TOKEN
) ) {