4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2012 Milan Jurik. All rights reserved.
29 * Token processing for auditreduce.
37 extern int re_exec2(char *);
39 static void anchor_path(char *path
);
40 static char *collapse_path(char *s
);
41 static void get_string(adr_t
*adr
, char **p
);
42 static int ipc_type_match(int flag
, char type
);
43 static void skip_string(adr_t
*adr
);
44 static int xgeneric(adr_t
*adr
);
52 if ((id
< 0) || (id
> MAXTOKEN
) ||
53 (tokentable
[id
].func
== NOFUNC
)) {
54 (void) fprintf(stderr
,
55 "token_processing: token %d not found\n", id
);
72 case AUT_OTHER_FILE64
:
80 case AUT_SUBJECT32_EX
:
81 case AUT_PROCESS32_EX
:
85 case AUT_SUBJECT64_EX
:
86 case AUT_PROCESS64_EX
:
93 (void) fprintf(stderr
, "token_processing: %s%s\n",
94 tokentable
[id
].t_name
, suffix
);
96 #endif /* AUDIT_REC */
99 * Process a token in a record to determine whether the record is interesting.
103 token_processing(adr_t
*adr
, int tokenid
)
105 if ((tokenid
> 0) && (tokenid
<= MAXTOKEN
) &&
106 (tokentable
[tokenid
].func
!= NOFUNC
)) {
109 #endif /* AUDIT_REC */
110 return ((*tokentable
[tokenid
].func
)(adr
));
113 /* here if token id is not in table */
118 /* There should not be any file or header tokens in the middle of a record */
122 file_token(adr_t
*adr
)
129 file64_token(adr_t
*adr
)
136 header_token(adr_t
*adr
)
143 header32_ex_token(adr_t
*adr
)
150 header64_ex_token(adr_t
*adr
)
157 header64_token(adr_t
*adr
)
164 * ======================================================
165 * The following token processing routines return
166 * -1: if the record is not interesting
167 * -2: if an error is found
168 * ======================================================
172 trailer_token(adr_t
*adr
)
177 adrm_u_short(adr
, (ushort_t
*)&magic_number
, 1);
178 if (magic_number
!= AUT_TRAILER_MAGIC
) {
179 (void) fprintf(stderr
, "%s\n",
180 gettext("auditreduce: Bad trailer token"));
183 adrm_u_int32(adr
, &bytes
, 1);
190 * Format of arbitrary data token:
191 * arbitrary data token id adr char
192 * how to print adr_char
193 * basic unit adr_char
194 * unit count adr_char, specifying number of units of
195 * data items depends on basic unit
198 arbitrary_data_token(adr_t
*adr
)
205 char how_to_print
, basic_unit
, unit_count
;
207 /* get how_to_print, basic_unit, and unit_count */
208 adrm_char(adr
, &how_to_print
, 1);
209 adrm_char(adr
, &basic_unit
, 1);
210 adrm_char(adr
, &unit_count
, 1);
211 for (i
= 0; i
< unit_count
; i
++) {
212 switch (basic_unit
) {
213 /* case AUR_BYTE: has same value as AUR_CHAR */
215 adrm_char(adr
, &c1
, 1);
218 adrm_short(adr
, &c2
, 1);
221 adrm_int32(adr
, (int32_t *)&c3
, 1);
224 adrm_int64(adr
, (int64_t *)&c4
, 1);
235 * Format of opaque token:
236 * opaque token id adr_char
238 * data adr_char, size times
241 opaque_token(adr_t
*adr
)
250 * Format of return32 value token:
251 * return value token id adr_char
252 * error number adr_char
253 * return value adr_u_int32
256 return_value32_token(adr_t
*adr
)
261 adrm_char(adr
, &errnum
, 1);
262 adrm_u_int32(adr
, &value
, 1);
263 if ((flags
& M_SORF
) &&
264 ((global_class
& mask
.am_success
) && (errnum
== 0)) ||
265 ((global_class
& mask
.am_failure
) && (errnum
!= 0))) {
266 checkflags
|= M_SORF
;
272 * Format of return64 value token:
273 * return value token id adr_char
274 * error number adr_char
275 * return value adr_u_int64
278 return_value64_token(adr_t
*adr
)
283 adrm_char(adr
, &errnum
, 1);
284 adrm_u_int64(adr
, &value
, 1);
285 if ((flags
& M_SORF
) &&
286 ((global_class
& mask
.am_success
) && (errnum
== 0)) ||
287 ((global_class
& mask
.am_failure
) && (errnum
!= 0))) {
288 checkflags
|= M_SORF
;
295 * Format of sequence token:
296 * sequence token id adr_char
297 * audit_count int32_t
300 sequence_token(adr_t
*adr
)
304 adrm_int32(adr
, &audit_count
, 1);
310 * Format of text token:
311 * text token id adr_char
315 text_token(adr_t
*adr
)
323 * Format of ip_addr token:
324 * ip token id adr_char
328 ip_addr_token(adr_t
*adr
)
332 adrm_char(adr
, (char *)&address
, 4);
338 * Format of ip_addr_ex token:
339 * ip token id adr_char
341 * ip address adr_u_char*type
344 ip_addr_ex_token(adr_t
*adr
)
349 adrm_int32(adr
, (int32_t *)&type
, 1);
350 adrm_u_char(adr
, address
, type
);
356 * Format of ip token:
357 * ip header token id adr_char
359 * type of service adr_char
365 * checksum adr_u_short
366 * source address adr_int32
367 * destination address adr_int32
375 unsigned short id
, offset
, checksum
;
379 adrm_char(adr
, &version
, 1);
380 adrm_char(adr
, &type
, 1);
381 adrm_short(adr
, &len
, 1);
382 adrm_u_short(adr
, &id
, 1);
383 adrm_u_short(adr
, &offset
, 1);
384 adrm_char(adr
, &ttl
, 1);
385 adrm_char(adr
, &protocol
, 1);
386 adrm_u_short(adr
, &checksum
, 1);
387 adrm_char(adr
, (char *)&src
, 4);
388 adrm_char(adr
, (char *)&dest
, 4);
395 * Format of iport token:
396 * ip port address token id adr_char
397 * port address adr_short
400 iport_token(adr_t
*adr
)
404 adrm_short(adr
, &address
, 1);
411 * Format of groups token:
412 * group token id adr_char
413 * group list adr_int32, 16 times
416 group_token(adr_t
*adr
)
422 for (i
= 0; i
< 16; i
++) {
423 adrm_int32(adr
, (int32_t *)&gid
[i
], 1);
424 if (flags
& M_GROUPR
) {
425 if ((unsigned short)m_groupr
== gid
[i
])
430 if (flags
& M_GROUPR
) {
432 checkflags
|= M_GROUPR
;
438 * Format of newgroups token:
439 * group token id adr_char
440 * number of groups adr_short
441 * group list adr_int32, "number" times
444 newgroup_token(adr_t
*adr
)
450 adrm_short(adr
, &number
, 1);
452 for (i
= 0; i
< number
; i
++) {
453 adrm_int32(adr
, (int32_t *)&gid
, 1);
454 if (flags
& M_GROUPR
) {
456 checkflags
|= M_GROUPR
;
464 * Format of argument32 token:
465 * argument token id adr_char
466 * argument number adr_char
467 * argument value adr_int32
468 * argument description adr_string
471 argument32_token(adr_t
*adr
)
476 adrm_char(adr
, &arg_num
, 1);
477 adrm_int32(adr
, &arg_val
, 1);
484 * Format of argument64 token:
485 * argument token id adr_char
486 * argument number adr_char
487 * argument value adr_int64
488 * argument description adr_string
491 argument64_token(adr_t
*adr
)
496 adrm_char(adr
, &arg_num
, 1);
497 adrm_int64(adr
, &arg_val
, 1);
504 * Format of acl token:
505 * acl token id adr_char
506 * acl type adr_u_int32
507 * acl value adr_u_int32 (depends on type)
508 * file mode adr_u_int (in octal)
511 acl_token(adr_t
*adr
)
518 adrm_int32(adr
, &type
, 1);
519 adrm_int32(adr
, &id
, 1);
520 adrm_int32(adr
, &mode
, 1);
526 * Format of ace token:
527 * ace token id adr_char
528 * ace who adr_u_int32 (uid/gid)
529 * access mask adr_u_int32
530 * ace flags adr_u_int16
531 * ace type adr_u_int16
534 ace_token(adr_t
*adr
)
537 uint32_t access_mask
;
538 uint16_t flags
, type
;
540 adrm_uid(adr
, &who
, 1);
541 adrm_u_int32(adr
, &access_mask
, 1);
542 adrm_u_short(adr
, &flags
, 1);
543 adrm_u_short(adr
, &type
, 1);
549 * Format of attribute token: (old pre SunOS 5.7 format)
550 * attribute token id adr_char
551 * mode adr_int32 (printed in octal)
554 * file system id adr_int32
559 attribute_token(adr_t
*adr
)
568 adrm_int32(adr
, &mode
, 1);
569 adrm_int32(adr
, &uid
, 1);
570 adrm_int32(adr
, &gid
, 1);
571 adrm_int32(adr
, &file_sysid
, 1);
572 adrm_int32(adr
, &nodeid
, 1);
573 adrm_int32(adr
, &dev
, 1);
575 if (!new_mode
&& (flags
& M_USERE
)) {
577 checkflags
|= M_USERE
;
579 if (!new_mode
&& (flags
& M_GROUPE
)) {
581 checkflags
|= M_GROUPE
;
584 if (flags
& M_OBJECT
) {
585 if ((obj_flag
& OBJ_FGROUP
) &&
587 checkflags
|= M_OBJECT
;
588 else if ((obj_flag
& OBJ_FOWNER
) &&
590 checkflags
|= M_OBJECT
;
596 * Format of attribute32 token:
597 * attribute token id adr_char
598 * mode adr_int32 (printed in octal)
601 * file system id adr_int32
606 attribute32_token(adr_t
*adr
)
615 adrm_int32(adr
, &mode
, 1);
616 adrm_int32(adr
, &uid
, 1);
617 adrm_int32(adr
, &gid
, 1);
618 adrm_int32(adr
, &file_sysid
, 1);
619 adrm_int64(adr
, &nodeid
, 1);
620 adrm_int32(adr
, &dev
, 1);
622 if (!new_mode
&& (flags
& M_USERE
)) {
624 checkflags
|= M_USERE
;
626 if (!new_mode
&& (flags
& M_GROUPE
)) {
628 checkflags
|= M_GROUPE
;
631 if (flags
& M_OBJECT
) {
632 if ((obj_flag
& OBJ_FGROUP
) &&
634 checkflags
|= M_OBJECT
;
635 else if ((obj_flag
& OBJ_FOWNER
) &&
637 checkflags
|= M_OBJECT
;
643 * Format of attribute64 token:
644 * attribute token id adr_char
645 * mode adr_int32 (printed in octal)
648 * file system id adr_int32
653 attribute64_token(adr_t
*adr
)
662 adrm_int32(adr
, &mode
, 1);
663 adrm_int32(adr
, &uid
, 1);
664 adrm_int32(adr
, &gid
, 1);
665 adrm_int32(adr
, &file_sysid
, 1);
666 adrm_int64(adr
, &nodeid
, 1);
667 adrm_int64(adr
, &dev
, 1);
669 if (!new_mode
&& (flags
& M_USERE
)) {
671 checkflags
|= M_USERE
;
673 if (!new_mode
&& (flags
& M_GROUPE
)) {
675 checkflags
|= M_GROUPE
;
678 if (flags
& M_OBJECT
) {
679 if ((obj_flag
& OBJ_FGROUP
) &&
681 checkflags
|= M_OBJECT
;
682 else if ((obj_flag
& OBJ_FOWNER
) &&
684 checkflags
|= M_OBJECT
;
691 * Format of command token:
692 * attribute token id adr_char
694 * argv len adr_short variable amount of argv len
695 * argv text argv len and text
699 * envp count adr_short variable amount of envp len
700 * envp len adr_short and text
707 cmd_token(adr_t
*adr
)
712 adrm_short(adr
, &cnt
, 1);
714 for (i
= 0; i
< cnt
; i
++)
717 adrm_short(adr
, &cnt
, 1);
719 for (i
= 0; i
< cnt
; i
++)
727 * Format of exit token:
728 * attribute token id adr_char
729 * return value adr_int32
733 exit_token(adr_t
*adr
)
738 adrm_int32(adr
, &retval
, 1);
739 adrm_int32(adr
, &errno
, 1);
744 * Format of strings array token:
746 * count value adr_int32
747 * strings null terminated strings
750 strings_common_token(adr_t
*adr
)
755 adrm_int32(adr
, (int32_t *)&count
, 1);
756 for (i
= 1; i
<= count
; i
++) {
757 adrm_char(adr
, &c
, 1);
759 adrm_char(adr
, &c
, 1);
761 /* no dump option here, since we will have variable length fields */
766 path_attr_token(adr_t
*adr
)
768 return (strings_common_token(adr
));
772 exec_args_token(adr_t
*adr
)
774 return (strings_common_token(adr
));
778 exec_env_token(adr_t
*adr
)
780 return (strings_common_token(adr
));
784 * Format of liaison token:
787 liaison_token(adr_t
*adr
)
791 adrm_int32(adr
, &li
, 1);
797 * Format of path token:
801 path_token(adr_t
*adr
)
803 if ((flags
& M_OBJECT
) && (obj_flag
== OBJ_PATH
)) {
806 get_string(adr
, &path
);
809 * anchor the path. user apps may not do it.
813 * match against the collapsed path. that is what user sees.
815 if (re_exec2(collapse_path(path
)) == 1)
816 checkflags
|= M_OBJECT
;
826 * Format of System V IPC permission token:
827 * System V IPC permission token id adr_char
837 s5_IPC_perm_token(adr_t
*adr
)
839 int32_t uid
, gid
, cuid
, cgid
, mode
, seq
;
842 adrm_int32(adr
, &uid
, 1);
843 adrm_int32(adr
, &gid
, 1);
844 adrm_int32(adr
, &cuid
, 1);
845 adrm_int32(adr
, &cgid
, 1);
846 adrm_int32(adr
, &mode
, 1);
847 adrm_int32(adr
, &seq
, 1);
848 adrm_int32(adr
, &key
, 1);
850 if (!new_mode
&& (flags
& M_USERE
)) {
852 checkflags
|= M_USERE
;
855 if (!new_mode
&& (flags
& M_USERE
)) {
857 checkflags
|= M_USERE
;
860 if (!new_mode
&& (flags
& M_GROUPR
)) {
862 checkflags
|= M_GROUPR
;
865 if (!new_mode
&& (flags
& M_GROUPR
)) {
866 if (m_groupr
== cgid
)
867 checkflags
|= M_GROUPR
;
870 if ((flags
& M_OBJECT
) &&
871 ((obj_owner
== uid
) ||
872 (obj_owner
== cuid
) ||
873 (obj_group
== gid
) ||
874 (obj_group
== cgid
))) {
879 if (ipc_type_match(OBJ_MSG
, ipc_type
))
880 checkflags
|= M_OBJECT
;
884 if (ipc_type_match(OBJ_SEM
, ipc_type
))
885 checkflags
|= M_OBJECT
;
889 if (ipc_type_match(OBJ_SHM
, ipc_type
))
890 checkflags
|= M_OBJECT
;
899 * Format of process32 token:
900 * process token id adr_char
911 process32_token(adr_t
*adr
)
913 int32_t auid
, euid
, egid
, ruid
, rgid
, pid
;
915 int32_t port
, machine
;
917 adrm_int32(adr
, &auid
, 1);
918 adrm_int32(adr
, &euid
, 1);
919 adrm_int32(adr
, &egid
, 1);
920 adrm_int32(adr
, &ruid
, 1);
921 adrm_int32(adr
, &rgid
, 1);
922 adrm_int32(adr
, &pid
, 1);
923 adrm_int32(adr
, &sid
, 1);
924 adrm_int32(adr
, &port
, 1);
925 adrm_int32(adr
, &machine
, 1);
927 if (!new_mode
&& (flags
& M_USERA
)) {
929 checkflags
|= M_USERA
;
931 if (!new_mode
&& (flags
& M_USERE
)) {
933 checkflags
|= M_USERE
;
935 if (!new_mode
&& (flags
& M_USERR
)) {
937 checkflags
|= M_USERR
;
939 if (!new_mode
&& (flags
& M_GROUPR
)) {
940 if (m_groupr
== rgid
)
941 checkflags
|= M_GROUPR
;
943 if (!new_mode
&& (flags
& M_GROUPE
)) {
944 if (m_groupe
== egid
)
945 checkflags
|= M_GROUPE
;
948 if (flags
& M_OBJECT
) {
949 if ((obj_flag
& OBJ_PROC
) &&
951 checkflags
|= M_OBJECT
;
952 } else if ((obj_flag
& OBJ_PGROUP
) &&
953 ((obj_group
== egid
) ||
954 (obj_group
== rgid
))) {
955 checkflags
|= M_OBJECT
;
956 } else if ((obj_flag
& OBJ_POWNER
) &&
957 ((obj_owner
== euid
) ||
958 (obj_group
== ruid
))) {
959 checkflags
|= M_OBJECT
;
966 * Format of process32_ex token:
967 * process token id adr_char
978 * ip address adr_u_char*type
981 process32_ex_token(adr_t
*adr
)
983 int32_t auid
, euid
, egid
, ruid
, rgid
, pid
;
988 adrm_int32(adr
, &auid
, 1);
989 adrm_int32(adr
, &euid
, 1);
990 adrm_int32(adr
, &egid
, 1);
991 adrm_int32(adr
, &ruid
, 1);
992 adrm_int32(adr
, &rgid
, 1);
993 adrm_int32(adr
, &pid
, 1);
994 adrm_int32(adr
, &sid
, 1);
995 adrm_int32(adr
, &port
, 1);
996 adrm_int32(adr
, &type
, 1);
997 adrm_u_char(adr
, addr
, type
);
999 if (!new_mode
&& (flags
& M_USERA
)) {
1000 if (m_usera
== auid
)
1001 checkflags
= checkflags
| M_USERA
;
1003 if (!new_mode
&& (flags
& M_USERE
)) {
1004 if (m_usere
== euid
)
1005 checkflags
= checkflags
| M_USERE
;
1007 if (!new_mode
&& (flags
& M_USERR
)) {
1008 if (m_userr
== ruid
)
1009 checkflags
= checkflags
| M_USERR
;
1011 if (!new_mode
&& (flags
& M_GROUPR
)) {
1012 if (m_groupr
== egid
)
1013 checkflags
= checkflags
| M_GROUPR
;
1015 if (!new_mode
&& (flags
& M_GROUPE
)) {
1016 if (m_groupe
== egid
)
1017 checkflags
= checkflags
| M_GROUPE
;
1020 if (flags
& M_OBJECT
) {
1021 if ((obj_flag
& OBJ_PROC
) &&
1023 checkflags
= checkflags
| M_OBJECT
;
1024 } else if ((obj_flag
& OBJ_PGROUP
) &&
1025 ((obj_group
== egid
) ||
1026 (obj_group
== rgid
))) {
1027 checkflags
= checkflags
| M_OBJECT
;
1028 } else if ((obj_flag
& OBJ_POWNER
) &&
1029 ((obj_owner
== euid
) ||
1030 (obj_group
== ruid
))) {
1031 checkflags
= checkflags
| M_OBJECT
;
1038 * Format of process64 token:
1039 * process token id adr_char
1047 * termid adr_int64+adr_int32
1050 process64_token(adr_t
*adr
)
1052 int32_t auid
, euid
, egid
, ruid
, rgid
, pid
;
1057 adrm_int32(adr
, &auid
, 1);
1058 adrm_int32(adr
, &euid
, 1);
1059 adrm_int32(adr
, &egid
, 1);
1060 adrm_int32(adr
, &ruid
, 1);
1061 adrm_int32(adr
, &rgid
, 1);
1062 adrm_int32(adr
, &pid
, 1);
1063 adrm_int32(adr
, &sid
, 1);
1064 adrm_int64(adr
, &port
, 1);
1065 adrm_int32(adr
, &machine
, 1);
1067 if (!new_mode
&& (flags
& M_USERA
)) {
1068 if (m_usera
== auid
)
1069 checkflags
|= M_USERA
;
1071 if (!new_mode
&& (flags
& M_USERE
)) {
1072 if (m_usere
== euid
)
1073 checkflags
|= M_USERE
;
1075 if (!new_mode
&& (flags
& M_USERR
)) {
1076 if (m_userr
== ruid
)
1077 checkflags
|= M_USERR
;
1079 if (!new_mode
&& (flags
& M_GROUPR
)) {
1080 if (m_groupr
== rgid
)
1081 checkflags
|= M_GROUPR
;
1083 if (!new_mode
&& (flags
& M_GROUPE
)) {
1084 if (m_groupe
== egid
)
1085 checkflags
|= M_GROUPE
;
1088 if (flags
& M_OBJECT
) {
1089 if ((obj_flag
& OBJ_PROC
) &&
1091 checkflags
|= M_OBJECT
;
1092 } else if ((obj_flag
& OBJ_PGROUP
) &&
1093 ((obj_group
== egid
) ||
1094 (obj_group
== rgid
))) {
1095 checkflags
|= M_OBJECT
;
1096 } else if ((obj_flag
& OBJ_POWNER
) &&
1097 ((obj_owner
== euid
) ||
1098 (obj_group
== ruid
))) {
1099 checkflags
|= M_OBJECT
;
1106 * Format of process64_ex token:
1107 * process token id adr_char
1118 * ip address adr_u_char*type
1121 process64_ex_token(adr_t
*adr
)
1123 int32_t auid
, euid
, egid
, ruid
, rgid
, pid
;
1129 adrm_int32(adr
, &auid
, 1);
1130 adrm_int32(adr
, &euid
, 1);
1131 adrm_int32(adr
, &egid
, 1);
1132 adrm_int32(adr
, &ruid
, 1);
1133 adrm_int32(adr
, &rgid
, 1);
1134 adrm_int32(adr
, &pid
, 1);
1135 adrm_int32(adr
, &sid
, 1);
1136 adrm_int64(adr
, &port
, 1);
1137 adrm_int32(adr
, &type
, 1);
1138 adrm_u_char(adr
, addr
, type
);
1140 if (!new_mode
&& (flags
& M_USERA
)) {
1141 if (m_usera
== auid
)
1142 checkflags
= checkflags
| M_USERA
;
1144 if (!new_mode
&& (flags
& M_USERE
)) {
1145 if (m_usere
== euid
)
1146 checkflags
= checkflags
| M_USERE
;
1148 if (!new_mode
&& (flags
& M_USERR
)) {
1149 if (m_userr
== ruid
)
1150 checkflags
= checkflags
| M_USERR
;
1152 if (!new_mode
&& (flags
& M_GROUPR
)) {
1153 if (m_groupr
== egid
)
1154 checkflags
= checkflags
| M_GROUPR
;
1156 if (!new_mode
&& (flags
& M_GROUPE
)) {
1157 if (m_groupe
== egid
)
1158 checkflags
= checkflags
| M_GROUPE
;
1161 if (flags
& M_OBJECT
) {
1162 if ((obj_flag
& OBJ_PROC
) &&
1164 checkflags
= checkflags
| M_OBJECT
;
1165 } else if ((obj_flag
& OBJ_PGROUP
) &&
1166 ((obj_group
== egid
) ||
1167 (obj_group
== rgid
))) {
1168 checkflags
= checkflags
| M_OBJECT
;
1169 } else if ((obj_flag
& OBJ_POWNER
) &&
1170 ((obj_owner
== euid
) ||
1171 (obj_group
== ruid
))) {
1172 checkflags
= checkflags
| M_OBJECT
;
1179 * Format of System V IPC token:
1180 * System V IPC token id adr_char
1181 * object id adr_int32
1184 s5_IPC_token(adr_t
*adr
)
1188 adrm_char(adr
, &ipc_type
, 1); /* Global */
1189 adrm_int32(adr
, &ipc_id
, 1);
1191 if ((flags
& M_OBJECT
) &&
1192 ipc_type_match(obj_flag
, ipc_type
) &&
1194 checkflags
|= M_OBJECT
;
1201 * Format of socket token:
1202 * socket_type adrm_short
1203 * remote_port adrm_short
1204 * remote_inaddr adrm_int32
1207 socket_token(adr_t
*adr
)
1211 int32_t remote_inaddr
;
1213 adrm_short(adr
, &socket_type
, 1);
1214 adrm_short(adr
, &remote_port
, 1);
1215 adrm_char(adr
, (char *)&remote_inaddr
, 4);
1217 if ((flags
& M_OBJECT
) && (obj_flag
== OBJ_SOCK
)) {
1218 if (socket_flag
== SOCKFLG_MACHINE
) {
1219 if (remote_inaddr
== obj_id
)
1220 checkflags
|= M_OBJECT
;
1221 } else if (socket_flag
== SOCKFLG_PORT
) {
1222 if (remote_port
== obj_id
)
1223 checkflags
|= M_OBJECT
;
1231 * Format of socket_ex token:
1232 * socket_domain adrm_short
1233 * socket_type adrm_short
1234 * address_type adrm_short
1235 * local_port adrm_short
1236 * local_inaddr adrm_u_char*address_type
1237 * remote_port adrm_short
1238 * remote_inaddr adrm_u_char*address_type
1241 socket_ex_token(adr_t
*adr
)
1243 short socket_domain
;
1247 uchar_t local_inaddr
[16];
1249 uchar_t remote_inaddr
[16];
1250 uchar_t
*caddr
= (uchar_t
*)&obj_id
;
1252 adrm_short(adr
, &socket_domain
, 1);
1253 adrm_short(adr
, &socket_type
, 1);
1254 adrm_short(adr
, &ip_size
, 1);
1256 /* validate ip size */
1257 if ((ip_size
!= AU_IPv6
) && (ip_size
!= AU_IPv4
))
1260 adrm_short(adr
, &local_port
, 1);
1261 adrm_char(adr
, (char *)local_inaddr
, ip_size
);
1263 adrm_short(adr
, &remote_port
, 1);
1264 adrm_char(adr
, (char *)remote_inaddr
, ip_size
);
1266 /* if IP type mis-match, then nothing to do */
1267 if (ip_size
!= ip_type
)
1270 if ((flags
& M_OBJECT
) && (obj_flag
== OBJ_SOCK
)) {
1271 if (socket_flag
== SOCKFLG_MACHINE
) {
1272 if (ip_type
== AU_IPv6
) {
1273 caddr
= (uchar_t
*)ip_ipv6
;
1275 if ((memcmp(local_inaddr
, caddr
, ip_type
) == 0) ||
1276 (memcmp(remote_inaddr
, caddr
, ip_type
) == 0)) {
1277 checkflags
|= M_OBJECT
;
1279 } else if (socket_flag
== SOCKFLG_PORT
) {
1280 if ((local_port
== obj_id
) || (remote_port
== obj_id
)) {
1281 checkflags
|= M_OBJECT
;
1290 * Format of subject32 token:
1291 * subject token id adr_char
1299 * termid adr_int32*2
1302 subject32_token(adr_t
*adr
)
1304 int32_t auid
, euid
, egid
, ruid
, rgid
, pid
;
1306 int32_t port
, machine
;
1308 adrm_int32(adr
, &auid
, 1);
1309 adrm_int32(adr
, &euid
, 1);
1310 adrm_int32(adr
, &egid
, 1);
1311 adrm_int32(adr
, &ruid
, 1);
1312 adrm_int32(adr
, &rgid
, 1);
1313 adrm_int32(adr
, &pid
, 1);
1314 adrm_int32(adr
, &sid
, 1);
1315 adrm_int32(adr
, &port
, 1);
1316 adrm_int32(adr
, &machine
, 1);
1318 if (flags
& M_SUBJECT
) {
1320 checkflags
|= M_SUBJECT
;
1322 if (flags
& M_USERA
) {
1323 if (m_usera
== auid
)
1324 checkflags
|= M_USERA
;
1326 if (flags
& M_USERE
) {
1327 if (m_usere
== euid
)
1328 checkflags
|= M_USERE
;
1330 if (flags
& M_USERR
) {
1331 if (m_userr
== ruid
)
1332 checkflags
|= M_USERR
;
1334 if (flags
& M_GROUPR
) {
1335 if (m_groupr
== rgid
)
1336 checkflags
|= M_GROUPR
;
1338 if (flags
& M_GROUPE
) {
1339 if (m_groupe
== egid
)
1340 checkflags
|= M_GROUPE
;
1342 if (flags
& M_SID
) {
1343 if (m_sid
== (au_asid_t
)sid
)
1344 checkflags
|= M_SID
;
1350 * Format of subject32_ex token:
1351 * subject token id adr_char
1362 * ip address adr_u_char*type
1365 subject32_ex_token(adr_t
*adr
)
1367 int32_t auid
, euid
, egid
, ruid
, rgid
, pid
;
1372 adrm_int32(adr
, &auid
, 1);
1373 adrm_int32(adr
, &euid
, 1);
1374 adrm_int32(adr
, &egid
, 1);
1375 adrm_int32(adr
, &ruid
, 1);
1376 adrm_int32(adr
, &rgid
, 1);
1377 adrm_int32(adr
, &pid
, 1);
1378 adrm_int32(adr
, &sid
, 1);
1379 adrm_int32(adr
, &port
, 1);
1380 adrm_int32(adr
, &type
, 1);
1381 adrm_u_char(adr
, addr
, type
);
1383 if (flags
& M_SUBJECT
) {
1385 checkflags
= checkflags
| M_SUBJECT
;
1387 if (flags
& M_USERA
) {
1388 if (m_usera
== auid
)
1389 checkflags
= checkflags
| M_USERA
;
1391 if (flags
& M_USERE
) {
1392 if (m_usere
== euid
)
1393 checkflags
= checkflags
| M_USERE
;
1395 if (flags
& M_USERR
) {
1396 if (m_userr
== ruid
)
1397 checkflags
= checkflags
| M_USERR
;
1399 if (flags
& M_GROUPR
) {
1400 if (m_groupr
== egid
)
1401 checkflags
= checkflags
| M_GROUPR
;
1403 if (flags
& M_GROUPE
) {
1404 if (m_groupe
== egid
)
1405 checkflags
= checkflags
| M_GROUPE
;
1407 if (flags
& M_SID
) {
1408 if (m_sid
== (au_asid_t
)sid
)
1409 checkflags
= checkflags
| M_SID
;
1415 * Format of subject64 token:
1416 * subject token id adr_char
1424 * termid adr_int64+adr_int32
1427 subject64_token(adr_t
*adr
)
1429 int32_t auid
, euid
, egid
, ruid
, rgid
, pid
;
1434 adrm_int32(adr
, &auid
, 1);
1435 adrm_int32(adr
, &euid
, 1);
1436 adrm_int32(adr
, &egid
, 1);
1437 adrm_int32(adr
, &ruid
, 1);
1438 adrm_int32(adr
, &rgid
, 1);
1439 adrm_int32(adr
, &pid
, 1);
1440 adrm_int32(adr
, &sid
, 1);
1441 adrm_int64(adr
, &port
, 1);
1442 adrm_int32(adr
, &machine
, 1);
1444 if (flags
& M_SUBJECT
) {
1446 checkflags
|= M_SUBJECT
;
1448 if (flags
& M_USERA
) {
1449 if (m_usera
== auid
)
1450 checkflags
|= M_USERA
;
1452 if (flags
& M_USERE
) {
1453 if (m_usere
== euid
)
1454 checkflags
|= M_USERE
;
1456 if (flags
& M_USERR
) {
1457 if (m_userr
== ruid
)
1458 checkflags
|= M_USERR
;
1460 if (flags
& M_GROUPR
) {
1461 if (m_groupr
== rgid
)
1462 checkflags
|= M_GROUPR
;
1464 if (flags
& M_GROUPE
) {
1465 if (m_groupe
== egid
)
1466 checkflags
|= M_GROUPE
;
1468 if (flags
& M_SID
) {
1469 if (m_sid
== (au_asid_t
)sid
)
1470 checkflags
|= M_SID
;
1476 * Format of subject64_ex token:
1477 * subject token id adr_char
1488 * ip address adr_u_char*type
1491 subject64_ex_token(adr_t
*adr
)
1493 int32_t auid
, euid
, egid
, ruid
, rgid
, pid
;
1499 adrm_int32(adr
, &auid
, 1);
1500 adrm_int32(adr
, &euid
, 1);
1501 adrm_int32(adr
, &egid
, 1);
1502 adrm_int32(adr
, &ruid
, 1);
1503 adrm_int32(adr
, &rgid
, 1);
1504 adrm_int32(adr
, &pid
, 1);
1505 adrm_int32(adr
, &sid
, 1);
1506 adrm_int64(adr
, &port
, 1);
1507 adrm_int32(adr
, &type
, 1);
1508 adrm_u_char(adr
, addr
, type
);
1510 if (flags
& M_SUBJECT
) {
1512 checkflags
= checkflags
| M_SUBJECT
;
1514 if (flags
& M_USERA
) {
1515 if (m_usera
== auid
)
1516 checkflags
= checkflags
| M_USERA
;
1518 if (flags
& M_USERE
) {
1519 if (m_usere
== euid
)
1520 checkflags
= checkflags
| M_USERE
;
1522 if (flags
& M_USERR
) {
1523 if (m_userr
== ruid
)
1524 checkflags
= checkflags
| M_USERR
;
1526 if (flags
& M_GROUPR
) {
1527 if (m_groupr
== egid
)
1528 checkflags
= checkflags
| M_GROUPR
;
1530 if (flags
& M_GROUPE
) {
1531 if (m_groupe
== egid
)
1532 checkflags
= checkflags
| M_GROUPE
;
1534 if (flags
& M_SID
) {
1535 if (m_sid
== (au_asid_t
)sid
)
1536 checkflags
= checkflags
| M_SID
;
1542 * -----------------------------------------------------------------------
1543 * tid_token(): Process tid token and display contents
1545 * Format of tid token:
1546 * tid token id adr_char
1547 * address type adr_char
1548 * For address type of AU_IPADR...
1549 * remote port adr_short
1550 * local port adr_short
1552 * IP addr adr_int32 if IPv4
1553 * IP addr 4 x adr_int32 if IPv6
1554 * address types other than AU_IPADR are not yet defined
1555 * -----------------------------------------------------------------------
1558 tid_token(adr_t
*adr
)
1566 adrm_char(adr
, &tid_type
, 1);
1569 adrm_short(adr
, &rport
, 1);
1570 adrm_short(adr
, &lport
, 1);
1571 adrm_int32(adr
, &ip_type
, 1);
1572 adrm_char(adr
, (char *)&address
, ip_type
);
1581 * -----------------------------------------------------------------------
1582 * zonename_token(): Process zonename token and display contents
1584 * Format of zonename token:
1585 * zonename token id adr_char
1586 * zone name adr_string
1587 * -----------------------------------------------------------------------
1590 zonename_token(adr_t
*adr
)
1594 if (flags
& M_ZONENAME
) {
1595 get_string(adr
, &name
);
1596 if (strncmp(zonename
, name
, ZONENAME_MAX
) == 0)
1597 checkflags
|= M_ZONENAME
;
1608 * Format of fmri token:
1612 fmri_token(adr_t
*adr
)
1614 if ((flags
& M_OBJECT
) && (obj_flag
== OBJ_FMRI
)) {
1617 get_string(adr
, &fmri_name
);
1619 /* match token against service instance */
1620 if (scf_cmp_pattern(fmri_name
, &fmri
) == 1) {
1621 checkflags
|= M_OBJECT
;
1631 * Format of xatom token:
1634 xatom_token(adr_t
*adr
)
1642 * Format of xselect token:
1645 xselect_token(adr_t
*adr
)
1655 * anchor a path name with a slash
1656 * assume we have enough space
1659 anchor_path(char *path
)
1661 (void) memmove((void *)(path
+ 1), (void *)path
, strlen(path
) + 1);
1667 * copy path to collapsed path.
1668 * collapsed path does not contain:
1669 * successive slashes
1670 * instances of dot-slash
1671 * instances of dot-dot-slash
1672 * passed path must be anchored with a '/'
1675 collapse_path(char *s
)
1677 int id
; /* index of where we are in destination string */
1678 int is
; /* index of where we are in source string */
1679 int slashseen
; /* have we seen a slash */
1680 int ls
; /* length of source string */
1685 for (is
= 0, id
= 0; is
< ls
; is
++) {
1686 /* thats all folks, we've reached the end of input */
1687 if (s
[is
] == '\0') {
1688 if (id
> 1 && s
[id
-1] == '/') {
1694 /* previous character was a / */
1697 continue; /* another slash, ignore it */
1698 } else if (s
[is
] == '/') {
1699 /* we see a /, just copy it and try again */
1705 if (s
[is
] == '.' && s
[is
+1] == '/') {
1710 if (s
[is
] == '.' && s
[is
+1] == '\0') {
1716 if (s
[is
] == '.' && s
[is
+1] == '.' && s
[is
+2] == '\0') {
1720 while (id
> 0 && s
[--id
] != '/')
1726 if (s
[is
] == '.' && s
[is
+1] == '.' && s
[is
+2] == '/') {
1730 while (id
> 0 && s
[--id
] != '/')
1735 while (is
< ls
&& (s
[id
++] = s
[is
++]) != '/')
1744 ipc_type_match(int flag
, char type
)
1746 if (flag
== OBJ_SEM
&& type
== AT_IPC_SEM
)
1749 if (flag
== OBJ_MSG
&& type
== AT_IPC_MSG
)
1752 if (flag
== OBJ_SHM
&& type
== AT_IPC_SHM
)
1760 skip_string(adr_t
*adr
)
1764 adrm_u_short(adr
, &c
, 1);
1770 get_string(adr_t
*adr
, char **p
)
1774 adrm_u_short(adr
, &c
, 1);
1775 *p
= a_calloc(1, (size_t)c
);
1776 adrm_char(adr
, *p
, c
);
1781 * Format of host token:
1785 host_token(adr_t
*adr
)
1789 adrm_u_int32(adr
, &host
, 1);
1795 * Format of useofauth token:
1796 * uauth token id adr_char
1800 useofauth_token(adr_t
*adr
)
1807 * Format of user token:
1808 * user token id adr_char
1810 * username adr_string
1813 user_token(adr_t
*adr
)
1817 adrm_uid(adr
, &uid
, 1);
1820 if ((flags
& M_OBJECT
) && (obj_flag
== OBJ_USER
) &&
1821 (uid
== obj_user
)) {
1822 checkflags
|= M_OBJECT
;
1829 xcolormap_token(adr_t
*adr
)
1831 return (xgeneric(adr
));
1835 xcursor_token(adr_t
*adr
)
1837 return (xgeneric(adr
));
1841 xfont_token(adr_t
*adr
)
1843 return (xgeneric(adr
));
1847 xgc_token(adr_t
*adr
)
1849 return (xgeneric(adr
));
1853 xpixmap_token(adr_t
*adr
)
1855 return (xgeneric(adr
));
1859 xwindow_token(adr_t
*adr
)
1861 return (xgeneric(adr
));
1866 * Format of xgeneric token:
1868 * creator UID adr_int32
1870 * Includes: xcolormap, xcursor, xfont, xgc, xpixmap, and xwindow
1873 xgeneric(adr_t
*adr
)
1878 adrm_int32(adr
, &xid
, 1);
1879 adrm_int32(adr
, &uid
, 1);
1881 if (flags
& M_USERE
) {
1883 checkflags
= checkflags
| M_USERE
;
1891 * Format of xproperty token:
1893 * creator UID adr_int32
1894 * atom string adr_string
1897 xproperty_token(adr_t
*adr
)
1902 adrm_int32(adr
, &xid
, 1);
1903 adrm_int32(adr
, &uid
, 1);
1906 if (flags
& M_USERE
) {
1908 checkflags
= checkflags
| M_USERE
;
1916 * Format of xclient token:
1917 * xclient id adr_int32
1920 xclient_token(adr_t
*adr
)
1924 adrm_int32(adr
, &client_id
, 1);
1930 * Format of privilege set token:
1931 * priv_set type string
1936 privilege_token(adr_t
*adr
)
1938 skip_string(adr
); /* set type name */
1939 skip_string(adr
); /* privilege set */
1944 * Format of security flags token:
1945 * security flag set string
1946 * security flags string
1950 secflags_token(adr_t
*adr
)
1952 skip_string(adr
); /* set name */
1953 skip_string(adr
); /* security flags */
1958 * Format of label token:
1960 * compartment length 1 byte
1961 * classification 2 bytes
1962 * compartment words <compartment length> * 4 bytes
1965 label_token(adr_t
*adr
)
1967 static m_label_t
*label
= NULL
;
1968 static size32_t l_size
;
1971 if (label
== NULL
) {
1972 label
= m_label_alloc(MAC_LABEL
);
1973 l_size
= blabel_size() - 4;
1976 if (label
== NULL
) {
1977 /* out of memory, should never happen; skip label */
1978 char l
; /* length */
1980 adr
->adr_now
+= sizeof (char);
1981 adrm_char(adr
, (char *)&l
, 1);
1982 adr
->adr_now
+= sizeof (short) + (4 * l
);
1986 adrm_char(adr
, (char *)label
, 4);
1987 len
= (int)(((char *)label
)[1] * 4);
1991 adrm_char(adr
, &((char *)label
)[4], len
);
1993 if (flags
& M_LABEL
) {
1994 if (blinrange(label
, m_label
))
1995 checkflags
= checkflags
| M_LABEL
;
2003 * Format of useofpriv token:
2004 * success/failure adr_char
2005 * privilege(s) adr_string
2009 useofpriv_token(adr_t
*adr
)
2013 adrm_char(adr
, &flag
, 1);