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.
27 #include <sys/types.h>
29 #include <bsm/audit.h>
30 #include <bsm/audit_record.h>
31 #include <bsm/libbsm.h>
34 #include <sys/param.h>
35 #include <sys/socket.h>
37 #include <sys/vnode.h>
39 #include <net/route.h>
40 #include <netinet/in.h>
41 #include <netinet/in_pcb.h>
45 #include <sys/tsol/label.h>
47 #define NGROUPS 16 /* XXX - temporary */
49 token_t
*au_to_arg(char n
, char *text
, uint32_t v
);
50 #pragma weak au_to_arg = au_to_arg32
51 token_t
*au_to_return(char number
, uint32_t value
);
52 #pragma weak au_to_return = au_to_return32
54 static token_t
*au_to_exec(char **, char);
59 token_t
*token
; /* Resultant token */
61 if ((token
= (token_t
*)malloc(sizeof (token_t
))) == NULL
)
63 if ((token
->tt_data
= malloc(s
)) == NULL
) {
68 token
->tt_next
= NULL
;
75 * pointer to header token.
78 au_to_header(au_event_t e_type
, au_emod_t e_mod
)
80 adr_t adr
; /* adr memory stream header */
81 token_t
*token
; /* token pointer */
82 char version
= TOKEN_VERSION
; /* version of token family */
86 char data_header
= AUT_HEADER64
; /* header for this token */
88 token
= get_token(2 * sizeof (char) + sizeof (int32_t) +
89 2 * sizeof (int64_t) + 2 * sizeof (short));
91 char data_header
= AUT_HEADER32
;
93 token
= get_token(2 * sizeof (char) + 3 * sizeof (int32_t) +
99 adr_start(&adr
, token
->tt_data
);
100 adr_char(&adr
, &data_header
, 1); /* token ID */
101 adr_int32(&adr
, &byte_count
, 1); /* length of audit record */
102 adr_char(&adr
, &version
, 1); /* version of audit tokens */
103 adr_ushort(&adr
, &e_type
, 1); /* event ID */
104 adr_ushort(&adr
, &e_mod
, 1); /* event ID modifier */
106 adr_int64(&adr
, (int64_t *)&tv
, 2); /* time & date */
108 adr_int32(&adr
, (int32_t *)&tv
, 2); /* time & date */
116 * pointer to header token.
119 au_to_header_ex(au_event_t e_type
, au_emod_t e_mod
)
121 adr_t adr
; /* adr memory stream header */
122 token_t
*token
; /* token pointer */
123 char version
= TOKEN_VERSION
; /* version of token family */
126 auditinfo_addr_t audit_info
;
127 au_tid_addr_t
*host_info
= &audit_info
.ai_termid
;
129 char data_header
= AUT_HEADER64_EX
; /* header for this token */
131 char data_header
= AUT_HEADER32_EX
;
134 /* If our host address can't be determined, revert to un-extended hdr */
136 if (auditon(A_GETKAUDIT
, (caddr_t
)&audit_info
,
137 sizeof (audit_info
)) < 0)
138 return (au_to_header(e_type
, e_mod
));
140 if (host_info
->at_type
== AU_IPv6
)
141 if (IN6_IS_ADDR_UNSPECIFIED((in6_addr_t
*)host_info
->at_addr
))
142 return (au_to_header(e_type
, e_mod
));
144 if (host_info
->at_addr
[0] == htonl(INADDR_ANY
))
145 return (au_to_header(e_type
, e_mod
));
148 token
= get_token(2 * sizeof (char) + sizeof (int32_t) +
149 2 * sizeof (int64_t) + 2 * sizeof (short) +
150 sizeof (int32_t) + host_info
->at_type
);
152 token
= get_token(2 * sizeof (char) + 3 * sizeof (int32_t) +
153 2 * sizeof (short) + sizeof (int32_t) + host_info
->at_type
);
158 adr_start(&adr
, token
->tt_data
);
159 adr_char(&adr
, &data_header
, 1); /* token ID */
160 adr_int32(&adr
, &byte_count
, 1); /* length of audit record */
161 adr_char(&adr
, &version
, 1); /* version of audit tokens */
162 adr_ushort(&adr
, &e_type
, 1); /* event ID */
163 adr_ushort(&adr
, &e_mod
, 1); /* event ID modifier */
164 adr_int32(&adr
, (int32_t *)&host_info
->at_type
, 1);
165 adr_char(&adr
, (char *)host_info
->at_addr
,
166 (int)host_info
->at_type
);
168 adr_int64(&adr
, (int64_t *)&tv
, 2); /* time & date */
170 adr_int32(&adr
, (int32_t *)&tv
, 2); /* time & date */
178 * pointer to a trailer token.
183 adr_t adr
; /* adr memory stream header */
184 token_t
*token
; /* token pointer */
185 char data_header
= AUT_TRAILER
; /* header for this token */
186 short magic
= (short)AUT_TRAILER_MAGIC
; /* trailer magic number */
189 token
= get_token(sizeof (char) + sizeof (int32_t) + sizeof (short));
192 adr_start(&adr
, token
->tt_data
);
193 adr_char(&adr
, &data_header
, 1); /* token ID */
194 adr_short(&adr
, &magic
, 1); /* magic number */
195 adr_int32(&adr
, &byte_count
, 1); /* length of audit record */
203 * pointer to an argument token.
206 au_to_arg32(char n
, char *text
, uint32_t v
)
208 token_t
*token
; /* local token */
209 adr_t adr
; /* adr memory stream header */
210 char data_header
= AUT_ARG32
; /* header for this token */
211 short bytes
; /* length of string */
213 bytes
= strlen(text
) + 1;
215 token
= get_token((int)(2 * sizeof (char) + sizeof (int32_t) +
216 sizeof (short) + bytes
));
219 adr_start(&adr
, token
->tt_data
);
220 adr_char(&adr
, &data_header
, 1); /* token type */
221 adr_char(&adr
, &n
, 1); /* argument id */
222 adr_int32(&adr
, (int32_t *)&v
, 1); /* argument value */
223 adr_short(&adr
, &bytes
, 1);
224 adr_char(&adr
, text
, bytes
);
232 * pointer to an argument token.
235 au_to_arg64(char n
, char *text
, uint64_t v
)
237 token_t
*token
; /* local token */
238 adr_t adr
; /* adr memory stream header */
239 char data_header
= AUT_ARG64
; /* header for this token */
240 short bytes
; /* length of string */
242 bytes
= strlen(text
) + 1;
244 token
= get_token((int)(2 * sizeof (char) + sizeof (int64_t) +
245 sizeof (short) + bytes
));
248 adr_start(&adr
, token
->tt_data
);
249 adr_char(&adr
, &data_header
, 1); /* token type */
250 adr_char(&adr
, &n
, 1); /* argument id */
251 adr_int64(&adr
, (int64_t *)&v
, 1); /* argument value */
252 adr_short(&adr
, &bytes
, 1);
253 adr_char(&adr
, text
, bytes
);
262 * pointer to an attribute token.
265 au_to_attr(struct vattr
*attr
)
267 token_t
*token
; /* local token */
268 adr_t adr
; /* adr memory stream header */
271 char data_header
= AUT_ATTR64
; /* header for this token */
273 token
= get_token(sizeof (char) +
274 sizeof (int32_t) * 4 +
275 sizeof (int64_t) * 2);
277 char data_header
= AUT_ATTR32
;
279 token
= get_token(sizeof (char) + sizeof (int32_t) * 5 +
285 adr_start(&adr
, token
->tt_data
);
286 adr_char(&adr
, &data_header
, 1);
287 value
= (int32_t)attr
->va_mode
;
288 adr_int32(&adr
, &value
, 1);
289 value
= (int32_t)attr
->va_uid
;
290 adr_int32(&adr
, &value
, 1);
291 value
= (int32_t)attr
->va_gid
;
292 adr_int32(&adr
, &value
, 1);
293 adr_int32(&adr
, (int32_t *)&(attr
->va_fsid
), 1);
294 adr_int64(&adr
, (int64_t *)&(attr
->va_nodeid
), 1);
296 adr_int64(&adr
, (int64_t *)&(attr
->va_rdev
), 1);
298 adr_int32(&adr
, (int32_t *)&(attr
->va_rdev
), 1);
307 * pointer to a data token.
310 au_to_data(char unit_print
, char unit_type
, char unit_count
, char *p
)
312 adr_t adr
; /* adr memory stream header */
313 token_t
*token
; /* token pointer */
314 char data_header
= AUT_DATA
; /* header for this token */
315 int byte_count
; /* number of bytes */
317 if (p
== NULL
|| unit_count
< 1)
321 * Check validity of print type
323 if (unit_print
< AUP_BINARY
|| unit_print
> AUP_STRING
)
328 byte_count
= unit_count
* sizeof (short);
331 byte_count
= unit_count
* sizeof (int32_t);
334 byte_count
= unit_count
* sizeof (int64_t);
338 byte_count
= unit_count
* sizeof (char);
344 token
= get_token((int)(4 * sizeof (char) + byte_count
));
347 adr_start(&adr
, token
->tt_data
);
348 adr_char(&adr
, &data_header
, 1);
349 adr_char(&adr
, &unit_print
, 1);
350 adr_char(&adr
, &unit_type
, 1);
351 adr_char(&adr
, &unit_count
, 1);
356 adr_short(&adr
, (short *)p
, unit_count
);
360 adr_int32(&adr
, (int32_t *)p
, unit_count
);
364 adr_int64(&adr
, (int64_t *)p
, unit_count
);
368 adr_char(&adr
, p
, unit_count
);
378 * priv_type (LIMIT, INHERIT...) is the first string and privilege
379 * in translated into the second string. The format is as follows:
382 * priv type adr_string (short, string)
383 * priv set adr_string (short, string)
386 * pointer to a AUT_PRIV token.
389 au_to_privset(const char *priv_type
, const priv_set_t
*privilege
)
391 token_t
*token
; /* local token */
392 adr_t adr
; /* adr memory stream header */
393 char data_header
= AUT_PRIV
; /* header for this token */
394 short t_bytes
; /* length of type string */
395 short p_bytes
; /* length of privilege string */
396 char *priv_string
; /* privilege string */
398 t_bytes
= strlen(priv_type
) + 1;
400 if ((privilege
== NULL
) || (priv_string
=
401 priv_set_to_str(privilege
, ',',
402 PRIV_STR_LIT
)) == NULL
)
405 p_bytes
= strlen(priv_string
) + 1;
407 token
= get_token((int)(sizeof (char) + (2 * sizeof (short)) + t_bytes
412 adr_start(&adr
, token
->tt_data
);
413 adr_char(&adr
, &data_header
, 1);
414 adr_short(&adr
, &t_bytes
, 1);
415 adr_char(&adr
, (char *)priv_type
, t_bytes
);
416 adr_short(&adr
, &p_bytes
, 1);
417 adr_char(&adr
, priv_string
, p_bytes
);
427 * pointer to a process token.
431 au_to_process(au_id_t auid
, uid_t euid
, gid_t egid
, uid_t ruid
, gid_t rgid
,
432 pid_t pid
, au_asid_t sid
, au_tid_t
*tid
)
434 token_t
*token
; /* local token */
435 adr_t adr
; /* adr memory stream header */
437 char data_header
= AUT_PROCESS64
; /* header for this token */
439 token
= get_token(sizeof (char) + 8 * sizeof (int32_t) +
442 char data_header
= AUT_PROCESS32
;
444 token
= get_token(sizeof (char) + 9 * sizeof (int32_t));
449 adr_start(&adr
, token
->tt_data
);
450 adr_char(&adr
, &data_header
, 1);
451 adr_int32(&adr
, (int32_t *)&auid
, 1);
452 adr_int32(&adr
, (int32_t *)&euid
, 1);
453 adr_int32(&adr
, (int32_t *)&egid
, 1);
454 adr_int32(&adr
, (int32_t *)&ruid
, 1);
455 adr_int32(&adr
, (int32_t *)&rgid
, 1);
456 adr_int32(&adr
, (int32_t *)&pid
, 1);
457 adr_int32(&adr
, (int32_t *)&sid
, 1);
459 adr_int64(&adr
, (int64_t *)&tid
->port
, 1);
461 adr_int32(&adr
, (int32_t *)&tid
->port
, 1);
463 adr_int32(&adr
, (int32_t *)&tid
->machine
, 1);
471 * pointer to a process_ex token.
474 au_to_process_ex(au_id_t auid
, uid_t euid
, gid_t egid
, uid_t ruid
, gid_t rgid
,
475 pid_t pid
, au_asid_t sid
, au_tid_addr_t
*tid
)
477 token_t
*token
; /* local token */
478 adr_t adr
; /* adr memory stream header */
479 char data_header
; /* header for this token */
482 if (tid
->at_type
== AU_IPv6
) {
483 data_header
= AUT_PROCESS64_EX
;
484 token
= get_token(sizeof (char) + sizeof (int64_t) +
485 12 * sizeof (int32_t));
487 data_header
= AUT_PROCESS64
;
488 token
= get_token(sizeof (char) + sizeof (int64_t) +
489 8 * sizeof (int32_t));
492 if (tid
->at_type
== AU_IPv6
) {
493 data_header
= AUT_PROCESS32_EX
;
494 token
= get_token(sizeof (char) + 13 * sizeof (int32_t));
496 data_header
= AUT_PROCESS32
;
497 token
= get_token(sizeof (char) + 9 * sizeof (int32_t));
502 adr_start(&adr
, token
->tt_data
);
503 adr_char(&adr
, &data_header
, 1);
504 adr_int32(&adr
, (int32_t *)&auid
, 1);
505 adr_int32(&adr
, (int32_t *)&euid
, 1);
506 adr_int32(&adr
, (int32_t *)&egid
, 1);
507 adr_int32(&adr
, (int32_t *)&ruid
, 1);
508 adr_int32(&adr
, (int32_t *)&rgid
, 1);
509 adr_int32(&adr
, (int32_t *)&pid
, 1);
510 adr_int32(&adr
, (int32_t *)&sid
, 1);
512 adr_int64(&adr
, (int64_t *)&tid
->at_port
, 1);
514 adr_int32(&adr
, (int32_t *)&tid
->at_port
, 1);
516 if (tid
->at_type
== AU_IPv6
) {
517 adr_int32(&adr
, (int32_t *)&tid
->at_type
, 1);
518 adr_char(&adr
, (char *)tid
->at_addr
, 16);
520 adr_char(&adr
, (char *)tid
->at_addr
, 4);
529 * pointer to token chain containing a sequence token
532 au_to_seq(int audit_count
)
534 token_t
*token
; /* local token */
535 adr_t adr
; /* adr memory stream header */
536 char data_header
= AUT_SEQ
; /* header for this token */
538 token
= get_token(sizeof (char) + sizeof (int32_t));
541 adr_start(&adr
, token
->tt_data
);
542 adr_char(&adr
, &data_header
, 1);
543 adr_int32(&adr
, (int32_t *)&audit_count
, 1);
551 * pointer to mbuf chain containing a socket token.
554 au_to_socket(struct oldsocket
*so
)
558 char data_header
= AUT_SOCKET
;
559 struct inpcb
*inp
= so
->so_pcb
;
561 token
= get_token(sizeof (char) + sizeof (short) * 3 +
562 sizeof (int32_t) * 2);
565 adr_start(&adr
, token
->tt_data
);
566 adr_char(&adr
, &data_header
, 1);
567 adr_short(&adr
, (short *)&so
->so_type
, 1);
568 adr_short(&adr
, (short *)&inp
->inp_lport
, 1);
569 adr_int32(&adr
, (int32_t *)&inp
->inp_laddr
, 1);
570 adr_short(&adr
, (short *)&inp
->inp_fport
, 1);
571 adr_int32(&adr
, (int32_t *)&inp
->inp_faddr
, 1);
579 * pointer to a process token.
583 au_to_subject(au_id_t auid
, uid_t euid
, gid_t egid
, uid_t ruid
, gid_t rgid
,
584 pid_t pid
, au_asid_t sid
, au_tid_t
*tid
)
586 token_t
*token
; /* local token */
587 adr_t adr
; /* adr memory stream header */
589 char data_header
= AUT_SUBJECT64
; /* header for this token */
591 token
= get_token(sizeof (char) + sizeof (int64_t) +
592 8 * sizeof (int32_t));
594 char data_header
= AUT_SUBJECT32
;
596 token
= get_token(sizeof (char) + 9 * sizeof (int32_t));
601 adr_start(&adr
, token
->tt_data
);
602 adr_char(&adr
, &data_header
, 1);
603 adr_int32(&adr
, (int32_t *)&auid
, 1);
604 adr_int32(&adr
, (int32_t *)&euid
, 1);
605 adr_int32(&adr
, (int32_t *)&egid
, 1);
606 adr_int32(&adr
, (int32_t *)&ruid
, 1);
607 adr_int32(&adr
, (int32_t *)&rgid
, 1);
608 adr_int32(&adr
, (int32_t *)&pid
, 1);
609 adr_int32(&adr
, (int32_t *)&sid
, 1);
611 adr_int64(&adr
, (int64_t *)&tid
->port
, 1);
613 adr_int32(&adr
, (int32_t *)&tid
->port
, 1);
615 adr_int32(&adr
, (int32_t *)&tid
->machine
, 1);
623 * pointer to a process token.
627 au_to_subject_ex(au_id_t auid
, uid_t euid
, gid_t egid
, uid_t ruid
, gid_t rgid
,
628 pid_t pid
, au_asid_t sid
, au_tid_addr_t
*tid
)
630 token_t
*token
; /* local token */
631 adr_t adr
; /* adr memory stream header */
633 char data_header
; /* header for this token */
635 if (tid
->at_type
== AU_IPv6
) {
636 data_header
= AUT_SUBJECT64_EX
;
637 token
= get_token(sizeof (char) + sizeof (int64_t) +
638 12 * sizeof (int32_t));
640 data_header
= AUT_SUBJECT64
;
641 token
= get_token(sizeof (char) + sizeof (int64_t) +
642 8 * sizeof (int32_t));
645 char data_header
; /* header for this token */
647 if (tid
->at_type
== AU_IPv6
) {
648 data_header
= AUT_SUBJECT32_EX
;
649 token
= get_token(sizeof (char) + 13 * sizeof (int32_t));
651 data_header
= AUT_SUBJECT32
;
652 token
= get_token(sizeof (char) + 9 * sizeof (int32_t));
658 adr_start(&adr
, token
->tt_data
);
659 adr_char(&adr
, &data_header
, 1);
660 adr_int32(&adr
, (int32_t *)&auid
, 1);
661 adr_int32(&adr
, (int32_t *)&euid
, 1);
662 adr_int32(&adr
, (int32_t *)&egid
, 1);
663 adr_int32(&adr
, (int32_t *)&ruid
, 1);
664 adr_int32(&adr
, (int32_t *)&rgid
, 1);
665 adr_int32(&adr
, (int32_t *)&pid
, 1);
666 adr_int32(&adr
, (int32_t *)&sid
, 1);
668 adr_int64(&adr
, (int64_t *)&tid
->at_port
, 1);
670 adr_int32(&adr
, (int32_t *)&tid
->at_port
, 1);
672 if (tid
->at_type
== AU_IPv6
) {
673 adr_int32(&adr
, (int32_t *)&tid
->at_type
, 1);
674 adr_char(&adr
, (char *)tid
->at_addr
, 16);
676 adr_char(&adr
, (char *)tid
->at_addr
, 4);
685 * pointer to a process token.
691 auditinfo_addr_t info
;
693 if (getaudit_addr(&info
, sizeof (info
)))
695 return (au_to_subject_ex(info
.ai_auid
, geteuid(), getegid(), getuid(),
696 getgid(), getpid(), info
.ai_asid
, &info
.ai_termid
));
701 * pointer to a text token.
704 au_to_text(char *text
)
706 token_t
*token
; /* local token */
707 adr_t adr
; /* adr memory stream header */
708 char data_header
= AUT_TEXT
; /* header for this token */
709 short bytes
; /* length of string */
711 bytes
= strlen(text
) + 1;
712 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
715 adr_start(&adr
, token
->tt_data
);
716 adr_char(&adr
, &data_header
, 1);
717 adr_short(&adr
, &bytes
, 1);
718 adr_char(&adr
, text
, bytes
);
726 * pointer to a path token.
729 au_to_path(char *path
)
731 token_t
*token
; /* local token */
732 adr_t adr
; /* adr memory stream header */
733 char data_header
= AUT_PATH
; /* header for this token */
734 short bytes
; /* length of string */
736 bytes
= (short)strlen(path
) + 1;
738 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
741 adr_start(&adr
, token
->tt_data
);
742 adr_char(&adr
, &data_header
, 1);
743 adr_short(&adr
, &bytes
, 1);
744 adr_char(&adr
, path
, bytes
);
752 * pointer to an command line argument token
755 au_to_cmd(uint_t argc
, char **argv
, char **envp
)
757 token_t
*token
; /* local token */
758 adr_t adr
; /* adr memory stream header */
759 char data_header
= AUT_CMD
; /* header for this token */
763 short largc
= (short)argc
;
766 * one char for the header, one short for argc,
767 * one short for # envp strings.
769 len
= sizeof (char) + sizeof (short) + sizeof (short);
771 /* get sizes of strings */
773 for (cnt
= 0; cnt
< argc
; cnt
++) {
774 len
+= (short)sizeof (short) + (short)(strlen(argv
[cnt
]) + 1);
778 for (envc
= 0; envp
[envc
] != NULL
; envc
++) {
779 len
+= (short)sizeof (short) +
780 (short)(strlen(envp
[envc
]) + 1);
784 token
= get_token(len
);
788 adr_start(&adr
, token
->tt_data
);
789 adr_char(&adr
, &data_header
, 1);
791 adr_short(&adr
, &largc
, 1);
793 for (cnt
= 0; cnt
< argc
; cnt
++) {
794 len
= (short)(strlen(argv
[cnt
]) + 1);
795 adr_short(&adr
, &len
, 1);
796 adr_char(&adr
, argv
[cnt
], len
);
799 adr_short(&adr
, &envc
, 1);
801 for (cnt
= 0; cnt
< envc
; cnt
++) {
802 len
= (short)(strlen(envp
[cnt
]) + 1);
803 adr_short(&adr
, &len
, 1);
804 adr_char(&adr
, envp
[cnt
], len
);
813 * pointer to a exit value token.
816 au_to_exit(int retval
, int err
)
818 token_t
*token
; /* local token */
819 adr_t adr
; /* adr memory stream header */
820 char data_header
= AUT_EXIT
; /* header for this token */
822 token
= get_token(sizeof (char) + (2 * sizeof (int32_t)));
825 adr_start(&adr
, token
->tt_data
);
826 adr_char(&adr
, &data_header
, 1);
827 adr_int32(&adr
, (int32_t *)&retval
, 1);
828 adr_int32(&adr
, (int32_t *)&err
, 1);
836 * pointer to a return value token.
839 au_to_return32(char number
, uint32_t value
)
841 token_t
*token
; /* local token */
842 adr_t adr
; /* adr memory stream header */
843 char data_header
= AUT_RETURN32
; /* header for this token */
845 token
= get_token(2 * sizeof (char) + sizeof (int32_t));
848 adr_start(&adr
, token
->tt_data
);
849 adr_char(&adr
, &data_header
, 1);
850 adr_char(&adr
, &number
, 1);
851 adr_int32(&adr
, (int32_t *)&value
, 1);
859 * pointer to a return value token.
862 au_to_return64(char number
, uint64_t value
)
864 token_t
*token
; /* local token */
865 adr_t adr
; /* adr memory stream header */
866 char data_header
= AUT_RETURN64
; /* header for this token */
868 token
= get_token(2 * sizeof (char) + sizeof (int64_t));
871 adr_start(&adr
, token
->tt_data
);
872 adr_char(&adr
, &data_header
, 1);
873 adr_char(&adr
, &number
, 1);
874 adr_int64(&adr
, (int64_t *)&value
, 1);
883 * pointer to a opaque token.
886 au_to_opaque(char *opaque
, short bytes
)
888 token_t
*token
; /* local token */
889 adr_t adr
; /* adr memory stream header */
890 char data_header
= AUT_OPAQUE
; /* header for this token */
895 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
898 adr_start(&adr
, token
->tt_data
);
899 adr_char(&adr
, &data_header
, 1);
900 adr_short(&adr
, &bytes
, 1);
901 adr_char(&adr
, opaque
, bytes
);
909 * pointer to an internet address token
912 au_to_in_addr(struct in_addr
*internet_addr
)
914 token_t
*token
; /* local token */
915 adr_t adr
; /* adr memory stream header */
916 char data_header
= AUT_IN_ADDR
; /* header for this token */
918 token
= get_token(sizeof (char) + sizeof (struct in_addr
));
921 adr_start(&adr
, token
->tt_data
);
922 adr_char(&adr
, &data_header
, 1);
923 adr_char(&adr
, (char *)internet_addr
, sizeof (struct in_addr
));
931 * pointer to an internet extended token
934 au_to_in_addr_ex(struct in6_addr
*addr
)
939 if (IN6_IS_ADDR_V4MAPPED(addr
)) {
943 * An IPv4-mapped IPv6 address is really an IPv4 address
947 IN6_V4MAPPED_TO_IPADDR(addr
, in4
);
948 return (au_to_in_addr((struct in_addr
*)&in4
));
951 char data_header
= AUT_IN_ADDR_EX
;
952 int32_t type
= AU_IPv6
;
954 if ((token
= get_token(sizeof (char) + sizeof (int32_t) +
955 sizeof (struct in6_addr
))) == NULL
) {
959 adr_start(&adr
, token
->tt_data
);
960 adr_char(&adr
, &data_header
, 1);
961 adr_int32(&adr
, &type
, 1);
962 adr_char(&adr
, (char *)addr
, sizeof (struct in6_addr
));
971 * pointer to token chain containing a ip port address token
974 au_to_iport(ushort_t iport
)
976 token_t
*token
; /* local token */
977 adr_t adr
; /* adr memory stream header */
978 char data_header
= AUT_IPORT
; /* header for this token */
980 token
= get_token(sizeof (char) + sizeof (short));
983 adr_start(&adr
, token
->tt_data
);
984 adr_char(&adr
, &data_header
, 1);
985 adr_short(&adr
, (short *)&iport
, 1);
991 au_to_ipc(char type
, int id
)
993 token_t
*token
; /* local token */
994 adr_t adr
; /* adr memory stream header */
995 char data_header
= AUT_IPC
; /* header for this token */
997 token
= get_token((2 * sizeof (char)) + sizeof (int32_t));
1000 adr_start(&adr
, token
->tt_data
);
1001 adr_char(&adr
, &data_header
, 1);
1002 adr_char(&adr
, &type
, 1);
1003 adr_int32(&adr
, (int32_t *)&id
, 1);
1011 * output format depends on type; at present only IP v4 and v6 addresses
1014 * IPv4 -- tid type, 16 bit remote port, 16 bit local port, ip type,
1015 * 32 bit IP address.
1016 * IPv6 -- tid type, 16 bit remote port, 16 bit local port, ip type,
1017 * 4 x 32 bit IP address.
1021 au_to_tid(au_generic_tid_t
*tid
)
1023 char data_header
= AUT_TID
; /* header for this token */
1024 adr_t adr
; /* adr memory stream header */
1025 token_t
*token
; /* local token */
1028 switch (tid
->gt_type
) {
1030 ip
= &(tid
->gt_adr
.at_ip
);
1031 token
= get_token((int)(2 * sizeof (char) + 2 * sizeof (short) +
1032 sizeof (uint32_t) + ip
->at_type
));
1036 adr_start(&adr
, token
->tt_data
);
1037 adr_char(&adr
, &data_header
, 1);
1038 adr_char(&adr
, (char *)&(tid
->gt_type
), 1);
1039 adr_short(&adr
, (short *)&(ip
->at_r_port
), 1);
1040 adr_short(&adr
, (short *)&(ip
->at_l_port
), 1);
1041 adr_int32(&adr
, (int32_t *)&(ip
->at_type
), 1);
1043 adr_char(&adr
, (char *)ip
->at_addr
, ip
->at_type
);
1053 * The Modifier tokens
1059 * pointer to a group list token.
1061 * This function is obsolete. Please use au_to_newgroups.
1064 au_to_groups(int *groups
)
1066 token_t
*token
; /* local token */
1067 adr_t adr
; /* adr memory stream header */
1068 char data_header
= AUT_GROUPS
; /* header for this token */
1070 token
= get_token(sizeof (char) + NGROUPS
* sizeof (int32_t));
1073 adr_start(&adr
, token
->tt_data
);
1074 adr_char(&adr
, &data_header
, 1);
1075 adr_int32(&adr
, (int32_t *)groups
, NGROUPS
);
1083 * pointer to a group list token.
1086 au_to_newgroups(int n
, gid_t
*groups
)
1088 token_t
*token
; /* local token */
1089 adr_t adr
; /* adr memory stream header */
1090 char data_header
= AUT_NEWGROUPS
; /* header for this token */
1093 if (n
< 0 || n
> SHRT_MAX
|| groups
== NULL
)
1095 token
= get_token(sizeof (char) + sizeof (short) + n
* sizeof (gid_t
));
1098 n_groups
= (short)n
;
1099 adr_start(&adr
, token
->tt_data
);
1100 adr_char(&adr
, &data_header
, 1);
1101 adr_short(&adr
, &n_groups
, 1);
1102 adr_int32(&adr
, (int32_t *)groups
, n_groups
);
1110 * pointer to an exec args token.
1113 au_to_exec_args(char **argv
)
1115 return (au_to_exec(argv
, AUT_EXEC_ARGS
));
1121 * pointer to an exec args token.
1124 au_to_exec_env(char **envp
)
1126 return (au_to_exec(envp
, AUT_EXEC_ENV
));
1132 * pointer to an exec args token.
1135 au_to_exec(char **v
, char data_header
)
1143 for (p
= v
; *p
!= NULL
; p
++) {
1144 len
+= strlen(*p
) + 1;
1147 token
= get_token(sizeof (char) + sizeof (int32_t) + len
);
1148 if (token
== (token_t
*)NULL
)
1149 return ((token_t
*)NULL
);
1150 adr_start(&adr
, token
->tt_data
);
1151 adr_char(&adr
, &data_header
, 1);
1152 adr_int32(&adr
, &n
, 1);
1153 for (p
= v
; *p
!= NULL
; p
++) {
1154 adr_char(&adr
, *p
, strlen(*p
) + 1);
1162 * pointer to a uauth token.
1165 au_to_uauth(char *text
)
1167 token_t
*token
; /* local token */
1168 adr_t adr
; /* adr memory stream header */
1169 char data_header
= AUT_UAUTH
; /* header for this token */
1170 short bytes
; /* length of string */
1172 bytes
= strlen(text
) + 1;
1174 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
1177 adr_start(&adr
, token
->tt_data
);
1178 adr_char(&adr
, &data_header
, 1);
1179 adr_short(&adr
, &bytes
, 1);
1180 adr_char(&adr
, text
, bytes
);
1188 * pointer to a use of privilege token.
1191 au_to_upriv(char sorf
, char *priv
)
1193 token_t
*token
; /* local token */
1194 adr_t adr
; /* adr memory stream header */
1195 char data_header
= AUT_UAUTH
; /* header for this token */
1196 short bytes
; /* length of string */
1198 bytes
= strlen(priv
) + 1;
1200 token
= get_token(sizeof (char) + sizeof (char) + sizeof (short) +
1204 adr_start(&adr
, token
->tt_data
);
1205 adr_char(&adr
, &data_header
, 1);
1206 adr_char(&adr
, &sorf
, 1); /* success/failure */
1207 adr_short(&adr
, &bytes
, 1);
1208 adr_char(&adr
, priv
, bytes
);
1216 * pointer to a user token.
1219 au_to_user(uid_t uid
, char *username
)
1221 token_t
*token
; /* local token */
1222 adr_t adr
; /* adr memory stream header */
1223 char data_header
= AUT_USER
; /* header for this token */
1224 short bytes
; /* length of string */
1226 bytes
= (short)strlen(username
) + 1;
1228 token
= get_token(sizeof (char) + sizeof (uid_t
) + sizeof (short) +
1232 adr_start(&adr
, token
->tt_data
);
1233 adr_char(&adr
, &data_header
, 1);
1234 adr_uid(&adr
, &uid
, 1);
1235 adr_short(&adr
, &bytes
, 1);
1236 adr_char(&adr
, username
, bytes
);
1244 * pointer to a xatom token.
1247 au_to_xatom(char *atom
)
1249 token_t
*token
; /* local token */
1250 adr_t adr
; /* adr memory stream header */
1251 char data_header
= AUT_XATOM
; /* header for this token */
1254 len
= strlen(atom
) + 1;
1256 token
= get_token(sizeof (char) + sizeof (short) + len
);
1259 adr_start(&adr
, token
->tt_data
);
1260 adr_char(&adr
, &data_header
, 1);
1261 adr_short(&adr
, (short *)&len
, 1);
1262 adr_char(&adr
, atom
, len
);
1270 * pointer to a X select token.
1273 au_to_xselect(char *propname
, char *proptype
, char *windata
)
1275 token_t
*token
; /* local token */
1276 adr_t adr
; /* adr memory stream header */
1277 char data_header
= AUT_XSELECT
; /* header for this token */
1282 proplen
= strlen(propname
) + 1;
1283 typelen
= strlen(proptype
) + 1;
1284 datalen
= strlen(windata
) + 1;
1286 token
= get_token(sizeof (char) + (sizeof (short) * 3) +
1287 proplen
+ typelen
+ datalen
);
1290 adr_start(&adr
, token
->tt_data
);
1291 adr_char(&adr
, &data_header
, 1);
1292 adr_short(&adr
, &proplen
, 1);
1293 adr_char(&adr
, propname
, proplen
);
1294 adr_short(&adr
, &typelen
, 1);
1295 adr_char(&adr
, proptype
, typelen
);
1296 adr_short(&adr
, &datalen
, 1);
1297 adr_char(&adr
, windata
, datalen
);
1305 * pointer to a common X token.
1309 x_common(char data_header
, int32_t xid
, uid_t cuid
)
1311 token_t
*token
; /* local token */
1312 adr_t adr
; /* adr memory stream header */
1314 token
= get_token(sizeof (char) + sizeof (int32_t) + sizeof (uid_t
));
1317 adr_start(&adr
, token
->tt_data
);
1318 adr_char(&adr
, &data_header
, 1);
1319 adr_int32(&adr
, &xid
, 1);
1320 adr_uid(&adr
, &cuid
, 1);
1328 * pointer to a X Colormap token.
1332 au_to_xcolormap(int32_t xid
, uid_t cuid
)
1334 return (x_common(AUT_XCOLORMAP
, xid
, cuid
));
1340 * pointer to a X Cursor token.
1344 au_to_xcursor(int32_t xid
, uid_t cuid
)
1346 return (x_common(AUT_XCURSOR
, xid
, cuid
));
1352 * pointer to a X Font token.
1356 au_to_xfont(int32_t xid
, uid_t cuid
)
1358 return (x_common(AUT_XFONT
, xid
, cuid
));
1364 * pointer to a X Graphic Context token.
1368 au_to_xgc(int32_t xid
, uid_t cuid
)
1370 return (x_common(AUT_XGC
, xid
, cuid
));
1376 * pointer to a X Pixal Map token.
1380 au_to_xpixmap(int32_t xid
, uid_t cuid
)
1382 return (x_common(AUT_XPIXMAP
, xid
, cuid
));
1388 * pointer to a X Window token.
1392 au_to_xwindow(int32_t xid
, uid_t cuid
)
1394 return (x_common(AUT_XWINDOW
, xid
, cuid
));
1400 * pointer to a X Property token.
1404 au_to_xproperty(int32_t xid
, uid_t cuid
, char *propname
)
1406 token_t
*token
; /* local token */
1407 adr_t adr
; /* adr memory stream header */
1408 char data_header
= AUT_XPROPERTY
; /* header for this token */
1411 proplen
= strlen(propname
) + 1;
1413 token
= get_token(sizeof (char) + sizeof (int32_t) + sizeof (uid_t
) +
1414 sizeof (short) + proplen
);
1417 adr_start(&adr
, token
->tt_data
);
1418 adr_char(&adr
, &data_header
, 1);
1419 adr_int32(&adr
, &xid
, 1);
1420 adr_uid(&adr
, &cuid
, 1);
1421 adr_short(&adr
, &proplen
, 1);
1422 adr_char(&adr
, propname
, proplen
);
1430 * pointer to a X Client token
1434 au_to_xclient(uint32_t client
)
1436 token_t
*token
; /* local token */
1437 adr_t adr
; /* adr memory stream header */
1438 char data_header
= AUT_XCLIENT
; /* header for this token */
1440 token
= get_token(sizeof (char) + sizeof (uint32_t));
1443 adr_start(&adr
, token
->tt_data
);
1444 adr_char(&adr
, &data_header
, 1);
1445 adr_int32(&adr
, (int32_t *)&client
, 1);
1453 * pointer to a label token.
1456 au_to_label(m_label_t
*label
)
1458 token_t
*token
; /* local token */
1459 adr_t adr
; /* adr memory stream header */
1460 char data_header
= AUT_LABEL
; /* header for this token */
1461 size32_t llen
= blabel_size();
1463 token
= get_token(sizeof (char) + llen
);
1464 if (token
== NULL
) {
1466 } else if (label
== NULL
) {
1470 adr_start(&adr
, token
->tt_data
);
1471 adr_char(&adr
, &data_header
, 1);
1472 adr_char(&adr
, (char *)label
, llen
);
1480 * pointer to a label token.
1488 if ((uc
= ucred_get(P_MYID
)) == NULL
) {
1492 token
= au_to_label(ucred_getlabel(uc
));
1500 * pointer to a zonename token.
1503 au_to_zonename(char *name
)
1505 token_t
*token
; /* local token */
1506 adr_t adr
; /* adr memory stream header */
1507 char data_header
= AUT_ZONENAME
; /* header for this token */
1508 short bytes
; /* length of string */
1513 bytes
= strlen(name
) + 1;
1514 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
1517 adr_start(&adr
, token
->tt_data
);
1518 adr_char(&adr
, &data_header
, 1);
1519 adr_short(&adr
, &bytes
, 1);
1520 adr_char(&adr
, name
, bytes
);
1528 * pointer to a fmri token.
1531 au_to_fmri(char *fmri
)
1533 token_t
*token
; /* local token */
1534 adr_t adr
; /* adr memory stream header */
1535 char data_header
= AUT_FMRI
; /* header for this token */
1536 short bytes
; /* length of string */
1541 bytes
= strlen(fmri
) + 1;
1542 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
1545 adr_start(&adr
, token
->tt_data
);
1546 adr_char(&adr
, &data_header
, 1);
1547 adr_short(&adr
, &bytes
, 1);
1548 adr_char(&adr
, fmri
, bytes
);