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>
46 #define NGROUPS 16 /* XXX - temporary */
48 token_t
*au_to_arg(char n
, char *text
, uint32_t v
);
49 #pragma weak au_to_arg = au_to_arg32
50 token_t
*au_to_return(char number
, uint32_t value
);
51 #pragma weak au_to_return = au_to_return32
53 static token_t
*au_to_exec(char **, char);
58 token_t
*token
; /* Resultant token */
60 if ((token
= (token_t
*)malloc(sizeof (token_t
))) == NULL
)
62 if ((token
->tt_data
= malloc(s
)) == NULL
) {
67 token
->tt_next
= NULL
;
74 * pointer to header token.
77 au_to_header(au_event_t e_type
, au_emod_t e_mod
)
79 adr_t adr
; /* adr memory stream header */
80 token_t
*token
; /* token pointer */
81 char version
= TOKEN_VERSION
; /* version of token family */
85 char data_header
= AUT_HEADER64
; /* header for this token */
87 token
= get_token(2 * sizeof (char) + sizeof (int32_t) +
88 2 * sizeof (int64_t) + 2 * sizeof (short));
90 char data_header
= AUT_HEADER32
;
92 token
= get_token(2 * sizeof (char) + 3 * sizeof (int32_t) +
98 adr_start(&adr
, token
->tt_data
);
99 adr_char(&adr
, &data_header
, 1); /* token ID */
100 adr_int32(&adr
, &byte_count
, 1); /* length of audit record */
101 adr_char(&adr
, &version
, 1); /* version of audit tokens */
102 adr_ushort(&adr
, &e_type
, 1); /* event ID */
103 adr_ushort(&adr
, &e_mod
, 1); /* event ID modifier */
105 adr_int64(&adr
, (int64_t *)&tv
, 2); /* time & date */
107 adr_int32(&adr
, (int32_t *)&tv
, 2); /* time & date */
115 * pointer to header token.
118 au_to_header_ex(au_event_t e_type
, au_emod_t e_mod
)
120 adr_t adr
; /* adr memory stream header */
121 token_t
*token
; /* token pointer */
122 char version
= TOKEN_VERSION
; /* version of token family */
125 auditinfo_addr_t audit_info
;
126 au_tid_addr_t
*host_info
= &audit_info
.ai_termid
;
128 char data_header
= AUT_HEADER64_EX
; /* header for this token */
130 char data_header
= AUT_HEADER32_EX
;
133 /* If our host address can't be determined, revert to un-extended hdr */
135 if (auditon(A_GETKAUDIT
, (caddr_t
)&audit_info
,
136 sizeof (audit_info
)) < 0)
137 return (au_to_header(e_type
, e_mod
));
139 if (host_info
->at_type
== AU_IPv6
)
140 if (IN6_IS_ADDR_UNSPECIFIED((in6_addr_t
*)host_info
->at_addr
))
141 return (au_to_header(e_type
, e_mod
));
143 if (host_info
->at_addr
[0] == htonl(INADDR_ANY
))
144 return (au_to_header(e_type
, e_mod
));
147 token
= get_token(2 * sizeof (char) + sizeof (int32_t) +
148 2 * sizeof (int64_t) + 2 * sizeof (short) +
149 sizeof (int32_t) + host_info
->at_type
);
151 token
= get_token(2 * sizeof (char) + 3 * sizeof (int32_t) +
152 2 * sizeof (short) + sizeof (int32_t) + host_info
->at_type
);
157 adr_start(&adr
, token
->tt_data
);
158 adr_char(&adr
, &data_header
, 1); /* token ID */
159 adr_int32(&adr
, &byte_count
, 1); /* length of audit record */
160 adr_char(&adr
, &version
, 1); /* version of audit tokens */
161 adr_ushort(&adr
, &e_type
, 1); /* event ID */
162 adr_ushort(&adr
, &e_mod
, 1); /* event ID modifier */
163 adr_int32(&adr
, (int32_t *)&host_info
->at_type
, 1);
164 adr_char(&adr
, (char *)host_info
->at_addr
,
165 (int)host_info
->at_type
);
167 adr_int64(&adr
, (int64_t *)&tv
, 2); /* time & date */
169 adr_int32(&adr
, (int32_t *)&tv
, 2); /* time & date */
177 * pointer to a trailer token.
182 adr_t adr
; /* adr memory stream header */
183 token_t
*token
; /* token pointer */
184 char data_header
= AUT_TRAILER
; /* header for this token */
185 short magic
= (short)AUT_TRAILER_MAGIC
; /* trailer magic number */
188 token
= get_token(sizeof (char) + sizeof (int32_t) + sizeof (short));
191 adr_start(&adr
, token
->tt_data
);
192 adr_char(&adr
, &data_header
, 1); /* token ID */
193 adr_short(&adr
, &magic
, 1); /* magic number */
194 adr_int32(&adr
, &byte_count
, 1); /* length of audit record */
202 * pointer to an argument token.
205 au_to_arg32(char n
, char *text
, uint32_t v
)
207 token_t
*token
; /* local token */
208 adr_t adr
; /* adr memory stream header */
209 char data_header
= AUT_ARG32
; /* header for this token */
210 short bytes
; /* length of string */
212 bytes
= strlen(text
) + 1;
214 token
= get_token((int)(2 * sizeof (char) + sizeof (int32_t) +
215 sizeof (short) + bytes
));
218 adr_start(&adr
, token
->tt_data
);
219 adr_char(&adr
, &data_header
, 1); /* token type */
220 adr_char(&adr
, &n
, 1); /* argument id */
221 adr_int32(&adr
, (int32_t *)&v
, 1); /* argument value */
222 adr_short(&adr
, &bytes
, 1);
223 adr_char(&adr
, text
, bytes
);
231 * pointer to an argument token.
234 au_to_arg64(char n
, char *text
, uint64_t v
)
236 token_t
*token
; /* local token */
237 adr_t adr
; /* adr memory stream header */
238 char data_header
= AUT_ARG64
; /* header for this token */
239 short bytes
; /* length of string */
241 bytes
= strlen(text
) + 1;
243 token
= get_token((int)(2 * sizeof (char) + sizeof (int64_t) +
244 sizeof (short) + bytes
));
247 adr_start(&adr
, token
->tt_data
);
248 adr_char(&adr
, &data_header
, 1); /* token type */
249 adr_char(&adr
, &n
, 1); /* argument id */
250 adr_int64(&adr
, (int64_t *)&v
, 1); /* argument value */
251 adr_short(&adr
, &bytes
, 1);
252 adr_char(&adr
, text
, bytes
);
261 * pointer to an attribute token.
264 au_to_attr(struct vattr
*attr
)
266 token_t
*token
; /* local token */
267 adr_t adr
; /* adr memory stream header */
270 char data_header
= AUT_ATTR64
; /* header for this token */
272 token
= get_token(sizeof (char) +
273 sizeof (int32_t) * 4 +
274 sizeof (int64_t) * 2);
276 char data_header
= AUT_ATTR32
;
278 token
= get_token(sizeof (char) + sizeof (int32_t) * 5 +
284 adr_start(&adr
, token
->tt_data
);
285 adr_char(&adr
, &data_header
, 1);
286 value
= (int32_t)attr
->va_mode
;
287 adr_int32(&adr
, &value
, 1);
288 value
= (int32_t)attr
->va_uid
;
289 adr_int32(&adr
, &value
, 1);
290 value
= (int32_t)attr
->va_gid
;
291 adr_int32(&adr
, &value
, 1);
292 adr_int32(&adr
, (int32_t *)&(attr
->va_fsid
), 1);
293 adr_int64(&adr
, (int64_t *)&(attr
->va_nodeid
), 1);
295 adr_int64(&adr
, (int64_t *)&(attr
->va_rdev
), 1);
297 adr_int32(&adr
, (int32_t *)&(attr
->va_rdev
), 1);
306 * pointer to a data token.
309 au_to_data(char unit_print
, char unit_type
, char unit_count
, char *p
)
311 adr_t adr
; /* adr memory stream header */
312 token_t
*token
; /* token pointer */
313 char data_header
= AUT_DATA
; /* header for this token */
314 int byte_count
; /* number of bytes */
316 if (p
== NULL
|| unit_count
< 1)
320 * Check validity of print type
322 if (unit_print
< AUP_BINARY
|| unit_print
> AUP_STRING
)
327 byte_count
= unit_count
* sizeof (short);
330 byte_count
= unit_count
* sizeof (int32_t);
333 byte_count
= unit_count
* sizeof (int64_t);
337 byte_count
= unit_count
* sizeof (char);
343 token
= get_token((int)(4 * sizeof (char) + byte_count
));
346 adr_start(&adr
, token
->tt_data
);
347 adr_char(&adr
, &data_header
, 1);
348 adr_char(&adr
, &unit_print
, 1);
349 adr_char(&adr
, &unit_type
, 1);
350 adr_char(&adr
, &unit_count
, 1);
355 adr_short(&adr
, (short *)p
, unit_count
);
359 adr_int32(&adr
, (int32_t *)p
, unit_count
);
363 adr_int64(&adr
, (int64_t *)p
, unit_count
);
367 adr_char(&adr
, p
, unit_count
);
377 * priv_type (LIMIT, INHERIT...) is the first string and privilege
378 * in translated into the second string. The format is as follows:
381 * priv type adr_string (short, string)
382 * priv set adr_string (short, string)
385 * pointer to a AUT_PRIV token.
388 au_to_privset(const char *priv_type
, const priv_set_t
*privilege
)
390 token_t
*token
; /* local token */
391 adr_t adr
; /* adr memory stream header */
392 char data_header
= AUT_PRIV
; /* header for this token */
393 short t_bytes
; /* length of type string */
394 short p_bytes
; /* length of privilege string */
395 char *priv_string
; /* privilege string */
397 t_bytes
= strlen(priv_type
) + 1;
399 if ((privilege
== NULL
) || (priv_string
=
400 priv_set_to_str(privilege
, ',',
401 PRIV_STR_LIT
)) == NULL
)
404 p_bytes
= strlen(priv_string
) + 1;
406 token
= get_token((int)(sizeof (char) + (2 * sizeof (short)) + t_bytes
411 adr_start(&adr
, token
->tt_data
);
412 adr_char(&adr
, &data_header
, 1);
413 adr_short(&adr
, &t_bytes
, 1);
414 adr_char(&adr
, (char *)priv_type
, t_bytes
);
415 adr_short(&adr
, &p_bytes
, 1);
416 adr_char(&adr
, priv_string
, p_bytes
);
426 * pointer to a process token.
430 au_to_process(au_id_t auid
, uid_t euid
, gid_t egid
, uid_t ruid
, gid_t rgid
,
431 pid_t pid
, au_asid_t sid
, au_tid_t
*tid
)
433 token_t
*token
; /* local token */
434 adr_t adr
; /* adr memory stream header */
436 char data_header
= AUT_PROCESS64
; /* header for this token */
438 token
= get_token(sizeof (char) + 8 * sizeof (int32_t) +
441 char data_header
= AUT_PROCESS32
;
443 token
= get_token(sizeof (char) + 9 * sizeof (int32_t));
448 adr_start(&adr
, token
->tt_data
);
449 adr_char(&adr
, &data_header
, 1);
450 adr_int32(&adr
, (int32_t *)&auid
, 1);
451 adr_int32(&adr
, (int32_t *)&euid
, 1);
452 adr_int32(&adr
, (int32_t *)&egid
, 1);
453 adr_int32(&adr
, (int32_t *)&ruid
, 1);
454 adr_int32(&adr
, (int32_t *)&rgid
, 1);
455 adr_int32(&adr
, (int32_t *)&pid
, 1);
456 adr_int32(&adr
, (int32_t *)&sid
, 1);
458 adr_int64(&adr
, (int64_t *)&tid
->port
, 1);
460 adr_int32(&adr
, (int32_t *)&tid
->port
, 1);
462 adr_int32(&adr
, (int32_t *)&tid
->machine
, 1);
470 * pointer to a process_ex token.
473 au_to_process_ex(au_id_t auid
, uid_t euid
, gid_t egid
, uid_t ruid
, gid_t rgid
,
474 pid_t pid
, au_asid_t sid
, au_tid_addr_t
*tid
)
476 token_t
*token
; /* local token */
477 adr_t adr
; /* adr memory stream header */
478 char data_header
; /* header for this token */
481 if (tid
->at_type
== AU_IPv6
) {
482 data_header
= AUT_PROCESS64_EX
;
483 token
= get_token(sizeof (char) + sizeof (int64_t) +
484 12 * sizeof (int32_t));
486 data_header
= AUT_PROCESS64
;
487 token
= get_token(sizeof (char) + sizeof (int64_t) +
488 8 * sizeof (int32_t));
491 if (tid
->at_type
== AU_IPv6
) {
492 data_header
= AUT_PROCESS32_EX
;
493 token
= get_token(sizeof (char) + 13 * sizeof (int32_t));
495 data_header
= AUT_PROCESS32
;
496 token
= get_token(sizeof (char) + 9 * sizeof (int32_t));
501 adr_start(&adr
, token
->tt_data
);
502 adr_char(&adr
, &data_header
, 1);
503 adr_int32(&adr
, (int32_t *)&auid
, 1);
504 adr_int32(&adr
, (int32_t *)&euid
, 1);
505 adr_int32(&adr
, (int32_t *)&egid
, 1);
506 adr_int32(&adr
, (int32_t *)&ruid
, 1);
507 adr_int32(&adr
, (int32_t *)&rgid
, 1);
508 adr_int32(&adr
, (int32_t *)&pid
, 1);
509 adr_int32(&adr
, (int32_t *)&sid
, 1);
511 adr_int64(&adr
, (int64_t *)&tid
->at_port
, 1);
513 adr_int32(&adr
, (int32_t *)&tid
->at_port
, 1);
515 if (tid
->at_type
== AU_IPv6
) {
516 adr_int32(&adr
, (int32_t *)&tid
->at_type
, 1);
517 adr_char(&adr
, (char *)tid
->at_addr
, 16);
519 adr_char(&adr
, (char *)tid
->at_addr
, 4);
528 * pointer to token chain containing a sequence token
531 au_to_seq(int audit_count
)
533 token_t
*token
; /* local token */
534 adr_t adr
; /* adr memory stream header */
535 char data_header
= AUT_SEQ
; /* header for this token */
537 token
= get_token(sizeof (char) + sizeof (int32_t));
540 adr_start(&adr
, token
->tt_data
);
541 adr_char(&adr
, &data_header
, 1);
542 adr_int32(&adr
, (int32_t *)&audit_count
, 1);
550 * pointer to mbuf chain containing a socket token.
553 au_to_socket(struct oldsocket
*so
)
557 char data_header
= AUT_SOCKET
;
558 struct inpcb
*inp
= so
->so_pcb
;
560 token
= get_token(sizeof (char) + sizeof (short) * 3 +
561 sizeof (int32_t) * 2);
564 adr_start(&adr
, token
->tt_data
);
565 adr_char(&adr
, &data_header
, 1);
566 adr_short(&adr
, (short *)&so
->so_type
, 1);
567 adr_short(&adr
, (short *)&inp
->inp_lport
, 1);
568 adr_int32(&adr
, (int32_t *)&inp
->inp_laddr
, 1);
569 adr_short(&adr
, (short *)&inp
->inp_fport
, 1);
570 adr_int32(&adr
, (int32_t *)&inp
->inp_faddr
, 1);
578 * pointer to a process token.
582 au_to_subject(au_id_t auid
, uid_t euid
, gid_t egid
, uid_t ruid
, gid_t rgid
,
583 pid_t pid
, au_asid_t sid
, au_tid_t
*tid
)
585 token_t
*token
; /* local token */
586 adr_t adr
; /* adr memory stream header */
588 char data_header
= AUT_SUBJECT64
; /* header for this token */
590 token
= get_token(sizeof (char) + sizeof (int64_t) +
591 8 * sizeof (int32_t));
593 char data_header
= AUT_SUBJECT32
;
595 token
= get_token(sizeof (char) + 9 * sizeof (int32_t));
600 adr_start(&adr
, token
->tt_data
);
601 adr_char(&adr
, &data_header
, 1);
602 adr_int32(&adr
, (int32_t *)&auid
, 1);
603 adr_int32(&adr
, (int32_t *)&euid
, 1);
604 adr_int32(&adr
, (int32_t *)&egid
, 1);
605 adr_int32(&adr
, (int32_t *)&ruid
, 1);
606 adr_int32(&adr
, (int32_t *)&rgid
, 1);
607 adr_int32(&adr
, (int32_t *)&pid
, 1);
608 adr_int32(&adr
, (int32_t *)&sid
, 1);
610 adr_int64(&adr
, (int64_t *)&tid
->port
, 1);
612 adr_int32(&adr
, (int32_t *)&tid
->port
, 1);
614 adr_int32(&adr
, (int32_t *)&tid
->machine
, 1);
622 * pointer to a process token.
626 au_to_subject_ex(au_id_t auid
, uid_t euid
, gid_t egid
, uid_t ruid
, gid_t rgid
,
627 pid_t pid
, au_asid_t sid
, au_tid_addr_t
*tid
)
629 token_t
*token
; /* local token */
630 adr_t adr
; /* adr memory stream header */
632 char data_header
; /* header for this token */
634 if (tid
->at_type
== AU_IPv6
) {
635 data_header
= AUT_SUBJECT64_EX
;
636 token
= get_token(sizeof (char) + sizeof (int64_t) +
637 12 * sizeof (int32_t));
639 data_header
= AUT_SUBJECT64
;
640 token
= get_token(sizeof (char) + sizeof (int64_t) +
641 8 * sizeof (int32_t));
644 char data_header
; /* header for this token */
646 if (tid
->at_type
== AU_IPv6
) {
647 data_header
= AUT_SUBJECT32_EX
;
648 token
= get_token(sizeof (char) + 13 * sizeof (int32_t));
650 data_header
= AUT_SUBJECT32
;
651 token
= get_token(sizeof (char) + 9 * sizeof (int32_t));
657 adr_start(&adr
, token
->tt_data
);
658 adr_char(&adr
, &data_header
, 1);
659 adr_int32(&adr
, (int32_t *)&auid
, 1);
660 adr_int32(&adr
, (int32_t *)&euid
, 1);
661 adr_int32(&adr
, (int32_t *)&egid
, 1);
662 adr_int32(&adr
, (int32_t *)&ruid
, 1);
663 adr_int32(&adr
, (int32_t *)&rgid
, 1);
664 adr_int32(&adr
, (int32_t *)&pid
, 1);
665 adr_int32(&adr
, (int32_t *)&sid
, 1);
667 adr_int64(&adr
, (int64_t *)&tid
->at_port
, 1);
669 adr_int32(&adr
, (int32_t *)&tid
->at_port
, 1);
671 if (tid
->at_type
== AU_IPv6
) {
672 adr_int32(&adr
, (int32_t *)&tid
->at_type
, 1);
673 adr_char(&adr
, (char *)tid
->at_addr
, 16);
675 adr_char(&adr
, (char *)tid
->at_addr
, 4);
684 * pointer to a process token.
690 auditinfo_addr_t info
;
692 if (getaudit_addr(&info
, sizeof (info
)))
694 return (au_to_subject_ex(info
.ai_auid
, geteuid(), getegid(), getuid(),
695 getgid(), getpid(), info
.ai_asid
, &info
.ai_termid
));
700 * pointer to a text token.
703 au_to_text(char *text
)
705 token_t
*token
; /* local token */
706 adr_t adr
; /* adr memory stream header */
707 char data_header
= AUT_TEXT
; /* header for this token */
708 short bytes
; /* length of string */
710 bytes
= strlen(text
) + 1;
711 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
714 adr_start(&adr
, token
->tt_data
);
715 adr_char(&adr
, &data_header
, 1);
716 adr_short(&adr
, &bytes
, 1);
717 adr_char(&adr
, text
, bytes
);
725 * pointer to a path token.
728 au_to_path(char *path
)
730 token_t
*token
; /* local token */
731 adr_t adr
; /* adr memory stream header */
732 char data_header
= AUT_PATH
; /* header for this token */
733 short bytes
; /* length of string */
735 bytes
= (short)strlen(path
) + 1;
737 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
740 adr_start(&adr
, token
->tt_data
);
741 adr_char(&adr
, &data_header
, 1);
742 adr_short(&adr
, &bytes
, 1);
743 adr_char(&adr
, path
, bytes
);
751 * pointer to an command line argument token
754 au_to_cmd(uint_t argc
, char **argv
, char **envp
)
756 token_t
*token
; /* local token */
757 adr_t adr
; /* adr memory stream header */
758 char data_header
= AUT_CMD
; /* header for this token */
762 short largc
= (short)argc
;
765 * one char for the header, one short for argc,
766 * one short for # envp strings.
768 len
= sizeof (char) + sizeof (short) + sizeof (short);
770 /* get sizes of strings */
772 for (cnt
= 0; cnt
< argc
; cnt
++) {
773 len
+= (short)sizeof (short) + (short)(strlen(argv
[cnt
]) + 1);
777 for (envc
= 0; envp
[envc
] != NULL
; envc
++) {
778 len
+= (short)sizeof (short) +
779 (short)(strlen(envp
[envc
]) + 1);
783 token
= get_token(len
);
787 adr_start(&adr
, token
->tt_data
);
788 adr_char(&adr
, &data_header
, 1);
790 adr_short(&adr
, &largc
, 1);
792 for (cnt
= 0; cnt
< argc
; cnt
++) {
793 len
= (short)(strlen(argv
[cnt
]) + 1);
794 adr_short(&adr
, &len
, 1);
795 adr_char(&adr
, argv
[cnt
], len
);
798 adr_short(&adr
, &envc
, 1);
800 for (cnt
= 0; cnt
< envc
; cnt
++) {
801 len
= (short)(strlen(envp
[cnt
]) + 1);
802 adr_short(&adr
, &len
, 1);
803 adr_char(&adr
, envp
[cnt
], len
);
812 * pointer to a exit value token.
815 au_to_exit(int retval
, int err
)
817 token_t
*token
; /* local token */
818 adr_t adr
; /* adr memory stream header */
819 char data_header
= AUT_EXIT
; /* header for this token */
821 token
= get_token(sizeof (char) + (2 * sizeof (int32_t)));
824 adr_start(&adr
, token
->tt_data
);
825 adr_char(&adr
, &data_header
, 1);
826 adr_int32(&adr
, (int32_t *)&retval
, 1);
827 adr_int32(&adr
, (int32_t *)&err
, 1);
835 * pointer to a return value token.
838 au_to_return32(char number
, uint32_t value
)
840 token_t
*token
; /* local token */
841 adr_t adr
; /* adr memory stream header */
842 char data_header
= AUT_RETURN32
; /* header for this token */
844 token
= get_token(2 * sizeof (char) + sizeof (int32_t));
847 adr_start(&adr
, token
->tt_data
);
848 adr_char(&adr
, &data_header
, 1);
849 adr_char(&adr
, &number
, 1);
850 adr_int32(&adr
, (int32_t *)&value
, 1);
858 * pointer to a return value token.
861 au_to_return64(char number
, uint64_t value
)
863 token_t
*token
; /* local token */
864 adr_t adr
; /* adr memory stream header */
865 char data_header
= AUT_RETURN64
; /* header for this token */
867 token
= get_token(2 * sizeof (char) + sizeof (int64_t));
870 adr_start(&adr
, token
->tt_data
);
871 adr_char(&adr
, &data_header
, 1);
872 adr_char(&adr
, &number
, 1);
873 adr_int64(&adr
, (int64_t *)&value
, 1);
882 * pointer to a opaque token.
885 au_to_opaque(char *opaque
, short bytes
)
887 token_t
*token
; /* local token */
888 adr_t adr
; /* adr memory stream header */
889 char data_header
= AUT_OPAQUE
; /* header for this token */
894 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
897 adr_start(&adr
, token
->tt_data
);
898 adr_char(&adr
, &data_header
, 1);
899 adr_short(&adr
, &bytes
, 1);
900 adr_char(&adr
, opaque
, bytes
);
908 * pointer to an internet address token
911 au_to_in_addr(struct in_addr
*internet_addr
)
913 token_t
*token
; /* local token */
914 adr_t adr
; /* adr memory stream header */
915 char data_header
= AUT_IN_ADDR
; /* header for this token */
917 token
= get_token(sizeof (char) + sizeof (struct in_addr
));
920 adr_start(&adr
, token
->tt_data
);
921 adr_char(&adr
, &data_header
, 1);
922 adr_char(&adr
, (char *)internet_addr
, sizeof (struct in_addr
));
930 * pointer to an internet extended token
933 au_to_in_addr_ex(struct in6_addr
*addr
)
938 if (IN6_IS_ADDR_V4MAPPED(addr
)) {
942 * An IPv4-mapped IPv6 address is really an IPv4 address
946 IN6_V4MAPPED_TO_IPADDR(addr
, in4
);
947 return (au_to_in_addr((struct in_addr
*)&in4
));
950 char data_header
= AUT_IN_ADDR_EX
;
951 int32_t type
= AU_IPv6
;
953 if ((token
= get_token(sizeof (char) + sizeof (int32_t) +
954 sizeof (struct in6_addr
))) == NULL
) {
958 adr_start(&adr
, token
->tt_data
);
959 adr_char(&adr
, &data_header
, 1);
960 adr_int32(&adr
, &type
, 1);
961 adr_char(&adr
, (char *)addr
, sizeof (struct in6_addr
));
970 * pointer to token chain containing a ip port address token
973 au_to_iport(ushort_t iport
)
975 token_t
*token
; /* local token */
976 adr_t adr
; /* adr memory stream header */
977 char data_header
= AUT_IPORT
; /* header for this token */
979 token
= get_token(sizeof (char) + sizeof (short));
982 adr_start(&adr
, token
->tt_data
);
983 adr_char(&adr
, &data_header
, 1);
984 adr_short(&adr
, (short *)&iport
, 1);
990 au_to_ipc(char type
, int id
)
992 token_t
*token
; /* local token */
993 adr_t adr
; /* adr memory stream header */
994 char data_header
= AUT_IPC
; /* header for this token */
996 token
= get_token((2 * sizeof (char)) + sizeof (int32_t));
999 adr_start(&adr
, token
->tt_data
);
1000 adr_char(&adr
, &data_header
, 1);
1001 adr_char(&adr
, &type
, 1);
1002 adr_int32(&adr
, (int32_t *)&id
, 1);
1010 * output format depends on type; at present only IP v4 and v6 addresses
1013 * IPv4 -- tid type, 16 bit remote port, 16 bit local port, ip type,
1014 * 32 bit IP address.
1015 * IPv6 -- tid type, 16 bit remote port, 16 bit local port, ip type,
1016 * 4 x 32 bit IP address.
1020 au_to_tid(au_generic_tid_t
*tid
)
1022 char data_header
= AUT_TID
; /* header for this token */
1023 adr_t adr
; /* adr memory stream header */
1024 token_t
*token
; /* local token */
1027 switch (tid
->gt_type
) {
1029 ip
= &(tid
->gt_adr
.at_ip
);
1030 token
= get_token((int)(2 * sizeof (char) + 2 * sizeof (short) +
1031 sizeof (uint32_t) + ip
->at_type
));
1035 adr_start(&adr
, token
->tt_data
);
1036 adr_char(&adr
, &data_header
, 1);
1037 adr_char(&adr
, (char *)&(tid
->gt_type
), 1);
1038 adr_short(&adr
, (short *)&(ip
->at_r_port
), 1);
1039 adr_short(&adr
, (short *)&(ip
->at_l_port
), 1);
1040 adr_int32(&adr
, (int32_t *)&(ip
->at_type
), 1);
1042 adr_char(&adr
, (char *)ip
->at_addr
, ip
->at_type
);
1052 * The Modifier tokens
1058 * pointer to a group list token.
1060 * This function is obsolete. Please use au_to_newgroups.
1063 au_to_groups(int *groups
)
1065 token_t
*token
; /* local token */
1066 adr_t adr
; /* adr memory stream header */
1067 char data_header
= AUT_GROUPS
; /* header for this token */
1069 token
= get_token(sizeof (char) + NGROUPS
* sizeof (int32_t));
1072 adr_start(&adr
, token
->tt_data
);
1073 adr_char(&adr
, &data_header
, 1);
1074 adr_int32(&adr
, (int32_t *)groups
, NGROUPS
);
1082 * pointer to a group list token.
1085 au_to_newgroups(int n
, gid_t
*groups
)
1087 token_t
*token
; /* local token */
1088 adr_t adr
; /* adr memory stream header */
1089 char data_header
= AUT_NEWGROUPS
; /* header for this token */
1092 if (n
< 0 || n
> SHRT_MAX
|| groups
== NULL
)
1094 token
= get_token(sizeof (char) + sizeof (short) + n
* sizeof (gid_t
));
1097 n_groups
= (short)n
;
1098 adr_start(&adr
, token
->tt_data
);
1099 adr_char(&adr
, &data_header
, 1);
1100 adr_short(&adr
, &n_groups
, 1);
1101 adr_int32(&adr
, (int32_t *)groups
, n_groups
);
1109 * pointer to an exec args token.
1112 au_to_exec_args(char **argv
)
1114 return (au_to_exec(argv
, AUT_EXEC_ARGS
));
1120 * pointer to an exec args token.
1123 au_to_exec_env(char **envp
)
1125 return (au_to_exec(envp
, AUT_EXEC_ENV
));
1131 * pointer to an exec args token.
1134 au_to_exec(char **v
, char data_header
)
1142 for (p
= v
; *p
!= NULL
; p
++) {
1143 len
+= strlen(*p
) + 1;
1146 token
= get_token(sizeof (char) + sizeof (int32_t) + len
);
1147 if (token
== (token_t
*)NULL
)
1148 return ((token_t
*)NULL
);
1149 adr_start(&adr
, token
->tt_data
);
1150 adr_char(&adr
, &data_header
, 1);
1151 adr_int32(&adr
, &n
, 1);
1152 for (p
= v
; *p
!= NULL
; p
++) {
1153 adr_char(&adr
, *p
, strlen(*p
) + 1);
1161 * pointer to a uauth token.
1164 au_to_uauth(char *text
)
1166 token_t
*token
; /* local token */
1167 adr_t adr
; /* adr memory stream header */
1168 char data_header
= AUT_UAUTH
; /* header for this token */
1169 short bytes
; /* length of string */
1171 bytes
= strlen(text
) + 1;
1173 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
1176 adr_start(&adr
, token
->tt_data
);
1177 adr_char(&adr
, &data_header
, 1);
1178 adr_short(&adr
, &bytes
, 1);
1179 adr_char(&adr
, text
, bytes
);
1187 * pointer to a use of privilege token.
1190 au_to_upriv(char sorf
, char *priv
)
1192 token_t
*token
; /* local token */
1193 adr_t adr
; /* adr memory stream header */
1194 char data_header
= AUT_UAUTH
; /* header for this token */
1195 short bytes
; /* length of string */
1197 bytes
= strlen(priv
) + 1;
1199 token
= get_token(sizeof (char) + sizeof (char) + sizeof (short) +
1203 adr_start(&adr
, token
->tt_data
);
1204 adr_char(&adr
, &data_header
, 1);
1205 adr_char(&adr
, &sorf
, 1); /* success/failure */
1206 adr_short(&adr
, &bytes
, 1);
1207 adr_char(&adr
, priv
, bytes
);
1215 * pointer to a user token.
1218 au_to_user(uid_t uid
, char *username
)
1220 token_t
*token
; /* local token */
1221 adr_t adr
; /* adr memory stream header */
1222 char data_header
= AUT_USER
; /* header for this token */
1223 short bytes
; /* length of string */
1225 bytes
= (short)strlen(username
) + 1;
1227 token
= get_token(sizeof (char) + sizeof (uid_t
) + sizeof (short) +
1231 adr_start(&adr
, token
->tt_data
);
1232 adr_char(&adr
, &data_header
, 1);
1233 adr_uid(&adr
, &uid
, 1);
1234 adr_short(&adr
, &bytes
, 1);
1235 adr_char(&adr
, username
, bytes
);
1243 * pointer to a xatom token.
1246 au_to_xatom(char *atom
)
1248 token_t
*token
; /* local token */
1249 adr_t adr
; /* adr memory stream header */
1250 char data_header
= AUT_XATOM
; /* header for this token */
1253 len
= strlen(atom
) + 1;
1255 token
= get_token(sizeof (char) + sizeof (short) + len
);
1258 adr_start(&adr
, token
->tt_data
);
1259 adr_char(&adr
, &data_header
, 1);
1260 adr_short(&adr
, (short *)&len
, 1);
1261 adr_char(&adr
, atom
, len
);
1269 * pointer to a X select token.
1272 au_to_xselect(char *propname
, char *proptype
, char *windata
)
1274 token_t
*token
; /* local token */
1275 adr_t adr
; /* adr memory stream header */
1276 char data_header
= AUT_XSELECT
; /* header for this token */
1281 proplen
= strlen(propname
) + 1;
1282 typelen
= strlen(proptype
) + 1;
1283 datalen
= strlen(windata
) + 1;
1285 token
= get_token(sizeof (char) + (sizeof (short) * 3) +
1286 proplen
+ typelen
+ datalen
);
1289 adr_start(&adr
, token
->tt_data
);
1290 adr_char(&adr
, &data_header
, 1);
1291 adr_short(&adr
, &proplen
, 1);
1292 adr_char(&adr
, propname
, proplen
);
1293 adr_short(&adr
, &typelen
, 1);
1294 adr_char(&adr
, proptype
, typelen
);
1295 adr_short(&adr
, &datalen
, 1);
1296 adr_char(&adr
, windata
, datalen
);
1304 * pointer to a common X token.
1308 x_common(char data_header
, int32_t xid
, uid_t cuid
)
1310 token_t
*token
; /* local token */
1311 adr_t adr
; /* adr memory stream header */
1313 token
= get_token(sizeof (char) + sizeof (int32_t) + sizeof (uid_t
));
1316 adr_start(&adr
, token
->tt_data
);
1317 adr_char(&adr
, &data_header
, 1);
1318 adr_int32(&adr
, &xid
, 1);
1319 adr_uid(&adr
, &cuid
, 1);
1327 * pointer to a X Colormap token.
1331 au_to_xcolormap(int32_t xid
, uid_t cuid
)
1333 return (x_common(AUT_XCOLORMAP
, xid
, cuid
));
1339 * pointer to a X Cursor token.
1343 au_to_xcursor(int32_t xid
, uid_t cuid
)
1345 return (x_common(AUT_XCURSOR
, xid
, cuid
));
1351 * pointer to a X Font token.
1355 au_to_xfont(int32_t xid
, uid_t cuid
)
1357 return (x_common(AUT_XFONT
, xid
, cuid
));
1363 * pointer to a X Graphic Context token.
1367 au_to_xgc(int32_t xid
, uid_t cuid
)
1369 return (x_common(AUT_XGC
, xid
, cuid
));
1375 * pointer to a X Pixal Map token.
1379 au_to_xpixmap(int32_t xid
, uid_t cuid
)
1381 return (x_common(AUT_XPIXMAP
, xid
, cuid
));
1387 * pointer to a X Window token.
1391 au_to_xwindow(int32_t xid
, uid_t cuid
)
1393 return (x_common(AUT_XWINDOW
, xid
, cuid
));
1399 * pointer to a X Property token.
1403 au_to_xproperty(int32_t xid
, uid_t cuid
, char *propname
)
1405 token_t
*token
; /* local token */
1406 adr_t adr
; /* adr memory stream header */
1407 char data_header
= AUT_XPROPERTY
; /* header for this token */
1410 proplen
= strlen(propname
) + 1;
1412 token
= get_token(sizeof (char) + sizeof (int32_t) + sizeof (uid_t
) +
1413 sizeof (short) + proplen
);
1416 adr_start(&adr
, token
->tt_data
);
1417 adr_char(&adr
, &data_header
, 1);
1418 adr_int32(&adr
, &xid
, 1);
1419 adr_uid(&adr
, &cuid
, 1);
1420 adr_short(&adr
, &proplen
, 1);
1421 adr_char(&adr
, propname
, proplen
);
1429 * pointer to a X Client token
1433 au_to_xclient(uint32_t client
)
1435 token_t
*token
; /* local token */
1436 adr_t adr
; /* adr memory stream header */
1437 char data_header
= AUT_XCLIENT
; /* header for this token */
1439 token
= get_token(sizeof (char) + sizeof (uint32_t));
1442 adr_start(&adr
, token
->tt_data
);
1443 adr_char(&adr
, &data_header
, 1);
1444 adr_int32(&adr
, (int32_t *)&client
, 1);
1453 * pointer to a zonename token.
1456 au_to_zonename(char *name
)
1458 token_t
*token
; /* local token */
1459 adr_t adr
; /* adr memory stream header */
1460 char data_header
= AUT_ZONENAME
; /* header for this token */
1461 short bytes
; /* length of string */
1466 bytes
= strlen(name
) + 1;
1467 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
1470 adr_start(&adr
, token
->tt_data
);
1471 adr_char(&adr
, &data_header
, 1);
1472 adr_short(&adr
, &bytes
, 1);
1473 adr_char(&adr
, name
, bytes
);
1481 * pointer to a fmri token.
1484 au_to_fmri(char *fmri
)
1486 token_t
*token
; /* local token */
1487 adr_t adr
; /* adr memory stream header */
1488 char data_header
= AUT_FMRI
; /* header for this token */
1489 short bytes
; /* length of string */
1494 bytes
= strlen(fmri
) + 1;
1495 token
= get_token((int)(sizeof (char) + sizeof (short) + bytes
));
1498 adr_start(&adr
, token
->tt_data
);
1499 adr_char(&adr
, &data_header
, 1);
1500 adr_short(&adr
, &bytes
, 1);
1501 adr_char(&adr
, fmri
, bytes
);