]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/kern_bsm_token.c
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 #include <sys/types.h>
26 #include <sys/bsm_token.h>
27 #include <sys/audit.h>
29 #include <kern/clock.h>
31 #define GET_TOKEN_AREA(tok, dptr, length) \
33 kmem_alloc(kernel_map, &tok, sizeof(*tok)); \
37 kmem_alloc(kernel_map, &tok->t_data, \
38 length * sizeof(u_char));\
39 if((dptr = tok->t_data) == NULL)\
41 kmem_free(kernel_map, tok, sizeof(*tok));\
46 memset(dptr, 0, length);\
56 * argument value 4 bytes/8 bytes (32-bit/64-bit value)
58 * text N bytes + 1 terminating NULL byte
60 token_t
*au_to_arg32(char n
, char *text
, u_int32_t v
)
70 /* Make sure that text is null terminated */
71 textlen
= strlen(text
);
72 if(text
[textlen
] != '\0') {
76 GET_TOKEN_AREA(t
, dptr
, 9 + textlen
);
83 ADD_U_CHAR(dptr
, AU_ARG32_TOKEN
);
86 ADD_U_INT16(dptr
, textlen
);
87 ADD_STRING(dptr
, text
, textlen
);
93 token_t
*au_to_arg64(char n
, char *text
, u_int64_t v
)
103 /* Make sure that text is null terminated */
104 textlen
= strlen(text
);
105 if(text
[textlen
] != '\0') {
109 GET_TOKEN_AREA(t
, dptr
, 13 + textlen
);
116 ADD_U_CHAR(dptr
, AU_ARG64_TOKEN
);
118 ADD_U_INT64(dptr
, v
);
119 ADD_U_INT16(dptr
, textlen
);
120 ADD_STRING(dptr
, text
, textlen
);
126 token_t
*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(struct vattr
*attr
)
150 GET_TOKEN_AREA(t
, dptr
, 29);
155 ADD_U_CHAR(dptr
, AU_ATTR32_TOKEN
);
156 ADD_U_INT32(dptr
, attr
->va_mode
);
157 ADD_U_INT32(dptr
, attr
->va_uid
);
158 ADD_U_INT32(dptr
, attr
->va_gid
);
159 ADD_U_INT32(dptr
, attr
->va_fsid
);
160 ADD_U_INT64(dptr
, attr
->va_fileid
);
161 ADD_U_INT32(dptr
, attr
->va_rdev
);
166 token_t
*au_to_attr64(struct vattr
*attr
)
176 GET_TOKEN_AREA(t
, dptr
, 33);
181 ADD_U_CHAR(dptr
, AU_ATTR64_TOKEN
);
182 ADD_U_INT32(dptr
, attr
->va_mode
);
183 ADD_U_INT32(dptr
, attr
->va_uid
);
184 ADD_U_INT32(dptr
, attr
->va_gid
);
185 ADD_U_INT32(dptr
, attr
->va_fsid
);
186 ADD_U_INT64(dptr
, attr
->va_fileid
);
187 ADD_U_INT64(dptr
, attr
->va_rdev
);
192 token_t
*au_to_attr(struct vattr
*attr
)
194 return au_to_attr32(attr
);
201 * how to print 1 byte
204 * data items (depends on basic unit)
206 token_t
*au_to_data(char unit_print
, char unit_type
,
207 char unit_count
, char *p
)
211 size_t datasize
, totdata
;
217 /* Determine the size of the basic unit */
219 case AUR_BYTE
: datasize
= AUR_BYTE_SIZE
;
222 case AUR_SHORT
: datasize
= AUR_SHORT_SIZE
;
225 case AUR_LONG
: datasize
= AUR_LONG_SIZE
;
228 default: return NULL
;
231 totdata
= datasize
* unit_count
;
233 GET_TOKEN_AREA(t
, dptr
, totdata
+ 4);
238 ADD_U_CHAR(dptr
, AU_ARB_TOKEN
);
239 ADD_U_CHAR(dptr
, unit_print
);
240 ADD_U_CHAR(dptr
, unit_type
);
241 ADD_U_CHAR(dptr
, unit_count
);
242 ADD_MEM(dptr
, p
, totdata
);
251 * return value 4 bytes
253 token_t
*au_to_exit(int retval
, int err
)
258 GET_TOKEN_AREA(t
, dptr
, 9);
263 ADD_U_CHAR(dptr
, AU_EXIT_TOKEN
);
264 ADD_U_INT32(dptr
, err
);
265 ADD_U_INT32(dptr
, retval
);
272 token_t
*au_to_groups(int *groups
)
274 return au_to_newgroups(MAX_GROUPS
, groups
);
279 * number groups 2 bytes
280 * group list count * 4 bytes
282 token_t
*au_to_newgroups(u_int16_t n
, gid_t
*groups
)
292 GET_TOKEN_AREA(t
, dptr
, n
* 4 + 3);
297 ADD_U_CHAR(dptr
, AU_NEWGROUPS_TOKEN
);
298 ADD_U_INT16(dptr
, n
);
299 for(i
= 0; i
< n
; i
++) {
300 ADD_U_INT32(dptr
, groups
[i
]);
311 * internet address 4 bytes
313 token_t
*au_to_in_addr(struct in_addr
*internet_addr
)
318 if(internet_addr
== NULL
) {
322 GET_TOKEN_AREA(t
, dptr
, 5);
327 ADD_U_CHAR(dptr
, AU_IN_ADDR_TOKEN
);
328 ADD_U_INT32(dptr
, internet_addr
->s_addr
);
335 * address type/length 4 bytes
338 token_t
*au_to_in_addr_ex(struct in6_addr
*internet_addr
)
343 if(internet_addr
== NULL
) {
347 GET_TOKEN_AREA(t
, dptr
, 21);
352 ADD_U_CHAR(dptr
, AU_IN_ADDR_EX_TOKEN
);
353 ADD_U_INT32(dptr
, internet_addr
->__u6_addr
.__u6_addr32
[0]);
354 ADD_U_INT32(dptr
, internet_addr
->__u6_addr
.__u6_addr32
[1]);
355 ADD_U_INT32(dptr
, internet_addr
->__u6_addr
.__u6_addr32
[2]);
356 ADD_U_INT32(dptr
, internet_addr
->__u6_addr
.__u6_addr32
[3]);
365 token_t
*au_to_ip(struct ip
*ip
)
374 GET_TOKEN_AREA(t
, dptr
, 21);
379 ADD_U_CHAR(dptr
, AU_IP_TOKEN
);
380 ADD_MEM(dptr
, ip
, sizeof(struct ip
));
387 * object ID type 1 byte
390 token_t
*au_to_ipc(char type
, int id
)
396 GET_TOKEN_AREA(t
, dptr
, 6);
401 ADD_U_CHAR(dptr
, AU_IPC_TOKEN
);
402 ADD_U_CHAR(dptr
, type
);
403 ADD_U_INT32(dptr
, id
);
410 * owner user ID 4 bytes
411 * owner group ID 4 bytes
412 * creator user ID 4 bytes
413 * creator group ID 4 bytes
414 * access mode 4 bytes
415 * slot sequence # 4 bytes
418 token_t
*au_to_ipc_perm(struct ipc_perm
*perm
)
427 GET_TOKEN_AREA(t
, dptr
, 29);
432 ADD_U_CHAR(dptr
, AU_IPCPERM_TOKEN
);
433 ADD_U_INT32(dptr
, perm
->uid
);
434 ADD_U_INT32(dptr
, perm
->gid
);
435 ADD_U_INT32(dptr
, perm
->cuid
);
436 ADD_U_INT32(dptr
, perm
->cgid
);
437 ADD_U_INT32(dptr
, perm
->mode
);
438 ADD_U_INT32(dptr
, perm
->seq
);
439 ADD_U_INT32(dptr
, perm
->key
);
447 * port IP address 2 bytes
449 token_t
*au_to_iport(u_int16_t iport
)
455 GET_TOKEN_AREA(t
, dptr
, 3);
460 ADD_U_CHAR(dptr
, AU_IPORT_TOKEN
);
461 ADD_U_INT16(dptr
, iport
);
472 token_t
*au_to_opaque(char *data
, u_int16_t bytes
)
477 if((data
== NULL
) || (bytes
<= 0)) {
481 GET_TOKEN_AREA(t
, dptr
, bytes
+ 3);
486 ADD_U_CHAR(dptr
, AU_OPAQUE_TOKEN
);
487 ADD_U_INT16(dptr
, bytes
);
488 ADD_MEM(dptr
, data
, bytes
);
495 * Kernel version of the add file token function, where the time value
496 * is passed in as an additional parameter.
498 * seconds of time 4 bytes
499 * milliseconds of time 4 bytes
500 * file name len 2 bytes
501 * file pathname N bytes + 1 terminating NULL byte
503 token_t
*kau_to_file(char *file
, struct timeval
*tv
)
508 u_int32_t timems
= tv
->tv_usec
/1000; /* We need time in ms */
513 /* Make sure that text is null terminated */
514 filelen
= strlen(file
);
515 if(file
[filelen
] != '\0') {
519 GET_TOKEN_AREA(t
, dptr
, filelen
+ 12);
526 ADD_U_CHAR(dptr
, AU_FILE_TOKEN
);
528 /* Add the timestamp */
529 ADD_U_INT32(dptr
, tv
->tv_sec
);
530 ADD_U_INT32(dptr
, timems
);
532 ADD_U_INT16(dptr
, filelen
);
533 ADD_STRING(dptr
, file
, filelen
);
542 * text length 2 bytes
543 * text N bytes + 1 terminating NULL byte
545 token_t
*au_to_text(char *text
)
554 /* Make sure that text is null terminated */
555 textlen
= strlen(text
);
556 if(text
[textlen
] != '\0') {
560 GET_TOKEN_AREA(t
, dptr
, textlen
+ 4);
567 ADD_U_CHAR(dptr
, AU_TEXT_TOKEN
);
568 ADD_U_INT16(dptr
, textlen
);
569 ADD_STRING(dptr
, text
, textlen
);
576 * path length 2 bytes
577 * path N bytes + 1 terminating NULL byte
579 token_t
*au_to_path(char *text
)
588 /* Make sure that text is null terminated */
589 textlen
= strlen(text
);
590 if(text
[textlen
] != '\0') {
594 GET_TOKEN_AREA(t
, dptr
, textlen
+ 4);
601 ADD_U_CHAR(dptr
, AU_PATH_TOKEN
);
602 ADD_U_INT16(dptr
, textlen
);
603 ADD_STRING(dptr
, text
, textlen
);
611 * effective user ID 4 bytes
612 * effective group ID 4 bytes
613 * real user ID 4 bytes
614 * real group ID 4 bytes
618 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
619 * machine address 4 bytes
621 token_t
*au_to_process32(au_id_t auid
, uid_t euid
, gid_t egid
,
622 uid_t ruid
, gid_t rgid
, pid_t pid
,
623 au_asid_t sid
, au_tid_t
*tid
)
632 GET_TOKEN_AREA(t
, dptr
, 37);
637 ADD_U_CHAR(dptr
, AU_PROCESS_32_TOKEN
);
638 ADD_U_INT32(dptr
, auid
);
639 ADD_U_INT32(dptr
, euid
);
640 ADD_U_INT32(dptr
, egid
);
641 ADD_U_INT32(dptr
, ruid
);
642 ADD_U_INT32(dptr
, rgid
);
643 ADD_U_INT32(dptr
, pid
);
644 ADD_U_INT32(dptr
, sid
);
645 ADD_U_INT32(dptr
, tid
->port
);
646 ADD_U_INT32(dptr
, tid
->machine
);
651 token_t
*au_to_process64(au_id_t auid
, uid_t euid
, gid_t egid
,
652 uid_t ruid
, gid_t rgid
, pid_t pid
,
653 au_asid_t sid
, au_tid_t
*tid
)
662 GET_TOKEN_AREA(t
, dptr
, 41);
667 ADD_U_CHAR(dptr
, AU_PROCESS_64_TOKEN
);
668 ADD_U_INT32(dptr
, auid
);
669 ADD_U_INT32(dptr
, euid
);
670 ADD_U_INT32(dptr
, egid
);
671 ADD_U_INT32(dptr
, ruid
);
672 ADD_U_INT32(dptr
, rgid
);
673 ADD_U_INT32(dptr
, pid
);
674 ADD_U_INT32(dptr
, sid
);
675 ADD_U_INT64(dptr
, tid
->port
);
676 ADD_U_INT32(dptr
, tid
->machine
);
681 token_t
*au_to_process(au_id_t auid
, uid_t euid
, gid_t egid
,
682 uid_t ruid
, gid_t rgid
, pid_t pid
,
683 au_asid_t sid
, au_tid_t
*tid
)
685 return au_to_process32(auid
, euid
, egid
, ruid
, rgid
, pid
,
693 * effective user ID 4 bytes
694 * effective group ID 4 bytes
695 * real user ID 4 bytes
696 * real group ID 4 bytes
700 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
701 * address type-len 4 bytes
702 * machine address 16 bytes
704 token_t
*au_to_process32_ex(au_id_t auid
, uid_t euid
, gid_t egid
,
705 uid_t ruid
, gid_t rgid
, pid_t pid
,
706 au_asid_t sid
, au_tid_addr_t
*tid
)
715 GET_TOKEN_AREA(t
, dptr
, 53);
720 ADD_U_CHAR(dptr
, AU_PROCESS_32_EX_TOKEN
);
721 ADD_U_INT32(dptr
, auid
);
722 ADD_U_INT32(dptr
, euid
);
723 ADD_U_INT32(dptr
, egid
);
724 ADD_U_INT32(dptr
, ruid
);
725 ADD_U_INT32(dptr
, rgid
);
726 ADD_U_INT32(dptr
, pid
);
727 ADD_U_INT32(dptr
, sid
);
728 ADD_U_INT32(dptr
, tid
->at_port
);
729 ADD_U_INT32(dptr
, tid
->at_type
);
730 ADD_U_INT32(dptr
, tid
->at_addr
[0]);
731 ADD_U_INT32(dptr
, tid
->at_addr
[1]);
732 ADD_U_INT32(dptr
, tid
->at_addr
[2]);
733 ADD_U_INT32(dptr
, tid
->at_addr
[3]);
738 token_t
*au_to_process64_ex(au_id_t auid
, uid_t euid
, gid_t egid
,
739 uid_t ruid
, gid_t rgid
, pid_t pid
,
740 au_asid_t sid
, au_tid_addr_t
*tid
)
749 GET_TOKEN_AREA(t
, dptr
, 57);
754 ADD_U_CHAR(dptr
, AU_PROCESS_64_EX_TOKEN
);
755 ADD_U_INT32(dptr
, auid
);
756 ADD_U_INT32(dptr
, euid
);
757 ADD_U_INT32(dptr
, egid
);
758 ADD_U_INT32(dptr
, ruid
);
759 ADD_U_INT32(dptr
, rgid
);
760 ADD_U_INT32(dptr
, pid
);
761 ADD_U_INT32(dptr
, sid
);
762 ADD_U_INT64(dptr
, tid
->at_port
);
763 ADD_U_INT32(dptr
, tid
->at_type
);
764 ADD_U_INT32(dptr
, tid
->at_addr
[0]);
765 ADD_U_INT32(dptr
, tid
->at_addr
[1]);
766 ADD_U_INT32(dptr
, tid
->at_addr
[2]);
767 ADD_U_INT32(dptr
, tid
->at_addr
[3]);
772 token_t
*au_to_process_ex(au_id_t auid
, uid_t euid
, gid_t egid
,
773 uid_t ruid
, gid_t rgid
, pid_t pid
,
774 au_asid_t sid
, au_tid_addr_t
*tid
)
776 return au_to_process32_ex(auid
, euid
, egid
, ruid
, rgid
,
782 * error status 1 byte
783 * return value 4 bytes/8 bytes (32-bit/64-bit value)
785 token_t
*au_to_return32(char status
, u_int32_t ret
)
791 GET_TOKEN_AREA(t
, dptr
, 6);
796 ADD_U_CHAR(dptr
, AU_RETURN_32_TOKEN
);
797 ADD_U_CHAR(dptr
, status
);
798 ADD_U_INT32(dptr
, ret
);
803 token_t
*au_to_return64(char status
, u_int64_t ret
)
809 GET_TOKEN_AREA(t
, dptr
, 10);
814 ADD_U_CHAR(dptr
, AU_RETURN_64_TOKEN
);
815 ADD_U_CHAR(dptr
, status
);
816 ADD_U_INT64(dptr
, ret
);
821 token_t
*au_to_return(char status
, u_int32_t ret
)
823 return au_to_return32(status
, ret
);
828 * sequence number 4 bytes
830 token_t
*au_to_seq(long audit_count
)
836 GET_TOKEN_AREA(t
, dptr
, 5);
841 ADD_U_CHAR(dptr
, AU_SEQ_TOKEN
);
842 ADD_U_INT32(dptr
, audit_count
);
849 * socket type 2 bytes
850 * remote port 2 bytes
851 * remote Internet address 4 bytes
853 token_t
*au_to_socket(struct socket
*so
)
855 return au_to_socket_ex_32(so
);
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(struct socket
*so
)
872 token_t
*au_to_socket_ex_128(struct socket
*so
)
879 * socket family 2 bytes
881 * socket address 4 bytes
883 token_t
*au_to_sock_inet32(struct sockaddr_in
*so
)
892 GET_TOKEN_AREA(t
, dptr
, 9);
897 ADD_U_CHAR(dptr
, AU_SOCK_INET_32_TOKEN
);
898 /* In Darwin, sin_family is one octet, but BSM defines the token
899 * to store two. So we copy in a 0 first.
902 ADD_U_CHAR(dptr
, so
->sin_family
);
903 ADD_U_INT16(dptr
, so
->sin_port
);
904 ADD_U_INT32(dptr
, so
->sin_addr
.s_addr
);
910 token_t
*au_to_sock_inet128(struct sockaddr_in6
*so
)
919 GET_TOKEN_AREA(t
, dptr
, 21);
924 ADD_U_CHAR(dptr
, AU_SOCK_INET_128_TOKEN
);
925 /* In Darwin, sin_family is one octet, but BSM defines the token
926 * to store two. So we copy in a 0 first.
929 ADD_U_CHAR(dptr
, so
->sin6_family
);
930 ADD_U_INT16(dptr
, so
->sin6_port
);
931 ADD_U_INT32(dptr
, so
->sin6_addr
.__u6_addr
.__u6_addr32
[0]);
932 ADD_U_INT32(dptr
, so
->sin6_addr
.__u6_addr
.__u6_addr32
[1]);
933 ADD_U_INT32(dptr
, so
->sin6_addr
.__u6_addr
.__u6_addr32
[2]);
934 ADD_U_INT32(dptr
, so
->sin6_addr
.__u6_addr
.__u6_addr32
[3]);
944 * socket family 2 bytes
947 token_t
*au_to_sock_unix(struct sockaddr_un
*so
)
956 GET_TOKEN_AREA(t
, dptr
, 107);
961 ADD_U_CHAR(dptr
, AU_SOCK_UNIX_TOKEN
);
962 /* BSM token has two bytes for family */
964 ADD_U_CHAR(dptr
, so
->sun_family
);
965 ADD_STRING(dptr
, so
->sun_path
, strlen(so
->sun_path
));
971 token_t
*au_to_sock_inet(struct sockaddr_in
*so
)
973 return au_to_sock_inet32(so
);
979 * effective user ID 4 bytes
980 * effective group ID 4 bytes
981 * real user ID 4 bytes
982 * real group ID 4 bytes
986 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
987 * machine address 4 bytes
989 token_t
*au_to_subject32(au_id_t auid
, uid_t euid
, gid_t egid
,
990 uid_t ruid
, gid_t rgid
, pid_t pid
,
991 au_asid_t sid
, au_tid_t
*tid
)
1000 GET_TOKEN_AREA(t
, dptr
, 37);
1005 ADD_U_CHAR(dptr
, AU_SUBJECT_32_TOKEN
);
1006 ADD_U_INT32(dptr
, auid
);
1007 ADD_U_INT32(dptr
, euid
);
1008 ADD_U_INT32(dptr
, egid
);
1009 ADD_U_INT32(dptr
, ruid
);
1010 ADD_U_INT32(dptr
, rgid
);
1011 ADD_U_INT32(dptr
, pid
);
1012 ADD_U_INT32(dptr
, sid
);
1013 ADD_U_INT32(dptr
, tid
->port
);
1014 ADD_U_INT32(dptr
, tid
->machine
);
1019 token_t
*au_to_subject64(au_id_t auid
, uid_t euid
, gid_t egid
,
1020 uid_t ruid
, gid_t rgid
, pid_t pid
,
1021 au_asid_t sid
, au_tid_t
*tid
)
1030 GET_TOKEN_AREA(t
, dptr
, 41);
1035 ADD_U_CHAR(dptr
, AU_SUBJECT_64_TOKEN
);
1036 ADD_U_INT32(dptr
, auid
);
1037 ADD_U_INT32(dptr
, euid
);
1038 ADD_U_INT32(dptr
, egid
);
1039 ADD_U_INT32(dptr
, ruid
);
1040 ADD_U_INT32(dptr
, rgid
);
1041 ADD_U_INT32(dptr
, pid
);
1042 ADD_U_INT32(dptr
, sid
);
1043 ADD_U_INT64(dptr
, tid
->port
);
1044 ADD_U_INT32(dptr
, tid
->machine
);
1049 token_t
*au_to_subject(au_id_t auid
, uid_t euid
, gid_t egid
,
1050 uid_t ruid
, gid_t rgid
, pid_t pid
,
1051 au_asid_t sid
, au_tid_t
*tid
)
1053 return au_to_subject32(auid
, euid
, egid
, ruid
, rgid
,
1061 * effective user ID 4 bytes
1062 * effective group ID 4 bytes
1063 * real user ID 4 bytes
1064 * real group ID 4 bytes
1065 * process ID 4 bytes
1066 * session ID 4 bytes
1068 * port ID 4 bytes/8 bytes (32-bit/64-bit value)
1069 * address type/length 4 bytes
1070 * machine address 16 bytes
1072 token_t
*au_to_subject32_ex(au_id_t auid
, uid_t euid
,
1073 gid_t egid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
1074 au_asid_t sid
, au_tid_addr_t
*tid
)
1083 GET_TOKEN_AREA(t
, dptr
, 53);
1088 ADD_U_CHAR(dptr
, AU_SUBJECT_32_EX_TOKEN
);
1089 ADD_U_INT32(dptr
, auid
);
1090 ADD_U_INT32(dptr
, euid
);
1091 ADD_U_INT32(dptr
, egid
);
1092 ADD_U_INT32(dptr
, ruid
);
1093 ADD_U_INT32(dptr
, rgid
);
1094 ADD_U_INT32(dptr
, pid
);
1095 ADD_U_INT32(dptr
, sid
);
1096 ADD_U_INT32(dptr
, tid
->at_port
);
1097 ADD_U_INT32(dptr
, tid
->at_type
);
1098 ADD_U_INT32(dptr
, tid
->at_addr
[0]);
1099 ADD_U_INT32(dptr
, tid
->at_addr
[1]);
1100 ADD_U_INT32(dptr
, tid
->at_addr
[2]);
1101 ADD_U_INT32(dptr
, tid
->at_addr
[3]);
1106 token_t
*au_to_subject64_ex(au_id_t auid
, uid_t euid
,
1107 gid_t egid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
1108 au_asid_t sid
, au_tid_addr_t
*tid
)
1117 GET_TOKEN_AREA(t
, dptr
, 57);
1122 ADD_U_CHAR(dptr
, AU_SUBJECT_64_EX_TOKEN
);
1123 ADD_U_INT32(dptr
, auid
);
1124 ADD_U_INT32(dptr
, euid
);
1125 ADD_U_INT32(dptr
, egid
);
1126 ADD_U_INT32(dptr
, ruid
);
1127 ADD_U_INT32(dptr
, rgid
);
1128 ADD_U_INT32(dptr
, pid
);
1129 ADD_U_INT32(dptr
, sid
);
1130 ADD_U_INT64(dptr
, tid
->at_port
);
1131 ADD_U_INT32(dptr
, tid
->at_type
);
1132 ADD_U_INT32(dptr
, tid
->at_addr
[0]);
1133 ADD_U_INT32(dptr
, tid
->at_addr
[1]);
1134 ADD_U_INT32(dptr
, tid
->at_addr
[2]);
1135 ADD_U_INT32(dptr
, tid
->at_addr
[3]);
1140 token_t
*au_to_subject_ex(au_id_t auid
, uid_t euid
,
1141 gid_t egid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
1142 au_asid_t sid
, au_tid_addr_t
*tid
)
1144 return au_to_subject32_ex(auid
, euid
, egid
, ruid
, rgid
,
1152 * text count null-terminated strings
1154 token_t
*au_to_exec_args(const char **args
)
1158 const char *nextarg
;
1168 while(nextarg
!= NULL
) {
1171 nextlen
= strlen(nextarg
);
1172 if(nextarg
[nextlen
] != '\0') {
1176 totlen
+= nextlen
+ 1;
1178 nextarg
= *(args
+ count
);
1182 GET_TOKEN_AREA(t
, dptr
, 5 + totlen
);
1187 ADD_U_CHAR(dptr
, AU_EXEC_ARG_TOKEN
);
1188 ADD_U_INT32(dptr
, count
);
1190 for(i
=0; i
< count
; i
++) {
1191 nextarg
= *(args
+ i
);
1192 ADD_MEM(dptr
, nextarg
, strlen(nextarg
) + 1);
1202 * text count null-terminated strings
1204 token_t
*au_to_exec_env(const char **env
)
1210 const char *nextenv
;
1218 while(nextenv
!= NULL
) {
1221 nextlen
= strlen(nextenv
);
1222 if(nextenv
[nextlen
] != '\0') {
1226 totlen
+= nextlen
+ 1;
1228 nextenv
= *(env
+ count
);
1232 GET_TOKEN_AREA(t
, dptr
, 5 + totlen
);
1237 ADD_U_CHAR(dptr
, AU_EXEC_ENV_TOKEN
);
1238 ADD_U_INT32(dptr
, count
);
1240 for(i
=0; i
< count
; i
++) {
1241 nextenv
= *(env
+ i
);
1242 ADD_MEM(dptr
, nextenv
, strlen(nextenv
) + 1);
1251 * Kernel version of the BSM header token functions. These versions take
1252 * a timespec struct as an additional parameter in order to obtain the
1253 * create time value for the BSM audit record.
1255 * record byte count 4 bytes
1256 * version # 1 byte [2]
1257 * event type 2 bytes
1258 * event modifier 2 bytes
1259 * seconds of time 4 bytes/8 bytes (32-bit/64-bit value)
1260 * milliseconds of time 4 bytes/8 bytes (32-bit/64-bit value)
1262 token_t
*kau_to_header32(struct timespec
*ctime
, int rec_size
,
1263 au_event_t e_type
, au_emod_t e_mod
)
1267 u_int32_t timems
= ctime
->tv_nsec
/1000000; /* We need time in ms */
1269 GET_TOKEN_AREA(t
, dptr
, 18);
1274 ADD_U_CHAR(dptr
, AU_HEADER_32_TOKEN
);
1275 ADD_U_INT32(dptr
, rec_size
);
1276 ADD_U_CHAR(dptr
, HEADER_VERSION
);
1277 ADD_U_INT16(dptr
, e_type
);
1278 ADD_U_INT16(dptr
, e_mod
);
1280 /* Add the timestamp */
1281 ADD_U_INT32(dptr
, ctime
->tv_sec
);
1282 ADD_U_INT32(dptr
, timems
);
1287 token_t
*kau_to_header64(struct timespec
*ctime
, int rec_size
,
1288 au_event_t e_type
, au_emod_t e_mod
)
1292 u_int32_t timems
= ctime
->tv_nsec
/1000000; /* We need time in ms */
1294 GET_TOKEN_AREA(t
, dptr
, 26);
1299 ADD_U_CHAR(dptr
, AU_HEADER_64_TOKEN
);
1300 ADD_U_INT32(dptr
, rec_size
);
1301 ADD_U_CHAR(dptr
, HEADER_VERSION
);
1302 ADD_U_INT16(dptr
, e_type
);
1303 ADD_U_INT16(dptr
, e_mod
);
1305 /* Add the timestamp */
1306 ADD_U_INT32(dptr
, ctime
->tv_sec
);
1307 ADD_U_INT32(dptr
, timems
);
1312 token_t
*kau_to_header(struct timespec
*ctime
, int rec_size
,
1313 au_event_t e_type
, au_emod_t e_mod
)
1315 return kau_to_header32(ctime
, rec_size
, e_type
, e_mod
);
1322 * trailer magic number 2 bytes
1323 * record byte count 4 bytes
1325 token_t
*au_to_trailer(int rec_size
)
1329 u_int16_t magic
= TRAILER_PAD_MAGIC
;
1332 GET_TOKEN_AREA(t
, dptr
, 7);
1337 ADD_U_CHAR(dptr
, AU_TRAILER_TOKEN
);
1338 ADD_U_INT16(dptr
, magic
);
1339 ADD_U_INT32(dptr
, rec_size
);