2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #include <sys/types.h>
23 #include <sys/vnode_internal.h>
26 #include <sys/socketvar.h>
27 #include <sys/socket.h>
28 #include <sys/queue.h>
29 #include <sys/fcntl.h>
33 #include <bsm/audit.h>
34 #include <bsm/audit_record.h>
35 #include <bsm/audit_kernel.h>
36 #include <bsm/audit_kevents.h>
37 #include <bsm/audit_klib.h>
39 #include <netinet/in_systm.h>
40 #include <netinet/in.h>
41 #include <netinet/ip.h>
43 #include <kern/lock.h>
44 #include <kern/kalloc.h>
46 /* The number of BSM records allocated. */
47 static int bsm_rec_count
= 0;
50 * Records that can be recycled are maintained in the list given below
51 * The maximum number of elements that can be present in this list is
52 * bounded by MAX_AUDIT_RECORDS. Memory allocated for these records are never
55 LIST_HEAD(, au_record
) bsm_free_q
;
58 * Lock for serializing access to the list of audit records.
60 static mutex_t
*bsm_audit_mutex
;
62 static void audit_sys_auditon(struct audit_record
*ar
, struct au_record
*rec
);
65 * Initialize the BSM auditing subsystem.
70 printf("BSM auditing present\n");
71 LIST_INIT(&bsm_free_q
);
72 bsm_audit_mutex
= mutex_alloc(0);
77 * This call reserves memory for the audit record.
78 * Memory must be guaranteed before any auditable event can be
80 * The au_record structure maintains a reference to the
81 * memory allocated above and also the list of tokens associated
87 struct au_record
*rec
= NULL
;
90 * Find an unused record, remove it from the free list, mark as used
92 mutex_lock(bsm_audit_mutex
);
93 if (!LIST_EMPTY(&bsm_free_q
)) {
94 rec
= LIST_FIRST(&bsm_free_q
);
95 LIST_REMOVE(rec
, au_rec_q
);
97 mutex_unlock(bsm_audit_mutex
);
100 mutex_lock(bsm_audit_mutex
);
101 if (bsm_rec_count
>= MAX_AUDIT_RECORDS
) {
102 /* XXX We need to increase size of MAX_AUDIT_RECORDS */
103 mutex_unlock(bsm_audit_mutex
);
106 mutex_unlock(bsm_audit_mutex
);
109 * Create a new BSM kernel record.
111 rec
= (struct au_record
*)kalloc(sizeof(*rec
));
115 rec
->data
= (u_char
*)kalloc(MAX_AUDIT_RECORD_SIZE
* sizeof(u_char
));
116 if((rec
->data
) == NULL
) {
117 kfree(rec
, sizeof(*rec
));
120 mutex_lock(bsm_audit_mutex
);
122 mutex_unlock(bsm_audit_mutex
);
124 memset(rec
->data
, 0, MAX_AUDIT_RECORD_SIZE
);
126 TAILQ_INIT(&rec
->token_q
);
134 * Store the token with the record descriptor
137 int kau_write(struct au_record
*rec
, struct au_token
*tok
)
140 return -1; /* Invalid Token */
143 /* Add the token to the tail */
145 * XXX Not locking here -- we should not be writing to
146 * XXX the same audit record from different threads
148 TAILQ_INSERT_TAIL(&rec
->token_q
, tok
, tokens
);
150 rec
->len
+= tok
->len
; /* grow record length by token size bytes */
156 * Close out the audit record by adding the header token, identifying
157 * any missing tokens. Write out the tokens to the record memory.
160 kau_close(struct au_record
*rec
, struct timespec
*ctime
, short event
)
164 token_t
*cur
, *hdr
, *trail
;
167 tot_rec_size
= rec
->len
+ HEADER_SIZE
+ TRAILER_SIZE
;
168 if(tot_rec_size
<= MAX_AUDIT_RECORD_SIZE
) {
169 /* Create the header token */
170 hdr
= kau_to_header32(ctime
, tot_rec_size
, event
, 0);
173 /* Add to head of list */
174 TAILQ_INSERT_HEAD(&rec
->token_q
, hdr
, tokens
);
176 trail
= au_to_trailer(tot_rec_size
);
178 TAILQ_INSERT_TAIL(&rec
->token_q
, trail
, tokens
);
181 /* Serialize token data to the record */
183 rec
->len
= tot_rec_size
;
185 TAILQ_FOREACH(cur
, &rec
->token_q
, tokens
) {
186 memcpy(dptr
, cur
->t_data
, cur
->len
);
195 * Free a BSM audit record by releasing all the tokens and clearing the
196 * audit record information.
198 void kau_free(struct au_record
*rec
)
200 struct au_token
*tok
;
202 /* Free the token list */
203 while ((tok
= TAILQ_FIRST(&rec
->token_q
))) {
204 TAILQ_REMOVE(&rec
->token_q
, tok
, tokens
);
205 kfree(tok
, sizeof(*tok
) + tok
->len
);
211 mutex_lock(bsm_audit_mutex
);
213 /* Add the record to the freelist */
214 LIST_INSERT_HEAD(&bsm_free_q
, rec
, au_rec_q
);
216 mutex_unlock(bsm_audit_mutex
);
221 * XXX May want turn some (or all) of these macros into functions in order
222 * to reduce the generated code sized.
224 #define UPATH1_TOKENS \
226 if (ar->ar_valid_arg & ARG_UPATH1) { \
227 tok = au_to_path(ar->ar_arg_upath1); \
228 kau_write(rec, tok); \
232 #define UPATH2_TOKENS \
234 if (ar->ar_valid_arg & ARG_UPATH2) { \
235 tok = au_to_path(ar->ar_arg_upath2); \
236 kau_write(rec, tok); \
240 #define UPATH1_KPATH1_VNODE1_TOKENS \
242 if (ar->ar_valid_arg & ARG_UPATH1) { \
243 tok = au_to_path(ar->ar_arg_upath1); \
244 kau_write(rec, tok); \
246 if (ar->ar_valid_arg & ARG_KPATH1) { \
247 tok = au_to_path(ar->ar_arg_kpath1); \
248 kau_write(rec, tok); \
250 if (ar->ar_valid_arg & ARG_VNODE1) { \
251 tok = kau_to_attr32(&ar->ar_arg_vnode1);\
252 kau_write(rec, tok); \
256 #define KPATH1_VNODE1_TOKENS \
258 if (ar->ar_valid_arg & ARG_KPATH1) { \
259 tok = au_to_path(ar->ar_arg_kpath1); \
260 kau_write(rec, tok); \
262 if (ar->ar_valid_arg & ARG_VNODE1) { \
263 tok = kau_to_attr32(&ar->ar_arg_vnode1);\
264 kau_write(rec, tok); \
268 #define KPATH2_VNODE2_TOKENS \
270 if (ar->ar_valid_arg & ARG_KPATH2) { \
271 tok = au_to_path(ar->ar_arg_kpath2); \
272 kau_write(rec, tok); \
274 if (ar->ar_valid_arg & ARG_VNODE2) { \
275 tok = kau_to_attr32(&ar->ar_arg_vnode1);\
276 kau_write(rec, tok); \
280 #define FD_KPATH1_VNODE1_TOKENS \
282 if (ar->ar_valid_arg & ARG_KPATH1) { \
283 tok = au_to_path(ar->ar_arg_kpath1); \
284 kau_write(rec, tok); \
285 if (ar->ar_valid_arg & ARG_VNODE1) { \
286 tok = kau_to_attr32(&ar->ar_arg_vnode1);\
287 kau_write(rec, tok); \
290 tok = au_to_arg32(1, "no path: fd", ar->ar_arg_fd); \
291 kau_write(rec, tok); \
295 #define PROCESS_PID_TOKENS(argn) \
297 if ((ar->ar_arg_pid > 0) /* Kill a single process */ \
298 && (ar->ar_valid_arg & ARG_PROCESS)) { \
299 tok = au_to_process(ar->ar_arg_auid, ar->ar_arg_euid, \
300 ar->ar_arg_egid, ar->ar_arg_ruid, \
301 ar->ar_arg_rgid, ar->ar_arg_pid, \
302 ar->ar_arg_asid, &ar->ar_arg_termid); \
303 kau_write(rec, tok); \
305 tok = au_to_arg32(argn, "process", ar->ar_arg_pid);\
306 kau_write(rec, tok); \
311 * Implement auditing for the auditon() system call. The audit tokens
312 * that are generated depend on the command that was sent into the
313 * auditon() system call.
317 audit_sys_auditon(struct audit_record
*ar
, struct au_record
*rec
)
319 struct au_token
*tok
;
321 switch (ar
->ar_arg_cmd
) {
323 if (sizeof(ar
->ar_arg_auditon
.au_flags
) > 4)
324 tok
= au_to_arg64(1, "policy",
325 ar
->ar_arg_auditon
.au_flags
);
327 tok
= au_to_arg32(1, "policy",
328 ar
->ar_arg_auditon
.au_flags
);
332 tok
= au_to_arg32(2, "setkmask:as_success",
333 ar
->ar_arg_auditon
.au_mask
.am_success
);
335 tok
= au_to_arg32(2, "setkmask:as_failure",
336 ar
->ar_arg_auditon
.au_mask
.am_failure
);
340 tok
= au_to_arg32(3, "setqctrl:aq_hiwater",
341 ar
->ar_arg_auditon
.au_qctrl
.aq_hiwater
);
343 tok
= au_to_arg32(3, "setqctrl:aq_lowater",
344 ar
->ar_arg_auditon
.au_qctrl
.aq_lowater
);
346 tok
= au_to_arg32(3, "setqctrl:aq_bufsz",
347 ar
->ar_arg_auditon
.au_qctrl
.aq_bufsz
);
349 tok
= au_to_arg32(3, "setqctrl:aq_delay",
350 ar
->ar_arg_auditon
.au_qctrl
.aq_delay
);
352 tok
= au_to_arg32(3, "setqctrl:aq_minfree",
353 ar
->ar_arg_auditon
.au_qctrl
.aq_minfree
);
357 tok
= au_to_arg32(3, "setumask:as_success",
358 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_success
);
360 tok
= au_to_arg32(3, "setumask:as_failure",
361 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_failure
);
365 tok
= au_to_arg32(3, "setsmask:as_success",
366 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_success
);
368 tok
= au_to_arg32(3, "setsmask:as_failure",
369 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_failure
);
373 if (sizeof(ar
->ar_arg_auditon
.au_cond
) > 4)
374 tok
= au_to_arg64(3, "setcond",
375 ar
->ar_arg_auditon
.au_cond
);
377 tok
= au_to_arg32(3, "setcond",
378 ar
->ar_arg_auditon
.au_cond
);
382 tok
= au_to_arg32(2, "setclass:ec_event",
383 ar
->ar_arg_auditon
.au_evclass
.ec_number
);
385 tok
= au_to_arg32(3, "setclass:ec_class",
386 ar
->ar_arg_auditon
.au_evclass
.ec_class
);
390 tok
= au_to_arg32(2, "setpmask:as_success",
391 ar
->ar_arg_auditon
.au_aupinfo
.ap_mask
.am_success
);
393 tok
= au_to_arg32(2, "setpmask:as_failure",
394 ar
->ar_arg_auditon
.au_aupinfo
.ap_mask
.am_failure
);
398 tok
= au_to_arg32(2, "setfsize:filesize",
399 ar
->ar_arg_auditon
.au_fstat
.af_filesz
);
408 * Convert an internal kernel audit record to a BSM record and return
409 * a success/failure indicator. The BSM record is passed as an out
410 * parameter to this function.
412 * BSM_SUCCESS: The BSM record is valid
413 * BSM_FAILURE: Failure; the BSM record is NULL.
414 * BSM_NOAUDIT: The event is not auditable for BSM; the BSM record is NULL.
417 kaudit_to_bsm(struct kaudit_record
*kar
, struct au_record
**pau
)
419 struct au_token
*tok
, *subj_tok
;
420 struct au_record
*rec
;
422 struct audit_record
*ar
;
427 return (BSM_FAILURE
);
433 return (BSM_FAILURE
);
435 /* Create the subject token */
436 tid
.port
= ar
->ar_subj_term
.port
;
437 tid
.machine
= ar
->ar_subj_term
.machine
;
438 subj_tok
= au_to_subject32(ar
->ar_subj_auid
, /* audit ID */
439 ar
->ar_subj_cred
.cr_uid
, /* eff uid */
440 ar
->ar_subj_egid
, /* eff group id */
441 ar
->ar_subj_ruid
, /* real uid */
442 ar
->ar_subj_rgid
, /* real group id */
443 ar
->ar_subj_pid
, /* process id */
444 ar
->ar_subj_asid
, /* session ID */
447 /* The logic inside each case fills in the tokens required for the
448 * event, except for the header, trailer, and return tokens. The
449 * header and trailer tokens are added by the kau_close() function.
450 * The return token is added outside of the switch statement.
452 switch(ar
->ar_event
) {
455 * Socket-related events.
464 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
466 if (ar
->ar_valid_arg
& ARG_SADDRINET
) {
467 tok
= au_to_sock_inet(
468 (struct sockaddr_in
*)&ar
->ar_arg_sockaddr
);
471 if (ar
->ar_valid_arg
& ARG_SADDRUNIX
) {
472 tok
= au_to_sock_unix(
473 (struct sockaddr_un
*)&ar
->ar_arg_sockaddr
);
477 /* XXX Need to handle ARG_SADDRINET6 */
482 tok
= au_to_arg32(1,"domain", ar
->ar_arg_sockinfo
.so_domain
);
484 tok
= au_to_arg32(2,"type", ar
->ar_arg_sockinfo
.so_type
);
486 tok
= au_to_arg32(3,"protocol",ar
->ar_arg_sockinfo
.so_protocol
);
492 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
497 if (ar
->ar_valid_arg
& (ARG_KPATH1
| ARG_UPATH1
)) {
498 UPATH1_KPATH1_VNODE1_TOKENS
;
500 tok
= au_to_arg32(1, "accounting off", 0);
506 tok
= au_to_arg32(2, "setauid", ar
->ar_arg_auid
);
511 if (ar
->ar_valid_arg
& ARG_AUID
) {
512 tok
= au_to_arg32(1, "setaudit:auid", ar
->ar_arg_auid
);
514 tok
= au_to_arg32(1, "setaudit:port",
515 ar
->ar_arg_termid
.port
);
517 tok
= au_to_arg32(1, "setaudit:machine",
518 ar
->ar_arg_termid
.machine
);
520 tok
= au_to_arg32(1, "setaudit:as_success",
521 ar
->ar_arg_amask
.am_success
);
523 tok
= au_to_arg32(1, "setaudit:as_failure",
524 ar
->ar_arg_amask
.am_failure
);
526 tok
= au_to_arg32(1, "setaudit:asid", ar
->ar_arg_asid
);
531 case AUE_SETAUDIT_ADDR
:
532 break; /* XXX need to add arguments */
535 /* For AUDITON commands without own event, audit the cmd */
536 tok
= au_to_arg32(1, "cmd", ar
->ar_arg_cmd
);
540 case AUE_AUDITON_GETCAR
:
541 case AUE_AUDITON_GETCLASS
:
542 case AUE_AUDITON_GETCOND
:
543 case AUE_AUDITON_GETCWD
:
544 case AUE_AUDITON_GETKMASK
:
545 case AUE_AUDITON_GETSTAT
:
546 case AUE_AUDITON_GPOLICY
:
547 case AUE_AUDITON_GQCTRL
:
548 case AUE_AUDITON_SETCLASS
:
549 case AUE_AUDITON_SETCOND
:
550 case AUE_AUDITON_SETKMASK
:
551 case AUE_AUDITON_SETSMASK
:
552 case AUE_AUDITON_SETSTAT
:
553 case AUE_AUDITON_SETUMASK
:
554 case AUE_AUDITON_SPOLICY
:
555 case AUE_AUDITON_SQCTRL
:
556 if (ar
->ar_valid_arg
& ARG_AUDITON
) {
557 audit_sys_auditon(ar
, rec
);
562 UPATH1_KPATH1_VNODE1_TOKENS
;
569 case AUE_GETAUDIT_ADDR
:
576 case AUE_SETTIMEOFDAY
:
577 case AUE_NEWSYSTEMSHREG
:
578 /* Header, subject, and return tokens added at end */
585 case AUE_GETATTRLIST
:
594 case AUE_SETATTRLIST
:
601 UPATH1_KPATH1_VNODE1_TOKENS
;
605 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
607 UPATH1_KPATH1_VNODE1_TOKENS
;
611 tok
= au_to_arg32(2, "new file mode", ar
->ar_arg_mode
);
613 UPATH1_KPATH1_VNODE1_TOKENS
;
618 tok
= au_to_arg32(2, "new file uid", ar
->ar_arg_uid
);
620 tok
= au_to_arg32(3, "new file gid", ar
->ar_arg_gid
);
622 UPATH1_KPATH1_VNODE1_TOKENS
;
625 case AUE_EXCHANGEDATA
:
626 UPATH1_KPATH1_VNODE1_TOKENS
;
627 KPATH2_VNODE2_TOKENS
;
631 tok
= au_to_arg32(2, "fd", ar
->ar_arg_fd
);
633 UPATH1_KPATH1_VNODE1_TOKENS
;
637 tok
= au_to_arg32(2, "new file mode", ar
->ar_arg_mode
);
639 FD_KPATH1_VNODE1_TOKENS
;
643 tok
= au_to_arg32(1, "request", ar
->ar_arg_cmd
);
645 if (ar
->ar_valid_arg
& (ARG_KPATH1
| ARG_UPATH1
)) {
646 UPATH1_KPATH1_VNODE1_TOKENS
;
652 case AUE_FSTAT
: /* XXX Need to handle sockets and shm */
656 case AUE_GETDIRENTRIES
:
657 case AUE_GETDIRENTRIESATTR
:
658 FD_KPATH1_VNODE1_TOKENS
;
662 tok
= au_to_arg32(2, "new file uid", ar
->ar_arg_uid
);
664 tok
= au_to_arg32(3, "new file gid", ar
->ar_arg_gid
);
666 FD_KPATH1_VNODE1_TOKENS
;
670 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
672 if (ar
->ar_valid_arg
& ARG_VNODE1
) {
673 FD_KPATH1_VNODE1_TOKENS
;
678 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
680 FD_KPATH1_VNODE1_TOKENS
;
684 tok
= au_to_arg32(2, "operation", ar
->ar_arg_cmd
);
686 FD_KPATH1_VNODE1_TOKENS
;
691 tok
= au_to_arg32(0, "child PID", ar
->ar_arg_pid
);
696 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
698 tok
= au_to_arg32(1, "arg", (u_int32_t
)ar
->ar_arg_addr
);
700 if (ar
->ar_valid_arg
& ARG_VNODE1
) {
701 FD_KPATH1_VNODE1_TOKENS
;
703 if (ar
->ar_valid_arg
& ARG_SOCKINFO
) {
704 tok
= kau_to_socket(&ar
->ar_arg_sockinfo
);
707 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
714 tok
= au_to_arg32(2, "signal", ar
->ar_arg_signum
);
716 PROCESS_PID_TOKENS(1);
720 tok
= au_to_arg32(2, "ops", ar
->ar_arg_cmd
);
722 tok
= au_to_arg32(3, "trpoints", ar
->ar_arg_value
);
724 PROCESS_PID_TOKENS(4);
725 UPATH1_KPATH1_VNODE1_TOKENS
;
730 UPATH1_KPATH1_VNODE1_TOKENS
;
735 tok
= au_to_arg32(4, "base addr", (u_int32_t
)ar
->ar_arg_addr
);
737 UPATH1_KPATH1_VNODE1_TOKENS
;
741 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
743 UPATH1_KPATH1_VNODE1_TOKENS
;
747 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
749 tok
= au_to_arg32(3, "dev", ar
->ar_arg_dev
);
751 UPATH1_KPATH1_VNODE1_TOKENS
;
760 tok
= au_to_arg32(1, "addr", (u_int32_t
)ar
->ar_arg_addr
); /* LP64todo */
762 tok
= au_to_arg32(2, "len", ar
->ar_arg_len
); /* LP64todo */
764 if (ar
->ar_event
== AUE_MMAP
)
765 FD_KPATH1_VNODE1_TOKENS
;
766 if (ar
->ar_event
== AUE_MPROTECT
) {
767 tok
= au_to_arg32(3, "protection", ar
->ar_arg_value
);
770 if (ar
->ar_event
== AUE_MINHERIT
) {
771 tok
= au_to_arg32(3, "inherit", ar
->ar_arg_value
);
777 /* XXX Need to handle NFS mounts */
778 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
780 if (ar
->ar_valid_arg
& ARG_TEXT
) {
781 tok
= au_to_text(ar
->ar_arg_text
);
786 UPATH1_KPATH1_VNODE1_TOKENS
;
790 ar
->ar_event
= msgctl_to_event(ar
->ar_arg_svipc_cmd
);
794 tok
= au_to_arg32(1, "msg ID", ar
->ar_arg_svipc_id
);
796 if (ar
->ar_errno
!= EINVAL
) {
797 tok
= au_to_ipc(AT_IPC_MSG
, ar
->ar_arg_svipc_id
);
803 if (ar
->ar_errno
== 0) {
804 tok
= au_to_ipc(AT_IPC_MSG
, ar
->ar_arg_svipc_id
);
809 case AUE_RESETSHFILE
:
810 tok
= au_to_arg32(1, "base addr", (u_int32_t
)ar
->ar_arg_addr
);
820 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
831 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
833 UPATH1_KPATH1_VNODE1_TOKENS
;
837 tok
= au_to_arg32(1, "request", ar
->ar_arg_cmd
);
839 tok
= au_to_arg32(3, "addr", (u_int32_t
)ar
->ar_arg_addr
); /* LP64todo */
841 tok
= au_to_arg32(4, "data", ar
->ar_arg_value
);
843 PROCESS_PID_TOKENS(2);
847 tok
= au_to_arg32(2, "command", ar
->ar_arg_cmd
);
849 tok
= au_to_arg32(3, "uid", ar
->ar_arg_uid
);
851 UPATH1_KPATH1_VNODE1_TOKENS
;
855 tok
= au_to_arg32(1, "howto", ar
->ar_arg_cmd
);
860 ar
->ar_event
= semctl_to_event(ar
->ar_arg_svipc_cmd
);
863 tok
= au_to_arg32(1, "sem ID", ar
->ar_arg_svipc_id
);
865 if (ar
->ar_errno
!= EINVAL
) {
866 tok
= au_to_ipc(AT_IPC_SEM
, ar
->ar_arg_svipc_id
);
871 if (ar
->ar_errno
== 0) {
872 tok
= au_to_ipc(AT_IPC_SEM
, ar
->ar_arg_svipc_id
);
877 tok
= au_to_arg32(1, "gid", ar
->ar_arg_egid
);
881 tok
= au_to_arg32(1, "uid", ar
->ar_arg_euid
);
885 tok
= au_to_arg32(1, "gid", ar
->ar_arg_gid
);
889 tok
= au_to_arg32(1, "uid", ar
->ar_arg_uid
);
893 if (ar
->ar_valid_arg
& ARG_GROUPSET
) {
894 for(ctr
= 0; ctr
< ar
->ar_arg_groups
.gidset_size
; ctr
++)
896 tok
= au_to_arg32(1, "setgroups", ar
->ar_arg_groups
.gidset
[ctr
]);
903 if (ar
->ar_valid_arg
& ARG_TEXT
) {
904 tok
= au_to_text(ar
->ar_arg_text
);
909 case AUE_SETPRIORITY
:
910 tok
= au_to_arg32(1, "which", ar
->ar_arg_cmd
);
912 tok
= au_to_arg32(2, "who", ar
->ar_arg_uid
);
914 tok
= au_to_arg32(2, "priority", ar
->ar_arg_value
);
918 case AUE_SETPRIVEXEC
:
919 tok
= au_to_arg32(1, "flag", ar
->ar_arg_value
);
923 /* AUE_SHMAT, AUE_SHMCTL, AUE_SHMDT and AUE_SHMGET are SysV IPC */
925 tok
= au_to_arg32(1, "shmid", ar
->ar_arg_svipc_id
);
927 tok
= au_to_arg32(2, "shmaddr", (int)ar
->ar_arg_svipc_addr
);
929 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
930 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
932 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
938 tok
= au_to_arg32(1, "shmid", ar
->ar_arg_svipc_id
);
940 switch (ar
->ar_arg_svipc_cmd
) {
942 ar
->ar_event
= AUE_SHMCTL_STAT
;
943 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
944 tok
= au_to_ipc(AT_IPC_SHM
,
945 ar
->ar_arg_svipc_id
);
950 ar
->ar_event
= AUE_SHMCTL_RMID
;
951 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
952 tok
= au_to_ipc(AT_IPC_SHM
,
953 ar
->ar_arg_svipc_id
);
958 ar
->ar_event
= AUE_SHMCTL_SET
;
959 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
960 tok
= au_to_ipc(AT_IPC_SHM
,
961 ar
->ar_arg_svipc_id
);
963 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
968 break; /* We will audit a bad command */
973 tok
= au_to_arg32(1, "shmaddr", (int)ar
->ar_arg_svipc_addr
);
978 /* This is unusual; the return value is in an argument token */
979 tok
= au_to_arg32(0, "shmid", ar
->ar_arg_svipc_id
);
981 if (ar
->ar_valid_arg
& ARG_SVIPC_PERM
) {
982 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
984 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
989 /* AUE_SHMOPEN, AUE_SHMUNLINK, AUE_SEMOPEN, AUE_SEMCLOSE
990 * and AUE_SEMUNLINK are Posix IPC */
992 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
994 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
997 if (ar
->ar_valid_arg
& ARG_TEXT
) {
998 tok
= au_to_text(ar
->ar_arg_text
);
1001 if (ar
->ar_valid_arg
& ARG_POSIX_IPC_PERM
) {
1002 /* Create an ipc_perm token */
1003 struct ipc_perm perm
;
1004 perm
.uid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1005 perm
.gid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1006 perm
.cuid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1007 perm
.cgid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1008 perm
.mode
= ar
->ar_arg_pipc_perm
.pipc_mode
;
1011 tok
= au_to_ipc_perm(&perm
);
1012 kau_write(rec
, tok
);
1017 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1018 kau_write(rec
, tok
);
1019 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1020 kau_write(rec
, tok
);
1021 tok
= au_to_arg32(4, "value", ar
->ar_arg_value
);
1022 kau_write(rec
, tok
);
1025 if (ar
->ar_valid_arg
& ARG_TEXT
) {
1026 tok
= au_to_text(ar
->ar_arg_text
);
1027 kau_write(rec
, tok
);
1029 if (ar
->ar_valid_arg
& ARG_POSIX_IPC_PERM
) {
1030 /* Create an ipc_perm token */
1031 struct ipc_perm perm
;
1032 perm
.uid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1033 perm
.gid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1034 perm
.cuid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1035 perm
.cgid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1036 perm
.mode
= ar
->ar_arg_pipc_perm
.pipc_mode
;
1039 tok
= au_to_ipc_perm(&perm
);
1040 kau_write(rec
, tok
);
1045 tok
= au_to_arg32(1, "sem", ar
->ar_arg_fd
);
1046 kau_write(rec
, tok
);
1050 if (ar
->ar_valid_arg
& ARG_TEXT
) {
1051 tok
= au_to_text(ar
->ar_arg_text
);
1052 kau_write(rec
, tok
);
1054 UPATH1_KPATH1_VNODE1_TOKENS
;
1058 case AUE_SYSCTL_NONADMIN
:
1059 if (ar
->ar_valid_arg
& (ARG_CTLNAME
| ARG_LEN
)) {
1060 for (ctr
= 0; ctr
< ar
->ar_arg_len
; ctr
++) {
1061 tok
= au_to_arg32(1, "name", ar
->ar_arg_ctlname
[ctr
]);
1062 kau_write(rec
, tok
);
1065 if (ar
->ar_valid_arg
& ARG_VALUE
) {
1066 tok
= au_to_arg32(5, "newval", ar
->ar_arg_value
);
1067 kau_write(rec
, tok
);
1069 if (ar
->ar_valid_arg
& ARG_TEXT
) {
1070 tok
= au_to_text(ar
->ar_arg_text
);
1071 kau_write(rec
, tok
);
1076 tok
= au_to_arg32(1, "new mask", ar
->ar_arg_mask
);
1077 kau_write(rec
, tok
);
1078 tok
= au_to_arg32(0, "prev mask", ar
->ar_retval
);
1079 kau_write(rec
, tok
);
1082 /************************
1083 * Mach system calls *
1084 ************************/
1085 case AUE_INITPROCESS
:
1088 case AUE_PIDFORTASK
:
1089 tok
= au_to_arg32(1, "port", (u_int32_t
)ar
->ar_arg_mach_port1
);
1090 kau_write(rec
, tok
);
1091 if (ar
->ar_valid_arg
& ARG_PID
) {
1092 tok
= au_to_arg32(2, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1093 kau_write(rec
, tok
);
1097 case AUE_TASKFORPID
:
1098 tok
= au_to_arg32(1, "target port",
1099 (u_int32_t
)ar
->ar_arg_mach_port1
);
1100 kau_write(rec
, tok
);
1101 if (ar
->ar_valid_arg
& ARG_MACHPORT2
) {
1102 tok
= au_to_arg32(3, "task port",
1103 (u_int32_t
)ar
->ar_arg_mach_port2
);
1104 kau_write(rec
, tok
);
1106 PROCESS_PID_TOKENS(2);
1110 tok
= au_to_arg32(4, "priority",
1111 (u_int32_t
)ar
->ar_arg_value
);
1112 kau_write(rec
, tok
);
1113 UPATH1_KPATH1_VNODE1_TOKENS
;
1117 UPATH1_KPATH1_VNODE1_TOKENS
;
1121 tok
= au_to_arg32(3, "va", (u_int32_t
)ar
->ar_arg_addr
);
1122 kau_write(rec
, tok
);
1123 FD_KPATH1_VNODE1_TOKENS
;
1126 default: /* We shouldn't fall through to here. */
1127 printf("BSM conversion requested for unknown event %d\n",
1133 kau_write(rec
, subj_tok
);
1134 tok
= au_to_return32((char)ar
->ar_errno
, ar
->ar_retval
);
1135 kau_write(rec
, tok
); /* Every record gets a return token */
1137 kau_close(rec
, &ar
->ar_endtime
, ar
->ar_event
);
1144 * Verify that a record is a valid BSM record. This verification is
1145 * simple now, but may be expanded on sometime in the future.
1146 * Return 1 if the record is good, 0 otherwise.
1150 bsm_rec_verify(void* rec
)
1152 char c
= *(char *)rec
;
1154 * Check the token ID of the first token; it has to be a header
1157 /* XXXAUDIT There needs to be a token structure to map a token.
1158 * XXXAUDIT 'Shouldn't be simply looking at the first char.
1160 if ( (c
!= AU_HEADER_32_TOKEN
) &&
1161 (c
!= AU_HEADER_EX_32_TOKEN
) &&
1162 (c
!= AU_HEADER_64_TOKEN
) &&
1163 (c
!= AU_HEADER_EX_64_TOKEN
) ) {