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@
29 #include <sys/types.h>
31 #include <sys/event.h>
32 #include <sys/ucred.h>
35 #include <bsm/audit.h>
36 #include <bsm/audit_record.h>
37 #include <bsm/audit_klib.h>
38 #include <bsm/audit_kernel.h>
40 #include <kern/clock.h>
41 #include <kern/kalloc.h>
45 #define GET_TOKEN_AREA(tok, dptr, length) \
47 tok = (token_t *)kalloc(sizeof(*tok) + length); \
51 dptr = tok->t_data = (u_char *)&tok[1];\
52 memset(dptr, 0, length);\
61 * argument value 4 bytes/8 bytes (32-bit/64-bit value)
63 * text N bytes + 1 terminating NULL byte
66 au_to_arg32(char n
, const char *text
, u_int32_t v
)
76 textlen
= strlen(text
);
78 GET_TOKEN_AREA(t
, dptr
, 9 + textlen
);
85 ADD_U_CHAR(dptr
, AU_ARG32_TOKEN
);
88 ADD_U_INT16(dptr
, textlen
);
89 ADD_STRING(dptr
, text
, textlen
);
96 au_to_arg64(char n
, const char *text
, u_int64_t v
)
106 textlen
= strlen(text
);
108 GET_TOKEN_AREA(t
, dptr
, 13 + textlen
);
115 ADD_U_CHAR(dptr
, AU_ARG64_TOKEN
);
117 ADD_U_INT64(dptr
, v
);
118 ADD_U_INT16(dptr
, textlen
);
119 ADD_STRING(dptr
, text
, textlen
);
126 au_to_arg(char n
, char *text
, u_int32_t v
)
128 return au_to_arg32(n
, text
, v
);
133 * file access mode 4 bytes
134 * owner user ID 4 bytes
135 * owner group ID 4 bytes
136 * file system ID 4 bytes
138 * device 4 bytes/8 bytes (32-bit/64-bit)
140 token_t
*au_to_attr32(__unused
struct vnode_attr
*attr
)
145 /* Kernel-specific version of the above function */
146 token_t
*kau_to_attr32(struct vnode_au_info
*vni
)
151 u_int16_t pad0_16
= 0;
152 u_int32_t pad0_32
= 0;
158 GET_TOKEN_AREA(t
, dptr
, 29);
163 ADD_U_CHAR(dptr
, AU_ATTR32_TOKEN
);
166 * Darwin defines the size for the file mode as 2 bytes;
167 * BSM defines 4. So we copy in a 0 first.
169 ADD_U_INT16(dptr
, pad0_16
);
170 ADD_U_INT16(dptr
, vni
->vn_mode
);
172 ADD_U_INT32(dptr
, vni
->vn_uid
);
173 ADD_U_INT32(dptr
, vni
->vn_gid
);
174 ADD_U_INT32(dptr
, vni
->vn_fsid
);
177 * Darwin defines the size for fileid as 4 bytes;
178 * BSM defines 8. So we copy in a 0 first.
180 fileid
= vni
->vn_fileid
;
181 ADD_U_INT32(dptr
, pad0_32
);
182 ADD_U_INT32(dptr
, fileid
);
184 ADD_U_INT32(dptr
, vni
->vn_dev
);
189 token_t
*au_to_attr64(__unused
struct vnode_attr
*attr
)
194 token_t
*kau_to_attr64(__unused
struct vnode_au_info
*vni
)
199 token_t
*au_to_attr(struct vnode_attr
*attr
)
201 return au_to_attr32(attr
);
208 * how to print 1 byte
211 * data items (depends on basic unit)
213 token_t
*au_to_data(char unit_print
, char unit_type
,
214 char unit_count
, unsigned char *p
)
218 size_t datasize
, totdata
;
224 /* Determine the size of the basic unit */
226 case AUR_BYTE
: datasize
= AUR_BYTE_SIZE
;
229 case AUR_SHORT
: datasize
= AUR_SHORT_SIZE
;
232 case AUR_LONG
: datasize
= AUR_LONG_SIZE
;
235 default: return NULL
;
238 totdata
= datasize
* unit_count
;
240 GET_TOKEN_AREA(t
, dptr
, totdata
+ 4);
245 ADD_U_CHAR(dptr
, AU_ARB_TOKEN
);
246 ADD_U_CHAR(dptr
, unit_print
);
247 ADD_U_CHAR(dptr
, unit_type
);
248 ADD_U_CHAR(dptr
, unit_count
);
249 ADD_MEM(dptr
, p
, totdata
);
257 * return value 4 bytes
259 token_t
*au_to_exit(int retval
, int err
)
264 GET_TOKEN_AREA(t
, dptr
, 9);
269 ADD_U_CHAR(dptr
, AU_EXIT_TOKEN
);
270 ADD_U_INT32(dptr
, err
);
271 ADD_U_INT32(dptr
, retval
);
279 au_to_groups(gid_t
*groups
)
281 return au_to_newgroups(MAX_GROUPS
, groups
);
286 * number groups 2 bytes
287 * group list count * 4 bytes
289 token_t
*au_to_newgroups(u_int16_t n
, gid_t
*groups
)
299 GET_TOKEN_AREA(t
, dptr
, n
* 4 + 3);
304 ADD_U_CHAR(dptr
, AU_NEWGROUPS_TOKEN
);
305 ADD_U_INT16(dptr
, n
);
306 for(i
= 0; i
< n
; i
++) {
307 ADD_U_INT32(dptr
, groups
[i
]);
318 * internet address 4 bytes
320 token_t
*au_to_in_addr(struct in_addr
*internet_addr
)
325 if(internet_addr
== NULL
) {
329 GET_TOKEN_AREA(t
, dptr
, 5);
334 ADD_U_CHAR(dptr
, AU_IN_ADDR_TOKEN
);
335 ADD_U_INT32(dptr
, internet_addr
->s_addr
);
342 * address type/length 4 bytes
345 token_t
*au_to_in_addr_ex(struct in6_addr
*internet_addr
)
349 u_int32_t type
= AF_INET6
;
351 if(internet_addr
== NULL
) {
355 GET_TOKEN_AREA(t
, dptr
, 21);
360 ADD_U_CHAR(dptr
, AU_IN_ADDR_EX_TOKEN
);
361 ADD_U_INT32(dptr
, type
);
362 ADD_U_INT32(dptr
, internet_addr
->__u6_addr
.__u6_addr32
[0]);
363 ADD_U_INT32(dptr
, internet_addr
->__u6_addr
.__u6_addr32
[1]);
364 ADD_U_INT32(dptr
, internet_addr
->__u6_addr
.__u6_addr32
[2]);
365 ADD_U_INT32(dptr
, internet_addr
->__u6_addr
.__u6_addr32
[3]);
374 token_t
*au_to_ip(struct ip
*ip
)
383 GET_TOKEN_AREA(t
, dptr
, 21);
388 ADD_U_CHAR(dptr
, AU_IP_TOKEN
);
389 ADD_MEM(dptr
, ip
, sizeof(struct ip
));
396 * object ID type 1 byte
399 token_t
*au_to_ipc(char type
, int id
)
405 GET_TOKEN_AREA(t
, dptr
, 6);
410 ADD_U_CHAR(dptr
, AU_IPC_TOKEN
);
411 ADD_U_CHAR(dptr
, type
);
412 ADD_U_INT32(dptr
, id
);
419 * owner user ID 4 bytes
420 * owner group ID 4 bytes
421 * creator user ID 4 bytes
422 * creator group ID 4 bytes
423 * access mode 4 bytes
424 * slot sequence # 4 bytes
427 token_t
*au_to_ipc_perm(struct ipc_perm
*perm
)
437 GET_TOKEN_AREA(t
, dptr
, 29);
443 * Darwin defines the sizes for ipc_perm members
444 * as 2 bytes; BSM defines 4. So we copy in a 0 first.
446 ADD_U_CHAR(dptr
, AU_IPCPERM_TOKEN
);
448 ADD_U_INT32(dptr
, perm
->uid
);
449 ADD_U_INT32(dptr
, perm
->gid
);
450 ADD_U_INT32(dptr
, perm
->cuid
);
451 ADD_U_INT32(dptr
, perm
->cgid
);
453 ADD_U_INT16(dptr
, pad0
);
454 ADD_U_INT16(dptr
, perm
->mode
);
456 ADD_U_INT16(dptr
, pad0
);
457 ADD_U_INT16(dptr
, perm
->_seq
);
459 ADD_U_INT16(dptr
, pad0
);
460 ADD_U_INT16(dptr
, perm
->_key
);
468 * port IP address 2 bytes
470 token_t
*au_to_iport(u_int16_t iport
)
476 GET_TOKEN_AREA(t
, dptr
, 3);
481 ADD_U_CHAR(dptr
, AU_IPORT_TOKEN
);
482 ADD_U_INT16(dptr
, iport
);
493 token_t
*au_to_opaque(char *data
, u_int16_t bytes
)
498 if((data
== NULL
) || (bytes
<= 0)) {
502 GET_TOKEN_AREA(t
, dptr
, bytes
+ 3);
507 ADD_U_CHAR(dptr
, AU_OPAQUE_TOKEN
);
508 ADD_U_INT16(dptr
, bytes
);
509 ADD_MEM(dptr
, data
, bytes
);
515 * Kernel version of the add file token function, where the time value
516 * is passed in as an additional parameter.
518 * seconds of time 4 bytes
519 * milliseconds of time 4 bytes
520 * file name len 2 bytes
521 * file pathname N bytes + 1 terminating NULL byte
523 token_t
*kau_to_file(const char *file
, const struct timeval
*tv
)
528 u_int32_t timems
= tv
->tv_usec
/1000; /* We need time in ms */
533 filelen
= strlen(file
);
535 GET_TOKEN_AREA(t
, dptr
, filelen
+ 12);
542 ADD_U_CHAR(dptr
, AU_FILE_TOKEN
);
544 /* Add the timestamp */
545 ADD_U_INT32(dptr
, tv
->tv_sec
);
546 ADD_U_INT32(dptr
, timems
);
548 ADD_U_INT16(dptr
, filelen
);
549 ADD_STRING(dptr
, file
, filelen
);
557 * text length 2 bytes
558 * text N bytes + 1 terminating NULL byte
560 token_t
*au_to_text(const char *text
)
569 textlen
= strlen(text
);
571 GET_TOKEN_AREA(t
, dptr
, textlen
+ 4);
578 ADD_U_CHAR(dptr
, AU_TEXT_TOKEN
);
579 ADD_U_INT16(dptr
, textlen
);
580 ADD_STRING(dptr
, text
, textlen
);
587 * path length 2 bytes
588 * path N bytes + 1 terminating NULL byte
590 token_t
*au_to_path(char *text
)
599 textlen
= strlen(text
);
601 GET_TOKEN_AREA(t
, dptr
, textlen
+ 4);
608 ADD_U_CHAR(dptr
, AU_PATH_TOKEN
);
609 ADD_U_INT16(dptr
, textlen
);
610 ADD_STRING(dptr
, text
, textlen
);
618 * effective user ID 4 bytes
619 * effective group ID 4 bytes
620 * real user ID 4 bytes
621 * real group ID 4 bytes
625 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
626 * machine address 4 bytes
628 token_t
*au_to_process32(au_id_t auid
, uid_t euid
, gid_t egid
,
629 uid_t ruid
, gid_t rgid
, pid_t pid
,
630 au_asid_t sid
, au_tid_t
*tid
)
639 GET_TOKEN_AREA(t
, dptr
, 37);
644 ADD_U_CHAR(dptr
, AU_PROCESS_32_TOKEN
);
645 ADD_U_INT32(dptr
, auid
);
646 ADD_U_INT32(dptr
, euid
);
647 ADD_U_INT32(dptr
, egid
);
648 ADD_U_INT32(dptr
, ruid
);
649 ADD_U_INT32(dptr
, rgid
);
650 ADD_U_INT32(dptr
, pid
);
651 ADD_U_INT32(dptr
, sid
);
652 ADD_U_INT32(dptr
, tid
->port
);
653 ADD_U_INT32(dptr
, tid
->machine
);
658 token_t
*au_to_process64(__unused au_id_t auid
,
664 __unused au_asid_t sid
,
665 __unused au_tid_t
*tid
)
670 token_t
*au_to_process(au_id_t auid
, uid_t euid
, gid_t egid
,
671 uid_t ruid
, gid_t rgid
, pid_t pid
,
672 au_asid_t sid
, au_tid_t
*tid
)
674 return au_to_process32(auid
, euid
, egid
, ruid
, rgid
, pid
,
682 * effective user ID 4 bytes
683 * effective group ID 4 bytes
684 * real user ID 4 bytes
685 * real group ID 4 bytes
689 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
690 * address type-len 4 bytes
691 * machine address 16 bytes
693 token_t
*au_to_process32_ex(au_id_t auid
, uid_t euid
, gid_t egid
,
694 uid_t ruid
, gid_t rgid
, pid_t pid
,
695 au_asid_t sid
, au_tid_addr_t
*tid
)
704 GET_TOKEN_AREA(t
, dptr
, 53);
709 ADD_U_CHAR(dptr
, AU_PROCESS_32_EX_TOKEN
);
710 ADD_U_INT32(dptr
, auid
);
711 ADD_U_INT32(dptr
, euid
);
712 ADD_U_INT32(dptr
, egid
);
713 ADD_U_INT32(dptr
, ruid
);
714 ADD_U_INT32(dptr
, rgid
);
715 ADD_U_INT32(dptr
, pid
);
716 ADD_U_INT32(dptr
, sid
);
717 ADD_U_INT32(dptr
, tid
->at_port
);
718 ADD_U_INT32(dptr
, tid
->at_type
);
719 ADD_U_INT32(dptr
, tid
->at_addr
[0]);
720 ADD_U_INT32(dptr
, tid
->at_addr
[1]);
721 ADD_U_INT32(dptr
, tid
->at_addr
[2]);
722 ADD_U_INT32(dptr
, tid
->at_addr
[3]);
727 token_t
*au_to_process64_ex(
728 __unused au_id_t auid
,
734 __unused au_asid_t sid
,
735 __unused au_tid_addr_t
*tid
)
740 token_t
*au_to_process_ex(au_id_t auid
, uid_t euid
, gid_t egid
,
741 uid_t ruid
, gid_t rgid
, pid_t pid
,
742 au_asid_t sid
, au_tid_addr_t
*tid
)
744 return au_to_process32_ex(auid
, euid
, egid
, ruid
, rgid
,
750 * error status 1 byte
751 * return value 4 bytes/8 bytes (32-bit/64-bit value)
753 token_t
*au_to_return32(char status
, u_int32_t ret
)
759 GET_TOKEN_AREA(t
, dptr
, 6);
764 ADD_U_CHAR(dptr
, AU_RETURN_32_TOKEN
);
765 ADD_U_CHAR(dptr
, status
);
766 ADD_U_INT32(dptr
, ret
);
771 token_t
*au_to_return64(char status
, u_int64_t ret
)
777 GET_TOKEN_AREA(t
, dptr
, 10);
782 ADD_U_CHAR(dptr
, AU_RETURN_64_TOKEN
);
783 ADD_U_CHAR(dptr
, status
);
784 ADD_U_INT64(dptr
, ret
);
789 token_t
*au_to_return(char status
, u_int32_t ret
)
791 return au_to_return32(status
, ret
);
796 * sequence number 4 bytes
798 token_t
*au_to_seq(u_int32_t audit_count
)
804 GET_TOKEN_AREA(t
, dptr
, 5);
809 ADD_U_CHAR(dptr
, AU_SEQ_TOKEN
);
810 ADD_U_INT32(dptr
, audit_count
);
817 * socket type 2 bytes
819 * local Internet address 4 bytes
820 * remote port 2 bytes
821 * remote Internet address 4 bytes
823 token_t
*au_to_socket(__unused
struct socket
*so
)
829 * Kernel-specific version of the above function.
831 token_t
*kau_to_socket(struct socket_au_info
*soi
)
841 GET_TOKEN_AREA(t
, dptr
, 15);
846 ADD_U_CHAR(dptr
, AU_SOCK_TOKEN
);
847 /* Coerce the socket type into a short value */
848 so_type
= soi
->so_type
;
849 ADD_U_INT16(dptr
, so_type
);
850 ADD_U_INT16(dptr
, soi
->so_lport
);
851 ADD_U_INT32(dptr
, soi
->so_laddr
);
852 ADD_U_INT16(dptr
, soi
->so_rport
);
853 ADD_U_INT32(dptr
, soi
->so_raddr
);
860 * socket type 2 bytes
862 * address type/length 4 bytes
863 * local Internet address 4 bytes/16 bytes (IPv4/IPv6 address)
864 * remote port 4 bytes
865 * address type/length 4 bytes
866 * remote Internet address 4 bytes/16 bytes (IPv4/IPv6 address)
868 token_t
*au_to_socket_ex_32(
869 __unused u_int16_t lp
,
870 __unused u_int16_t rp
,
871 __unused
struct sockaddr
*la
,
872 __unused
struct sockaddr
*ra
)
877 token_t
*au_to_socket_ex_128(
878 __unused u_int16_t lp
,
879 __unused u_int16_t rp
,
880 __unused
struct sockaddr
*la
,
881 __unused
struct sockaddr
*ra
)
888 * socket family 2 bytes
890 * socket address 4 bytes
892 token_t
*au_to_sock_inet32(struct sockaddr_in
*so
)
901 GET_TOKEN_AREA(t
, dptr
, 9);
906 ADD_U_CHAR(dptr
, AU_SOCK_INET_32_TOKEN
);
907 /* In Darwin, sin_family is one octet, but BSM defines the token
908 * to store two. So we copy in a 0 first.
911 ADD_U_CHAR(dptr
, so
->sin_family
);
912 ADD_U_INT16(dptr
, so
->sin_port
);
913 ADD_U_INT32(dptr
, so
->sin_addr
.s_addr
);
919 token_t
*au_to_sock_inet128(struct sockaddr_in6
*so
)
928 GET_TOKEN_AREA(t
, dptr
, 21);
933 ADD_U_CHAR(dptr
, AU_SOCK_INET_128_TOKEN
);
934 /* In Darwin, sin_family is one octet, but BSM defines the token
935 * to store two. So we copy in a 0 first.
938 ADD_U_CHAR(dptr
, so
->sin6_family
);
939 ADD_U_INT16(dptr
, so
->sin6_port
);
940 ADD_U_INT32(dptr
, so
->sin6_addr
.__u6_addr
.__u6_addr32
[0]);
941 ADD_U_INT32(dptr
, so
->sin6_addr
.__u6_addr
.__u6_addr32
[1]);
942 ADD_U_INT32(dptr
, so
->sin6_addr
.__u6_addr
.__u6_addr32
[2]);
943 ADD_U_INT32(dptr
, so
->sin6_addr
.__u6_addr
.__u6_addr32
[3]);
953 * socket family 2 bytes
956 token_t
*au_to_sock_unix(struct sockaddr_un
*so
)
965 GET_TOKEN_AREA(t
, dptr
, 107);
970 ADD_U_CHAR(dptr
, AU_SOCK_UNIX_TOKEN
);
971 /* BSM token has two bytes for family */
973 ADD_U_CHAR(dptr
, so
->sun_family
);
974 ADD_STRING(dptr
, so
->sun_path
, strlen(so
->sun_path
));
980 token_t
*au_to_sock_inet(struct sockaddr_in
*so
)
982 return au_to_sock_inet32(so
);
988 * effective user ID 4 bytes
989 * effective group ID 4 bytes
990 * real user ID 4 bytes
991 * real group ID 4 bytes
995 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
996 * machine address 4 bytes
998 token_t
*au_to_subject32(au_id_t auid
, uid_t euid
, gid_t egid
,
999 uid_t ruid
, gid_t rgid
, pid_t pid
,
1000 au_asid_t sid
, au_tid_t
*tid
)
1009 GET_TOKEN_AREA(t
, dptr
, 37);
1014 ADD_U_CHAR(dptr
, AU_SUBJECT_32_TOKEN
);
1015 ADD_U_INT32(dptr
, auid
);
1016 ADD_U_INT32(dptr
, euid
);
1017 ADD_U_INT32(dptr
, egid
);
1018 ADD_U_INT32(dptr
, ruid
);
1019 ADD_U_INT32(dptr
, rgid
);
1020 ADD_U_INT32(dptr
, pid
);
1021 ADD_U_INT32(dptr
, sid
);
1022 ADD_U_INT32(dptr
, tid
->port
);
1023 ADD_U_INT32(dptr
, tid
->machine
);
1028 token_t
*au_to_subject64(
1029 __unused au_id_t auid
,
1030 __unused uid_t euid
,
1031 __unused gid_t egid
,
1032 __unused uid_t ruid
,
1033 __unused gid_t rgid
,
1035 __unused au_asid_t sid
,
1036 __unused au_tid_t
*tid
)
1041 token_t
*au_to_subject(au_id_t auid
, uid_t euid
, gid_t egid
,
1042 uid_t ruid
, gid_t rgid
, pid_t pid
,
1043 au_asid_t sid
, au_tid_t
*tid
)
1045 return au_to_subject32(auid
, euid
, egid
, ruid
, rgid
,
1053 * effective user ID 4 bytes
1054 * effective group ID 4 bytes
1055 * real user ID 4 bytes
1056 * real group ID 4 bytes
1057 * process ID 4 bytes
1058 * session ID 4 bytes
1060 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
1061 * address type/length 4 bytes
1062 * machine address 16 bytes
1064 token_t
*au_to_subject32_ex(au_id_t auid
, uid_t euid
,
1065 gid_t egid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
1066 au_asid_t sid
, au_tid_addr_t
*tid
)
1075 GET_TOKEN_AREA(t
, dptr
, 53);
1080 ADD_U_CHAR(dptr
, AU_SUBJECT_32_EX_TOKEN
);
1081 ADD_U_INT32(dptr
, auid
);
1082 ADD_U_INT32(dptr
, euid
);
1083 ADD_U_INT32(dptr
, egid
);
1084 ADD_U_INT32(dptr
, ruid
);
1085 ADD_U_INT32(dptr
, rgid
);
1086 ADD_U_INT32(dptr
, pid
);
1087 ADD_U_INT32(dptr
, sid
);
1088 ADD_U_INT32(dptr
, tid
->at_port
);
1089 ADD_U_INT32(dptr
, tid
->at_type
);
1090 ADD_U_INT32(dptr
, tid
->at_addr
[0]);
1091 ADD_U_INT32(dptr
, tid
->at_addr
[1]);
1092 ADD_U_INT32(dptr
, tid
->at_addr
[2]);
1093 ADD_U_INT32(dptr
, tid
->at_addr
[3]);
1098 token_t
*au_to_subject64_ex(
1099 __unused au_id_t auid
,
1100 __unused uid_t euid
,
1101 __unused gid_t egid
,
1102 __unused uid_t ruid
,
1103 __unused gid_t rgid
,
1105 __unused au_asid_t sid
,
1106 __unused au_tid_addr_t
*tid
)
1111 token_t
*au_to_subject_ex(au_id_t auid
, uid_t euid
,
1112 gid_t egid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
1113 au_asid_t sid
, au_tid_addr_t
*tid
)
1115 return au_to_subject32_ex(auid
, euid
, egid
, ruid
, rgid
,
1123 * text count null-terminated strings
1125 token_t
*au_to_exec_args(const char **args
)
1129 const char *nextarg
;
1139 while(nextarg
!= NULL
) {
1142 nextlen
= strlen(nextarg
);
1143 totlen
+= nextlen
+ 1;
1145 nextarg
= *(args
+ count
);
1149 GET_TOKEN_AREA(t
, dptr
, 5 + totlen
);
1154 ADD_U_CHAR(dptr
, AU_EXEC_ARG_TOKEN
);
1155 ADD_U_INT32(dptr
, count
);
1157 for(i
=0; i
< count
; i
++) {
1158 nextarg
= *(args
+ i
);
1159 ADD_MEM(dptr
, nextarg
, strlen(nextarg
) + 1);
1169 * text count null-terminated strings
1171 token_t
*au_to_exec_env(const char **env
)
1177 const char *nextenv
;
1185 while(nextenv
!= NULL
) {
1188 nextlen
= strlen(nextenv
);
1189 totlen
+= nextlen
+ 1;
1191 nextenv
= *(env
+ count
);
1195 GET_TOKEN_AREA(t
, dptr
, 5 + totlen
);
1200 ADD_U_CHAR(dptr
, AU_EXEC_ENV_TOKEN
);
1201 ADD_U_INT32(dptr
, count
);
1203 for(i
=0; i
< count
; i
++) {
1204 nextenv
= *(env
+ i
);
1205 ADD_MEM(dptr
, nextenv
, strlen(nextenv
) + 1);
1213 * Kernel version of the BSM header token functions. These versions take
1214 * a timespec struct as an additional parameter in order to obtain the
1215 * create time value for the BSM audit record.
1217 * record byte count 4 bytes
1218 * version # 1 byte [2]
1219 * event type 2 bytes
1220 * event modifier 2 bytes
1221 * seconds of time 4 bytes/8 bytes (32-bit/64-bit value)
1222 * milliseconds of time 4 bytes/8 bytes (32-bit/64-bit value)
1224 token_t
*kau_to_header32(const struct timespec
*ctime
, int rec_size
,
1225 au_event_t e_type
, au_emod_t e_mod
)
1229 u_int32_t timems
= ctime
->tv_nsec
/1000000; /* We need time in ms */
1231 GET_TOKEN_AREA(t
, dptr
, 18);
1236 ADD_U_CHAR(dptr
, AU_HEADER_32_TOKEN
);
1237 ADD_U_INT32(dptr
, rec_size
);
1238 ADD_U_CHAR(dptr
, HEADER_VERSION
);
1239 ADD_U_INT16(dptr
, e_type
);
1240 ADD_U_INT16(dptr
, e_mod
);
1242 /* Add the timestamp */
1243 ADD_U_INT32(dptr
, ctime
->tv_sec
);
1244 ADD_U_INT32(dptr
, timems
);
1249 token_t
*kau_to_header64(
1250 __unused
const struct timespec
*ctime
,
1251 __unused
int rec_size
,
1252 __unused au_event_t e_type
,
1253 __unused au_emod_t e_mod
)
1258 token_t
*kau_to_header(const struct timespec
*ctime
, int rec_size
,
1259 au_event_t e_type
, au_emod_t e_mod
)
1261 return kau_to_header32(ctime
, rec_size
, e_type
, e_mod
);
1266 * trailer magic number 2 bytes
1267 * record byte count 4 bytes
1269 token_t
*au_to_trailer(int rec_size
)
1273 u_int16_t magic
= TRAILER_PAD_MAGIC
;
1276 GET_TOKEN_AREA(t
, dptr
, 7);
1281 ADD_U_CHAR(dptr
, AU_TRAILER_TOKEN
);
1282 ADD_U_INT16(dptr
, magic
);
1283 ADD_U_INT32(dptr
, rec_size
);