xref: /titanic_44/usr/src/lib/libbsm/common/au_to.c (revision 047f6e6f42a3d50d3e38a05c00bf7dd3fafac726)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*047f6e6fSgww  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <unistd.h>
297c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
307c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
317c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
327c478bd9Sstevel@tonic-gate #include <priv.h>
337c478bd9Sstevel@tonic-gate #include <sys/ipc.h>
347c478bd9Sstevel@tonic-gate #include <sys/param.h>
357c478bd9Sstevel@tonic-gate #include <sys/socket.h>
367c478bd9Sstevel@tonic-gate #include <sys/time.h>
377c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
387c478bd9Sstevel@tonic-gate #include <malloc.h>
397c478bd9Sstevel@tonic-gate #include <net/route.h>
407c478bd9Sstevel@tonic-gate #include <netinet/in.h>
417c478bd9Sstevel@tonic-gate #include <netinet/in_pcb.h>
427c478bd9Sstevel@tonic-gate #include <string.h>
43c7bb2ee8Sgww #include <ucred.h>
4445916cd2Sjpk #include <zone.h>
4545916cd2Sjpk #include <sys/tsol/label.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	NGROUPS		16	/* XXX - temporary */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate token_t *au_to_arg(char n, char *text, uint32_t v);
507c478bd9Sstevel@tonic-gate #pragma weak au_to_arg = au_to_arg32
517c478bd9Sstevel@tonic-gate token_t *au_to_return(char number, uint32_t value);
527c478bd9Sstevel@tonic-gate #pragma weak au_to_return = au_to_return32
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate static token_t *au_to_exec(char **, char);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate static token_t *
get_token(int s)577c478bd9Sstevel@tonic-gate get_token(int s)
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate 	token_t *token;	/* Resultant token */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	if ((token = (token_t *)malloc(sizeof (token_t))) == NULL)
627c478bd9Sstevel@tonic-gate 		return (NULL);
637c478bd9Sstevel@tonic-gate 	if ((token->tt_data = malloc(s)) == NULL) {
647c478bd9Sstevel@tonic-gate 		free(token);
657c478bd9Sstevel@tonic-gate 		return (NULL);
667c478bd9Sstevel@tonic-gate 	}
677c478bd9Sstevel@tonic-gate 	token->tt_size = s;
687c478bd9Sstevel@tonic-gate 	token->tt_next = NULL;
697c478bd9Sstevel@tonic-gate 	return (token);
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * au_to_header
747c478bd9Sstevel@tonic-gate  * return s:
757c478bd9Sstevel@tonic-gate  *	pointer to header token.
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate token_t *
au_to_header(au_event_t e_type,au_emod_t e_mod)787c478bd9Sstevel@tonic-gate au_to_header(au_event_t e_type, au_emod_t e_mod)
797c478bd9Sstevel@tonic-gate {
807c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
817c478bd9Sstevel@tonic-gate 	token_t *token;			/* token pointer */
827c478bd9Sstevel@tonic-gate 	char version = TOKEN_VERSION;	/* version of token family */
837c478bd9Sstevel@tonic-gate 	int32_t byte_count;
847c478bd9Sstevel@tonic-gate 	struct timeval tv;
857c478bd9Sstevel@tonic-gate #ifdef _LP64
867c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER64;	/* header for this token */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + sizeof (int32_t) +
897c478bd9Sstevel@tonic-gate 	    2 * sizeof (int64_t) + 2 * sizeof (short));
907c478bd9Sstevel@tonic-gate #else
917c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER32;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + 3 * sizeof (int32_t) +
947c478bd9Sstevel@tonic-gate 	    2 * sizeof (short));
957c478bd9Sstevel@tonic-gate #endif
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	if (token == NULL)
987c478bd9Sstevel@tonic-gate 		return (NULL);
997c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
1007c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
1017c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &byte_count, 1);	/* length of audit record */
1027c478bd9Sstevel@tonic-gate 	adr_char(&adr, &version, 1);		/* version of audit tokens */
103d0fa49b7STony Nguyen 	adr_ushort(&adr, &e_type, 1);		/* event ID */
104d0fa49b7STony Nguyen 	adr_ushort(&adr, &e_mod, 1);		/* event ID modifier */
1057c478bd9Sstevel@tonic-gate #ifdef _LP64
1067c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tv, 2);	/* time & date */
1077c478bd9Sstevel@tonic-gate #else
1087c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tv, 2);	/* time & date */
1097c478bd9Sstevel@tonic-gate #endif
1107c478bd9Sstevel@tonic-gate 	return (token);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * au_to_header_ex
1157c478bd9Sstevel@tonic-gate  * return s:
1167c478bd9Sstevel@tonic-gate  *	pointer to header token.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate token_t *
au_to_header_ex(au_event_t e_type,au_emod_t e_mod)1197c478bd9Sstevel@tonic-gate au_to_header_ex(au_event_t e_type, au_emod_t e_mod)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
1227c478bd9Sstevel@tonic-gate 	token_t *token;			/* token pointer */
1237c478bd9Sstevel@tonic-gate 	char version = TOKEN_VERSION;	/* version of token family */
1247c478bd9Sstevel@tonic-gate 	int32_t byte_count;
1257c478bd9Sstevel@tonic-gate 	struct timeval tv;
1267c478bd9Sstevel@tonic-gate 	auditinfo_addr_t audit_info;
1277c478bd9Sstevel@tonic-gate 	au_tid_addr_t	*host_info = &audit_info.ai_termid;
1287c478bd9Sstevel@tonic-gate #ifdef _LP64
1297c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER64_EX;	/* header for this token */
1307c478bd9Sstevel@tonic-gate #else
1317c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER32_EX;
1327c478bd9Sstevel@tonic-gate #endif
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	/* If our host address can't be determined, revert to un-extended hdr */
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	if (auditon(A_GETKAUDIT, (caddr_t)&audit_info,
1377c478bd9Sstevel@tonic-gate 	    sizeof (audit_info)) < 0)
1387c478bd9Sstevel@tonic-gate 		return (au_to_header(e_type, e_mod));
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	if (host_info->at_type == AU_IPv6)
1417c478bd9Sstevel@tonic-gate 		if (IN6_IS_ADDR_UNSPECIFIED((in6_addr_t *)host_info->at_addr))
1427c478bd9Sstevel@tonic-gate 			return (au_to_header(e_type, e_mod));
1437c478bd9Sstevel@tonic-gate 	else
1447c478bd9Sstevel@tonic-gate 		if (host_info->at_addr[0] == htonl(INADDR_ANY))
1457c478bd9Sstevel@tonic-gate 			return (au_to_header(e_type, e_mod));
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate #ifdef _LP64
1487c478bd9Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + sizeof (int32_t) +
1497c478bd9Sstevel@tonic-gate 	    2 * sizeof (int64_t) + 2 * sizeof (short) +
1507c478bd9Sstevel@tonic-gate 	    sizeof (int32_t) + host_info->at_type);
1517c478bd9Sstevel@tonic-gate #else
1527c478bd9Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + 3 * sizeof (int32_t) +
1537c478bd9Sstevel@tonic-gate 	    2 * sizeof (short) + sizeof (int32_t) + host_info->at_type);
1547c478bd9Sstevel@tonic-gate #endif
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	if (token == NULL)
1577c478bd9Sstevel@tonic-gate 		return (NULL);
1587c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
1597c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
1607c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &byte_count, 1);	/* length of audit record */
1617c478bd9Sstevel@tonic-gate 	adr_char(&adr, &version, 1);		/* version of audit tokens */
162d0fa49b7STony Nguyen 	adr_ushort(&adr, &e_type, 1);		/* event ID */
163d0fa49b7STony Nguyen 	adr_ushort(&adr, &e_mod, 1);		/* event ID modifier */
1647c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&host_info->at_type, 1);
1657c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)host_info->at_addr,
1667c478bd9Sstevel@tonic-gate 	    (int)host_info->at_type);
1677c478bd9Sstevel@tonic-gate #ifdef _LP64
1687c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tv, 2);	/* time & date */
1697c478bd9Sstevel@tonic-gate #else
1707c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tv, 2);	/* time & date */
1717c478bd9Sstevel@tonic-gate #endif
1727c478bd9Sstevel@tonic-gate 	return (token);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate  * au_to_trailer
1777c478bd9Sstevel@tonic-gate  * return s:
1787c478bd9Sstevel@tonic-gate  *	pointer to a trailer token.
1797c478bd9Sstevel@tonic-gate  */
1807c478bd9Sstevel@tonic-gate token_t *
au_to_trailer(void)1817c478bd9Sstevel@tonic-gate au_to_trailer(void)
1827c478bd9Sstevel@tonic-gate {
1837c478bd9Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
1847c478bd9Sstevel@tonic-gate 	token_t *token;				/* token pointer */
1857c478bd9Sstevel@tonic-gate 	char data_header = AUT_TRAILER;		/* header for this token */
1867c478bd9Sstevel@tonic-gate 	short magic = (short)AUT_TRAILER_MAGIC;	/* trailer magic number */
1877c478bd9Sstevel@tonic-gate 	int32_t byte_count;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int32_t) + sizeof (short));
1907c478bd9Sstevel@tonic-gate 	if (token == NULL)
1917c478bd9Sstevel@tonic-gate 		return (NULL);
1927c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
1937c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
1947c478bd9Sstevel@tonic-gate 	adr_short(&adr, &magic, 1);		/* magic number */
1957c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &byte_count, 1);	/* length of audit record */
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	return (token);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * au_to_arg32
2027c478bd9Sstevel@tonic-gate  * return s:
2037c478bd9Sstevel@tonic-gate  *	pointer to an argument token.
2047c478bd9Sstevel@tonic-gate  */
2057c478bd9Sstevel@tonic-gate token_t *
au_to_arg32(char n,char * text,uint32_t v)2067c478bd9Sstevel@tonic-gate au_to_arg32(char n, char *text, uint32_t v)
2077c478bd9Sstevel@tonic-gate {
2087c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
2097c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
2107c478bd9Sstevel@tonic-gate 	char data_header = AUT_ARG32;	/* header for this token */
2117c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	bytes = strlen(text) + 1;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	token = get_token((int)(2 * sizeof (char) + sizeof (int32_t) +
2167c478bd9Sstevel@tonic-gate 	    sizeof (short) + bytes));
2177c478bd9Sstevel@tonic-gate 	if (token == NULL)
2187c478bd9Sstevel@tonic-gate 		return (NULL);
2197c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
2207c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token type */
2217c478bd9Sstevel@tonic-gate 	adr_char(&adr, &n, 1);			/* argument id */
2227c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&v, 1);	/* argument value */
2237c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
2247c478bd9Sstevel@tonic-gate 	adr_char(&adr, text, bytes);
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	return (token);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate  * au_to_arg64
2317c478bd9Sstevel@tonic-gate  * return s:
2327c478bd9Sstevel@tonic-gate  *	pointer to an argument token.
2337c478bd9Sstevel@tonic-gate  */
2347c478bd9Sstevel@tonic-gate token_t *
au_to_arg64(char n,char * text,uint64_t v)2357c478bd9Sstevel@tonic-gate au_to_arg64(char n, char *text, uint64_t v)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
2387c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
2397c478bd9Sstevel@tonic-gate 	char data_header = AUT_ARG64;	/* header for this token */
2407c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	bytes = strlen(text) + 1;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	token = get_token((int)(2 * sizeof (char) + sizeof (int64_t) +
2457c478bd9Sstevel@tonic-gate 	    sizeof (short) + bytes));
2467c478bd9Sstevel@tonic-gate 	if (token == NULL)
2477c478bd9Sstevel@tonic-gate 		return (NULL);
2487c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
2497c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token type */
2507c478bd9Sstevel@tonic-gate 	adr_char(&adr, &n, 1);			/* argument id */
2517c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&v, 1);	/* argument value */
2527c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
2537c478bd9Sstevel@tonic-gate 	adr_char(&adr, text, bytes);
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	return (token);
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate /*
2607c478bd9Sstevel@tonic-gate  * au_to_attr
2617c478bd9Sstevel@tonic-gate  * return s:
2627c478bd9Sstevel@tonic-gate  *	pointer to an attribute token.
2637c478bd9Sstevel@tonic-gate  */
2647c478bd9Sstevel@tonic-gate token_t *
au_to_attr(struct vattr * attr)2657c478bd9Sstevel@tonic-gate au_to_attr(struct vattr *attr)
2667c478bd9Sstevel@tonic-gate {
2677c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
2687c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
2697c478bd9Sstevel@tonic-gate 	int32_t value;
2707c478bd9Sstevel@tonic-gate #ifdef _LP64
2717c478bd9Sstevel@tonic-gate 	char data_header = AUT_ATTR64;	/* header for this token */
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) +
2747c478bd9Sstevel@tonic-gate 	    sizeof (int32_t) * 4 +
2757c478bd9Sstevel@tonic-gate 	    sizeof (int64_t) * 2);
2767c478bd9Sstevel@tonic-gate #else
2777c478bd9Sstevel@tonic-gate 	char data_header = AUT_ATTR32;
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int32_t) * 5 +
2807c478bd9Sstevel@tonic-gate 	    sizeof (int64_t));
2817c478bd9Sstevel@tonic-gate #endif
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	if (token == NULL)
2847c478bd9Sstevel@tonic-gate 		return (NULL);
2857c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
2867c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
2877c478bd9Sstevel@tonic-gate 	value = (int32_t)attr->va_mode;
2887c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
2897c478bd9Sstevel@tonic-gate 	value = (int32_t)attr->va_uid;
2907c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
2917c478bd9Sstevel@tonic-gate 	value = (int32_t)attr->va_gid;
2927c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
2937c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(attr->va_fsid), 1);
2947c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(attr->va_nodeid), 1);
2957c478bd9Sstevel@tonic-gate #ifdef _LP64
2967c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(attr->va_rdev), 1);
2977c478bd9Sstevel@tonic-gate #else
2987c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(attr->va_rdev), 1);
2997c478bd9Sstevel@tonic-gate #endif
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	return (token);
3027c478bd9Sstevel@tonic-gate }
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate /*
3057c478bd9Sstevel@tonic-gate  * au_to_data
3067c478bd9Sstevel@tonic-gate  * return s:
3077c478bd9Sstevel@tonic-gate  *	pointer to a data token.
3087c478bd9Sstevel@tonic-gate  */
3097c478bd9Sstevel@tonic-gate token_t *
au_to_data(char unit_print,char unit_type,char unit_count,char * p)3107c478bd9Sstevel@tonic-gate au_to_data(char unit_print, char unit_type, char unit_count, char *p)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
3137c478bd9Sstevel@tonic-gate 	token_t *token;			/* token pointer */
3147c478bd9Sstevel@tonic-gate 	char data_header = AUT_DATA;	/* header for this token */
3157c478bd9Sstevel@tonic-gate 	int byte_count;			/* number of bytes */
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	if (p == NULL || unit_count < 1)
3187c478bd9Sstevel@tonic-gate 		return (NULL);
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	/*
3217c478bd9Sstevel@tonic-gate 	 * Check validity of print type
3227c478bd9Sstevel@tonic-gate 	 */
3237c478bd9Sstevel@tonic-gate 	if (unit_print < AUP_BINARY || unit_print > AUP_STRING)
3247c478bd9Sstevel@tonic-gate 		return (NULL);
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	switch (unit_type) {
3277c478bd9Sstevel@tonic-gate 	case AUR_SHORT:
3287c478bd9Sstevel@tonic-gate 		byte_count = unit_count * sizeof (short);
3297c478bd9Sstevel@tonic-gate 		break;
3307c478bd9Sstevel@tonic-gate 	case AUR_INT32:
3317c478bd9Sstevel@tonic-gate 		byte_count = unit_count * sizeof (int32_t);
3327c478bd9Sstevel@tonic-gate 		break;
3337c478bd9Sstevel@tonic-gate 	case AUR_INT64:
3347c478bd9Sstevel@tonic-gate 		byte_count = unit_count * sizeof (int64_t);
3357c478bd9Sstevel@tonic-gate 		break;
3367c478bd9Sstevel@tonic-gate 	/* case AUR_CHAR: */
3377c478bd9Sstevel@tonic-gate 	case AUR_BYTE:
3387c478bd9Sstevel@tonic-gate 		byte_count = unit_count * sizeof (char);
3397c478bd9Sstevel@tonic-gate 		break;
3407c478bd9Sstevel@tonic-gate 	default:
3417c478bd9Sstevel@tonic-gate 		return (NULL);
3427c478bd9Sstevel@tonic-gate 	}
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 	token = get_token((int)(4 * sizeof (char) + byte_count));
3457c478bd9Sstevel@tonic-gate 	if (token == NULL)
3467c478bd9Sstevel@tonic-gate 		return (NULL);
3477c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
3487c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
3497c478bd9Sstevel@tonic-gate 	adr_char(&adr, &unit_print, 1);
3507c478bd9Sstevel@tonic-gate 	adr_char(&adr, &unit_type, 1);
3517c478bd9Sstevel@tonic-gate 	adr_char(&adr, &unit_count, 1);
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 	switch (unit_type) {
3547c478bd9Sstevel@tonic-gate 	case AUR_SHORT:
3557c478bd9Sstevel@tonic-gate 		/* LINTED */
3567c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)p, unit_count);
3577c478bd9Sstevel@tonic-gate 		break;
3587c478bd9Sstevel@tonic-gate 	case AUR_INT32:
3597c478bd9Sstevel@tonic-gate 		/* LINTED */
3607c478bd9Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)p, unit_count);
3617c478bd9Sstevel@tonic-gate 		break;
3627c478bd9Sstevel@tonic-gate 	case AUR_INT64:
3637c478bd9Sstevel@tonic-gate 		/* LINTED */
3647c478bd9Sstevel@tonic-gate 		adr_int64(&adr, (int64_t *)p, unit_count);
3657c478bd9Sstevel@tonic-gate 		break;
3667c478bd9Sstevel@tonic-gate 	/* case AUR_CHAR: */
3677c478bd9Sstevel@tonic-gate 	case AUR_BYTE:
3687c478bd9Sstevel@tonic-gate 		adr_char(&adr, p, unit_count);
3697c478bd9Sstevel@tonic-gate 		break;
3707c478bd9Sstevel@tonic-gate 	}
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 	return (token);
3737c478bd9Sstevel@tonic-gate }
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate /*
3767c478bd9Sstevel@tonic-gate  * au_to_privset
3777c478bd9Sstevel@tonic-gate  *
3787c478bd9Sstevel@tonic-gate  * priv_type (LIMIT, INHERIT...) is the first string and privilege
3797c478bd9Sstevel@tonic-gate  * in translated into the second string.  The format is as follows:
3807c478bd9Sstevel@tonic-gate  *
3817c478bd9Sstevel@tonic-gate  *	token id	adr_char
3827c478bd9Sstevel@tonic-gate  *	priv type	adr_string (short, string)
3837c478bd9Sstevel@tonic-gate  *	priv set	adr_string (short, string)
3847c478bd9Sstevel@tonic-gate  *
3857c478bd9Sstevel@tonic-gate  * return s:
3867c478bd9Sstevel@tonic-gate  *	pointer to a AUT_PRIV token.
3877c478bd9Sstevel@tonic-gate  */
3887c478bd9Sstevel@tonic-gate token_t *
au_to_privset(const char * priv_type,const priv_set_t * privilege)3897c478bd9Sstevel@tonic-gate au_to_privset(const char *priv_type, const priv_set_t *privilege)
3907c478bd9Sstevel@tonic-gate {
3917c478bd9Sstevel@tonic-gate 	token_t	*token;			/* local token */
3927c478bd9Sstevel@tonic-gate 	adr_t	adr;			/* adr memory stream header */
3937c478bd9Sstevel@tonic-gate 	char	data_header = AUT_PRIV;	/* header for this token */
3947c478bd9Sstevel@tonic-gate 	short	t_bytes;		/* length of type string */
3957c478bd9Sstevel@tonic-gate 	short	p_bytes;		/* length of privilege string */
3967c478bd9Sstevel@tonic-gate 	char	*priv_string;		/* privilege string */
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 	t_bytes = strlen(priv_type) + 1;
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 	if ((privilege == NULL) || (priv_string =
4017c478bd9Sstevel@tonic-gate 	    priv_set_to_str(privilege, ',',
4027c478bd9Sstevel@tonic-gate 	    PRIV_STR_LIT)) == NULL)
4037c478bd9Sstevel@tonic-gate 		return (NULL);
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate 	p_bytes = strlen(priv_string) + 1;
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + (2 * sizeof (short)) + t_bytes
4087c478bd9Sstevel@tonic-gate 	    + p_bytes));
4097c478bd9Sstevel@tonic-gate 	if (token == NULL)
4107c478bd9Sstevel@tonic-gate 		return (NULL);
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
4137c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
4147c478bd9Sstevel@tonic-gate 	adr_short(&adr, &t_bytes, 1);
4157c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)priv_type, t_bytes);
4167c478bd9Sstevel@tonic-gate 	adr_short(&adr, &p_bytes, 1);
4177c478bd9Sstevel@tonic-gate 	adr_char(&adr, priv_string, p_bytes);
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	free(priv_string);
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 	return (token);
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate /*
4257c478bd9Sstevel@tonic-gate  * au_to_process
4267c478bd9Sstevel@tonic-gate  * return s:
4277c478bd9Sstevel@tonic-gate  *	pointer to a process token.
4287c478bd9Sstevel@tonic-gate  */
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate token_t *
au_to_process(au_id_t auid,uid_t euid,gid_t egid,uid_t ruid,gid_t rgid,pid_t pid,au_asid_t sid,au_tid_t * tid)4317c478bd9Sstevel@tonic-gate au_to_process(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid,
4327c478bd9Sstevel@tonic-gate     pid_t pid, au_asid_t sid, au_tid_t *tid)
4337c478bd9Sstevel@tonic-gate {
4347c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
4357c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
4367c478bd9Sstevel@tonic-gate #ifdef _LP64
4377c478bd9Sstevel@tonic-gate 	char data_header = AUT_PROCESS64;	/* header for this token */
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + 8 * sizeof (int32_t) +
4407c478bd9Sstevel@tonic-gate 	    sizeof (int64_t));
4417c478bd9Sstevel@tonic-gate #else
4427c478bd9Sstevel@tonic-gate 	char data_header = AUT_PROCESS32;
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + 9 * sizeof (int32_t));
4457c478bd9Sstevel@tonic-gate #endif
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	if (token == NULL)
4487c478bd9Sstevel@tonic-gate 		return (NULL);
4497c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
4507c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
4517c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&auid, 1);
4527c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&euid, 1);
4537c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&egid, 1);
4547c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&ruid, 1);
4557c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&rgid, 1);
4567c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&pid, 1);
4577c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&sid, 1);
4587c478bd9Sstevel@tonic-gate #ifdef _LP64
4597c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tid->port, 1);
4607c478bd9Sstevel@tonic-gate #else
4617c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->port, 1);
4627c478bd9Sstevel@tonic-gate #endif
4637c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->machine, 1);
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	return (token);
4667c478bd9Sstevel@tonic-gate }
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate /*
4697c478bd9Sstevel@tonic-gate  * au_to_process_ex
4707c478bd9Sstevel@tonic-gate  * return s:
4717c478bd9Sstevel@tonic-gate  *	pointer to a process_ex token.
4727c478bd9Sstevel@tonic-gate  */
4737c478bd9Sstevel@tonic-gate token_t *
au_to_process_ex(au_id_t auid,uid_t euid,gid_t egid,uid_t ruid,gid_t rgid,pid_t pid,au_asid_t sid,au_tid_addr_t * tid)4747c478bd9Sstevel@tonic-gate au_to_process_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid,
4757c478bd9Sstevel@tonic-gate     pid_t pid, au_asid_t sid, au_tid_addr_t *tid)
4767c478bd9Sstevel@tonic-gate {
4777c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
4787c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
4797c478bd9Sstevel@tonic-gate 	char data_header;		/* header for this token */
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate #ifdef _LP64
4827c478bd9Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
4837c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS64_EX;
4847c478bd9Sstevel@tonic-gate 		token = get_token(sizeof (char) + sizeof (int64_t) +
4857c478bd9Sstevel@tonic-gate 		    12 * sizeof (int32_t));
4867c478bd9Sstevel@tonic-gate 	} else {
4877c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS64;
4887c478bd9Sstevel@tonic-gate 		token = get_token(sizeof (char) + sizeof (int64_t) +
4897c478bd9Sstevel@tonic-gate 		    8 * sizeof (int32_t));
4907c478bd9Sstevel@tonic-gate 	}
4917c478bd9Sstevel@tonic-gate #else
4927c478bd9Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
4937c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS32_EX;
4947c478bd9Sstevel@tonic-gate 		token = get_token(sizeof (char) + 13 * sizeof (int32_t));
4957c478bd9Sstevel@tonic-gate 	} else {
4967c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS32;
4977c478bd9Sstevel@tonic-gate 		token = get_token(sizeof (char) + 9 * sizeof (int32_t));
4987c478bd9Sstevel@tonic-gate 	}
4997c478bd9Sstevel@tonic-gate #endif
5007c478bd9Sstevel@tonic-gate 	if (token == NULL)
5017c478bd9Sstevel@tonic-gate 		return (NULL);
5027c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
5037c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
5047c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&auid, 1);
5057c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&euid, 1);
5067c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&egid, 1);
5077c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&ruid, 1);
5087c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&rgid, 1);
5097c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&pid, 1);
5107c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&sid, 1);
5117c478bd9Sstevel@tonic-gate #ifdef _LP64
5127c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tid->at_port, 1);
5137c478bd9Sstevel@tonic-gate #else
5147c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->at_port, 1);
5157c478bd9Sstevel@tonic-gate #endif
5167c478bd9Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
5177c478bd9Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)&tid->at_type, 1);
5187c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)tid->at_addr, 16);
5197c478bd9Sstevel@tonic-gate 	} else {
5207c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)tid->at_addr, 4);
5217c478bd9Sstevel@tonic-gate 	}
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	return (token);
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate /*
5277c478bd9Sstevel@tonic-gate  * au_to_seq
5287c478bd9Sstevel@tonic-gate  * return s:
5297c478bd9Sstevel@tonic-gate  *	pointer to token chain containing a sequence token
5307c478bd9Sstevel@tonic-gate  */
5317c478bd9Sstevel@tonic-gate token_t *
au_to_seq(int audit_count)5327c478bd9Sstevel@tonic-gate au_to_seq(int audit_count)
5337c478bd9Sstevel@tonic-gate {
5347c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
5357c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
5367c478bd9Sstevel@tonic-gate 	char data_header = AUT_SEQ;	/* header for this token */
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int32_t));
5397c478bd9Sstevel@tonic-gate 	if (token == NULL)
5407c478bd9Sstevel@tonic-gate 		return (NULL);
5417c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
5427c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
5437c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&audit_count, 1);
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	return (token);
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate /*
5497c478bd9Sstevel@tonic-gate  * au_to_socket
5507c478bd9Sstevel@tonic-gate  * return s:
5517c478bd9Sstevel@tonic-gate  *	pointer to mbuf chain containing a socket token.
5527c478bd9Sstevel@tonic-gate  */
5537c478bd9Sstevel@tonic-gate token_t *
au_to_socket(struct oldsocket * so)5547c478bd9Sstevel@tonic-gate au_to_socket(struct oldsocket *so)
5557c478bd9Sstevel@tonic-gate {
5567c478bd9Sstevel@tonic-gate 	adr_t adr;
5577c478bd9Sstevel@tonic-gate 	token_t *token;
5587c478bd9Sstevel@tonic-gate 	char data_header = AUT_SOCKET;
5597c478bd9Sstevel@tonic-gate 	struct inpcb *inp = so->so_pcb;
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (short) * 3 +
5627c478bd9Sstevel@tonic-gate 	    sizeof (int32_t) * 2);
5637c478bd9Sstevel@tonic-gate 	if (token == NULL)
5647c478bd9Sstevel@tonic-gate 		return (NULL);
5657c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
5667c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
5677c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&so->so_type, 1);
5687c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&inp->inp_lport, 1);
5697c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&inp->inp_laddr, 1);
5707c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&inp->inp_fport, 1);
5717c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&inp->inp_faddr, 1);
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	return (token);
5747c478bd9Sstevel@tonic-gate }
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate /*
5777c478bd9Sstevel@tonic-gate  * au_to_subject
5787c478bd9Sstevel@tonic-gate  * return s:
5797c478bd9Sstevel@tonic-gate  *	pointer to a process token.
5807c478bd9Sstevel@tonic-gate  */
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate token_t *
au_to_subject(au_id_t auid,uid_t euid,gid_t egid,uid_t ruid,gid_t rgid,pid_t pid,au_asid_t sid,au_tid_t * tid)5837c478bd9Sstevel@tonic-gate au_to_subject(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid,
5847c478bd9Sstevel@tonic-gate     pid_t pid, au_asid_t sid, au_tid_t *tid)
5857c478bd9Sstevel@tonic-gate {
5867c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
5877c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
5887c478bd9Sstevel@tonic-gate #ifdef _LP64
5897c478bd9Sstevel@tonic-gate 	char data_header = AUT_SUBJECT64;	/* header for this token */
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int64_t) +
5927c478bd9Sstevel@tonic-gate 	    8 * sizeof (int32_t));
5937c478bd9Sstevel@tonic-gate #else
5947c478bd9Sstevel@tonic-gate 	char data_header = AUT_SUBJECT32;
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + 9 * sizeof (int32_t));
5977c478bd9Sstevel@tonic-gate #endif
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 	if (token == NULL)
6007c478bd9Sstevel@tonic-gate 		return (NULL);
6017c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
6027c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
6037c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&auid, 1);
6047c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&euid, 1);
6057c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&egid, 1);
6067c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&ruid, 1);
6077c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&rgid, 1);
6087c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&pid, 1);
6097c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&sid, 1);
6107c478bd9Sstevel@tonic-gate #ifdef _LP64
6117c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tid->port, 1);
6127c478bd9Sstevel@tonic-gate #else
6137c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->port, 1);
6147c478bd9Sstevel@tonic-gate #endif
6157c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->machine, 1);
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate 	return (token);
6187c478bd9Sstevel@tonic-gate }
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate /*
6217c478bd9Sstevel@tonic-gate  * au_to_subject_ex
6227c478bd9Sstevel@tonic-gate  * return s:
6237c478bd9Sstevel@tonic-gate  *	pointer to a process token.
6247c478bd9Sstevel@tonic-gate  */
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate token_t *
au_to_subject_ex(au_id_t auid,uid_t euid,gid_t egid,uid_t ruid,gid_t rgid,pid_t pid,au_asid_t sid,au_tid_addr_t * tid)6277c478bd9Sstevel@tonic-gate au_to_subject_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid,
6287c478bd9Sstevel@tonic-gate     pid_t pid, au_asid_t sid, au_tid_addr_t *tid)
6297c478bd9Sstevel@tonic-gate {
6307c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
6317c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
6327c478bd9Sstevel@tonic-gate #ifdef _LP64
6337c478bd9Sstevel@tonic-gate 	char data_header;		/* header for this token */
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
6367c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT64_EX;
6377c478bd9Sstevel@tonic-gate 		token = get_token(sizeof (char) + sizeof (int64_t) +
6387c478bd9Sstevel@tonic-gate 		    12 * sizeof (int32_t));
6397c478bd9Sstevel@tonic-gate 	} else {
6407c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT64;
6417c478bd9Sstevel@tonic-gate 		token = get_token(sizeof (char) + sizeof (int64_t) +
6427c478bd9Sstevel@tonic-gate 		    8 * sizeof (int32_t));
6437c478bd9Sstevel@tonic-gate 	}
6447c478bd9Sstevel@tonic-gate #else
6457c478bd9Sstevel@tonic-gate 	char data_header;		/* header for this token */
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
6487c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT32_EX;
6497c478bd9Sstevel@tonic-gate 		token = get_token(sizeof (char) + 13 * sizeof (int32_t));
6507c478bd9Sstevel@tonic-gate 	} else {
6517c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT32;
6527c478bd9Sstevel@tonic-gate 		token = get_token(sizeof (char) + 9 * sizeof (int32_t));
6537c478bd9Sstevel@tonic-gate 	}
6547c478bd9Sstevel@tonic-gate #endif
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate 	if (token == NULL)
6577c478bd9Sstevel@tonic-gate 		return (NULL);
6587c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
6597c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
6607c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&auid, 1);
6617c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&euid, 1);
6627c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&egid, 1);
6637c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&ruid, 1);
6647c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&rgid, 1);
6657c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&pid, 1);
6667c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&sid, 1);
6677c478bd9Sstevel@tonic-gate #ifdef _LP64
6687c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tid->at_port, 1);
6697c478bd9Sstevel@tonic-gate #else
6707c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->at_port, 1);
6717c478bd9Sstevel@tonic-gate #endif
6727c478bd9Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
6737c478bd9Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)&tid->at_type, 1);
6747c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)tid->at_addr, 16);
6757c478bd9Sstevel@tonic-gate 	} else {
6767c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)tid->at_addr, 4);
6777c478bd9Sstevel@tonic-gate 	}
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 	return (token);
6807c478bd9Sstevel@tonic-gate }
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate /*
6837c478bd9Sstevel@tonic-gate  * au_to_me
6847c478bd9Sstevel@tonic-gate  * return s:
6857c478bd9Sstevel@tonic-gate  *	pointer to a process token.
6867c478bd9Sstevel@tonic-gate  */
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate token_t *
au_to_me(void)6897c478bd9Sstevel@tonic-gate au_to_me(void)
6907c478bd9Sstevel@tonic-gate {
6917c478bd9Sstevel@tonic-gate 	auditinfo_addr_t info;
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate 	if (getaudit_addr(&info, sizeof (info)))
6947c478bd9Sstevel@tonic-gate 		return (NULL);
6957c478bd9Sstevel@tonic-gate 	return (au_to_subject_ex(info.ai_auid, geteuid(), getegid(), getuid(),
6967c478bd9Sstevel@tonic-gate 	    getgid(), getpid(), info.ai_asid, &info.ai_termid));
6977c478bd9Sstevel@tonic-gate }
6987c478bd9Sstevel@tonic-gate /*
6997c478bd9Sstevel@tonic-gate  * au_to_text
7007c478bd9Sstevel@tonic-gate  * return s:
7017c478bd9Sstevel@tonic-gate  *	pointer to a text token.
7027c478bd9Sstevel@tonic-gate  */
7037c478bd9Sstevel@tonic-gate token_t *
au_to_text(char * text)7047c478bd9Sstevel@tonic-gate au_to_text(char *text)
7057c478bd9Sstevel@tonic-gate {
7067c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
7077c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7087c478bd9Sstevel@tonic-gate 	char data_header = AUT_TEXT;	/* header for this token */
7097c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate 	bytes = strlen(text) + 1;
7127c478bd9Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
7137c478bd9Sstevel@tonic-gate 	if (token == NULL)
7147c478bd9Sstevel@tonic-gate 		return (NULL);
7157c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
7167c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7177c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
7187c478bd9Sstevel@tonic-gate 	adr_char(&adr, text, bytes);
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate 	return (token);
7217c478bd9Sstevel@tonic-gate }
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate /*
7247c478bd9Sstevel@tonic-gate  * au_to_path
7257c478bd9Sstevel@tonic-gate  * return s:
7267c478bd9Sstevel@tonic-gate  *	pointer to a path token.
7277c478bd9Sstevel@tonic-gate  */
7287c478bd9Sstevel@tonic-gate token_t *
au_to_path(char * path)7297c478bd9Sstevel@tonic-gate au_to_path(char *path)
7307c478bd9Sstevel@tonic-gate {
7317c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
7327c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7337c478bd9Sstevel@tonic-gate 	char data_header = AUT_PATH;	/* header for this token */
7347c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate 	bytes = (short)strlen(path) + 1;
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) +  sizeof (short) + bytes));
7397c478bd9Sstevel@tonic-gate 	if (token == NULL)
7407c478bd9Sstevel@tonic-gate 		return (NULL);
7417c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
7427c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7437c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
7447c478bd9Sstevel@tonic-gate 	adr_char(&adr, path, bytes);
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate 	return (token);
7477c478bd9Sstevel@tonic-gate }
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate /*
7507c478bd9Sstevel@tonic-gate  * au_to_cmd
7517c478bd9Sstevel@tonic-gate  * return s:
7527c478bd9Sstevel@tonic-gate  *	pointer to an command line argument token
7537c478bd9Sstevel@tonic-gate  */
7547c478bd9Sstevel@tonic-gate token_t *
au_to_cmd(uint_t argc,char ** argv,char ** envp)7557c478bd9Sstevel@tonic-gate au_to_cmd(uint_t argc, char **argv, char **envp)
7567c478bd9Sstevel@tonic-gate {
7577c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
7587c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7597c478bd9Sstevel@tonic-gate 	char data_header = AUT_CMD;	/* header for this token */
7607c478bd9Sstevel@tonic-gate 	short len = 0;
7617c478bd9Sstevel@tonic-gate 	short cnt = 0;
7627c478bd9Sstevel@tonic-gate 	short envc = 0;
7637c478bd9Sstevel@tonic-gate 	short largc = (short)argc;
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 	/*
7667c478bd9Sstevel@tonic-gate 	 * one char for the header, one short for argc,
7677c478bd9Sstevel@tonic-gate 	 * one short for # envp strings.
7687c478bd9Sstevel@tonic-gate 	 */
7697c478bd9Sstevel@tonic-gate 	len = sizeof (char) + sizeof (short) + sizeof (short);
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 	/* get sizes of strings */
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate 	for (cnt = 0; cnt < argc; cnt++) {
7747c478bd9Sstevel@tonic-gate 		len += (short)sizeof (short) + (short)(strlen(argv[cnt]) + 1);
7757c478bd9Sstevel@tonic-gate 	}
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 	if (envp != NULL) {
7787c478bd9Sstevel@tonic-gate 		for (envc = 0; envp[envc] != NULL; envc++) {
7797c478bd9Sstevel@tonic-gate 			len += (short)sizeof (short) +
7807c478bd9Sstevel@tonic-gate 			    (short)(strlen(envp[envc]) + 1);
7817c478bd9Sstevel@tonic-gate 		}
7827c478bd9Sstevel@tonic-gate 	}
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate 	token = get_token(len);
7857c478bd9Sstevel@tonic-gate 	if (token == NULL)
7867c478bd9Sstevel@tonic-gate 		return (NULL);
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
7897c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7907c478bd9Sstevel@tonic-gate 
7917c478bd9Sstevel@tonic-gate 	adr_short(&adr, &largc, 1);
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate 	for (cnt = 0; cnt < argc; cnt++) {
7947c478bd9Sstevel@tonic-gate 		len = (short)(strlen(argv[cnt]) + 1);
7957c478bd9Sstevel@tonic-gate 		adr_short(&adr, &len, 1);
7967c478bd9Sstevel@tonic-gate 		adr_char(&adr, argv[cnt], len);
7977c478bd9Sstevel@tonic-gate 	}
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate 	adr_short(&adr, &envc, 1);
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 	for (cnt = 0; cnt < envc; cnt++) {
8027c478bd9Sstevel@tonic-gate 		len = (short)(strlen(envp[cnt]) + 1);
8037c478bd9Sstevel@tonic-gate 		adr_short(&adr, &len, 1);
8047c478bd9Sstevel@tonic-gate 		adr_char(&adr, envp[cnt], len);
8057c478bd9Sstevel@tonic-gate 	}
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate 	return (token);
8087c478bd9Sstevel@tonic-gate }
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate /*
8117c478bd9Sstevel@tonic-gate  * au_to_exit
8127c478bd9Sstevel@tonic-gate  * return s:
8137c478bd9Sstevel@tonic-gate  *	pointer to a exit value token.
8147c478bd9Sstevel@tonic-gate  */
8157c478bd9Sstevel@tonic-gate token_t *
au_to_exit(int retval,int err)8167c478bd9Sstevel@tonic-gate au_to_exit(int retval, int err)
8177c478bd9Sstevel@tonic-gate {
8187c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
8197c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
8207c478bd9Sstevel@tonic-gate 	char data_header = AUT_EXIT;	/* header for this token */
8217c478bd9Sstevel@tonic-gate 
8227c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + (2 * sizeof (int32_t)));
8237c478bd9Sstevel@tonic-gate 	if (token == NULL)
8247c478bd9Sstevel@tonic-gate 		return (NULL);
8257c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
8267c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
8277c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&retval, 1);
8287c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&err, 1);
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 	return (token);
8317c478bd9Sstevel@tonic-gate }
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate /*
8347c478bd9Sstevel@tonic-gate  * au_to_return
8357c478bd9Sstevel@tonic-gate  * return s:
8367c478bd9Sstevel@tonic-gate  *	pointer to a return  value token.
8377c478bd9Sstevel@tonic-gate  */
8387c478bd9Sstevel@tonic-gate token_t *
au_to_return32(char number,uint32_t value)8397c478bd9Sstevel@tonic-gate au_to_return32(char number, uint32_t value)
8407c478bd9Sstevel@tonic-gate {
8417c478bd9Sstevel@tonic-gate 	token_t *token;				/* local token */
8427c478bd9Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
8437c478bd9Sstevel@tonic-gate 	char data_header = AUT_RETURN32;	/* header for this token */
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + sizeof (int32_t));
8467c478bd9Sstevel@tonic-gate 	if (token == NULL)
8477c478bd9Sstevel@tonic-gate 		return (NULL);
8487c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
8497c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
8507c478bd9Sstevel@tonic-gate 	adr_char(&adr, &number, 1);
8517c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&value, 1);
8527c478bd9Sstevel@tonic-gate 
8537c478bd9Sstevel@tonic-gate 	return (token);
8547c478bd9Sstevel@tonic-gate }
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate /*
8577c478bd9Sstevel@tonic-gate  * au_to_return
8587c478bd9Sstevel@tonic-gate  * return s:
8597c478bd9Sstevel@tonic-gate  *	pointer to a return  value token.
8607c478bd9Sstevel@tonic-gate  */
8617c478bd9Sstevel@tonic-gate token_t *
au_to_return64(char number,uint64_t value)8627c478bd9Sstevel@tonic-gate au_to_return64(char number, uint64_t value)
8637c478bd9Sstevel@tonic-gate {
8647c478bd9Sstevel@tonic-gate 	token_t *token;				/* local token */
8657c478bd9Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
8667c478bd9Sstevel@tonic-gate 	char data_header = AUT_RETURN64;	/* header for this token */
8677c478bd9Sstevel@tonic-gate 
8687c478bd9Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + sizeof (int64_t));
8697c478bd9Sstevel@tonic-gate 	if (token == NULL)
8707c478bd9Sstevel@tonic-gate 		return (NULL);
8717c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
8727c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
8737c478bd9Sstevel@tonic-gate 	adr_char(&adr, &number, 1);
8747c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&value, 1);
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 	return (token);
8777c478bd9Sstevel@tonic-gate }
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate /*
8817c478bd9Sstevel@tonic-gate  * au_to_opaque
8827c478bd9Sstevel@tonic-gate  * return s:
8837c478bd9Sstevel@tonic-gate  *	pointer to a opaque token.
8847c478bd9Sstevel@tonic-gate  */
8857c478bd9Sstevel@tonic-gate token_t *
au_to_opaque(char * opaque,short bytes)8867c478bd9Sstevel@tonic-gate au_to_opaque(char *opaque, short bytes)
8877c478bd9Sstevel@tonic-gate {
8887c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
8897c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
8907c478bd9Sstevel@tonic-gate 	char data_header = AUT_OPAQUE;	/* header for this token */
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate 	if (bytes < 1)
8937c478bd9Sstevel@tonic-gate 		return (NULL);
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
8967c478bd9Sstevel@tonic-gate 	if (token == NULL)
8977c478bd9Sstevel@tonic-gate 		return (NULL);
8987c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
8997c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
9007c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
9017c478bd9Sstevel@tonic-gate 	adr_char(&adr, opaque, bytes);
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate 	return (token);
9047c478bd9Sstevel@tonic-gate }
9057c478bd9Sstevel@tonic-gate 
9067c478bd9Sstevel@tonic-gate /*
9077c478bd9Sstevel@tonic-gate  * au_to_in_addr
9087c478bd9Sstevel@tonic-gate  * return s:
909f72effdeSgww  *	pointer to an internet address token
9107c478bd9Sstevel@tonic-gate  */
9117c478bd9Sstevel@tonic-gate token_t *
au_to_in_addr(struct in_addr * internet_addr)9127c478bd9Sstevel@tonic-gate au_to_in_addr(struct in_addr *internet_addr)
9137c478bd9Sstevel@tonic-gate {
9147c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
9157c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
9167c478bd9Sstevel@tonic-gate 	char data_header = AUT_IN_ADDR;	/* header for this token */
9177c478bd9Sstevel@tonic-gate 
918f72effdeSgww 	token = get_token(sizeof (char) + sizeof (struct in_addr));
9197c478bd9Sstevel@tonic-gate 	if (token == NULL)
9207c478bd9Sstevel@tonic-gate 		return (NULL);
9217c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
9227c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
923f72effdeSgww 	adr_char(&adr, (char *)internet_addr, sizeof (struct in_addr));
924f72effdeSgww 
925f72effdeSgww 	return (token);
926f72effdeSgww }
927f72effdeSgww 
928f72effdeSgww /*
929f72effdeSgww  * au_to_in_addr_ex
930f72effdeSgww  * return s:
931f72effdeSgww  *	pointer to an internet extended token
932f72effdeSgww  */
933f72effdeSgww token_t *
au_to_in_addr_ex(struct in6_addr * addr)934f72effdeSgww au_to_in_addr_ex(struct in6_addr *addr)
935f72effdeSgww {
936f72effdeSgww 	token_t *token;
937f72effdeSgww 	adr_t adr;
938f72effdeSgww 
93911bc41c8Sgww 	if (IN6_IS_ADDR_V4MAPPED(addr)) {
94011bc41c8Sgww 		ipaddr_t in4;
94111bc41c8Sgww 
94211bc41c8Sgww 		/*
94311bc41c8Sgww 		 * An IPv4-mapped IPv6 address is really an IPv4 address
94411bc41c8Sgww 		 * in IPv6 format.
94511bc41c8Sgww 		 */
94611bc41c8Sgww 
94711bc41c8Sgww 		IN6_V4MAPPED_TO_IPADDR(addr, in4);
94811bc41c8Sgww 		return (au_to_in_addr((struct in_addr *)&in4));
94911bc41c8Sgww 
95011bc41c8Sgww 	} else {
95111bc41c8Sgww 		char data_header = AUT_IN_ADDR_EX;
95211bc41c8Sgww 		int32_t	type = AU_IPv6;
95311bc41c8Sgww 
95411bc41c8Sgww 		if ((token = get_token(sizeof (char) + sizeof (int32_t) +
95511bc41c8Sgww 		    sizeof (struct in6_addr))) == NULL) {
956f72effdeSgww 			return (NULL);
957f72effdeSgww 		}
958f72effdeSgww 
959f72effdeSgww 		adr_start(&adr, token->tt_data);
960f72effdeSgww 		adr_char(&adr, &data_header, 1);
96111bc41c8Sgww 		adr_int32(&adr, &type, 1);
962f72effdeSgww 		adr_char(&adr, (char *)addr, sizeof (struct in6_addr));
96311bc41c8Sgww 	}
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	return (token);
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate /*
9697c478bd9Sstevel@tonic-gate  * au_to_iport
9707c478bd9Sstevel@tonic-gate  * return s:
9717c478bd9Sstevel@tonic-gate  *	pointer to token chain containing a ip port address token
9727c478bd9Sstevel@tonic-gate  */
9737c478bd9Sstevel@tonic-gate token_t *
au_to_iport(ushort_t iport)9747c478bd9Sstevel@tonic-gate au_to_iport(ushort_t iport)
9757c478bd9Sstevel@tonic-gate {
9767c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
9777c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
9787c478bd9Sstevel@tonic-gate 	char data_header = AUT_IPORT;	/* header for this token */
9797c478bd9Sstevel@tonic-gate 
9807c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (short));
9817c478bd9Sstevel@tonic-gate 	if (token == NULL)
9827c478bd9Sstevel@tonic-gate 		return (NULL);
9837c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
9847c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
9857c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&iport, 1);
9867c478bd9Sstevel@tonic-gate 
9877c478bd9Sstevel@tonic-gate 	return (token);
9887c478bd9Sstevel@tonic-gate }
9897c478bd9Sstevel@tonic-gate 
9907c478bd9Sstevel@tonic-gate token_t *
au_to_ipc(char type,int id)9917c478bd9Sstevel@tonic-gate au_to_ipc(char type, int id)
9927c478bd9Sstevel@tonic-gate {
9937c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
9947c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
9957c478bd9Sstevel@tonic-gate 	char data_header = AUT_IPC;	/* header for this token */
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate 	token = get_token((2 * sizeof (char)) + sizeof (int32_t));
9987c478bd9Sstevel@tonic-gate 	if (token == NULL)
9997c478bd9Sstevel@tonic-gate 		return (NULL);
10007c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
10017c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
10027c478bd9Sstevel@tonic-gate 	adr_char(&adr, &type, 1);
10037c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&id, 1);
10047c478bd9Sstevel@tonic-gate 
10057c478bd9Sstevel@tonic-gate 	return (token);
10067c478bd9Sstevel@tonic-gate }
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate /*
10097c478bd9Sstevel@tonic-gate  * au_to_tid
10107c478bd9Sstevel@tonic-gate  *
10117c478bd9Sstevel@tonic-gate  * output format depends on type; at present only IP v4 and v6 addresses
10127c478bd9Sstevel@tonic-gate  * are defined.
10137c478bd9Sstevel@tonic-gate  *
10147c478bd9Sstevel@tonic-gate  * IPv4 -- tid type, 16 bit remote port, 16 bit local port, ip type,
10157c478bd9Sstevel@tonic-gate  *		32 bit IP address.
10167c478bd9Sstevel@tonic-gate  * IPv6 -- tid type, 16 bit remote port, 16 bit local port, ip type,
10177c478bd9Sstevel@tonic-gate  *		4 x 32 bit IP address.
10187c478bd9Sstevel@tonic-gate  *
10197c478bd9Sstevel@tonic-gate  */
10207c478bd9Sstevel@tonic-gate token_t *
au_to_tid(au_generic_tid_t * tid)10217c478bd9Sstevel@tonic-gate au_to_tid(au_generic_tid_t *tid)
10227c478bd9Sstevel@tonic-gate {
10237c478bd9Sstevel@tonic-gate 	char		data_header = AUT_TID;	/* header for this token */
10247c478bd9Sstevel@tonic-gate 	adr_t		adr;			/* adr memory stream header */
10257c478bd9Sstevel@tonic-gate 	token_t		*token;			/* local token */
10267c478bd9Sstevel@tonic-gate 	au_ip_t		*ip;
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	switch (tid->gt_type) {
10297c478bd9Sstevel@tonic-gate 	case AU_IPADR:
10307c478bd9Sstevel@tonic-gate 		ip = &(tid->gt_adr.at_ip);
10317c478bd9Sstevel@tonic-gate 		token = get_token((int)(2 * sizeof (char) + 2 * sizeof (short) +
10327c478bd9Sstevel@tonic-gate 		    sizeof (uint32_t) + ip->at_type));
10337c478bd9Sstevel@tonic-gate 		if (token == NULL)
10347c478bd9Sstevel@tonic-gate 			return (NULL);
10357c478bd9Sstevel@tonic-gate 
10367c478bd9Sstevel@tonic-gate 		adr_start(&adr, token->tt_data);
10377c478bd9Sstevel@tonic-gate 		adr_char(&adr, &data_header, 1);
10387c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&(tid->gt_type), 1);
10397c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&(ip->at_r_port), 1);
10407c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&(ip->at_l_port), 1);
10417c478bd9Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)&(ip->at_type), 1);
10427c478bd9Sstevel@tonic-gate 
10437c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)ip->at_addr, ip->at_type);
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate 		break;
10467c478bd9Sstevel@tonic-gate 	default:
10477c478bd9Sstevel@tonic-gate 		return (NULL);
10487c478bd9Sstevel@tonic-gate 	}
10497c478bd9Sstevel@tonic-gate 	return (token);
10507c478bd9Sstevel@tonic-gate }
10517c478bd9Sstevel@tonic-gate 
10527c478bd9Sstevel@tonic-gate /*
10537c478bd9Sstevel@tonic-gate  * The Modifier tokens
10547c478bd9Sstevel@tonic-gate  */
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate /*
10577c478bd9Sstevel@tonic-gate  * au_to_groups
10587c478bd9Sstevel@tonic-gate  * return s:
10597c478bd9Sstevel@tonic-gate  *	pointer to a group list token.
10607c478bd9Sstevel@tonic-gate  *
10617c478bd9Sstevel@tonic-gate  * This function is obsolete.  Please use au_to_newgroups.
10627c478bd9Sstevel@tonic-gate  */
10637c478bd9Sstevel@tonic-gate token_t *
au_to_groups(int * groups)10647c478bd9Sstevel@tonic-gate au_to_groups(int *groups)
10657c478bd9Sstevel@tonic-gate {
10667c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
10677c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
10687c478bd9Sstevel@tonic-gate 	char data_header = AUT_GROUPS;	/* header for this token */
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + NGROUPS * sizeof (int32_t));
10717c478bd9Sstevel@tonic-gate 	if (token == NULL)
10727c478bd9Sstevel@tonic-gate 		return (NULL);
10737c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
10747c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
10757c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)groups, NGROUPS);
10767c478bd9Sstevel@tonic-gate 
10777c478bd9Sstevel@tonic-gate 	return (token);
10787c478bd9Sstevel@tonic-gate }
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate /*
10817c478bd9Sstevel@tonic-gate  * au_to_newgroups
10827c478bd9Sstevel@tonic-gate  * return s:
10837c478bd9Sstevel@tonic-gate  *	pointer to a group list token.
10847c478bd9Sstevel@tonic-gate  */
10857c478bd9Sstevel@tonic-gate token_t *
au_to_newgroups(int n,gid_t * groups)10867c478bd9Sstevel@tonic-gate au_to_newgroups(int n, gid_t *groups)
10877c478bd9Sstevel@tonic-gate {
10887c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
10897c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
10907c478bd9Sstevel@tonic-gate 	char data_header = AUT_NEWGROUPS;	/* header for this token */
10917c478bd9Sstevel@tonic-gate 	short n_groups;
10927c478bd9Sstevel@tonic-gate 
109367dbe2beSCasper H.S. Dik 	if (n < 0 || n > SHRT_MAX || groups == NULL)
10947c478bd9Sstevel@tonic-gate 		return (NULL);
10957c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (short) + n * sizeof (gid_t));
10967c478bd9Sstevel@tonic-gate 	if (token == NULL)
10977c478bd9Sstevel@tonic-gate 		return (NULL);
10987c478bd9Sstevel@tonic-gate 	n_groups = (short)n;
10997c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
11007c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
11017c478bd9Sstevel@tonic-gate 	adr_short(&adr, &n_groups, 1);
11027c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)groups, n_groups);
11037c478bd9Sstevel@tonic-gate 
11047c478bd9Sstevel@tonic-gate 	return (token);
11057c478bd9Sstevel@tonic-gate }
11067c478bd9Sstevel@tonic-gate 
11077c478bd9Sstevel@tonic-gate /*
11087c478bd9Sstevel@tonic-gate  * au_to_exec_args
11097c478bd9Sstevel@tonic-gate  * returns:
11107c478bd9Sstevel@tonic-gate  *	pointer to an exec args token.
11117c478bd9Sstevel@tonic-gate  */
11127c478bd9Sstevel@tonic-gate token_t *
au_to_exec_args(char ** argv)11137c478bd9Sstevel@tonic-gate au_to_exec_args(char **argv)
11147c478bd9Sstevel@tonic-gate {
11157c478bd9Sstevel@tonic-gate 	return (au_to_exec(argv, AUT_EXEC_ARGS));
11167c478bd9Sstevel@tonic-gate }
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate /*
11197c478bd9Sstevel@tonic-gate  * au_to_exec_env
11207c478bd9Sstevel@tonic-gate  * returns:
11217c478bd9Sstevel@tonic-gate  *	pointer to an exec args token.
11227c478bd9Sstevel@tonic-gate  */
11237c478bd9Sstevel@tonic-gate token_t *
au_to_exec_env(char ** envp)11247c478bd9Sstevel@tonic-gate au_to_exec_env(char **envp)
11257c478bd9Sstevel@tonic-gate {
11267c478bd9Sstevel@tonic-gate 	return (au_to_exec(envp, AUT_EXEC_ENV));
11277c478bd9Sstevel@tonic-gate }
11287c478bd9Sstevel@tonic-gate 
11297c478bd9Sstevel@tonic-gate /*
11307c478bd9Sstevel@tonic-gate  * au_to_exec
11317c478bd9Sstevel@tonic-gate  * returns:
11327c478bd9Sstevel@tonic-gate  *	pointer to an exec args token.
11337c478bd9Sstevel@tonic-gate  */
11347c478bd9Sstevel@tonic-gate static token_t *
au_to_exec(char ** v,char data_header)11357c478bd9Sstevel@tonic-gate au_to_exec(char **v, char data_header)
11367c478bd9Sstevel@tonic-gate {
11377c478bd9Sstevel@tonic-gate 	token_t *token;
11387c478bd9Sstevel@tonic-gate 	adr_t adr;
11397c478bd9Sstevel@tonic-gate 	char **p;
11407c478bd9Sstevel@tonic-gate 	int32_t n = 0;
11417c478bd9Sstevel@tonic-gate 	int len = 0;
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate 	for (p = v; *p != NULL; p++) {
11447c478bd9Sstevel@tonic-gate 		len += strlen(*p) + 1;
11457c478bd9Sstevel@tonic-gate 		n++;
11467c478bd9Sstevel@tonic-gate 	}
11477c478bd9Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int32_t) + len);
11487c478bd9Sstevel@tonic-gate 	if (token == (token_t *)NULL)
11497c478bd9Sstevel@tonic-gate 		return ((token_t *)NULL);
11507c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
11517c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
11527c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &n, 1);
11537c478bd9Sstevel@tonic-gate 	for (p = v; *p != NULL; p++) {
11547c478bd9Sstevel@tonic-gate 		adr_char(&adr, *p, strlen(*p) + 1);
11557c478bd9Sstevel@tonic-gate 	}
11567c478bd9Sstevel@tonic-gate 	return (token);
11577c478bd9Sstevel@tonic-gate }
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate /*
11607c478bd9Sstevel@tonic-gate  * au_to_uauth
11617c478bd9Sstevel@tonic-gate  * return s:
11627c478bd9Sstevel@tonic-gate  *	pointer to a uauth token.
11637c478bd9Sstevel@tonic-gate  */
11647c478bd9Sstevel@tonic-gate token_t *
au_to_uauth(char * text)11657c478bd9Sstevel@tonic-gate au_to_uauth(char *text)
11667c478bd9Sstevel@tonic-gate {
11677c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
11687c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
11697c478bd9Sstevel@tonic-gate 	char data_header = AUT_UAUTH;	/* header for this token */
11707c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
11717c478bd9Sstevel@tonic-gate 
11727c478bd9Sstevel@tonic-gate 	bytes = strlen(text) + 1;
11737c478bd9Sstevel@tonic-gate 
11747c478bd9Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
11757c478bd9Sstevel@tonic-gate 	if (token == NULL)
11767c478bd9Sstevel@tonic-gate 		return (NULL);
11777c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
11787c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
11797c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
11807c478bd9Sstevel@tonic-gate 	adr_char(&adr, text, bytes);
11817c478bd9Sstevel@tonic-gate 
11827c478bd9Sstevel@tonic-gate 	return (token);
11837c478bd9Sstevel@tonic-gate }
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate /*
118661e717d6Sgww  * au_to_upriv
118761e717d6Sgww  * return s:
118861e717d6Sgww  *	pointer to a use of privilege token.
118961e717d6Sgww  */
119061e717d6Sgww token_t *
au_to_upriv(char sorf,char * priv)119161e717d6Sgww au_to_upriv(char sorf, char *priv)
119261e717d6Sgww {
119361e717d6Sgww 	token_t *token;			/* local token */
119461e717d6Sgww 	adr_t adr;			/* adr memory stream header */
119561e717d6Sgww 	char data_header = AUT_UAUTH;	/* header for this token */
119661e717d6Sgww 	short bytes;			/* length of string */
119761e717d6Sgww 
119861e717d6Sgww 	bytes = strlen(priv) + 1;
119961e717d6Sgww 
120061e717d6Sgww 	token = get_token(sizeof (char) + sizeof (char) + sizeof (short) +
120161e717d6Sgww 	    bytes);
120261e717d6Sgww 	if (token == NULL)
120361e717d6Sgww 		return (NULL);
120461e717d6Sgww 	adr_start(&adr, token->tt_data);
120561e717d6Sgww 	adr_char(&adr, &data_header, 1);
120661e717d6Sgww 	adr_char(&adr, &sorf, 1);	/* success/failure */
120761e717d6Sgww 	adr_short(&adr, &bytes, 1);
120861e717d6Sgww 	adr_char(&adr, priv, bytes);
120961e717d6Sgww 
121061e717d6Sgww 	return (token);
121161e717d6Sgww }
121261e717d6Sgww 
121361e717d6Sgww /*
1214*047f6e6fSgww  * au_to_user
1215*047f6e6fSgww  * return s:
1216*047f6e6fSgww  *	pointer to a user token.
1217*047f6e6fSgww  */
1218*047f6e6fSgww token_t *
au_to_user(uid_t uid,char * username)1219*047f6e6fSgww au_to_user(uid_t uid,  char *username)
1220*047f6e6fSgww {
1221*047f6e6fSgww 	token_t *token;			/* local token */
1222*047f6e6fSgww 	adr_t adr;			/* adr memory stream header */
1223*047f6e6fSgww 	char data_header = AUT_USER;	/* header for this token */
1224*047f6e6fSgww 	short  bytes;			/* length of string */
1225*047f6e6fSgww 
1226*047f6e6fSgww 	bytes = (short)strlen(username) + 1;
1227*047f6e6fSgww 
1228*047f6e6fSgww 	token = get_token(sizeof (char) + sizeof (uid_t) + sizeof (short) +
1229*047f6e6fSgww 	    bytes);
1230*047f6e6fSgww 	if (token == NULL)
1231*047f6e6fSgww 		return (NULL);
1232*047f6e6fSgww 	adr_start(&adr, token->tt_data);
1233*047f6e6fSgww 	adr_char(&adr, &data_header, 1);
1234*047f6e6fSgww 	adr_uid(&adr, &uid, 1);
1235*047f6e6fSgww 	adr_short(&adr, &bytes, 1);
1236*047f6e6fSgww 	adr_char(&adr, username, bytes);
1237*047f6e6fSgww 
1238*047f6e6fSgww 	return (token);
1239*047f6e6fSgww }
1240*047f6e6fSgww 
1241*047f6e6fSgww /*
12427c478bd9Sstevel@tonic-gate  * au_to_xatom
12437c478bd9Sstevel@tonic-gate  * return s:
12447c478bd9Sstevel@tonic-gate  *	pointer to a xatom token.
12457c478bd9Sstevel@tonic-gate  */
12467c478bd9Sstevel@tonic-gate token_t *
au_to_xatom(char * atom)124761e717d6Sgww au_to_xatom(char *atom)
12487c478bd9Sstevel@tonic-gate {
12497c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
12507c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
12517c478bd9Sstevel@tonic-gate 	char data_header = AUT_XATOM;	/* header for this token */
125261e717d6Sgww 	short len;
12537c478bd9Sstevel@tonic-gate 
125461e717d6Sgww 	len = strlen(atom) + 1;
125561e717d6Sgww 
125661e717d6Sgww 	token = get_token(sizeof (char) + sizeof (short) + len);
12577c478bd9Sstevel@tonic-gate 	if (token == NULL)
12587c478bd9Sstevel@tonic-gate 		return (NULL);
12597c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
12607c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
12617c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&len, 1);
12627c478bd9Sstevel@tonic-gate 	adr_char(&adr, atom, len);
12637c478bd9Sstevel@tonic-gate 
12647c478bd9Sstevel@tonic-gate 	return (token);
12657c478bd9Sstevel@tonic-gate }
12667c478bd9Sstevel@tonic-gate 
12677c478bd9Sstevel@tonic-gate /*
12687c478bd9Sstevel@tonic-gate  * au_to_xselect
12697c478bd9Sstevel@tonic-gate  * return s:
12707c478bd9Sstevel@tonic-gate  *	pointer to a X select token.
12717c478bd9Sstevel@tonic-gate  */
12727c478bd9Sstevel@tonic-gate token_t *
au_to_xselect(char * propname,char * proptype,char * windata)127361e717d6Sgww au_to_xselect(char *propname, char *proptype, char *windata)
12747c478bd9Sstevel@tonic-gate {
12757c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
12767c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
12777c478bd9Sstevel@tonic-gate 	char data_header = AUT_XSELECT;	/* header for this token */
127861e717d6Sgww 	short proplen;
127961e717d6Sgww 	short typelen;
128061e717d6Sgww 	short datalen;
12817c478bd9Sstevel@tonic-gate 
128261e717d6Sgww 	proplen = strlen(propname) + 1;
128361e717d6Sgww 	typelen = strlen(proptype) + 1;
128461e717d6Sgww 	datalen = strlen(windata) + 1;
128561e717d6Sgww 
128661e717d6Sgww 	token = get_token(sizeof (char) + (sizeof (short) * 3) +
128761e717d6Sgww 	    proplen + typelen + datalen);
12887c478bd9Sstevel@tonic-gate 	if (token == NULL)
12897c478bd9Sstevel@tonic-gate 		return (NULL);
12907c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
12917c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
129261e717d6Sgww 	adr_short(&adr, &proplen, 1);
129361e717d6Sgww 	adr_char(&adr, propname, proplen);
129461e717d6Sgww 	adr_short(&adr, &typelen, 1);
129561e717d6Sgww 	adr_char(&adr, proptype, typelen);
129661e717d6Sgww 	adr_short(&adr, &datalen, 1);
129761e717d6Sgww 	adr_char(&adr, windata, datalen);
129861e717d6Sgww 
129961e717d6Sgww 	return (token);
130061e717d6Sgww }
130161e717d6Sgww 
130261e717d6Sgww /*
130361e717d6Sgww  * x_common
130461e717d6Sgww  * return s:
130561e717d6Sgww  *	pointer to a common X token.
130661e717d6Sgww  */
130761e717d6Sgww 
130861e717d6Sgww static token_t *
x_common(char data_header,int32_t xid,uid_t cuid)130961e717d6Sgww x_common(char data_header, int32_t xid, uid_t cuid)
131061e717d6Sgww {
131161e717d6Sgww 	token_t *token;			/* local token */
131261e717d6Sgww 	adr_t adr;			/* adr memory stream header */
131361e717d6Sgww 
131461e717d6Sgww 	token = get_token(sizeof (char) + sizeof (int32_t) + sizeof (uid_t));
131561e717d6Sgww 	if (token == NULL)
131661e717d6Sgww 		return (NULL);
131761e717d6Sgww 	adr_start(&adr, token->tt_data);
131861e717d6Sgww 	adr_char(&adr, &data_header, 1);
131961e717d6Sgww 	adr_int32(&adr, &xid, 1);
132061e717d6Sgww 	adr_uid(&adr, &cuid, 1);
132161e717d6Sgww 
132261e717d6Sgww 	return (token);
132361e717d6Sgww }
132461e717d6Sgww 
132561e717d6Sgww /*
132661e717d6Sgww  * au_to_xcolormap
132761e717d6Sgww  * return s:
132861e717d6Sgww  *	pointer to a X Colormap token.
132961e717d6Sgww  */
133061e717d6Sgww 
133161e717d6Sgww token_t *
au_to_xcolormap(int32_t xid,uid_t cuid)133261e717d6Sgww au_to_xcolormap(int32_t xid, uid_t cuid)
133361e717d6Sgww {
133461e717d6Sgww 	return (x_common(AUT_XCOLORMAP, xid, cuid));
133561e717d6Sgww }
133661e717d6Sgww 
133761e717d6Sgww /*
133861e717d6Sgww  * au_to_xcursor
133961e717d6Sgww  * return s:
134061e717d6Sgww  *	pointer to a X Cursor token.
134161e717d6Sgww  */
134261e717d6Sgww 
134361e717d6Sgww token_t *
au_to_xcursor(int32_t xid,uid_t cuid)134461e717d6Sgww au_to_xcursor(int32_t xid, uid_t cuid)
134561e717d6Sgww {
134661e717d6Sgww 	return (x_common(AUT_XCURSOR, xid, cuid));
134761e717d6Sgww }
134861e717d6Sgww 
134961e717d6Sgww /*
135061e717d6Sgww  * au_to_xfont
135161e717d6Sgww  * return s:
135261e717d6Sgww  *	pointer to a X Font token.
135361e717d6Sgww  */
135461e717d6Sgww 
135561e717d6Sgww token_t *
au_to_xfont(int32_t xid,uid_t cuid)135661e717d6Sgww au_to_xfont(int32_t xid, uid_t cuid)
135761e717d6Sgww {
135861e717d6Sgww 	return (x_common(AUT_XFONT, xid, cuid));
135961e717d6Sgww }
136061e717d6Sgww 
136161e717d6Sgww /*
136261e717d6Sgww  * au_to_xgc
136361e717d6Sgww  * return s:
136461e717d6Sgww  *	pointer to a X Graphic Context token.
136561e717d6Sgww  */
136661e717d6Sgww 
136761e717d6Sgww token_t *
au_to_xgc(int32_t xid,uid_t cuid)136861e717d6Sgww au_to_xgc(int32_t xid, uid_t cuid)
136961e717d6Sgww {
137061e717d6Sgww 	return (x_common(AUT_XGC, xid, cuid));
137161e717d6Sgww }
137261e717d6Sgww 
137361e717d6Sgww /*
137461e717d6Sgww  * au_to_xpixmap
137561e717d6Sgww  * return s:
137661e717d6Sgww  *	pointer to a X Pixal Map token.
137761e717d6Sgww  */
137861e717d6Sgww 
137961e717d6Sgww token_t *
au_to_xpixmap(int32_t xid,uid_t cuid)138061e717d6Sgww au_to_xpixmap(int32_t xid, uid_t cuid)
138161e717d6Sgww {
138261e717d6Sgww 	return (x_common(AUT_XPIXMAP, xid, cuid));
138361e717d6Sgww }
138461e717d6Sgww 
138561e717d6Sgww /*
138661e717d6Sgww  * au_to_xwindow
138761e717d6Sgww  * return s:
138861e717d6Sgww  *	pointer to a X Window token.
138961e717d6Sgww  */
139061e717d6Sgww 
139161e717d6Sgww token_t *
au_to_xwindow(int32_t xid,uid_t cuid)139261e717d6Sgww au_to_xwindow(int32_t xid, uid_t cuid)
139361e717d6Sgww {
139461e717d6Sgww 	return (x_common(AUT_XWINDOW, xid, cuid));
139561e717d6Sgww }
139661e717d6Sgww 
139761e717d6Sgww /*
139861e717d6Sgww  * au_to_xproperty
139961e717d6Sgww  * return s:
140061e717d6Sgww  *	pointer to a X Property token.
140161e717d6Sgww  */
140261e717d6Sgww 
140361e717d6Sgww token_t *
au_to_xproperty(int32_t xid,uid_t cuid,char * propname)140461e717d6Sgww au_to_xproperty(int32_t xid, uid_t cuid, char *propname)
140561e717d6Sgww {
140661e717d6Sgww 	token_t *token;			/* local token */
140761e717d6Sgww 	adr_t adr;			/* adr memory stream header */
140861e717d6Sgww 	char data_header = AUT_XPROPERTY;	/* header for this token */
140961e717d6Sgww 	short proplen;
141061e717d6Sgww 
141161e717d6Sgww 	proplen = strlen(propname) + 1;
141261e717d6Sgww 
141361e717d6Sgww 	token = get_token(sizeof (char) + sizeof (int32_t) + sizeof (uid_t) +
141461e717d6Sgww 	    sizeof (short) + proplen);
141561e717d6Sgww 	if (token == NULL)
141661e717d6Sgww 		return (NULL);
141761e717d6Sgww 	adr_start(&adr, token->tt_data);
141861e717d6Sgww 	adr_char(&adr, &data_header, 1);
141961e717d6Sgww 	adr_int32(&adr, &xid, 1);
142061e717d6Sgww 	adr_uid(&adr, &cuid, 1);
142161e717d6Sgww 	adr_short(&adr, &proplen, 1);
142261e717d6Sgww 	adr_char(&adr, propname, proplen);
142361e717d6Sgww 
142461e717d6Sgww 	return (token);
142561e717d6Sgww }
142661e717d6Sgww 
142761e717d6Sgww /*
142861e717d6Sgww  * au_to_xclient
142961e717d6Sgww  * return s:
143061e717d6Sgww  *	pointer to a X Client token
143161e717d6Sgww  */
143261e717d6Sgww 
143361e717d6Sgww token_t *
au_to_xclient(uint32_t client)143461e717d6Sgww au_to_xclient(uint32_t client)
143561e717d6Sgww {
143661e717d6Sgww 	token_t *token;			/* local token */
143761e717d6Sgww 	adr_t adr;			/* adr memory stream header */
143861e717d6Sgww 	char data_header = AUT_XCLIENT;	/* header for this token */
143961e717d6Sgww 
144061e717d6Sgww 	token = get_token(sizeof (char) + sizeof (uint32_t));
144161e717d6Sgww 	if (token == NULL)
144261e717d6Sgww 		return (NULL);
144361e717d6Sgww 	adr_start(&adr, token->tt_data);
144461e717d6Sgww 	adr_char(&adr, &data_header, 1);
144561e717d6Sgww 	adr_int32(&adr, (int32_t *)&client, 1);
144661e717d6Sgww 
14477c478bd9Sstevel@tonic-gate 	return (token);
14487c478bd9Sstevel@tonic-gate }
14497c478bd9Sstevel@tonic-gate 
14507c478bd9Sstevel@tonic-gate /*
145145916cd2Sjpk  * au_to_label
145245916cd2Sjpk  * return s:
1453c7bb2ee8Sgww  *	pointer to a label token.
145445916cd2Sjpk  */
145545916cd2Sjpk token_t *
au_to_label(m_label_t * label)1456c7bb2ee8Sgww au_to_label(m_label_t *label)
145745916cd2Sjpk {
145845916cd2Sjpk 	token_t *token;			/* local token */
145945916cd2Sjpk 	adr_t adr;			/* adr memory stream header */
146045916cd2Sjpk 	char data_header = AUT_LABEL;	/* header for this token */
146142096647STony Nguyen 	size32_t llen = blabel_size();
146245916cd2Sjpk 
1463c7bb2ee8Sgww 	token = get_token(sizeof (char) + llen);
1464c7bb2ee8Sgww 	if (token == NULL) {
146545916cd2Sjpk 		return (NULL);
1466c7bb2ee8Sgww 	} else if (label == NULL) {
1467c7bb2ee8Sgww 		free(token);
1468c7bb2ee8Sgww 		return (NULL);
1469c7bb2ee8Sgww 	}
147045916cd2Sjpk 	adr_start(&adr, token->tt_data);
147145916cd2Sjpk 	adr_char(&adr, &data_header, 1);
1472c7bb2ee8Sgww 	adr_char(&adr, (char *)label, llen);
147345916cd2Sjpk 
147445916cd2Sjpk 	return (token);
147545916cd2Sjpk }
147645916cd2Sjpk 
147745916cd2Sjpk /*
147845916cd2Sjpk  * au_to_mylabel
147945916cd2Sjpk  * return s:
1480c7bb2ee8Sgww  *	pointer to a label token.
148145916cd2Sjpk  */
148245916cd2Sjpk token_t *
au_to_mylabel(void)148345916cd2Sjpk au_to_mylabel(void)
148445916cd2Sjpk {
1485c7bb2ee8Sgww 	ucred_t		*uc;
1486c7bb2ee8Sgww 	token_t		*token;
148745916cd2Sjpk 
1488c7bb2ee8Sgww 	if ((uc = ucred_get(P_MYID)) == NULL) {
148945916cd2Sjpk 		return (NULL);
149045916cd2Sjpk 	}
1491c7bb2ee8Sgww 
1492c7bb2ee8Sgww 	token = au_to_label(ucred_getlabel(uc));
1493c7bb2ee8Sgww 	ucred_free(uc);
1494c7bb2ee8Sgww 	return (token);
149545916cd2Sjpk }
149645916cd2Sjpk 
149745916cd2Sjpk /*
14987c478bd9Sstevel@tonic-gate  * au_to_zonename
14997c478bd9Sstevel@tonic-gate  * return s:
15007c478bd9Sstevel@tonic-gate  *	pointer to a zonename token.
15017c478bd9Sstevel@tonic-gate  */
15027c478bd9Sstevel@tonic-gate token_t *
au_to_zonename(char * name)15037c478bd9Sstevel@tonic-gate au_to_zonename(char *name)
15047c478bd9Sstevel@tonic-gate {
15057c478bd9Sstevel@tonic-gate 	token_t *token;			/* local token */
15067c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
15077c478bd9Sstevel@tonic-gate 	char data_header = AUT_ZONENAME;	/* header for this token */
15087c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
15097c478bd9Sstevel@tonic-gate 
15107c478bd9Sstevel@tonic-gate 	if (name == NULL)
15117c478bd9Sstevel@tonic-gate 		return (NULL);
15127c478bd9Sstevel@tonic-gate 
15137c478bd9Sstevel@tonic-gate 	bytes = strlen(name) + 1;
15147c478bd9Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
15157c478bd9Sstevel@tonic-gate 	if (token == NULL)
15167c478bd9Sstevel@tonic-gate 		return (NULL);
15177c478bd9Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
15187c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
15197c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
15207c478bd9Sstevel@tonic-gate 	adr_char(&adr, name, bytes);
15217c478bd9Sstevel@tonic-gate 
15227c478bd9Sstevel@tonic-gate 	return (token);
15237c478bd9Sstevel@tonic-gate }
1524103b2b15Sgww 
1525103b2b15Sgww /*
1526103b2b15Sgww  * au_to_fmri
1527103b2b15Sgww  * return s:
1528103b2b15Sgww  *	pointer to a fmri token.
1529103b2b15Sgww  */
1530103b2b15Sgww token_t *
au_to_fmri(char * fmri)1531103b2b15Sgww au_to_fmri(char *fmri)
1532103b2b15Sgww {
1533103b2b15Sgww 	token_t *token;			/* local token */
1534103b2b15Sgww 	adr_t adr;			/* adr memory stream header */
1535103b2b15Sgww 	char data_header = AUT_FMRI;	/* header for this token */
1536103b2b15Sgww 	short bytes;			/* length of string */
1537103b2b15Sgww 
1538103b2b15Sgww 	if (fmri == NULL)
1539103b2b15Sgww 		return (NULL);
1540103b2b15Sgww 
1541103b2b15Sgww 	bytes = strlen(fmri) + 1;
1542103b2b15Sgww 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
1543103b2b15Sgww 	if (token == NULL)
1544103b2b15Sgww 		return (NULL);
1545103b2b15Sgww 	adr_start(&adr, token->tt_data);
1546103b2b15Sgww 	adr_char(&adr, &data_header, 1);
1547103b2b15Sgww 	adr_short(&adr, &bytes, 1);
1548103b2b15Sgww 	adr_char(&adr, fmri, bytes);
1549103b2b15Sgww 
1550103b2b15Sgww 	return (token);
1551103b2b15Sgww }
1552