xref: /onnv-gate/usr/src/lib/libbsm/common/au_to.c (revision 11893:ff6e80260186)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51676Sjpk  * Common Development and Distribution License (the "License").
61676Sjpk  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11893Sgww@eng.sun.com  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <unistd.h>
290Sstevel@tonic-gate #include <bsm/audit.h>
300Sstevel@tonic-gate #include <bsm/audit_record.h>
310Sstevel@tonic-gate #include <bsm/libbsm.h>
320Sstevel@tonic-gate #include <priv.h>
330Sstevel@tonic-gate #include <sys/ipc.h>
340Sstevel@tonic-gate #include <sys/param.h>
350Sstevel@tonic-gate #include <sys/socket.h>
360Sstevel@tonic-gate #include <sys/time.h>
370Sstevel@tonic-gate #include <sys/vnode.h>
380Sstevel@tonic-gate #include <malloc.h>
390Sstevel@tonic-gate #include <net/route.h>
400Sstevel@tonic-gate #include <netinet/in.h>
410Sstevel@tonic-gate #include <netinet/in_pcb.h>
420Sstevel@tonic-gate #include <string.h>
432376Sgww #include <ucred.h>
441676Sjpk #include <zone.h>
451676Sjpk #include <sys/tsol/label.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #define	NGROUPS		16	/* XXX - temporary */
480Sstevel@tonic-gate 
490Sstevel@tonic-gate token_t *au_to_arg(char n, char *text, uint32_t v);
500Sstevel@tonic-gate #pragma weak au_to_arg = au_to_arg32
510Sstevel@tonic-gate token_t *au_to_return(char number, uint32_t value);
520Sstevel@tonic-gate #pragma weak au_to_return = au_to_return32
530Sstevel@tonic-gate 
540Sstevel@tonic-gate static token_t *au_to_exec(char **, char);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate static token_t *
get_token(int s)570Sstevel@tonic-gate get_token(int s)
580Sstevel@tonic-gate {
590Sstevel@tonic-gate 	token_t *token;	/* Resultant token */
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 	if ((token = (token_t *)malloc(sizeof (token_t))) == NULL)
620Sstevel@tonic-gate 		return (NULL);
630Sstevel@tonic-gate 	if ((token->tt_data = malloc(s)) == NULL) {
640Sstevel@tonic-gate 		free(token);
650Sstevel@tonic-gate 		return (NULL);
660Sstevel@tonic-gate 	}
670Sstevel@tonic-gate 	token->tt_size = s;
680Sstevel@tonic-gate 	token->tt_next = NULL;
690Sstevel@tonic-gate 	return (token);
700Sstevel@tonic-gate }
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * au_to_header
740Sstevel@tonic-gate  * return s:
750Sstevel@tonic-gate  *	pointer to header token.
760Sstevel@tonic-gate  */
770Sstevel@tonic-gate token_t *
au_to_header(au_event_t e_type,au_emod_t e_mod)780Sstevel@tonic-gate au_to_header(au_event_t e_type, au_emod_t e_mod)
790Sstevel@tonic-gate {
800Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
810Sstevel@tonic-gate 	token_t *token;			/* token pointer */
820Sstevel@tonic-gate 	char version = TOKEN_VERSION;	/* version of token family */
830Sstevel@tonic-gate 	int32_t byte_count;
840Sstevel@tonic-gate 	struct timeval tv;
850Sstevel@tonic-gate #ifdef _LP64
860Sstevel@tonic-gate 	char data_header = AUT_HEADER64;	/* header for this token */
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + sizeof (int32_t) +
890Sstevel@tonic-gate 	    2 * sizeof (int64_t) + 2 * sizeof (short));
900Sstevel@tonic-gate #else
910Sstevel@tonic-gate 	char data_header = AUT_HEADER32;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + 3 * sizeof (int32_t) +
940Sstevel@tonic-gate 	    2 * sizeof (short));
950Sstevel@tonic-gate #endif
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	if (token == NULL)
980Sstevel@tonic-gate 		return (NULL);
990Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
1000Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
1010Sstevel@tonic-gate 	adr_int32(&adr, &byte_count, 1);	/* length of audit record */
1020Sstevel@tonic-gate 	adr_char(&adr, &version, 1);		/* version of audit tokens */
1037753STon.Nguyen@Sun.COM 	adr_ushort(&adr, &e_type, 1);		/* event ID */
1047753STon.Nguyen@Sun.COM 	adr_ushort(&adr, &e_mod, 1);		/* event ID modifier */
1050Sstevel@tonic-gate #ifdef _LP64
1060Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tv, 2);	/* time & date */
1070Sstevel@tonic-gate #else
1080Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tv, 2);	/* time & date */
1090Sstevel@tonic-gate #endif
1100Sstevel@tonic-gate 	return (token);
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /*
1140Sstevel@tonic-gate  * au_to_header_ex
1150Sstevel@tonic-gate  * return s:
1160Sstevel@tonic-gate  *	pointer to header token.
1170Sstevel@tonic-gate  */
1180Sstevel@tonic-gate token_t *
au_to_header_ex(au_event_t e_type,au_emod_t e_mod)1190Sstevel@tonic-gate au_to_header_ex(au_event_t e_type, au_emod_t e_mod)
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
1220Sstevel@tonic-gate 	token_t *token;			/* token pointer */
1230Sstevel@tonic-gate 	char version = TOKEN_VERSION;	/* version of token family */
1240Sstevel@tonic-gate 	int32_t byte_count;
1250Sstevel@tonic-gate 	struct timeval tv;
1260Sstevel@tonic-gate 	auditinfo_addr_t audit_info;
1270Sstevel@tonic-gate 	au_tid_addr_t	*host_info = &audit_info.ai_termid;
1280Sstevel@tonic-gate #ifdef _LP64
1290Sstevel@tonic-gate 	char data_header = AUT_HEADER64_EX;	/* header for this token */
1300Sstevel@tonic-gate #else
1310Sstevel@tonic-gate 	char data_header = AUT_HEADER32_EX;
1320Sstevel@tonic-gate #endif
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	/* If our host address can't be determined, revert to un-extended hdr */
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	if (auditon(A_GETKAUDIT, (caddr_t)&audit_info,
1370Sstevel@tonic-gate 	    sizeof (audit_info)) < 0)
1380Sstevel@tonic-gate 		return (au_to_header(e_type, e_mod));
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	if (host_info->at_type == AU_IPv6)
1410Sstevel@tonic-gate 		if (IN6_IS_ADDR_UNSPECIFIED((in6_addr_t *)host_info->at_addr))
1420Sstevel@tonic-gate 			return (au_to_header(e_type, e_mod));
1430Sstevel@tonic-gate 	else
1440Sstevel@tonic-gate 		if (host_info->at_addr[0] == htonl(INADDR_ANY))
1450Sstevel@tonic-gate 			return (au_to_header(e_type, e_mod));
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate #ifdef _LP64
1480Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + sizeof (int32_t) +
1490Sstevel@tonic-gate 	    2 * sizeof (int64_t) + 2 * sizeof (short) +
1500Sstevel@tonic-gate 	    sizeof (int32_t) + host_info->at_type);
1510Sstevel@tonic-gate #else
1520Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + 3 * sizeof (int32_t) +
1530Sstevel@tonic-gate 	    2 * sizeof (short) + sizeof (int32_t) + host_info->at_type);
1540Sstevel@tonic-gate #endif
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	if (token == NULL)
1570Sstevel@tonic-gate 		return (NULL);
1580Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
1590Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
1600Sstevel@tonic-gate 	adr_int32(&adr, &byte_count, 1);	/* length of audit record */
1610Sstevel@tonic-gate 	adr_char(&adr, &version, 1);		/* version of audit tokens */
1627753STon.Nguyen@Sun.COM 	adr_ushort(&adr, &e_type, 1);		/* event ID */
1637753STon.Nguyen@Sun.COM 	adr_ushort(&adr, &e_mod, 1);		/* event ID modifier */
1640Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&host_info->at_type, 1);
1650Sstevel@tonic-gate 	adr_char(&adr, (char *)host_info->at_addr,
1660Sstevel@tonic-gate 	    (int)host_info->at_type);
1670Sstevel@tonic-gate #ifdef _LP64
1680Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tv, 2);	/* time & date */
1690Sstevel@tonic-gate #else
1700Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tv, 2);	/* time & date */
1710Sstevel@tonic-gate #endif
1720Sstevel@tonic-gate 	return (token);
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate /*
1760Sstevel@tonic-gate  * au_to_trailer
1770Sstevel@tonic-gate  * return s:
1780Sstevel@tonic-gate  *	pointer to a trailer token.
1790Sstevel@tonic-gate  */
1800Sstevel@tonic-gate token_t *
au_to_trailer(void)1810Sstevel@tonic-gate au_to_trailer(void)
1820Sstevel@tonic-gate {
1830Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
1840Sstevel@tonic-gate 	token_t *token;				/* token pointer */
1850Sstevel@tonic-gate 	char data_header = AUT_TRAILER;		/* header for this token */
1860Sstevel@tonic-gate 	short magic = (short)AUT_TRAILER_MAGIC;	/* trailer magic number */
1870Sstevel@tonic-gate 	int32_t byte_count;
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int32_t) + sizeof (short));
1900Sstevel@tonic-gate 	if (token == NULL)
1910Sstevel@tonic-gate 		return (NULL);
1920Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
1930Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
1940Sstevel@tonic-gate 	adr_short(&adr, &magic, 1);		/* magic number */
1950Sstevel@tonic-gate 	adr_int32(&adr, &byte_count, 1);	/* length of audit record */
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	return (token);
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate  * au_to_arg32
2020Sstevel@tonic-gate  * return s:
2030Sstevel@tonic-gate  *	pointer to an argument token.
2040Sstevel@tonic-gate  */
2050Sstevel@tonic-gate token_t *
au_to_arg32(char n,char * text,uint32_t v)2060Sstevel@tonic-gate au_to_arg32(char n, char *text, uint32_t v)
2070Sstevel@tonic-gate {
2080Sstevel@tonic-gate 	token_t *token;			/* local token */
2090Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
2100Sstevel@tonic-gate 	char data_header = AUT_ARG32;	/* header for this token */
2110Sstevel@tonic-gate 	short bytes;			/* length of string */
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 	bytes = strlen(text) + 1;
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate 	token = get_token((int)(2 * sizeof (char) + sizeof (int32_t) +
2160Sstevel@tonic-gate 	    sizeof (short) + bytes));
2170Sstevel@tonic-gate 	if (token == NULL)
2180Sstevel@tonic-gate 		return (NULL);
2190Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
2200Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token type */
2210Sstevel@tonic-gate 	adr_char(&adr, &n, 1);			/* argument id */
2220Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&v, 1);	/* argument value */
2230Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
2240Sstevel@tonic-gate 	adr_char(&adr, text, bytes);
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	return (token);
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate /*
2300Sstevel@tonic-gate  * au_to_arg64
2310Sstevel@tonic-gate  * return s:
2320Sstevel@tonic-gate  *	pointer to an argument token.
2330Sstevel@tonic-gate  */
2340Sstevel@tonic-gate token_t *
au_to_arg64(char n,char * text,uint64_t v)2350Sstevel@tonic-gate au_to_arg64(char n, char *text, uint64_t v)
2360Sstevel@tonic-gate {
2370Sstevel@tonic-gate 	token_t *token;			/* local token */
2380Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
2390Sstevel@tonic-gate 	char data_header = AUT_ARG64;	/* header for this token */
2400Sstevel@tonic-gate 	short bytes;			/* length of string */
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate 	bytes = strlen(text) + 1;
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 	token = get_token((int)(2 * sizeof (char) + sizeof (int64_t) +
2450Sstevel@tonic-gate 	    sizeof (short) + bytes));
2460Sstevel@tonic-gate 	if (token == NULL)
2470Sstevel@tonic-gate 		return (NULL);
2480Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
2490Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token type */
2500Sstevel@tonic-gate 	adr_char(&adr, &n, 1);			/* argument id */
2510Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&v, 1);	/* argument value */
2520Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
2530Sstevel@tonic-gate 	adr_char(&adr, text, bytes);
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate 	return (token);
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate /*
2600Sstevel@tonic-gate  * au_to_attr
2610Sstevel@tonic-gate  * return s:
2620Sstevel@tonic-gate  *	pointer to an attribute token.
2630Sstevel@tonic-gate  */
2640Sstevel@tonic-gate token_t *
au_to_attr(struct vattr * attr)2650Sstevel@tonic-gate au_to_attr(struct vattr *attr)
2660Sstevel@tonic-gate {
2670Sstevel@tonic-gate 	token_t *token;			/* local token */
2680Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
2690Sstevel@tonic-gate 	int32_t value;
2700Sstevel@tonic-gate #ifdef _LP64
2710Sstevel@tonic-gate 	char data_header = AUT_ATTR64;	/* header for this token */
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	token = get_token(sizeof (char) +
2740Sstevel@tonic-gate 	    sizeof (int32_t) * 4 +
2750Sstevel@tonic-gate 	    sizeof (int64_t) * 2);
2760Sstevel@tonic-gate #else
2770Sstevel@tonic-gate 	char data_header = AUT_ATTR32;
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int32_t) * 5 +
2800Sstevel@tonic-gate 	    sizeof (int64_t));
2810Sstevel@tonic-gate #endif
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	if (token == NULL)
2840Sstevel@tonic-gate 		return (NULL);
2850Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
2860Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
2870Sstevel@tonic-gate 	value = (int32_t)attr->va_mode;
2880Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
2890Sstevel@tonic-gate 	value = (int32_t)attr->va_uid;
2900Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
2910Sstevel@tonic-gate 	value = (int32_t)attr->va_gid;
2920Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
2930Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(attr->va_fsid), 1);
2940Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(attr->va_nodeid), 1);
2950Sstevel@tonic-gate #ifdef _LP64
2960Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(attr->va_rdev), 1);
2970Sstevel@tonic-gate #else
2980Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(attr->va_rdev), 1);
2990Sstevel@tonic-gate #endif
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	return (token);
3020Sstevel@tonic-gate }
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate /*
3050Sstevel@tonic-gate  * au_to_data
3060Sstevel@tonic-gate  * return s:
3070Sstevel@tonic-gate  *	pointer to a data token.
3080Sstevel@tonic-gate  */
3090Sstevel@tonic-gate token_t *
au_to_data(char unit_print,char unit_type,char unit_count,char * p)3100Sstevel@tonic-gate au_to_data(char unit_print, char unit_type, char unit_count, char *p)
3110Sstevel@tonic-gate {
3120Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
3130Sstevel@tonic-gate 	token_t *token;			/* token pointer */
3140Sstevel@tonic-gate 	char data_header = AUT_DATA;	/* header for this token */
3150Sstevel@tonic-gate 	int byte_count;			/* number of bytes */
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate 	if (p == NULL || unit_count < 1)
3180Sstevel@tonic-gate 		return (NULL);
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 	/*
3210Sstevel@tonic-gate 	 * Check validity of print type
3220Sstevel@tonic-gate 	 */
3230Sstevel@tonic-gate 	if (unit_print < AUP_BINARY || unit_print > AUP_STRING)
3240Sstevel@tonic-gate 		return (NULL);
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 	switch (unit_type) {
3270Sstevel@tonic-gate 	case AUR_SHORT:
3280Sstevel@tonic-gate 		byte_count = unit_count * sizeof (short);
3290Sstevel@tonic-gate 		break;
3300Sstevel@tonic-gate 	case AUR_INT32:
3310Sstevel@tonic-gate 		byte_count = unit_count * sizeof (int32_t);
3320Sstevel@tonic-gate 		break;
3330Sstevel@tonic-gate 	case AUR_INT64:
3340Sstevel@tonic-gate 		byte_count = unit_count * sizeof (int64_t);
3350Sstevel@tonic-gate 		break;
3360Sstevel@tonic-gate 	/* case AUR_CHAR: */
3370Sstevel@tonic-gate 	case AUR_BYTE:
3380Sstevel@tonic-gate 		byte_count = unit_count * sizeof (char);
3390Sstevel@tonic-gate 		break;
3400Sstevel@tonic-gate 	default:
3410Sstevel@tonic-gate 		return (NULL);
3420Sstevel@tonic-gate 	}
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 	token = get_token((int)(4 * sizeof (char) + byte_count));
3450Sstevel@tonic-gate 	if (token == NULL)
3460Sstevel@tonic-gate 		return (NULL);
3470Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
3480Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
3490Sstevel@tonic-gate 	adr_char(&adr, &unit_print, 1);
3500Sstevel@tonic-gate 	adr_char(&adr, &unit_type, 1);
3510Sstevel@tonic-gate 	adr_char(&adr, &unit_count, 1);
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate 	switch (unit_type) {
3540Sstevel@tonic-gate 	case AUR_SHORT:
3550Sstevel@tonic-gate 		/* LINTED */
3560Sstevel@tonic-gate 		adr_short(&adr, (short *)p, unit_count);
3570Sstevel@tonic-gate 		break;
3580Sstevel@tonic-gate 	case AUR_INT32:
3590Sstevel@tonic-gate 		/* LINTED */
3600Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)p, unit_count);
3610Sstevel@tonic-gate 		break;
3620Sstevel@tonic-gate 	case AUR_INT64:
3630Sstevel@tonic-gate 		/* LINTED */
3640Sstevel@tonic-gate 		adr_int64(&adr, (int64_t *)p, unit_count);
3650Sstevel@tonic-gate 		break;
3660Sstevel@tonic-gate 	/* case AUR_CHAR: */
3670Sstevel@tonic-gate 	case AUR_BYTE:
3680Sstevel@tonic-gate 		adr_char(&adr, p, unit_count);
3690Sstevel@tonic-gate 		break;
3700Sstevel@tonic-gate 	}
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate 	return (token);
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate /*
3760Sstevel@tonic-gate  * au_to_privset
3770Sstevel@tonic-gate  *
3780Sstevel@tonic-gate  * priv_type (LIMIT, INHERIT...) is the first string and privilege
3790Sstevel@tonic-gate  * in translated into the second string.  The format is as follows:
3800Sstevel@tonic-gate  *
3810Sstevel@tonic-gate  *	token id	adr_char
3820Sstevel@tonic-gate  *	priv type	adr_string (short, string)
3830Sstevel@tonic-gate  *	priv set	adr_string (short, string)
3840Sstevel@tonic-gate  *
3850Sstevel@tonic-gate  * return s:
3860Sstevel@tonic-gate  *	pointer to a AUT_PRIV token.
3870Sstevel@tonic-gate  */
3880Sstevel@tonic-gate token_t *
au_to_privset(const char * priv_type,const priv_set_t * privilege)3890Sstevel@tonic-gate au_to_privset(const char *priv_type, const priv_set_t *privilege)
3900Sstevel@tonic-gate {
3910Sstevel@tonic-gate 	token_t	*token;			/* local token */
3920Sstevel@tonic-gate 	adr_t	adr;			/* adr memory stream header */
3930Sstevel@tonic-gate 	char	data_header = AUT_PRIV;	/* header for this token */
3940Sstevel@tonic-gate 	short	t_bytes;		/* length of type string */
3950Sstevel@tonic-gate 	short	p_bytes;		/* length of privilege string */
3960Sstevel@tonic-gate 	char	*priv_string;		/* privilege string */
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	t_bytes = strlen(priv_type) + 1;
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate 	if ((privilege == NULL) || (priv_string =
4010Sstevel@tonic-gate 	    priv_set_to_str(privilege, ',',
4020Sstevel@tonic-gate 	    PRIV_STR_LIT)) == NULL)
4030Sstevel@tonic-gate 		return (NULL);
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate 	p_bytes = strlen(priv_string) + 1;
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + (2 * sizeof (short)) + t_bytes
4080Sstevel@tonic-gate 	    + p_bytes));
4090Sstevel@tonic-gate 	if (token == NULL)
4100Sstevel@tonic-gate 		return (NULL);
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
4130Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
4140Sstevel@tonic-gate 	adr_short(&adr, &t_bytes, 1);
4150Sstevel@tonic-gate 	adr_char(&adr, (char *)priv_type, t_bytes);
4160Sstevel@tonic-gate 	adr_short(&adr, &p_bytes, 1);
4170Sstevel@tonic-gate 	adr_char(&adr, priv_string, p_bytes);
4180Sstevel@tonic-gate 
4190Sstevel@tonic-gate 	free(priv_string);
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate 	return (token);
4220Sstevel@tonic-gate }
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate /*
4250Sstevel@tonic-gate  * au_to_process
4260Sstevel@tonic-gate  * return s:
4270Sstevel@tonic-gate  *	pointer to a process token.
4280Sstevel@tonic-gate  */
4290Sstevel@tonic-gate 
4300Sstevel@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)4310Sstevel@tonic-gate au_to_process(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid,
4320Sstevel@tonic-gate     pid_t pid, au_asid_t sid, au_tid_t *tid)
4330Sstevel@tonic-gate {
4340Sstevel@tonic-gate 	token_t *token;			/* local token */
4350Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
4360Sstevel@tonic-gate #ifdef _LP64
4370Sstevel@tonic-gate 	char data_header = AUT_PROCESS64;	/* header for this token */
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate 	token = get_token(sizeof (char) + 8 * sizeof (int32_t) +
4400Sstevel@tonic-gate 	    sizeof (int64_t));
4410Sstevel@tonic-gate #else
4420Sstevel@tonic-gate 	char data_header = AUT_PROCESS32;
4430Sstevel@tonic-gate 
4440Sstevel@tonic-gate 	token = get_token(sizeof (char) + 9 * sizeof (int32_t));
4450Sstevel@tonic-gate #endif
4460Sstevel@tonic-gate 
4470Sstevel@tonic-gate 	if (token == NULL)
4480Sstevel@tonic-gate 		return (NULL);
4490Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
4500Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
4510Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&auid, 1);
4520Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&euid, 1);
4530Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&egid, 1);
4540Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&ruid, 1);
4550Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&rgid, 1);
4560Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&pid, 1);
4570Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&sid, 1);
4580Sstevel@tonic-gate #ifdef _LP64
4590Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tid->port, 1);
4600Sstevel@tonic-gate #else
4610Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->port, 1);
4620Sstevel@tonic-gate #endif
4630Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->machine, 1);
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 	return (token);
4660Sstevel@tonic-gate }
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate /*
4690Sstevel@tonic-gate  * au_to_process_ex
4700Sstevel@tonic-gate  * return s:
4710Sstevel@tonic-gate  *	pointer to a process_ex token.
4720Sstevel@tonic-gate  */
4730Sstevel@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)4740Sstevel@tonic-gate au_to_process_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid,
4750Sstevel@tonic-gate     pid_t pid, au_asid_t sid, au_tid_addr_t *tid)
4760Sstevel@tonic-gate {
4770Sstevel@tonic-gate 	token_t *token;			/* local token */
4780Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
4790Sstevel@tonic-gate 	char data_header;		/* header for this token */
4800Sstevel@tonic-gate 
4810Sstevel@tonic-gate #ifdef _LP64
4820Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
4830Sstevel@tonic-gate 		data_header = AUT_PROCESS64_EX;
4840Sstevel@tonic-gate 		token = get_token(sizeof (char) + sizeof (int64_t) +
4850Sstevel@tonic-gate 		    12 * sizeof (int32_t));
4860Sstevel@tonic-gate 	} else {
4870Sstevel@tonic-gate 		data_header = AUT_PROCESS64;
4880Sstevel@tonic-gate 		token = get_token(sizeof (char) + sizeof (int64_t) +
4890Sstevel@tonic-gate 		    8 * sizeof (int32_t));
4900Sstevel@tonic-gate 	}
4910Sstevel@tonic-gate #else
4920Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
4930Sstevel@tonic-gate 		data_header = AUT_PROCESS32_EX;
4940Sstevel@tonic-gate 		token = get_token(sizeof (char) + 13 * sizeof (int32_t));
4950Sstevel@tonic-gate 	} else {
4960Sstevel@tonic-gate 		data_header = AUT_PROCESS32;
4970Sstevel@tonic-gate 		token = get_token(sizeof (char) + 9 * sizeof (int32_t));
4980Sstevel@tonic-gate 	}
4990Sstevel@tonic-gate #endif
5000Sstevel@tonic-gate 	if (token == NULL)
5010Sstevel@tonic-gate 		return (NULL);
5020Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
5030Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
5040Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&auid, 1);
5050Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&euid, 1);
5060Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&egid, 1);
5070Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&ruid, 1);
5080Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&rgid, 1);
5090Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&pid, 1);
5100Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&sid, 1);
5110Sstevel@tonic-gate #ifdef _LP64
5120Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tid->at_port, 1);
5130Sstevel@tonic-gate #else
5140Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->at_port, 1);
5150Sstevel@tonic-gate #endif
5160Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
5170Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)&tid->at_type, 1);
5180Sstevel@tonic-gate 		adr_char(&adr, (char *)tid->at_addr, 16);
5190Sstevel@tonic-gate 	} else {
5200Sstevel@tonic-gate 		adr_char(&adr, (char *)tid->at_addr, 4);
5210Sstevel@tonic-gate 	}
5220Sstevel@tonic-gate 
5230Sstevel@tonic-gate 	return (token);
5240Sstevel@tonic-gate }
5250Sstevel@tonic-gate 
5260Sstevel@tonic-gate /*
5270Sstevel@tonic-gate  * au_to_seq
5280Sstevel@tonic-gate  * return s:
5290Sstevel@tonic-gate  *	pointer to token chain containing a sequence token
5300Sstevel@tonic-gate  */
5310Sstevel@tonic-gate token_t *
au_to_seq(int audit_count)5320Sstevel@tonic-gate au_to_seq(int audit_count)
5330Sstevel@tonic-gate {
5340Sstevel@tonic-gate 	token_t *token;			/* local token */
5350Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
5360Sstevel@tonic-gate 	char data_header = AUT_SEQ;	/* header for this token */
5370Sstevel@tonic-gate 
5380Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int32_t));
5390Sstevel@tonic-gate 	if (token == NULL)
5400Sstevel@tonic-gate 		return (NULL);
5410Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
5420Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
5430Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&audit_count, 1);
5440Sstevel@tonic-gate 
5450Sstevel@tonic-gate 	return (token);
5460Sstevel@tonic-gate }
5470Sstevel@tonic-gate 
5480Sstevel@tonic-gate /*
5490Sstevel@tonic-gate  * au_to_socket
5500Sstevel@tonic-gate  * return s:
5510Sstevel@tonic-gate  *	pointer to mbuf chain containing a socket token.
5520Sstevel@tonic-gate  */
5530Sstevel@tonic-gate token_t *
au_to_socket(struct oldsocket * so)5540Sstevel@tonic-gate au_to_socket(struct oldsocket *so)
5550Sstevel@tonic-gate {
5560Sstevel@tonic-gate 	adr_t adr;
5570Sstevel@tonic-gate 	token_t *token;
5580Sstevel@tonic-gate 	char data_header = AUT_SOCKET;
5590Sstevel@tonic-gate 	struct inpcb *inp = so->so_pcb;
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (short) * 3 +
5620Sstevel@tonic-gate 	    sizeof (int32_t) * 2);
5630Sstevel@tonic-gate 	if (token == NULL)
5640Sstevel@tonic-gate 		return (NULL);
5650Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
5660Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
5670Sstevel@tonic-gate 	adr_short(&adr, (short *)&so->so_type, 1);
5680Sstevel@tonic-gate 	adr_short(&adr, (short *)&inp->inp_lport, 1);
5690Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&inp->inp_laddr, 1);
5700Sstevel@tonic-gate 	adr_short(&adr, (short *)&inp->inp_fport, 1);
5710Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&inp->inp_faddr, 1);
5720Sstevel@tonic-gate 
5730Sstevel@tonic-gate 	return (token);
5740Sstevel@tonic-gate }
5750Sstevel@tonic-gate 
5760Sstevel@tonic-gate /*
5770Sstevel@tonic-gate  * au_to_subject
5780Sstevel@tonic-gate  * return s:
5790Sstevel@tonic-gate  *	pointer to a process token.
5800Sstevel@tonic-gate  */
5810Sstevel@tonic-gate 
5820Sstevel@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)5830Sstevel@tonic-gate au_to_subject(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid,
5840Sstevel@tonic-gate     pid_t pid, au_asid_t sid, au_tid_t *tid)
5850Sstevel@tonic-gate {
5860Sstevel@tonic-gate 	token_t *token;			/* local token */
5870Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
5880Sstevel@tonic-gate #ifdef _LP64
5890Sstevel@tonic-gate 	char data_header = AUT_SUBJECT64;	/* header for this token */
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int64_t) +
5920Sstevel@tonic-gate 	    8 * sizeof (int32_t));
5930Sstevel@tonic-gate #else
5940Sstevel@tonic-gate 	char data_header = AUT_SUBJECT32;
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate 	token = get_token(sizeof (char) + 9 * sizeof (int32_t));
5970Sstevel@tonic-gate #endif
5980Sstevel@tonic-gate 
5990Sstevel@tonic-gate 	if (token == NULL)
6000Sstevel@tonic-gate 		return (NULL);
6010Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
6020Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
6030Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&auid, 1);
6040Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&euid, 1);
6050Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&egid, 1);
6060Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&ruid, 1);
6070Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&rgid, 1);
6080Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&pid, 1);
6090Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&sid, 1);
6100Sstevel@tonic-gate #ifdef _LP64
6110Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tid->port, 1);
6120Sstevel@tonic-gate #else
6130Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->port, 1);
6140Sstevel@tonic-gate #endif
6150Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->machine, 1);
6160Sstevel@tonic-gate 
6170Sstevel@tonic-gate 	return (token);
6180Sstevel@tonic-gate }
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate /*
6210Sstevel@tonic-gate  * au_to_subject_ex
6220Sstevel@tonic-gate  * return s:
6230Sstevel@tonic-gate  *	pointer to a process token.
6240Sstevel@tonic-gate  */
6250Sstevel@tonic-gate 
6260Sstevel@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)6270Sstevel@tonic-gate au_to_subject_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid,
6280Sstevel@tonic-gate     pid_t pid, au_asid_t sid, au_tid_addr_t *tid)
6290Sstevel@tonic-gate {
6300Sstevel@tonic-gate 	token_t *token;			/* local token */
6310Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
6320Sstevel@tonic-gate #ifdef _LP64
6330Sstevel@tonic-gate 	char data_header;		/* header for this token */
6340Sstevel@tonic-gate 
6350Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
6360Sstevel@tonic-gate 		data_header = AUT_SUBJECT64_EX;
6370Sstevel@tonic-gate 		token = get_token(sizeof (char) + sizeof (int64_t) +
6380Sstevel@tonic-gate 		    12 * sizeof (int32_t));
6390Sstevel@tonic-gate 	} else {
6400Sstevel@tonic-gate 		data_header = AUT_SUBJECT64;
6410Sstevel@tonic-gate 		token = get_token(sizeof (char) + sizeof (int64_t) +
6420Sstevel@tonic-gate 		    8 * sizeof (int32_t));
6430Sstevel@tonic-gate 	}
6440Sstevel@tonic-gate #else
6450Sstevel@tonic-gate 	char data_header;		/* header for this token */
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
6480Sstevel@tonic-gate 		data_header = AUT_SUBJECT32_EX;
6490Sstevel@tonic-gate 		token = get_token(sizeof (char) + 13 * sizeof (int32_t));
6500Sstevel@tonic-gate 	} else {
6510Sstevel@tonic-gate 		data_header = AUT_SUBJECT32;
6520Sstevel@tonic-gate 		token = get_token(sizeof (char) + 9 * sizeof (int32_t));
6530Sstevel@tonic-gate 	}
6540Sstevel@tonic-gate #endif
6550Sstevel@tonic-gate 
6560Sstevel@tonic-gate 	if (token == NULL)
6570Sstevel@tonic-gate 		return (NULL);
6580Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
6590Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
6600Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&auid, 1);
6610Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&euid, 1);
6620Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&egid, 1);
6630Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&ruid, 1);
6640Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&rgid, 1);
6650Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&pid, 1);
6660Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&sid, 1);
6670Sstevel@tonic-gate #ifdef _LP64
6680Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&tid->at_port, 1);
6690Sstevel@tonic-gate #else
6700Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&tid->at_port, 1);
6710Sstevel@tonic-gate #endif
6720Sstevel@tonic-gate 	if (tid->at_type == AU_IPv6) {
6730Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)&tid->at_type, 1);
6740Sstevel@tonic-gate 		adr_char(&adr, (char *)tid->at_addr, 16);
6750Sstevel@tonic-gate 	} else {
6760Sstevel@tonic-gate 		adr_char(&adr, (char *)tid->at_addr, 4);
6770Sstevel@tonic-gate 	}
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate 	return (token);
6800Sstevel@tonic-gate }
6810Sstevel@tonic-gate 
6820Sstevel@tonic-gate /*
6830Sstevel@tonic-gate  * au_to_me
6840Sstevel@tonic-gate  * return s:
6850Sstevel@tonic-gate  *	pointer to a process token.
6860Sstevel@tonic-gate  */
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate token_t *
au_to_me(void)6890Sstevel@tonic-gate au_to_me(void)
6900Sstevel@tonic-gate {
6910Sstevel@tonic-gate 	auditinfo_addr_t info;
6920Sstevel@tonic-gate 
6930Sstevel@tonic-gate 	if (getaudit_addr(&info, sizeof (info)))
6940Sstevel@tonic-gate 		return (NULL);
6950Sstevel@tonic-gate 	return (au_to_subject_ex(info.ai_auid, geteuid(), getegid(), getuid(),
6960Sstevel@tonic-gate 	    getgid(), getpid(), info.ai_asid, &info.ai_termid));
6970Sstevel@tonic-gate }
6980Sstevel@tonic-gate /*
6990Sstevel@tonic-gate  * au_to_text
7000Sstevel@tonic-gate  * return s:
7010Sstevel@tonic-gate  *	pointer to a text token.
7020Sstevel@tonic-gate  */
7030Sstevel@tonic-gate token_t *
au_to_text(char * text)7040Sstevel@tonic-gate au_to_text(char *text)
7050Sstevel@tonic-gate {
7060Sstevel@tonic-gate 	token_t *token;			/* local token */
7070Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7080Sstevel@tonic-gate 	char data_header = AUT_TEXT;	/* header for this token */
7090Sstevel@tonic-gate 	short bytes;			/* length of string */
7100Sstevel@tonic-gate 
7110Sstevel@tonic-gate 	bytes = strlen(text) + 1;
7120Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
7130Sstevel@tonic-gate 	if (token == NULL)
7140Sstevel@tonic-gate 		return (NULL);
7150Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
7160Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7170Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
7180Sstevel@tonic-gate 	adr_char(&adr, text, bytes);
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate 	return (token);
7210Sstevel@tonic-gate }
7220Sstevel@tonic-gate 
7230Sstevel@tonic-gate /*
7240Sstevel@tonic-gate  * au_to_path
7250Sstevel@tonic-gate  * return s:
7260Sstevel@tonic-gate  *	pointer to a path token.
7270Sstevel@tonic-gate  */
7280Sstevel@tonic-gate token_t *
au_to_path(char * path)7290Sstevel@tonic-gate au_to_path(char *path)
7300Sstevel@tonic-gate {
7310Sstevel@tonic-gate 	token_t *token;			/* local token */
7320Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7330Sstevel@tonic-gate 	char data_header = AUT_PATH;	/* header for this token */
7340Sstevel@tonic-gate 	short bytes;			/* length of string */
7350Sstevel@tonic-gate 
7360Sstevel@tonic-gate 	bytes = (short)strlen(path) + 1;
7370Sstevel@tonic-gate 
7380Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) +  sizeof (short) + bytes));
7390Sstevel@tonic-gate 	if (token == NULL)
7400Sstevel@tonic-gate 		return (NULL);
7410Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
7420Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7430Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
7440Sstevel@tonic-gate 	adr_char(&adr, path, bytes);
7450Sstevel@tonic-gate 
7460Sstevel@tonic-gate 	return (token);
7470Sstevel@tonic-gate }
7480Sstevel@tonic-gate 
7490Sstevel@tonic-gate /*
7500Sstevel@tonic-gate  * au_to_cmd
7510Sstevel@tonic-gate  * return s:
7520Sstevel@tonic-gate  *	pointer to an command line argument token
7530Sstevel@tonic-gate  */
7540Sstevel@tonic-gate token_t *
au_to_cmd(uint_t argc,char ** argv,char ** envp)7550Sstevel@tonic-gate au_to_cmd(uint_t argc, char **argv, char **envp)
7560Sstevel@tonic-gate {
7570Sstevel@tonic-gate 	token_t *token;			/* local token */
7580Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7590Sstevel@tonic-gate 	char data_header = AUT_CMD;	/* header for this token */
7600Sstevel@tonic-gate 	short len = 0;
7610Sstevel@tonic-gate 	short cnt = 0;
7620Sstevel@tonic-gate 	short envc = 0;
7630Sstevel@tonic-gate 	short largc = (short)argc;
7640Sstevel@tonic-gate 
7650Sstevel@tonic-gate 	/*
7660Sstevel@tonic-gate 	 * one char for the header, one short for argc,
7670Sstevel@tonic-gate 	 * one short for # envp strings.
7680Sstevel@tonic-gate 	 */
7690Sstevel@tonic-gate 	len = sizeof (char) + sizeof (short) + sizeof (short);
7700Sstevel@tonic-gate 
7710Sstevel@tonic-gate 	/* get sizes of strings */
7720Sstevel@tonic-gate 
7730Sstevel@tonic-gate 	for (cnt = 0; cnt < argc; cnt++) {
7740Sstevel@tonic-gate 		len += (short)sizeof (short) + (short)(strlen(argv[cnt]) + 1);
7750Sstevel@tonic-gate 	}
7760Sstevel@tonic-gate 
7770Sstevel@tonic-gate 	if (envp != NULL) {
7780Sstevel@tonic-gate 		for (envc = 0; envp[envc] != NULL; envc++) {
7790Sstevel@tonic-gate 			len += (short)sizeof (short) +
7800Sstevel@tonic-gate 			    (short)(strlen(envp[envc]) + 1);
7810Sstevel@tonic-gate 		}
7820Sstevel@tonic-gate 	}
7830Sstevel@tonic-gate 
7840Sstevel@tonic-gate 	token = get_token(len);
7850Sstevel@tonic-gate 	if (token == NULL)
7860Sstevel@tonic-gate 		return (NULL);
7870Sstevel@tonic-gate 
7880Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
7890Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7900Sstevel@tonic-gate 
7910Sstevel@tonic-gate 	adr_short(&adr, &largc, 1);
7920Sstevel@tonic-gate 
7930Sstevel@tonic-gate 	for (cnt = 0; cnt < argc; cnt++) {
7940Sstevel@tonic-gate 		len = (short)(strlen(argv[cnt]) + 1);
7950Sstevel@tonic-gate 		adr_short(&adr, &len, 1);
7960Sstevel@tonic-gate 		adr_char(&adr, argv[cnt], len);
7970Sstevel@tonic-gate 	}
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate 	adr_short(&adr, &envc, 1);
8000Sstevel@tonic-gate 
8010Sstevel@tonic-gate 	for (cnt = 0; cnt < envc; cnt++) {
8020Sstevel@tonic-gate 		len = (short)(strlen(envp[cnt]) + 1);
8030Sstevel@tonic-gate 		adr_short(&adr, &len, 1);
8040Sstevel@tonic-gate 		adr_char(&adr, envp[cnt], len);
8050Sstevel@tonic-gate 	}
8060Sstevel@tonic-gate 
8070Sstevel@tonic-gate 	return (token);
8080Sstevel@tonic-gate }
8090Sstevel@tonic-gate 
8100Sstevel@tonic-gate /*
8110Sstevel@tonic-gate  * au_to_exit
8120Sstevel@tonic-gate  * return s:
8130Sstevel@tonic-gate  *	pointer to a exit value token.
8140Sstevel@tonic-gate  */
8150Sstevel@tonic-gate token_t *
au_to_exit(int retval,int err)8160Sstevel@tonic-gate au_to_exit(int retval, int err)
8170Sstevel@tonic-gate {
8180Sstevel@tonic-gate 	token_t *token;			/* local token */
8190Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
8200Sstevel@tonic-gate 	char data_header = AUT_EXIT;	/* header for this token */
8210Sstevel@tonic-gate 
8220Sstevel@tonic-gate 	token = get_token(sizeof (char) + (2 * sizeof (int32_t)));
8230Sstevel@tonic-gate 	if (token == NULL)
8240Sstevel@tonic-gate 		return (NULL);
8250Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
8260Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
8270Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&retval, 1);
8280Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&err, 1);
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate 	return (token);
8310Sstevel@tonic-gate }
8320Sstevel@tonic-gate 
8330Sstevel@tonic-gate /*
8340Sstevel@tonic-gate  * au_to_return
8350Sstevel@tonic-gate  * return s:
8360Sstevel@tonic-gate  *	pointer to a return  value token.
8370Sstevel@tonic-gate  */
8380Sstevel@tonic-gate token_t *
au_to_return32(char number,uint32_t value)8390Sstevel@tonic-gate au_to_return32(char number, uint32_t value)
8400Sstevel@tonic-gate {
8410Sstevel@tonic-gate 	token_t *token;				/* local token */
8420Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
8430Sstevel@tonic-gate 	char data_header = AUT_RETURN32;	/* header for this token */
8440Sstevel@tonic-gate 
8450Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + sizeof (int32_t));
8460Sstevel@tonic-gate 	if (token == NULL)
8470Sstevel@tonic-gate 		return (NULL);
8480Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
8490Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
8500Sstevel@tonic-gate 	adr_char(&adr, &number, 1);
8510Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&value, 1);
8520Sstevel@tonic-gate 
8530Sstevel@tonic-gate 	return (token);
8540Sstevel@tonic-gate }
8550Sstevel@tonic-gate 
8560Sstevel@tonic-gate /*
8570Sstevel@tonic-gate  * au_to_return
8580Sstevel@tonic-gate  * return s:
8590Sstevel@tonic-gate  *	pointer to a return  value token.
8600Sstevel@tonic-gate  */
8610Sstevel@tonic-gate token_t *
au_to_return64(char number,uint64_t value)8620Sstevel@tonic-gate au_to_return64(char number, uint64_t value)
8630Sstevel@tonic-gate {
8640Sstevel@tonic-gate 	token_t *token;				/* local token */
8650Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
8660Sstevel@tonic-gate 	char data_header = AUT_RETURN64;	/* header for this token */
8670Sstevel@tonic-gate 
8680Sstevel@tonic-gate 	token = get_token(2 * sizeof (char) + sizeof (int64_t));
8690Sstevel@tonic-gate 	if (token == NULL)
8700Sstevel@tonic-gate 		return (NULL);
8710Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
8720Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
8730Sstevel@tonic-gate 	adr_char(&adr, &number, 1);
8740Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&value, 1);
8750Sstevel@tonic-gate 
8760Sstevel@tonic-gate 	return (token);
8770Sstevel@tonic-gate }
8780Sstevel@tonic-gate 
8790Sstevel@tonic-gate 
8800Sstevel@tonic-gate /*
8810Sstevel@tonic-gate  * au_to_opaque
8820Sstevel@tonic-gate  * return s:
8830Sstevel@tonic-gate  *	pointer to a opaque token.
8840Sstevel@tonic-gate  */
8850Sstevel@tonic-gate token_t *
au_to_opaque(char * opaque,short bytes)8860Sstevel@tonic-gate au_to_opaque(char *opaque, short bytes)
8870Sstevel@tonic-gate {
8880Sstevel@tonic-gate 	token_t *token;			/* local token */
8890Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
8900Sstevel@tonic-gate 	char data_header = AUT_OPAQUE;	/* header for this token */
8910Sstevel@tonic-gate 
8920Sstevel@tonic-gate 	if (bytes < 1)
8930Sstevel@tonic-gate 		return (NULL);
8940Sstevel@tonic-gate 
8950Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
8960Sstevel@tonic-gate 	if (token == NULL)
8970Sstevel@tonic-gate 		return (NULL);
8980Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
8990Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
9000Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
9010Sstevel@tonic-gate 	adr_char(&adr, opaque, bytes);
9020Sstevel@tonic-gate 
9030Sstevel@tonic-gate 	return (token);
9040Sstevel@tonic-gate }
9050Sstevel@tonic-gate 
9060Sstevel@tonic-gate /*
9070Sstevel@tonic-gate  * au_to_in_addr
9080Sstevel@tonic-gate  * return s:
9095537Sgww  *	pointer to an internet address token
9100Sstevel@tonic-gate  */
9110Sstevel@tonic-gate token_t *
au_to_in_addr(struct in_addr * internet_addr)9120Sstevel@tonic-gate au_to_in_addr(struct in_addr *internet_addr)
9130Sstevel@tonic-gate {
9140Sstevel@tonic-gate 	token_t *token;			/* local token */
9150Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
9160Sstevel@tonic-gate 	char data_header = AUT_IN_ADDR;	/* header for this token */
9170Sstevel@tonic-gate 
9185537Sgww 	token = get_token(sizeof (char) + sizeof (struct in_addr));
9190Sstevel@tonic-gate 	if (token == NULL)
9200Sstevel@tonic-gate 		return (NULL);
9210Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
9220Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
9235537Sgww 	adr_char(&adr, (char *)internet_addr, sizeof (struct in_addr));
9245537Sgww 
9255537Sgww 	return (token);
9265537Sgww }
9275537Sgww 
9285537Sgww /*
9295537Sgww  * au_to_in_addr_ex
9305537Sgww  * return s:
9315537Sgww  *	pointer to an internet extended token
9325537Sgww  */
9335537Sgww token_t *
au_to_in_addr_ex(struct in6_addr * addr)9345537Sgww au_to_in_addr_ex(struct in6_addr *addr)
9355537Sgww {
9365537Sgww 	token_t *token;
9375537Sgww 	adr_t adr;
93810645Sgww@eng.sun.com 
93910645Sgww@eng.sun.com 	if (IN6_IS_ADDR_V4MAPPED(addr)) {
94010645Sgww@eng.sun.com 		ipaddr_t in4;
94110645Sgww@eng.sun.com 
94210645Sgww@eng.sun.com 		/*
94310645Sgww@eng.sun.com 		 * An IPv4-mapped IPv6 address is really an IPv4 address
94410645Sgww@eng.sun.com 		 * in IPv6 format.
94510645Sgww@eng.sun.com 		 */
94610645Sgww@eng.sun.com 
94710645Sgww@eng.sun.com 		IN6_V4MAPPED_TO_IPADDR(addr, in4);
94810645Sgww@eng.sun.com 		return (au_to_in_addr((struct in_addr *)&in4));
9495537Sgww 
95010645Sgww@eng.sun.com 	} else {
95110645Sgww@eng.sun.com 		char data_header = AUT_IN_ADDR_EX;
95210645Sgww@eng.sun.com 		int32_t	type = AU_IPv6;
95310645Sgww@eng.sun.com 
95410645Sgww@eng.sun.com 		if ((token = get_token(sizeof (char) + sizeof (int32_t) +
95510645Sgww@eng.sun.com 		    sizeof (struct in6_addr))) == NULL) {
95610645Sgww@eng.sun.com 			return (NULL);
95710645Sgww@eng.sun.com 		}
95810645Sgww@eng.sun.com 
95910645Sgww@eng.sun.com 		adr_start(&adr, token->tt_data);
96010645Sgww@eng.sun.com 		adr_char(&adr, &data_header, 1);
96110645Sgww@eng.sun.com 		adr_int32(&adr, &type, 1);
96210645Sgww@eng.sun.com 		adr_char(&adr, (char *)addr, sizeof (struct in6_addr));
9635537Sgww 	}
9645537Sgww 
9650Sstevel@tonic-gate 	return (token);
9660Sstevel@tonic-gate }
9670Sstevel@tonic-gate 
9680Sstevel@tonic-gate /*
9690Sstevel@tonic-gate  * au_to_iport
9700Sstevel@tonic-gate  * return s:
9710Sstevel@tonic-gate  *	pointer to token chain containing a ip port address token
9720Sstevel@tonic-gate  */
9730Sstevel@tonic-gate token_t *
au_to_iport(ushort_t iport)9740Sstevel@tonic-gate au_to_iport(ushort_t iport)
9750Sstevel@tonic-gate {
9760Sstevel@tonic-gate 	token_t *token;			/* local token */
9770Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
9780Sstevel@tonic-gate 	char data_header = AUT_IPORT;	/* header for this token */
9790Sstevel@tonic-gate 
9800Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (short));
9810Sstevel@tonic-gate 	if (token == NULL)
9820Sstevel@tonic-gate 		return (NULL);
9830Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
9840Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
9850Sstevel@tonic-gate 	adr_short(&adr, (short *)&iport, 1);
9860Sstevel@tonic-gate 
9870Sstevel@tonic-gate 	return (token);
9880Sstevel@tonic-gate }
9890Sstevel@tonic-gate 
9900Sstevel@tonic-gate token_t *
au_to_ipc(char type,int id)9910Sstevel@tonic-gate au_to_ipc(char type, int id)
9920Sstevel@tonic-gate {
9930Sstevel@tonic-gate 	token_t *token;			/* local token */
9940Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
9950Sstevel@tonic-gate 	char data_header = AUT_IPC;	/* header for this token */
9960Sstevel@tonic-gate 
9970Sstevel@tonic-gate 	token = get_token((2 * sizeof (char)) + sizeof (int32_t));
9980Sstevel@tonic-gate 	if (token == NULL)
9990Sstevel@tonic-gate 		return (NULL);
10000Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
10010Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
10020Sstevel@tonic-gate 	adr_char(&adr, &type, 1);
10030Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&id, 1);
10040Sstevel@tonic-gate 
10050Sstevel@tonic-gate 	return (token);
10060Sstevel@tonic-gate }
10070Sstevel@tonic-gate 
10080Sstevel@tonic-gate /*
10090Sstevel@tonic-gate  * au_to_tid
10100Sstevel@tonic-gate  *
10110Sstevel@tonic-gate  * output format depends on type; at present only IP v4 and v6 addresses
10120Sstevel@tonic-gate  * are defined.
10130Sstevel@tonic-gate  *
10140Sstevel@tonic-gate  * IPv4 -- tid type, 16 bit remote port, 16 bit local port, ip type,
10150Sstevel@tonic-gate  *		32 bit IP address.
10160Sstevel@tonic-gate  * IPv6 -- tid type, 16 bit remote port, 16 bit local port, ip type,
10170Sstevel@tonic-gate  *		4 x 32 bit IP address.
10180Sstevel@tonic-gate  *
10190Sstevel@tonic-gate  */
10200Sstevel@tonic-gate token_t *
au_to_tid(au_generic_tid_t * tid)10210Sstevel@tonic-gate au_to_tid(au_generic_tid_t *tid)
10220Sstevel@tonic-gate {
10230Sstevel@tonic-gate 	char		data_header = AUT_TID;	/* header for this token */
10240Sstevel@tonic-gate 	adr_t		adr;			/* adr memory stream header */
10250Sstevel@tonic-gate 	token_t		*token;			/* local token */
10260Sstevel@tonic-gate 	au_ip_t		*ip;
10270Sstevel@tonic-gate 
10280Sstevel@tonic-gate 	switch (tid->gt_type) {
10290Sstevel@tonic-gate 	case AU_IPADR:
10300Sstevel@tonic-gate 		ip = &(tid->gt_adr.at_ip);
10310Sstevel@tonic-gate 		token = get_token((int)(2 * sizeof (char) + 2 * sizeof (short) +
10325012Sgww 		    sizeof (uint32_t) + ip->at_type));
10330Sstevel@tonic-gate 		if (token == NULL)
10340Sstevel@tonic-gate 			return (NULL);
10350Sstevel@tonic-gate 
10360Sstevel@tonic-gate 		adr_start(&adr, token->tt_data);
10370Sstevel@tonic-gate 		adr_char(&adr, &data_header, 1);
10380Sstevel@tonic-gate 		adr_char(&adr, (char *)&(tid->gt_type), 1);
10390Sstevel@tonic-gate 		adr_short(&adr, (short *)&(ip->at_r_port), 1);
10400Sstevel@tonic-gate 		adr_short(&adr, (short *)&(ip->at_l_port), 1);
10410Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)&(ip->at_type), 1);
10420Sstevel@tonic-gate 
10430Sstevel@tonic-gate 		adr_char(&adr, (char *)ip->at_addr, ip->at_type);
10440Sstevel@tonic-gate 
10450Sstevel@tonic-gate 		break;
10460Sstevel@tonic-gate 	default:
10470Sstevel@tonic-gate 		return (NULL);
10480Sstevel@tonic-gate 	}
10490Sstevel@tonic-gate 	return (token);
10500Sstevel@tonic-gate }
10510Sstevel@tonic-gate 
10520Sstevel@tonic-gate /*
10530Sstevel@tonic-gate  * The Modifier tokens
10540Sstevel@tonic-gate  */
10550Sstevel@tonic-gate 
10560Sstevel@tonic-gate /*
10570Sstevel@tonic-gate  * au_to_groups
10580Sstevel@tonic-gate  * return s:
10590Sstevel@tonic-gate  *	pointer to a group list token.
10600Sstevel@tonic-gate  *
10610Sstevel@tonic-gate  * This function is obsolete.  Please use au_to_newgroups.
10620Sstevel@tonic-gate  */
10630Sstevel@tonic-gate token_t *
au_to_groups(int * groups)10640Sstevel@tonic-gate au_to_groups(int *groups)
10650Sstevel@tonic-gate {
10660Sstevel@tonic-gate 	token_t *token;			/* local token */
10670Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
10680Sstevel@tonic-gate 	char data_header = AUT_GROUPS;	/* header for this token */
10690Sstevel@tonic-gate 
10700Sstevel@tonic-gate 	token = get_token(sizeof (char) + NGROUPS * sizeof (int32_t));
10710Sstevel@tonic-gate 	if (token == NULL)
10720Sstevel@tonic-gate 		return (NULL);
10730Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
10740Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
10750Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)groups, NGROUPS);
10760Sstevel@tonic-gate 
10770Sstevel@tonic-gate 	return (token);
10780Sstevel@tonic-gate }
10790Sstevel@tonic-gate 
10800Sstevel@tonic-gate /*
10810Sstevel@tonic-gate  * au_to_newgroups
10820Sstevel@tonic-gate  * return s:
10830Sstevel@tonic-gate  *	pointer to a group list token.
10840Sstevel@tonic-gate  */
10850Sstevel@tonic-gate token_t *
au_to_newgroups(int n,gid_t * groups)10860Sstevel@tonic-gate au_to_newgroups(int n, gid_t *groups)
10870Sstevel@tonic-gate {
10880Sstevel@tonic-gate 	token_t *token;			/* local token */
10890Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
10900Sstevel@tonic-gate 	char data_header = AUT_NEWGROUPS;	/* header for this token */
10910Sstevel@tonic-gate 	short n_groups;
10920Sstevel@tonic-gate 
109311134SCasper.Dik@Sun.COM 	if (n < 0 || n > SHRT_MAX || groups == NULL)
10940Sstevel@tonic-gate 		return (NULL);
10950Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (short) + n * sizeof (gid_t));
10960Sstevel@tonic-gate 	if (token == NULL)
10970Sstevel@tonic-gate 		return (NULL);
10980Sstevel@tonic-gate 	n_groups = (short)n;
10990Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
11000Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
11010Sstevel@tonic-gate 	adr_short(&adr, &n_groups, 1);
11020Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)groups, n_groups);
11030Sstevel@tonic-gate 
11040Sstevel@tonic-gate 	return (token);
11050Sstevel@tonic-gate }
11060Sstevel@tonic-gate 
11070Sstevel@tonic-gate /*
11080Sstevel@tonic-gate  * au_to_exec_args
11090Sstevel@tonic-gate  * returns:
11100Sstevel@tonic-gate  *	pointer to an exec args token.
11110Sstevel@tonic-gate  */
11120Sstevel@tonic-gate token_t *
au_to_exec_args(char ** argv)11130Sstevel@tonic-gate au_to_exec_args(char **argv)
11140Sstevel@tonic-gate {
11150Sstevel@tonic-gate 	return (au_to_exec(argv, AUT_EXEC_ARGS));
11160Sstevel@tonic-gate }
11170Sstevel@tonic-gate 
11180Sstevel@tonic-gate /*
11190Sstevel@tonic-gate  * au_to_exec_env
11200Sstevel@tonic-gate  * returns:
11210Sstevel@tonic-gate  *	pointer to an exec args token.
11220Sstevel@tonic-gate  */
11230Sstevel@tonic-gate token_t *
au_to_exec_env(char ** envp)11240Sstevel@tonic-gate au_to_exec_env(char **envp)
11250Sstevel@tonic-gate {
11260Sstevel@tonic-gate 	return (au_to_exec(envp, AUT_EXEC_ENV));
11270Sstevel@tonic-gate }
11280Sstevel@tonic-gate 
11290Sstevel@tonic-gate /*
11300Sstevel@tonic-gate  * au_to_exec
11310Sstevel@tonic-gate  * returns:
11320Sstevel@tonic-gate  *	pointer to an exec args token.
11330Sstevel@tonic-gate  */
11340Sstevel@tonic-gate static token_t *
au_to_exec(char ** v,char data_header)11350Sstevel@tonic-gate au_to_exec(char **v, char data_header)
11360Sstevel@tonic-gate {
11370Sstevel@tonic-gate 	token_t *token;
11380Sstevel@tonic-gate 	adr_t adr;
11390Sstevel@tonic-gate 	char **p;
11400Sstevel@tonic-gate 	int32_t n = 0;
11410Sstevel@tonic-gate 	int len = 0;
11420Sstevel@tonic-gate 
11430Sstevel@tonic-gate 	for (p = v; *p != NULL; p++) {
11440Sstevel@tonic-gate 		len += strlen(*p) + 1;
11450Sstevel@tonic-gate 		n++;
11460Sstevel@tonic-gate 	}
11470Sstevel@tonic-gate 	token = get_token(sizeof (char) + sizeof (int32_t) + len);
11480Sstevel@tonic-gate 	if (token == (token_t *)NULL)
11490Sstevel@tonic-gate 		return ((token_t *)NULL);
11500Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
11510Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
11520Sstevel@tonic-gate 	adr_int32(&adr, &n, 1);
11530Sstevel@tonic-gate 	for (p = v; *p != NULL; p++) {
11540Sstevel@tonic-gate 		adr_char(&adr, *p, strlen(*p) + 1);
11550Sstevel@tonic-gate 	}
11560Sstevel@tonic-gate 	return (token);
11570Sstevel@tonic-gate }
11580Sstevel@tonic-gate 
11590Sstevel@tonic-gate /*
11600Sstevel@tonic-gate  * au_to_uauth
11610Sstevel@tonic-gate  * return s:
11620Sstevel@tonic-gate  *	pointer to a uauth token.
11630Sstevel@tonic-gate  */
11640Sstevel@tonic-gate token_t *
au_to_uauth(char * text)11650Sstevel@tonic-gate au_to_uauth(char *text)
11660Sstevel@tonic-gate {
11670Sstevel@tonic-gate 	token_t *token;			/* local token */
11680Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
11690Sstevel@tonic-gate 	char data_header = AUT_UAUTH;	/* header for this token */
11700Sstevel@tonic-gate 	short bytes;			/* length of string */
11710Sstevel@tonic-gate 
11720Sstevel@tonic-gate 	bytes = strlen(text) + 1;
11730Sstevel@tonic-gate 
11740Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
11750Sstevel@tonic-gate 	if (token == NULL)
11760Sstevel@tonic-gate 		return (NULL);
11770Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
11780Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
11790Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
11800Sstevel@tonic-gate 	adr_char(&adr, text, bytes);
11810Sstevel@tonic-gate 
11820Sstevel@tonic-gate 	return (token);
11830Sstevel@tonic-gate }
11840Sstevel@tonic-gate 
11850Sstevel@tonic-gate /*
11865012Sgww  * au_to_upriv
11875012Sgww  * return s:
11885012Sgww  *	pointer to a use of privilege token.
11895012Sgww  */
11905012Sgww token_t *
au_to_upriv(char sorf,char * priv)11915012Sgww au_to_upriv(char sorf, char *priv)
11925012Sgww {
11935012Sgww 	token_t *token;			/* local token */
11945012Sgww 	adr_t adr;			/* adr memory stream header */
11955012Sgww 	char data_header = AUT_UAUTH;	/* header for this token */
11965012Sgww 	short bytes;			/* length of string */
11975012Sgww 
11985012Sgww 	bytes = strlen(priv) + 1;
11995012Sgww 
12005012Sgww 	token = get_token(sizeof (char) + sizeof (char) + sizeof (short) +
12015012Sgww 	    bytes);
12025012Sgww 	if (token == NULL)
12035012Sgww 		return (NULL);
12045012Sgww 	adr_start(&adr, token->tt_data);
12055012Sgww 	adr_char(&adr, &data_header, 1);
12065012Sgww 	adr_char(&adr, &sorf, 1);	/* success/failure */
12075012Sgww 	adr_short(&adr, &bytes, 1);
12085012Sgww 	adr_char(&adr, priv, bytes);
12095012Sgww 
12105012Sgww 	return (token);
12115012Sgww }
12125012Sgww 
12135012Sgww /*
1214*11893Sgww@eng.sun.com  * au_to_user
1215*11893Sgww@eng.sun.com  * return s:
1216*11893Sgww@eng.sun.com  *	pointer to a user token.
1217*11893Sgww@eng.sun.com  */
1218*11893Sgww@eng.sun.com token_t *
au_to_user(uid_t uid,char * username)1219*11893Sgww@eng.sun.com au_to_user(uid_t uid,  char *username)
1220*11893Sgww@eng.sun.com {
1221*11893Sgww@eng.sun.com 	token_t *token;			/* local token */
1222*11893Sgww@eng.sun.com 	adr_t adr;			/* adr memory stream header */
1223*11893Sgww@eng.sun.com 	char data_header = AUT_USER;	/* header for this token */
1224*11893Sgww@eng.sun.com 	short  bytes;			/* length of string */
1225*11893Sgww@eng.sun.com 
1226*11893Sgww@eng.sun.com 	bytes = (short)strlen(username) + 1;
1227*11893Sgww@eng.sun.com 
1228*11893Sgww@eng.sun.com 	token = get_token(sizeof (char) + sizeof (uid_t) + sizeof (short) +
1229*11893Sgww@eng.sun.com 	    bytes);
1230*11893Sgww@eng.sun.com 	if (token == NULL)
1231*11893Sgww@eng.sun.com 		return (NULL);
1232*11893Sgww@eng.sun.com 	adr_start(&adr, token->tt_data);
1233*11893Sgww@eng.sun.com 	adr_char(&adr, &data_header, 1);
1234*11893Sgww@eng.sun.com 	adr_uid(&adr, &uid, 1);
1235*11893Sgww@eng.sun.com 	adr_short(&adr, &bytes, 1);
1236*11893Sgww@eng.sun.com 	adr_char(&adr, username, bytes);
1237*11893Sgww@eng.sun.com 
1238*11893Sgww@eng.sun.com 	return (token);
1239*11893Sgww@eng.sun.com }
1240*11893Sgww@eng.sun.com 
1241*11893Sgww@eng.sun.com /*
12420Sstevel@tonic-gate  * au_to_xatom
12430Sstevel@tonic-gate  * return s:
12440Sstevel@tonic-gate  *	pointer to a xatom token.
12450Sstevel@tonic-gate  */
12460Sstevel@tonic-gate token_t *
au_to_xatom(char * atom)12475012Sgww au_to_xatom(char *atom)
12480Sstevel@tonic-gate {
12490Sstevel@tonic-gate 	token_t *token;			/* local token */
12500Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
12510Sstevel@tonic-gate 	char data_header = AUT_XATOM;	/* header for this token */
12525012Sgww 	short len;
12530Sstevel@tonic-gate 
12545012Sgww 	len = strlen(atom) + 1;
12555012Sgww 
12565012Sgww 	token = get_token(sizeof (char) + sizeof (short) + len);
12570Sstevel@tonic-gate 	if (token == NULL)
12580Sstevel@tonic-gate 		return (NULL);
12590Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
12600Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
12610Sstevel@tonic-gate 	adr_short(&adr, (short *)&len, 1);
12620Sstevel@tonic-gate 	adr_char(&adr, atom, len);
12630Sstevel@tonic-gate 
12640Sstevel@tonic-gate 	return (token);
12650Sstevel@tonic-gate }
12660Sstevel@tonic-gate 
12670Sstevel@tonic-gate /*
12685012Sgww  * au_to_xselect
12690Sstevel@tonic-gate  * return s:
12705012Sgww  *	pointer to a X select token.
12710Sstevel@tonic-gate  */
12720Sstevel@tonic-gate token_t *
au_to_xselect(char * propname,char * proptype,char * windata)12735012Sgww au_to_xselect(char *propname, char *proptype, char *windata)
12740Sstevel@tonic-gate {
12750Sstevel@tonic-gate 	token_t *token;			/* local token */
12760Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
12775012Sgww 	char data_header = AUT_XSELECT;	/* header for this token */
12785012Sgww 	short proplen;
12795012Sgww 	short typelen;
12805012Sgww 	short datalen;
12810Sstevel@tonic-gate 
12825012Sgww 	proplen = strlen(propname) + 1;
12835012Sgww 	typelen = strlen(proptype) + 1;
12845012Sgww 	datalen = strlen(windata) + 1;
12855012Sgww 
12865012Sgww 	token = get_token(sizeof (char) + (sizeof (short) * 3) +
12875012Sgww 	    proplen + typelen + datalen);
12880Sstevel@tonic-gate 	if (token == NULL)
12890Sstevel@tonic-gate 		return (NULL);
12900Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
12910Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
12925012Sgww 	adr_short(&adr, &proplen, 1);
12935012Sgww 	adr_char(&adr, propname, proplen);
12945012Sgww 	adr_short(&adr, &typelen, 1);
12955012Sgww 	adr_char(&adr, proptype, typelen);
12965012Sgww 	adr_short(&adr, &datalen, 1);
12975012Sgww 	adr_char(&adr, windata, datalen);
12985012Sgww 
12995012Sgww 	return (token);
13005012Sgww }
13015012Sgww 
13025012Sgww /*
13035012Sgww  * x_common
13045012Sgww  * return s:
13055012Sgww  *	pointer to a common X token.
13065012Sgww  */
13075012Sgww 
13085012Sgww static token_t *
x_common(char data_header,int32_t xid,uid_t cuid)13095012Sgww x_common(char data_header, int32_t xid, uid_t cuid)
13105012Sgww {
13115012Sgww 	token_t *token;			/* local token */
13125012Sgww 	adr_t adr;			/* adr memory stream header */
13135012Sgww 
13145012Sgww 	token = get_token(sizeof (char) + sizeof (int32_t) + sizeof (uid_t));
13155012Sgww 	if (token == NULL)
13165012Sgww 		return (NULL);
13175012Sgww 	adr_start(&adr, token->tt_data);
13185012Sgww 	adr_char(&adr, &data_header, 1);
13195012Sgww 	adr_int32(&adr, &xid, 1);
13205012Sgww 	adr_uid(&adr, &cuid, 1);
13210Sstevel@tonic-gate 
13220Sstevel@tonic-gate 	return (token);
13230Sstevel@tonic-gate }
13240Sstevel@tonic-gate 
13250Sstevel@tonic-gate /*
13265012Sgww  * au_to_xcolormap
13275012Sgww  * return s:
13285012Sgww  *	pointer to a X Colormap token.
13295012Sgww  */
13305012Sgww 
13315012Sgww token_t *
au_to_xcolormap(int32_t xid,uid_t cuid)13325012Sgww au_to_xcolormap(int32_t xid, uid_t cuid)
13335012Sgww {
13345012Sgww 	return (x_common(AUT_XCOLORMAP, xid, cuid));
13355012Sgww }
13365012Sgww 
13375012Sgww /*
13385012Sgww  * au_to_xcursor
13395012Sgww  * return s:
13405012Sgww  *	pointer to a X Cursor token.
13415012Sgww  */
13425012Sgww 
13435012Sgww token_t *
au_to_xcursor(int32_t xid,uid_t cuid)13445012Sgww au_to_xcursor(int32_t xid, uid_t cuid)
13455012Sgww {
13465012Sgww 	return (x_common(AUT_XCURSOR, xid, cuid));
13475012Sgww }
13485012Sgww 
13495012Sgww /*
13505012Sgww  * au_to_xfont
13515012Sgww  * return s:
13525012Sgww  *	pointer to a X Font token.
13535012Sgww  */
13545012Sgww 
13555012Sgww token_t *
au_to_xfont(int32_t xid,uid_t cuid)13565012Sgww au_to_xfont(int32_t xid, uid_t cuid)
13575012Sgww {
13585012Sgww 	return (x_common(AUT_XFONT, xid, cuid));
13595012Sgww }
13605012Sgww 
13615012Sgww /*
13625012Sgww  * au_to_xgc
13630Sstevel@tonic-gate  * return s:
13645012Sgww  *	pointer to a X Graphic Context token.
13655012Sgww  */
13665012Sgww 
13675012Sgww token_t *
au_to_xgc(int32_t xid,uid_t cuid)13685012Sgww au_to_xgc(int32_t xid, uid_t cuid)
13695012Sgww {
13705012Sgww 	return (x_common(AUT_XGC, xid, cuid));
13715012Sgww }
13725012Sgww 
13735012Sgww /*
13745012Sgww  * au_to_xpixmap
13755012Sgww  * return s:
13765012Sgww  *	pointer to a X Pixal Map token.
13770Sstevel@tonic-gate  */
13785012Sgww 
13790Sstevel@tonic-gate token_t *
au_to_xpixmap(int32_t xid,uid_t cuid)13805012Sgww au_to_xpixmap(int32_t xid, uid_t cuid)
13815012Sgww {
13825012Sgww 	return (x_common(AUT_XPIXMAP, xid, cuid));
13835012Sgww }
13845012Sgww 
13855012Sgww /*
13865012Sgww  * au_to_xwindow
13875012Sgww  * return s:
13885012Sgww  *	pointer to a X Window token.
13895012Sgww  */
13905012Sgww 
13915012Sgww token_t *
au_to_xwindow(int32_t xid,uid_t cuid)13925012Sgww au_to_xwindow(int32_t xid, uid_t cuid)
13935012Sgww {
13945012Sgww 	return (x_common(AUT_XWINDOW, xid, cuid));
13955012Sgww }
13965012Sgww 
13975012Sgww /*
13985012Sgww  * au_to_xproperty
13995012Sgww  * return s:
14005012Sgww  *	pointer to a X Property token.
14015012Sgww  */
14025012Sgww 
14035012Sgww token_t *
au_to_xproperty(int32_t xid,uid_t cuid,char * propname)14045012Sgww au_to_xproperty(int32_t xid, uid_t cuid, char *propname)
14050Sstevel@tonic-gate {
14060Sstevel@tonic-gate 	token_t *token;			/* local token */
14070Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
14085012Sgww 	char data_header = AUT_XPROPERTY;	/* header for this token */
14095012Sgww 	short proplen;
14100Sstevel@tonic-gate 
14115012Sgww 	proplen = strlen(propname) + 1;
14125012Sgww 
14135012Sgww 	token = get_token(sizeof (char) + sizeof (int32_t) + sizeof (uid_t) +
14145012Sgww 	    sizeof (short) + proplen);
14150Sstevel@tonic-gate 	if (token == NULL)
14160Sstevel@tonic-gate 		return (NULL);
14170Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
14180Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
14195012Sgww 	adr_int32(&adr, &xid, 1);
14205012Sgww 	adr_uid(&adr, &cuid, 1);
14215012Sgww 	adr_short(&adr, &proplen, 1);
14225012Sgww 	adr_char(&adr, propname, proplen);
14230Sstevel@tonic-gate 
14240Sstevel@tonic-gate 	return (token);
14250Sstevel@tonic-gate }
14260Sstevel@tonic-gate 
14270Sstevel@tonic-gate /*
14285012Sgww  * au_to_xclient
14290Sstevel@tonic-gate  * return s:
14305012Sgww  *	pointer to a X Client token
14310Sstevel@tonic-gate  */
14325012Sgww 
14330Sstevel@tonic-gate token_t *
au_to_xclient(uint32_t client)14345012Sgww au_to_xclient(uint32_t client)
14350Sstevel@tonic-gate {
14360Sstevel@tonic-gate 	token_t *token;			/* local token */
14370Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
14385012Sgww 	char data_header = AUT_XCLIENT;	/* header for this token */
14390Sstevel@tonic-gate 
14405012Sgww 	token = get_token(sizeof (char) + sizeof (uint32_t));
14410Sstevel@tonic-gate 	if (token == NULL)
14420Sstevel@tonic-gate 		return (NULL);
14430Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
14440Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
14455012Sgww 	adr_int32(&adr, (int32_t *)&client, 1);
14465012Sgww 
14470Sstevel@tonic-gate 	return (token);
14480Sstevel@tonic-gate }
14490Sstevel@tonic-gate 
14500Sstevel@tonic-gate /*
14511676Sjpk  * au_to_label
14521676Sjpk  * return s:
14532376Sgww  *	pointer to a label token.
14541676Sjpk  */
14551676Sjpk token_t *
au_to_label(m_label_t * label)14562376Sgww au_to_label(m_label_t *label)
14571676Sjpk {
14581676Sjpk 	token_t *token;			/* local token */
14591676Sjpk 	adr_t adr;			/* adr memory stream header */
14601676Sjpk 	char data_header = AUT_LABEL;	/* header for this token */
14619112STon.Nguyen@Sun.COM 	size32_t llen = blabel_size();
14621676Sjpk 
14632376Sgww 	token = get_token(sizeof (char) + llen);
14642376Sgww 	if (token == NULL) {
14651676Sjpk 		return (NULL);
14662376Sgww 	} else if (label == NULL) {
14672376Sgww 		free(token);
14682376Sgww 		return (NULL);
14692376Sgww 	}
14701676Sjpk 	adr_start(&adr, token->tt_data);
14711676Sjpk 	adr_char(&adr, &data_header, 1);
14722376Sgww 	adr_char(&adr, (char *)label, llen);
14731676Sjpk 
14741676Sjpk 	return (token);
14751676Sjpk }
14761676Sjpk 
14771676Sjpk /*
14781676Sjpk  * au_to_mylabel
14791676Sjpk  * return s:
14802376Sgww  *	pointer to a label token.
14811676Sjpk  */
14821676Sjpk token_t *
au_to_mylabel(void)14831676Sjpk au_to_mylabel(void)
14841676Sjpk {
14852376Sgww 	ucred_t		*uc;
14862376Sgww 	token_t		*token;
14871676Sjpk 
14882376Sgww 	if ((uc = ucred_get(P_MYID)) == NULL) {
14892376Sgww 		return (NULL);
14901676Sjpk 	}
14912376Sgww 
14922376Sgww 	token = au_to_label(ucred_getlabel(uc));
14932376Sgww 	ucred_free(uc);
14942376Sgww 	return (token);
14951676Sjpk }
14961676Sjpk 
14971676Sjpk /*
14980Sstevel@tonic-gate  * au_to_zonename
14990Sstevel@tonic-gate  * return s:
15000Sstevel@tonic-gate  *	pointer to a zonename token.
15010Sstevel@tonic-gate  */
15020Sstevel@tonic-gate token_t *
au_to_zonename(char * name)15030Sstevel@tonic-gate au_to_zonename(char *name)
15040Sstevel@tonic-gate {
15050Sstevel@tonic-gate 	token_t *token;			/* local token */
15060Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
15070Sstevel@tonic-gate 	char data_header = AUT_ZONENAME;	/* header for this token */
15080Sstevel@tonic-gate 	short bytes;			/* length of string */
15090Sstevel@tonic-gate 
15100Sstevel@tonic-gate 	if (name == NULL)
15110Sstevel@tonic-gate 		return (NULL);
15120Sstevel@tonic-gate 
15130Sstevel@tonic-gate 	bytes = strlen(name) + 1;
15140Sstevel@tonic-gate 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
15150Sstevel@tonic-gate 	if (token == NULL)
15160Sstevel@tonic-gate 		return (NULL);
15170Sstevel@tonic-gate 	adr_start(&adr, token->tt_data);
15180Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
15190Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
15200Sstevel@tonic-gate 	adr_char(&adr, name, bytes);
15210Sstevel@tonic-gate 
15220Sstevel@tonic-gate 	return (token);
15230Sstevel@tonic-gate }
15241780Sgww 
15251780Sgww /*
15261780Sgww  * au_to_fmri
15271780Sgww  * return s:
15281780Sgww  *	pointer to a fmri token.
15291780Sgww  */
15301780Sgww token_t *
au_to_fmri(char * fmri)15311780Sgww au_to_fmri(char *fmri)
15321780Sgww {
15331780Sgww 	token_t *token;			/* local token */
15341780Sgww 	adr_t adr;			/* adr memory stream header */
15351780Sgww 	char data_header = AUT_FMRI;	/* header for this token */
15361780Sgww 	short bytes;			/* length of string */
15371780Sgww 
15381780Sgww 	if (fmri == NULL)
15391780Sgww 		return (NULL);
15401780Sgww 
15411780Sgww 	bytes = strlen(fmri) + 1;
15421780Sgww 	token = get_token((int)(sizeof (char) + sizeof (short) + bytes));
15431780Sgww 	if (token == NULL)
15441780Sgww 		return (NULL);
15451780Sgww 	adr_start(&adr, token->tt_data);
15461780Sgww 	adr_char(&adr, &data_header, 1);
15471780Sgww 	adr_short(&adr, &bytes, 1);
15481780Sgww 	adr_char(&adr, fmri, bytes);
15491780Sgww 
15501780Sgww 	return (token);
15511780Sgww }
1552