xref: /illumos-gate/usr/src/uts/common/c2/audit_token.c (revision d2a70789)
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 /*
2261b9bf51Srica  * Copyright 2008 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  * Support routines for building audit records.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/param.h>
317c478bd9Sstevel@tonic-gate #include <sys/systm.h>		/* for rval */
327c478bd9Sstevel@tonic-gate #include <sys/time.h>
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
357c478bd9Sstevel@tonic-gate #include <sys/mode.h>
367c478bd9Sstevel@tonic-gate #include <sys/user.h>
377c478bd9Sstevel@tonic-gate #include <sys/session.h>
387c478bd9Sstevel@tonic-gate #include <sys/acl.h>
397c478bd9Sstevel@tonic-gate #include <sys/ipc_impl.h>
407c478bd9Sstevel@tonic-gate #include <netinet/in_systm.h>
417c478bd9Sstevel@tonic-gate #include <netinet/in.h>
427c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
437c478bd9Sstevel@tonic-gate #include <sys/socket.h>
447c478bd9Sstevel@tonic-gate #include <net/route.h>
457c478bd9Sstevel@tonic-gate #include <netinet/in_pcb.h>
467c478bd9Sstevel@tonic-gate #include <c2/audit.h>
477c478bd9Sstevel@tonic-gate #include <c2/audit_kernel.h>
487c478bd9Sstevel@tonic-gate #include <c2/audit_record.h>
497c478bd9Sstevel@tonic-gate #include <sys/model.h>		/* for model_t */
507c478bd9Sstevel@tonic-gate #include <sys/vmparam.h>	/* for USRSTACK/USRSTACK32 */
517c478bd9Sstevel@tonic-gate #include <sys/vfs.h>		/* for sonode */
527c478bd9Sstevel@tonic-gate #include <sys/socketvar.h>	/* for sonode */
537c478bd9Sstevel@tonic-gate #include <sys/zone.h>
5445916cd2Sjpk #include <sys/tsol/label.h>
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * These are the control tokens
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * au_to_header
627c478bd9Sstevel@tonic-gate  * returns:
637c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a header token.
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate token_t *
au_to_header(int byte_count,au_event_t e_type,au_emod_t e_mod)66d0fa49b7STony Nguyen au_to_header(int byte_count, au_event_t e_type, au_emod_t e_mod)
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
697c478bd9Sstevel@tonic-gate 	token_t *m;			/* au_membuf pointer */
707c478bd9Sstevel@tonic-gate #ifdef _LP64
717c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER64;	/* header for this token */
727c478bd9Sstevel@tonic-gate 	static int64_t zerotime[2];
737c478bd9Sstevel@tonic-gate #else
747c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER32;
757c478bd9Sstevel@tonic-gate 	static int32_t zerotime[2];
767c478bd9Sstevel@tonic-gate #endif
777c478bd9Sstevel@tonic-gate 	char version = TOKEN_VERSION;	/* version of token family */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	m = au_getclr();
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
827c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
837c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&byte_count, 1);	/* length of */
847c478bd9Sstevel@tonic-gate 							/* audit record */
857c478bd9Sstevel@tonic-gate 	adr_char(&adr, &version, 1);		/* version of audit tokens */
86d0fa49b7STony Nguyen 	adr_ushort(&adr, &e_type, 1);		/* event ID */
87d0fa49b7STony Nguyen 	adr_ushort(&adr, &e_mod, 1);		/* event ID modifier */
887c478bd9Sstevel@tonic-gate #ifdef _LP64
897c478bd9Sstevel@tonic-gate 	adr_int64(&adr, zerotime, 2);		/* time & date space */
907c478bd9Sstevel@tonic-gate #else
917c478bd9Sstevel@tonic-gate 	adr_int32(&adr, zerotime, 2);
927c478bd9Sstevel@tonic-gate #endif
937c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	return (m);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate token_t *
au_to_header_ex(int byte_count,au_event_t e_type,au_emod_t e_mod)997c478bd9Sstevel@tonic-gate au_to_header_ex(int byte_count, au_event_t e_type, au_emod_t e_mod)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
1027c478bd9Sstevel@tonic-gate 	token_t *m;			/* au_membuf pointer */
1039e9e6ab8Spaulson 	au_kcontext_t	*kctx = GET_KCTX_PZ;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #ifdef _LP64
1067c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER64_EX;	/* header for this token */
1077c478bd9Sstevel@tonic-gate 	static int64_t zerotime[2];
1087c478bd9Sstevel@tonic-gate #else
1097c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER32_EX;
1107c478bd9Sstevel@tonic-gate 	static int32_t zerotime[2];
1117c478bd9Sstevel@tonic-gate #endif
1127c478bd9Sstevel@tonic-gate 	char version = TOKEN_VERSION;	/* version of token family */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	m = au_getclr();
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
1177c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
1187c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&byte_count, 1);	/* length of */
1197c478bd9Sstevel@tonic-gate 							/* audit record */
1207c478bd9Sstevel@tonic-gate 	adr_char(&adr, &version, 1);		/* version of audit tokens */
121d0fa49b7STony Nguyen 	adr_ushort(&adr, &e_type, 1);		/* event ID */
122d0fa49b7STony Nguyen 	adr_ushort(&adr, &e_mod, 1);		/* event ID modifier */
1237c478bd9Sstevel@tonic-gate 	adr_uint32(&adr, &kctx->auk_info.ai_termid.at_type, 1);
1247c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)&kctx->auk_info.ai_termid.at_addr[0],
1257c478bd9Sstevel@tonic-gate 	    (int)kctx->auk_info.ai_termid.at_type);
1267c478bd9Sstevel@tonic-gate #ifdef _LP64
1277c478bd9Sstevel@tonic-gate 	adr_int64(&adr, zerotime, 2);		/* time & date */
1287c478bd9Sstevel@tonic-gate #else
1297c478bd9Sstevel@tonic-gate 	adr_int32(&adr, zerotime, 2);
1307c478bd9Sstevel@tonic-gate #endif
1317c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	return (m);
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * au_to_trailer
1387c478bd9Sstevel@tonic-gate  * returns:
1397c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a trailer token.
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate token_t *
au_to_trailer(int byte_count)1427c478bd9Sstevel@tonic-gate au_to_trailer(int byte_count)
1437c478bd9Sstevel@tonic-gate {
1447c478bd9Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
1457c478bd9Sstevel@tonic-gate 	token_t *m;				/* au_membuf pointer */
1467c478bd9Sstevel@tonic-gate 	char data_header = AUT_TRAILER;		/* header for this token */
1477c478bd9Sstevel@tonic-gate 	short magic = (short)AUT_TRAILER_MAGIC; /* trailer magic number */
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	m = au_getclr();
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
1527c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);		/* token ID */
1537c478bd9Sstevel@tonic-gate 	adr_short(&adr, &magic, 1);			/* magic number */
1547c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&byte_count, 1);	/* length of */
1557c478bd9Sstevel@tonic-gate 							/* audit record */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	return (m);
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * These are the data tokens
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate  * au_to_data
1677c478bd9Sstevel@tonic-gate  * returns:
1687c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a data token.
1697c478bd9Sstevel@tonic-gate  */
1707c478bd9Sstevel@tonic-gate token_t *
au_to_data(char unit_print,char unit_type,char unit_count,char * p)1717c478bd9Sstevel@tonic-gate au_to_data(char unit_print, char unit_type, char unit_count, char *p)
1727c478bd9Sstevel@tonic-gate {
1737c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
1747c478bd9Sstevel@tonic-gate 	token_t *m;			/* au_membuf pointer */
1757c478bd9Sstevel@tonic-gate 	char data_header = AUT_DATA;	/* header for this token */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	ASSERT(p != NULL);
1787c478bd9Sstevel@tonic-gate 	ASSERT(unit_count != 0);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	switch (unit_type) {
1817c478bd9Sstevel@tonic-gate 	case AUR_SHORT:
1827c478bd9Sstevel@tonic-gate 		if (sizeof (short) * unit_count >= AU_BUFSIZE)
1837c478bd9Sstevel@tonic-gate 			return (au_to_text("au_to_data: unit count too big"));
1847c478bd9Sstevel@tonic-gate 		break;
1857c478bd9Sstevel@tonic-gate 	case AUR_INT32:
1867c478bd9Sstevel@tonic-gate 		if (sizeof (int32_t) * unit_count >= AU_BUFSIZE)
1877c478bd9Sstevel@tonic-gate 			return (au_to_text("au_to_data: unit count too big"));
1887c478bd9Sstevel@tonic-gate 		break;
1897c478bd9Sstevel@tonic-gate 	case AUR_INT64:
1907c478bd9Sstevel@tonic-gate 		if (sizeof (int64_t) * unit_count >= AU_BUFSIZE)
1917c478bd9Sstevel@tonic-gate 			return (au_to_text("au_to_data: unit count too big"));
1927c478bd9Sstevel@tonic-gate 		break;
1937c478bd9Sstevel@tonic-gate 	case AUR_BYTE:
1947c478bd9Sstevel@tonic-gate 	default:
1957c478bd9Sstevel@tonic-gate #ifdef _CHAR_IS_UNSIGNED
1967c478bd9Sstevel@tonic-gate 		if (sizeof (char) * unit_count >= AU_BUFSIZE)
1977c478bd9Sstevel@tonic-gate 			return (au_to_text("au_to_data: unit count too big"));
1987c478bd9Sstevel@tonic-gate #endif
1997c478bd9Sstevel@tonic-gate 		/*
2007c478bd9Sstevel@tonic-gate 		 * we used to check for this:
2017c478bd9Sstevel@tonic-gate 		 * sizeof (char) * (int)unit_count >= AU_BUFSIZE).
2027c478bd9Sstevel@tonic-gate 		 * but the compiler is smart enough to see that
2037c478bd9Sstevel@tonic-gate 		 * will never be >= AU_BUFSIZE, since that's 128
2047c478bd9Sstevel@tonic-gate 		 * and unit_count maxes out at 127 (signed char),
2057c478bd9Sstevel@tonic-gate 		 * and complain.
2067c478bd9Sstevel@tonic-gate 		 */
2077c478bd9Sstevel@tonic-gate 		break;
2087c478bd9Sstevel@tonic-gate 	}
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	m = au_getclr();
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
2137c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
2147c478bd9Sstevel@tonic-gate 	adr_char(&adr, &unit_print, 1);
2157c478bd9Sstevel@tonic-gate 	adr_char(&adr, &unit_type, 1);
2167c478bd9Sstevel@tonic-gate 	adr_char(&adr, &unit_count, 1);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	switch (unit_type) {
2197c478bd9Sstevel@tonic-gate 	case AUR_SHORT:
2207c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)p, unit_count);
2217c478bd9Sstevel@tonic-gate 		break;
2227c478bd9Sstevel@tonic-gate 	case AUR_INT32:
2237c478bd9Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)p, unit_count);
2247c478bd9Sstevel@tonic-gate 		break;
2257c478bd9Sstevel@tonic-gate 	case AUR_INT64:
2267c478bd9Sstevel@tonic-gate 		adr_int64(&adr, (int64_t *)p, unit_count);
2277c478bd9Sstevel@tonic-gate 		break;
2287c478bd9Sstevel@tonic-gate 	case AUR_BYTE:
2297c478bd9Sstevel@tonic-gate 	default:
2307c478bd9Sstevel@tonic-gate 		adr_char(&adr, p, unit_count);
2317c478bd9Sstevel@tonic-gate 		break;
2327c478bd9Sstevel@tonic-gate 	}
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	return (m);
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * au_to_process
2417c478bd9Sstevel@tonic-gate  * au_to_subject
2427c478bd9Sstevel@tonic-gate  * returns:
2437c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a process token.
2447c478bd9Sstevel@tonic-gate  */
2457c478bd9Sstevel@tonic-gate static token_t *au_to_any_process(char, uid_t, gid_t, uid_t, gid_t,
2467c478bd9Sstevel@tonic-gate     pid_t, au_id_t, au_asid_t, const au_tid_addr_t *atid);
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate token_t *
au_to_process(uid_t uid,gid_t gid,uid_t ruid,gid_t rgid,pid_t pid,au_id_t auid,au_asid_t asid,const au_tid_addr_t * atid)2497c478bd9Sstevel@tonic-gate au_to_process(uid_t uid, gid_t gid, uid_t ruid, gid_t rgid, pid_t pid,
2507c478bd9Sstevel@tonic-gate     au_id_t auid, au_asid_t asid, const au_tid_addr_t *atid)
2517c478bd9Sstevel@tonic-gate {
2527c478bd9Sstevel@tonic-gate 	char data_header;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate #ifdef _LP64
2557c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6)
2567c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS64_EX;
2577c478bd9Sstevel@tonic-gate 	else
2587c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS64;
2597c478bd9Sstevel@tonic-gate #else
2607c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6)
2617c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS32_EX;
2627c478bd9Sstevel@tonic-gate 	else
2637c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS32;
2647c478bd9Sstevel@tonic-gate #endif
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	return (au_to_any_process(data_header, uid, gid, ruid,
2677c478bd9Sstevel@tonic-gate 	    rgid, pid, auid, asid, atid));
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate token_t *
au_to_subject(uid_t uid,gid_t gid,uid_t ruid,gid_t rgid,pid_t pid,au_id_t auid,au_asid_t asid,const au_tid_addr_t * atid)2717c478bd9Sstevel@tonic-gate au_to_subject(uid_t uid, gid_t gid, uid_t ruid, gid_t rgid, pid_t pid,
2727c478bd9Sstevel@tonic-gate     au_id_t auid, au_asid_t asid, const au_tid_addr_t *atid)
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate 	char data_header;
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate #ifdef _LP64
2777c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6)
2787c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT64_EX;
2797c478bd9Sstevel@tonic-gate 	else
2807c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT64;
2817c478bd9Sstevel@tonic-gate #else
2827c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6)
2837c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT32_EX;
2847c478bd9Sstevel@tonic-gate 	else
2857c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT32;
2867c478bd9Sstevel@tonic-gate #endif
2877c478bd9Sstevel@tonic-gate 	return (au_to_any_process(data_header, uid, gid, ruid,
2887c478bd9Sstevel@tonic-gate 	    rgid, pid, auid, asid, atid));
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate static token_t *
au_to_any_process(char data_header,uid_t uid,gid_t gid,uid_t ruid,gid_t rgid,pid_t pid,au_id_t auid,au_asid_t asid,const au_tid_addr_t * atid)2937c478bd9Sstevel@tonic-gate au_to_any_process(char data_header,
2947c478bd9Sstevel@tonic-gate     uid_t uid, gid_t gid, uid_t ruid, gid_t rgid, pid_t pid,
2957c478bd9Sstevel@tonic-gate     au_id_t auid, au_asid_t asid, const au_tid_addr_t *atid)
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate 	token_t *m;	/* local au_membuf */
2987c478bd9Sstevel@tonic-gate 	adr_t adr;	/* adr memory stream header */
2997c478bd9Sstevel@tonic-gate 	int32_t value;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	m = au_getclr();
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
3047c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
3057c478bd9Sstevel@tonic-gate 	value = (int32_t)auid;
3067c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
3077c478bd9Sstevel@tonic-gate 	value = (int32_t)uid;
3087c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
3097c478bd9Sstevel@tonic-gate 	value = (int32_t)gid;
3107c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
3117c478bd9Sstevel@tonic-gate 	value = (int32_t)ruid;
3127c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
3137c478bd9Sstevel@tonic-gate 	value = (int32_t)rgid;
3147c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
3157c478bd9Sstevel@tonic-gate 	value = (int32_t)pid;
3167c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
3177c478bd9Sstevel@tonic-gate 	value = (int32_t)asid;
3187c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
3197c478bd9Sstevel@tonic-gate #ifdef _LP64
3207c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(atid->at_port), 1);
3217c478bd9Sstevel@tonic-gate #else
3227c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(atid->at_port), 1);
3237c478bd9Sstevel@tonic-gate #endif
3247c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6) {
3257c478bd9Sstevel@tonic-gate 		adr_uint32(&adr, (uint_t *)&atid->at_type, 1);
3267c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&atid->at_addr[0], 16);
3277c478bd9Sstevel@tonic-gate 	} else {
3287c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&(atid->at_addr[0]), 4);
3297c478bd9Sstevel@tonic-gate 	}
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	return (m);
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate /*
3377c478bd9Sstevel@tonic-gate  * au_to_text
3387c478bd9Sstevel@tonic-gate  * returns:
3397c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a text token.
3407c478bd9Sstevel@tonic-gate  */
3417c478bd9Sstevel@tonic-gate token_t *
au_to_text(const char * text)3427c478bd9Sstevel@tonic-gate au_to_text(const char *text)
3437c478bd9Sstevel@tonic-gate {
3447c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
3457c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
3467c478bd9Sstevel@tonic-gate 	char data_header = AUT_TEXT;	/* header for this token */
3477c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	token = au_getclr();
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	bytes = (short)strlen(text) + 1;
3527c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
3537c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
3547c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	token->len = (char)adr_count(&adr);
3577c478bd9Sstevel@tonic-gate 	/*
3587c478bd9Sstevel@tonic-gate 	 * Now attach the text
3597c478bd9Sstevel@tonic-gate 	 */
3607c478bd9Sstevel@tonic-gate 	(void) au_append_buf(text, bytes, token);
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	return (token);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate  * au_zonename_length
3677c478bd9Sstevel@tonic-gate  * returns:
3687c478bd9Sstevel@tonic-gate  * -	length of zonename token to be generated
3697c478bd9Sstevel@tonic-gate  * -	zone name up to ZONENAME_MAX + 1 in length
3707c478bd9Sstevel@tonic-gate  */
3717c478bd9Sstevel@tonic-gate #define	ZONE_TOKEN_OVERHEAD 3
3727c478bd9Sstevel@tonic-gate 	/*
3737c478bd9Sstevel@tonic-gate 	 * the zone token is
3747c478bd9Sstevel@tonic-gate 	 * token id (1 byte)
3757c478bd9Sstevel@tonic-gate 	 * string length (2 bytes)
3767c478bd9Sstevel@tonic-gate 	 * the string (strlen(zonename) + 1)
3777c478bd9Sstevel@tonic-gate 	 */
3787c478bd9Sstevel@tonic-gate size_t
au_zonename_length(zone_t * zone)3791d7bfecdStz au_zonename_length(zone_t *zone)
3807c478bd9Sstevel@tonic-gate {
3811d7bfecdStz 	if (zone == NULL)
3821d7bfecdStz 		zone = curproc->p_zone;
3831d7bfecdStz 	return (strlen(zone->zone_name) + 1 +
3847c478bd9Sstevel@tonic-gate 	    ZONE_TOKEN_OVERHEAD);
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate /*
3887c478bd9Sstevel@tonic-gate  * au_to_zonename
3897c478bd9Sstevel@tonic-gate  *
3907c478bd9Sstevel@tonic-gate  * A length of zero input to au_to_zonename means the length is not
3917c478bd9Sstevel@tonic-gate  * pre-calculated.
3927c478bd9Sstevel@tonic-gate  *
3937c478bd9Sstevel@tonic-gate  * The caller is responsible for checking the AUDIT_ZONENAME policy
3947c478bd9Sstevel@tonic-gate  * before calling au_zonename_length() and au_to_zonename().  If
3957c478bd9Sstevel@tonic-gate  * the policy changes between the calls, no harm is done, so the
3967c478bd9Sstevel@tonic-gate  * policy only needs to be checked once.
3977c478bd9Sstevel@tonic-gate  *
3987c478bd9Sstevel@tonic-gate  * returns:
3997c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a zonename token; NULL if
4007c478bd9Sstevel@tonic-gate  *	policy is off.
4017c478bd9Sstevel@tonic-gate  *
4027c478bd9Sstevel@tonic-gate  *	if the zonename token is generated at token generation close time,
4037c478bd9Sstevel@tonic-gate  *	the length of the token is already known and it is ASSERTed that
4047c478bd9Sstevel@tonic-gate  *	it has not changed.  If not precalculated, zone_length must be
4057c478bd9Sstevel@tonic-gate  *	zero.
4067c478bd9Sstevel@tonic-gate  */
4077c478bd9Sstevel@tonic-gate token_t *
au_to_zonename(size_t zone_length,zone_t * zone)4081d7bfecdStz au_to_zonename(size_t zone_length, zone_t *zone)
4097c478bd9Sstevel@tonic-gate {
4107c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
4117c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
4127c478bd9Sstevel@tonic-gate 	char data_header = AUT_ZONENAME;	/* header for this token */
4137c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 	token = au_getclr();
4167c478bd9Sstevel@tonic-gate 
4171d7bfecdStz 	if (zone == NULL)
4181d7bfecdStz 		zone = curproc->p_zone;
4191d7bfecdStz 	bytes = (short)strlen(zone->zone_name) + 1;
4207c478bd9Sstevel@tonic-gate 	/*
4217c478bd9Sstevel@tonic-gate 	 * If zone_length != 0, it was precalculated and is
4227c478bd9Sstevel@tonic-gate 	 * the token length, not the string length.
4237c478bd9Sstevel@tonic-gate 	 */
4247c478bd9Sstevel@tonic-gate 	ASSERT((zone_length == 0) ||
4257c478bd9Sstevel@tonic-gate 	    (zone_length == (bytes + ZONE_TOKEN_OVERHEAD)));
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
4287c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
4297c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	token->len = (char)adr_count(&adr);
4321d7bfecdStz 	(void) au_append_buf(zone->zone_name, bytes, token);
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	return (token);
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate /*
4387c478bd9Sstevel@tonic-gate  * au_to_strings
4397c478bd9Sstevel@tonic-gate  * returns:
4407c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a strings array token.
4417c478bd9Sstevel@tonic-gate  */
4427c478bd9Sstevel@tonic-gate token_t *
au_to_strings(char header,const char * kstrp,ssize_t count)4437c478bd9Sstevel@tonic-gate au_to_strings(
4447c478bd9Sstevel@tonic-gate 	char header,		/* token type */
4457c478bd9Sstevel@tonic-gate 	const char *kstrp,	/* kernel string pointer */
4467c478bd9Sstevel@tonic-gate 	ssize_t count)		/* count of arguments */
4477c478bd9Sstevel@tonic-gate {
4487c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
4497c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
4507c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
4517c478bd9Sstevel@tonic-gate 	size_t len;
4527c478bd9Sstevel@tonic-gate 	int32_t tlen;
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 	token = au_getclr();
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
4577c478bd9Sstevel@tonic-gate 	adr_char(&adr, &header, 1);
4587c478bd9Sstevel@tonic-gate 	tlen = (int32_t)count;
4597c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &tlen, 1);
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	token->len = (char)adr_count(&adr);
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 	while (count-- > 0) {
4647c478bd9Sstevel@tonic-gate 		m = au_getclr();
4657c478bd9Sstevel@tonic-gate 		len = strlen(kstrp) + 1;
4667c478bd9Sstevel@tonic-gate 		(void) au_append_buf(kstrp, len, m);
4677c478bd9Sstevel@tonic-gate 		(void) au_append_rec((token_t *)token, (token_t *)m, AU_PACK);
4687c478bd9Sstevel@tonic-gate 		kstrp += len;
4697c478bd9Sstevel@tonic-gate 	}
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 	return (token);
4727c478bd9Sstevel@tonic-gate }
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate /*
4757c478bd9Sstevel@tonic-gate  * au_to_exec_args
4767c478bd9Sstevel@tonic-gate  * returns:
4777c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a argv token.
4787c478bd9Sstevel@tonic-gate  */
4797c478bd9Sstevel@tonic-gate token_t *
au_to_exec_args(const char * kstrp,ssize_t argc)4807c478bd9Sstevel@tonic-gate au_to_exec_args(const char *kstrp, ssize_t argc)
4817c478bd9Sstevel@tonic-gate {
4827c478bd9Sstevel@tonic-gate 	return (au_to_strings(AUT_EXEC_ARGS, kstrp, argc));
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate /*
4867c478bd9Sstevel@tonic-gate  * au_to_exec_env
4877c478bd9Sstevel@tonic-gate  * returns:
4887c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a arge token.
4897c478bd9Sstevel@tonic-gate  */
4907c478bd9Sstevel@tonic-gate token_t *
au_to_exec_env(const char * kstrp,ssize_t envc)4917c478bd9Sstevel@tonic-gate au_to_exec_env(const char *kstrp, ssize_t envc)
4927c478bd9Sstevel@tonic-gate {
4937c478bd9Sstevel@tonic-gate 	return (au_to_strings(AUT_EXEC_ENV, kstrp, envc));
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate /*
4977c478bd9Sstevel@tonic-gate  * au_to_arg32
4987c478bd9Sstevel@tonic-gate  *	char   n;	argument # being used
4997c478bd9Sstevel@tonic-gate  *	char  *text;	text describing argument
5007c478bd9Sstevel@tonic-gate  *	uint32_t v;	argument value
5017c478bd9Sstevel@tonic-gate  * returns:
5027c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing an argument token.
5037c478bd9Sstevel@tonic-gate  */
5047c478bd9Sstevel@tonic-gate token_t *
au_to_arg32(char n,char * text,uint32_t v)5057c478bd9Sstevel@tonic-gate au_to_arg32(char n, char *text, uint32_t v)
5067c478bd9Sstevel@tonic-gate {
5077c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
5087c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
5097c478bd9Sstevel@tonic-gate 	char data_header = AUT_ARG32;	/* header for this token */
5107c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 	token = au_getclr();
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	bytes = strlen(text) + 1;
5157c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
5167c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token type */
5177c478bd9Sstevel@tonic-gate 	adr_char(&adr, &n, 1);			/* argument id */
5187c478bd9Sstevel@tonic-gate 	adr_uint32(&adr, &v, 1);		/* argument value */
5197c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 	token->len = adr_count(&adr);
5227c478bd9Sstevel@tonic-gate 	/*
5237c478bd9Sstevel@tonic-gate 	 * Now add the description
5247c478bd9Sstevel@tonic-gate 	 */
5257c478bd9Sstevel@tonic-gate 	(void) au_append_buf(text, bytes, token);
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 	return (token);
5287c478bd9Sstevel@tonic-gate }
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate /*
5327c478bd9Sstevel@tonic-gate  * au_to_arg64
5337c478bd9Sstevel@tonic-gate  *	char		n;	argument # being used
5347c478bd9Sstevel@tonic-gate  *	char		*text;	text describing argument
5357c478bd9Sstevel@tonic-gate  *	uint64_t	v;	argument value
5367c478bd9Sstevel@tonic-gate  * returns:
5377c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing an argument token.
5387c478bd9Sstevel@tonic-gate  */
5397c478bd9Sstevel@tonic-gate token_t *
au_to_arg64(char n,char * text,uint64_t v)5407c478bd9Sstevel@tonic-gate au_to_arg64(char n, char *text, uint64_t v)
5417c478bd9Sstevel@tonic-gate {
5427c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
5437c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
5447c478bd9Sstevel@tonic-gate 	char data_header = AUT_ARG64;	/* header for this token */
5457c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate 	token = au_getclr();
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	bytes = strlen(text) + 1;
5507c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
5517c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token type */
5527c478bd9Sstevel@tonic-gate 	adr_char(&adr, &n, 1);			/* argument id */
5537c478bd9Sstevel@tonic-gate 	adr_uint64(&adr, &v, 1);		/* argument value */
5547c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 	token->len = adr_count(&adr);
5577c478bd9Sstevel@tonic-gate 	/*
5587c478bd9Sstevel@tonic-gate 	 * Now the description
5597c478bd9Sstevel@tonic-gate 	 */
5607c478bd9Sstevel@tonic-gate 	(void) au_append_buf(text, bytes, token);
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	return (token);
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate /*
5677c478bd9Sstevel@tonic-gate  * au_to_path
5687c478bd9Sstevel@tonic-gate  * returns:
5697c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a path token.
5707c478bd9Sstevel@tonic-gate  */
5717c478bd9Sstevel@tonic-gate token_t *
au_to_path(struct audit_path * app)5727c478bd9Sstevel@tonic-gate au_to_path(struct audit_path *app)
5737c478bd9Sstevel@tonic-gate {
5747c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
5757c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
5767c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
5777c478bd9Sstevel@tonic-gate 	char data_header = AUT_PATH;	/* header for this token */
5787c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
5797c478bd9Sstevel@tonic-gate 	char *path = app->audp_sect[0];
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	bytes = (short)(app->audp_sect[1] - app->audp_sect[0]);
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 	/*
5847c478bd9Sstevel@tonic-gate 	 * generate path token header
5857c478bd9Sstevel@tonic-gate 	 */
5867c478bd9Sstevel@tonic-gate 	m = au_getclr();
5877c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
5887c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
5897c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
5907c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate 	/* append path string */
5937c478bd9Sstevel@tonic-gate 	token = m;
5947c478bd9Sstevel@tonic-gate 	(void) au_append_buf(path, bytes, token);
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 	if (app->audp_cnt > 1) {
5977c478bd9Sstevel@tonic-gate 		/* generate attribute path strings token */
5987c478bd9Sstevel@tonic-gate 		m = au_to_strings(AUT_XATPATH, app->audp_sect[1],
5997c478bd9Sstevel@tonic-gate 		    app->audp_cnt - 1);
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate 		token = au_append_token(token, m);
6027c478bd9Sstevel@tonic-gate 	}
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 	return (token);
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate /*
6087c478bd9Sstevel@tonic-gate  * au_to_ipc
6097c478bd9Sstevel@tonic-gate  * returns:
6107c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a System V IPC token.
6117c478bd9Sstevel@tonic-gate  */
6127c478bd9Sstevel@tonic-gate token_t *
au_to_ipc(char type,int id)6137c478bd9Sstevel@tonic-gate au_to_ipc(char type, int id)
6147c478bd9Sstevel@tonic-gate {
6157c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
6167c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
6177c478bd9Sstevel@tonic-gate 	char data_header = AUT_IPC;	/* header for this token */
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate 	m = au_getclr();
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
6227c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
6237c478bd9Sstevel@tonic-gate 	adr_char(&adr, &type, 1);		/* type of IPC object */
6247c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&id, 1);
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	return (m);
6297c478bd9Sstevel@tonic-gate }
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate /*
6327c478bd9Sstevel@tonic-gate  * au_to_return32
6337c478bd9Sstevel@tonic-gate  * returns:
6347c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a return value token.
6357c478bd9Sstevel@tonic-gate  */
6367c478bd9Sstevel@tonic-gate token_t *
au_to_return32(int error,int32_t rv)6377c478bd9Sstevel@tonic-gate au_to_return32(int error, int32_t rv)
6387c478bd9Sstevel@tonic-gate {
6397c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
6407c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
6417c478bd9Sstevel@tonic-gate 	char data_header = AUT_RETURN32; /* header for this token */
6427c478bd9Sstevel@tonic-gate 	int32_t val;
6437c478bd9Sstevel@tonic-gate 	char ed = error;
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 	m = au_getclr();
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
6487c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
6497c478bd9Sstevel@tonic-gate 	adr_char(&adr, &ed, 1);
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	if (error) {
6527c478bd9Sstevel@tonic-gate 		val = -1;
6537c478bd9Sstevel@tonic-gate 		adr_int32(&adr, &val, 1);
6547c478bd9Sstevel@tonic-gate 	} else {
6557c478bd9Sstevel@tonic-gate 		adr_int32(&adr, &rv, 1);
6567c478bd9Sstevel@tonic-gate 	}
6577c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate 	return (m);
6607c478bd9Sstevel@tonic-gate }
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate /*
6637c478bd9Sstevel@tonic-gate  * au_to_return64
6647c478bd9Sstevel@tonic-gate  * returns:
6657c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a return value token.
6667c478bd9Sstevel@tonic-gate  */
6677c478bd9Sstevel@tonic-gate token_t *
au_to_return64(int error,int64_t rv)6687c478bd9Sstevel@tonic-gate au_to_return64(int error, int64_t rv)
6697c478bd9Sstevel@tonic-gate {
6707c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
6717c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
6727c478bd9Sstevel@tonic-gate 	char data_header = AUT_RETURN64; /* header for this token */
6737c478bd9Sstevel@tonic-gate 	int64_t val;
6747c478bd9Sstevel@tonic-gate 	char ed = error;
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	m = au_getclr();
6777c478bd9Sstevel@tonic-gate 
6787c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
6797c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
6807c478bd9Sstevel@tonic-gate 	adr_char(&adr, &ed, 1);
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate 	if (error) {
6837c478bd9Sstevel@tonic-gate 		val = -1;
6847c478bd9Sstevel@tonic-gate 		adr_int64(&adr, &val, 1);
6857c478bd9Sstevel@tonic-gate 	} else {
6867c478bd9Sstevel@tonic-gate 		adr_int64(&adr, &rv, 1);
6877c478bd9Sstevel@tonic-gate 	}
6887c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 	return (m);
6917c478bd9Sstevel@tonic-gate }
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate #ifdef	AU_MAY_USE_SOMEDAY
6947c478bd9Sstevel@tonic-gate /*
6957c478bd9Sstevel@tonic-gate  * au_to_opaque
6967c478bd9Sstevel@tonic-gate  * returns:
6977c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a opaque token.
6987c478bd9Sstevel@tonic-gate  */
6997c478bd9Sstevel@tonic-gate token_t *
au_to_opaque(short bytes,char * opaque)7007c478bd9Sstevel@tonic-gate au_to_opaque(short bytes, char *opaque)
7017c478bd9Sstevel@tonic-gate {
7027c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
7037c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7047c478bd9Sstevel@tonic-gate 	char data_header = AUT_OPAQUE;	/* header for this token */
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 	token = au_getclr();
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
7097c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7107c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 	token->len = adr_count(&adr);
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate 	/*
7157c478bd9Sstevel@tonic-gate 	 * Now attach the data
7167c478bd9Sstevel@tonic-gate 	 */
7177c478bd9Sstevel@tonic-gate 	(void) au_append_buf(opaque, bytes, token);
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate 	return (token);
7207c478bd9Sstevel@tonic-gate }
7217c478bd9Sstevel@tonic-gate #endif	/* AU_MAY_USE_SOMEDAY */
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate /*
7247c478bd9Sstevel@tonic-gate  * au_to_ip
7257c478bd9Sstevel@tonic-gate  * returns:
7267c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a ip header token
7277c478bd9Sstevel@tonic-gate  */
7287c478bd9Sstevel@tonic-gate token_t *
au_to_ip(struct ip * ipp)7297c478bd9Sstevel@tonic-gate au_to_ip(struct ip *ipp)
7307c478bd9Sstevel@tonic-gate {
7317c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
7327c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7337c478bd9Sstevel@tonic-gate 	char data_header = AUT_IP;	/* header for this token */
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate 	m = au_getclr();
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
7387c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7397c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)ipp, 2);
7407c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&(ipp->ip_len), 3);
7417c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)&(ipp->ip_ttl), 2);
7427c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&(ipp->ip_sum), 1);
7437c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(ipp->ip_src), 2);
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate 	return (m);
7487c478bd9Sstevel@tonic-gate }
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate /*
7517c478bd9Sstevel@tonic-gate  * au_to_iport
7527c478bd9Sstevel@tonic-gate  * returns:
7537c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a ip path token
7547c478bd9Sstevel@tonic-gate  */
7557c478bd9Sstevel@tonic-gate token_t *
au_to_iport(ushort_t iport)7567c478bd9Sstevel@tonic-gate au_to_iport(ushort_t iport)
7577c478bd9Sstevel@tonic-gate {
7587c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
7597c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7607c478bd9Sstevel@tonic-gate 	char data_header = AUT_IPORT;	/* header for this token */
7617c478bd9Sstevel@tonic-gate 
7627c478bd9Sstevel@tonic-gate 	m = au_getclr();
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
7657c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7667c478bd9Sstevel@tonic-gate 	adr_ushort(&adr, &iport, 1);
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate 	return (m);
7717c478bd9Sstevel@tonic-gate }
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate /*
7747c478bd9Sstevel@tonic-gate  * au_to_in_addr
7757c478bd9Sstevel@tonic-gate  * returns:
7767c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a ip path token
7777c478bd9Sstevel@tonic-gate  */
7787c478bd9Sstevel@tonic-gate token_t *
au_to_in_addr(struct in_addr * internet_addr)7797c478bd9Sstevel@tonic-gate au_to_in_addr(struct in_addr *internet_addr)
7807c478bd9Sstevel@tonic-gate {
7817c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
7827c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
7837c478bd9Sstevel@tonic-gate 	char data_header = AUT_IN_ADDR;	/* header for this token */
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate 	m = au_getclr();
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
7887c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
7897c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)internet_addr, sizeof (struct in_addr));
7907c478bd9Sstevel@tonic-gate 
7917c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate 	return (m);
7947c478bd9Sstevel@tonic-gate }
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate /*
7977c478bd9Sstevel@tonic-gate  * au_to_in_addr_ex
7987c478bd9Sstevel@tonic-gate  * returns:
7997c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing an ipv6 token
8007c478bd9Sstevel@tonic-gate  */
8017c478bd9Sstevel@tonic-gate token_t *
au_to_in_addr_ex(int32_t * internet_addr)8027c478bd9Sstevel@tonic-gate au_to_in_addr_ex(int32_t *internet_addr)
8037c478bd9Sstevel@tonic-gate {
8047c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
8057c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
8067c478bd9Sstevel@tonic-gate 	char data_header_v4 = AUT_IN_ADDR;	/* header for v4 token */
8077c478bd9Sstevel@tonic-gate 	char data_header_v6 = AUT_IN_ADDR_EX;	/* header for v6 token */
8087c478bd9Sstevel@tonic-gate 	int32_t type = AU_IPv6;
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate 	m = au_getclr();
8117c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 	if (IN6_IS_ADDR_V4MAPPED((in6_addr_t *)internet_addr)) {
814d3e710c8SRic Aleshire 		ipaddr_t in4;
81561b9bf51Srica 
81661b9bf51Srica 		/*
81761b9bf51Srica 		 * An IPv4-mapped IPv6 address is really an IPv4 address
81861b9bf51Srica 		 * in IPv6 format.
81961b9bf51Srica 		 */
82061b9bf51Srica 		IN6_V4MAPPED_TO_IPADDR((in6_addr_t *)internet_addr, in4);
82161b9bf51Srica 
8227c478bd9Sstevel@tonic-gate 		adr_char(&adr, &data_header_v4, 1);
823d3e710c8SRic Aleshire 		adr_char(&adr, (char *)&in4, sizeof (ipaddr_t));
8247c478bd9Sstevel@tonic-gate 	} else {
8257c478bd9Sstevel@tonic-gate 		adr_char(&adr, &data_header_v6, 1);
8267c478bd9Sstevel@tonic-gate 		adr_int32(&adr, &type, 1);
8277c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)internet_addr, sizeof (struct in6_addr));
8287c478bd9Sstevel@tonic-gate 	}
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate 	return (m);
8337c478bd9Sstevel@tonic-gate }
8347c478bd9Sstevel@tonic-gate 
8357c478bd9Sstevel@tonic-gate /*
8367c478bd9Sstevel@tonic-gate  * The Modifier tokens
8377c478bd9Sstevel@tonic-gate  */
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate /*
8407c478bd9Sstevel@tonic-gate  * au_to_attr
8417c478bd9Sstevel@tonic-gate  * returns:
8427c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing an attribute token.
8437c478bd9Sstevel@tonic-gate  */
8447c478bd9Sstevel@tonic-gate token_t *
au_to_attr(struct vattr * attr)8457c478bd9Sstevel@tonic-gate au_to_attr(struct vattr *attr)
8467c478bd9Sstevel@tonic-gate {
8477c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
8487c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
8497c478bd9Sstevel@tonic-gate #ifdef _LP64
8507c478bd9Sstevel@tonic-gate 	char data_header = AUT_ATTR64;	/* header for this token */
8517c478bd9Sstevel@tonic-gate #else
8527c478bd9Sstevel@tonic-gate 	char data_header = AUT_ATTR32;
8537c478bd9Sstevel@tonic-gate #endif
8547c478bd9Sstevel@tonic-gate 	int32_t value;
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate 	m = au_getclr();
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
8597c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
8607c478bd9Sstevel@tonic-gate 	value = (int32_t)attr->va_mode;
8617c478bd9Sstevel@tonic-gate 	value |= (int32_t)(VTTOIF(attr->va_type));
8627c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
8637c478bd9Sstevel@tonic-gate 	value = (int32_t)attr->va_uid;
8647c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
8657c478bd9Sstevel@tonic-gate 	value = (int32_t)attr->va_gid;
8667c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
8677c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(attr->va_fsid), 1);
8687c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(attr->va_nodeid), 1);
8697c478bd9Sstevel@tonic-gate #ifdef _LP64
8707c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(attr->va_rdev), 1);
8717c478bd9Sstevel@tonic-gate #else
8727c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(attr->va_rdev), 1);
8737c478bd9Sstevel@tonic-gate #endif
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 	return (m);
8787c478bd9Sstevel@tonic-gate }
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate token_t *
au_to_acl(struct acl * aclp)8817c478bd9Sstevel@tonic-gate au_to_acl(struct acl *aclp)
8827c478bd9Sstevel@tonic-gate {
8837c478bd9Sstevel@tonic-gate 	token_t *m;				/* local au_membuf */
8847c478bd9Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
8857c478bd9Sstevel@tonic-gate 	char data_header = AUT_ACL;		/* header for this token */
8867c478bd9Sstevel@tonic-gate 	int32_t value;
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 	m = au_getclr();
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
8917c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate 	value = (int32_t)aclp->a_type;
8947c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
8957c478bd9Sstevel@tonic-gate 	value = (int32_t)aclp->a_id;
8967c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
8977c478bd9Sstevel@tonic-gate 	value = (int32_t)aclp->a_perm;
8987c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
8997c478bd9Sstevel@tonic-gate 
9007c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
9017c478bd9Sstevel@tonic-gate 	return (m);
9027c478bd9Sstevel@tonic-gate }
9037c478bd9Sstevel@tonic-gate 
904a7746f66Stz token_t *
au_to_ace(ace_t * acep)905a7746f66Stz au_to_ace(ace_t *acep)
906a7746f66Stz {
907a7746f66Stz 	token_t *m;				/* local au_membuf */
908a7746f66Stz 	adr_t adr;				/* adr memory stream header */
909a7746f66Stz 	char data_header = AUT_ACE;		/* header for this token */
910a7746f66Stz 
911a7746f66Stz 	m = au_getclr();
912a7746f66Stz 
913a7746f66Stz 	adr_start(&adr, memtod(m, char *));
914a7746f66Stz 	adr_char(&adr, &data_header, 1);
915a7746f66Stz 
916a7746f66Stz 	adr_uint32(&adr, &(acep->a_who), 1);
917a7746f66Stz 	adr_uint32(&adr, &(acep->a_access_mask), 1);
918a7746f66Stz 	adr_ushort(&adr, &(acep->a_flags), 1);
919a7746f66Stz 	adr_ushort(&adr, &(acep->a_type), 1);
920a7746f66Stz 
921a7746f66Stz 	m->len = adr_count(&adr);
922a7746f66Stz 	return (m);
923a7746f66Stz }
924a7746f66Stz 
9257c478bd9Sstevel@tonic-gate /*
9267c478bd9Sstevel@tonic-gate  * au_to_ipc_perm
9277c478bd9Sstevel@tonic-gate  * returns:
9287c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a System V IPC attribute token.
9297c478bd9Sstevel@tonic-gate  */
9307c478bd9Sstevel@tonic-gate token_t *
au_to_ipc_perm(struct kipc_perm * perm)9317c478bd9Sstevel@tonic-gate au_to_ipc_perm(struct kipc_perm *perm)
9327c478bd9Sstevel@tonic-gate {
9337c478bd9Sstevel@tonic-gate 	token_t *m;				/* local au_membuf */
9347c478bd9Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
9357c478bd9Sstevel@tonic-gate 	char data_header = AUT_IPC_PERM;	/* header for this token */
9367c478bd9Sstevel@tonic-gate 	int32_t value;
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 	m = au_getclr();
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
9417c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
9427c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_uid;
9437c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
9447c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_gid;
9457c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
9467c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_cuid;
9477c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
9487c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_cgid;
9497c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
9507c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_mode;
9517c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
9527c478bd9Sstevel@tonic-gate 	value = 0;			/* seq is now obsolete */
9537c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
9547c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_key;
9557c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
9567c478bd9Sstevel@tonic-gate 
9577c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 	return (m);
9607c478bd9Sstevel@tonic-gate }
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate token_t *
au_to_groups(const gid_t * crgroups,uint_t crngroups)9637c478bd9Sstevel@tonic-gate au_to_groups(const gid_t *crgroups, uint_t crngroups)
9647c478bd9Sstevel@tonic-gate {
9657c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
9667c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
9677c478bd9Sstevel@tonic-gate 	char data_header = AUT_NEWGROUPS;	/* header for this token */
9687c478bd9Sstevel@tonic-gate 	short n_groups;
9697c478bd9Sstevel@tonic-gate 
9707c478bd9Sstevel@tonic-gate 	m = au_getclr();
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
9737c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
9747c478bd9Sstevel@tonic-gate 	n_groups = (short)crngroups;
9757c478bd9Sstevel@tonic-gate 	adr_short(&adr, &n_groups, 1);
9767c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)crgroups, (int)crngroups);
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
9797c478bd9Sstevel@tonic-gate 
9807c478bd9Sstevel@tonic-gate 	return (m);
9817c478bd9Sstevel@tonic-gate }
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate /*
9847c478bd9Sstevel@tonic-gate  * au_to_socket_ex
9857c478bd9Sstevel@tonic-gate  * returns:
9867c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a socket token.
9877c478bd9Sstevel@tonic-gate  */
9887c478bd9Sstevel@tonic-gate token_t *
au_to_socket_ex(short dom,short type,char * l,char * f)9897c478bd9Sstevel@tonic-gate au_to_socket_ex(short dom, short type, char *l, char *f)
9907c478bd9Sstevel@tonic-gate {
9917c478bd9Sstevel@tonic-gate 	adr_t adr;
9927c478bd9Sstevel@tonic-gate 	token_t *m;
9937c478bd9Sstevel@tonic-gate 	char data_header = AUT_SOCKET_EX;
9947c478bd9Sstevel@tonic-gate 	struct sockaddr_in6 *addr6;
9957c478bd9Sstevel@tonic-gate 	struct sockaddr_in  *addr4;
9967c478bd9Sstevel@tonic-gate 	short size;
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate 	m = au_getclr();
9997c478bd9Sstevel@tonic-gate 
10007c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
10017c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
10027c478bd9Sstevel@tonic-gate 	adr_short(&adr, &dom, 1);		/* dom of socket */
10037c478bd9Sstevel@tonic-gate 	adr_short(&adr, &type, 1);		/* type of socket */
10047c478bd9Sstevel@tonic-gate 
10057c478bd9Sstevel@tonic-gate 	if (dom == AF_INET6) {
10067c478bd9Sstevel@tonic-gate 		size = AU_IPv6;
10077c478bd9Sstevel@tonic-gate 		adr_short(&adr, &size, 1);	/* type of addresses */
10087c478bd9Sstevel@tonic-gate 		addr6 = (struct sockaddr_in6 *)l;
10097c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&addr6->sin6_port, 1);
10107c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&addr6->sin6_addr, size);
10117c478bd9Sstevel@tonic-gate 		addr6 = (struct sockaddr_in6 *)f;
10127c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&addr6->sin6_port, 1);
10137c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&addr6->sin6_addr, size);
10147c478bd9Sstevel@tonic-gate 	} else if (dom == AF_INET) {
10157c478bd9Sstevel@tonic-gate 		size = AU_IPv4;
10167c478bd9Sstevel@tonic-gate 		adr_short(&adr, &size, 1);	/* type of addresses */
10177c478bd9Sstevel@tonic-gate 		addr4 = (struct sockaddr_in *)l;
10187c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&addr4->sin_port, 1);
10197c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&addr4->sin_addr, size);
10207c478bd9Sstevel@tonic-gate 		addr4 = (struct sockaddr_in *)f;
10217c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&addr4->sin_port, 1);
10227c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&addr4->sin_addr, size);
10237c478bd9Sstevel@tonic-gate 	}
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	return (m);
10297c478bd9Sstevel@tonic-gate }
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate /*
10327c478bd9Sstevel@tonic-gate  * au_to_seq
10337c478bd9Sstevel@tonic-gate  * returns:
10347c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a sequence token.
10357c478bd9Sstevel@tonic-gate  */
10367c478bd9Sstevel@tonic-gate token_t *
au_to_seq()10377c478bd9Sstevel@tonic-gate au_to_seq()
10387c478bd9Sstevel@tonic-gate {
10397c478bd9Sstevel@tonic-gate 	adr_t adr;
10407c478bd9Sstevel@tonic-gate 	token_t *m;
10417c478bd9Sstevel@tonic-gate 	char data_header = AUT_SEQ;
10427c478bd9Sstevel@tonic-gate 	static int32_t zerocount;
10437c478bd9Sstevel@tonic-gate 
10447c478bd9Sstevel@tonic-gate 	m = au_getclr();
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
10497c478bd9Sstevel@tonic-gate 
10507c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &zerocount, 1);
10517c478bd9Sstevel@tonic-gate 
10527c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 	return (m);
10557c478bd9Sstevel@tonic-gate }
10567c478bd9Sstevel@tonic-gate 
10577c478bd9Sstevel@tonic-gate token_t *
au_to_sock_inet(struct sockaddr_in * s_inet)10587c478bd9Sstevel@tonic-gate au_to_sock_inet(struct sockaddr_in *s_inet)
10597c478bd9Sstevel@tonic-gate {
10607c478bd9Sstevel@tonic-gate 	adr_t adr;
10617c478bd9Sstevel@tonic-gate 	token_t *m;
10627c478bd9Sstevel@tonic-gate 	char data_header = AUT_SOCKET;
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate 	m = au_getclr();
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
10677c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
10687c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&s_inet->sin_family, 1);
10697c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&s_inet->sin_port, 1);
10707c478bd9Sstevel@tonic-gate 
10717c478bd9Sstevel@tonic-gate 	/* remote addr */
10727c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&s_inet->sin_addr.s_addr, 1);
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 	m->len = (uchar_t)adr_count(&adr);
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 	return (m);
10777c478bd9Sstevel@tonic-gate }
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate extern int maxprivbytes;
10807c478bd9Sstevel@tonic-gate 
10817c478bd9Sstevel@tonic-gate token_t *
au_to_privset(const char * set,const priv_set_t * pset,char data_header,int success)10827c478bd9Sstevel@tonic-gate au_to_privset(
10837c478bd9Sstevel@tonic-gate     const char *set,
10847c478bd9Sstevel@tonic-gate     const priv_set_t *pset,
10857c478bd9Sstevel@tonic-gate     char data_header,
10867c478bd9Sstevel@tonic-gate     int success)
10877c478bd9Sstevel@tonic-gate {
10887c478bd9Sstevel@tonic-gate 	token_t *token, *m;
10897c478bd9Sstevel@tonic-gate 	adr_t adr;
10907c478bd9Sstevel@tonic-gate 	int priv;
10917c478bd9Sstevel@tonic-gate 	const char *pname;
10927c478bd9Sstevel@tonic-gate 	char sf = (char)success;
10937c478bd9Sstevel@tonic-gate 	char *buf, *q;
10947c478bd9Sstevel@tonic-gate 	short sz;
10957c478bd9Sstevel@tonic-gate 	boolean_t full;
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate 	token = au_getclr();
10987c478bd9Sstevel@tonic-gate 
10997c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
11007c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
11017c478bd9Sstevel@tonic-gate 	/*
11027c478bd9Sstevel@tonic-gate 	 * set is not used for AUT_UPRIV and sf (== success) is not
11037c478bd9Sstevel@tonic-gate 	 * used for AUT_PRIV
11047c478bd9Sstevel@tonic-gate 	 */
11057c478bd9Sstevel@tonic-gate 	if (data_header == AUT_UPRIV) {
11067c478bd9Sstevel@tonic-gate 		adr_char(&adr, &sf, 1);
11077c478bd9Sstevel@tonic-gate 	} else {
11087c478bd9Sstevel@tonic-gate 		sz = strlen(set) + 1;
11097c478bd9Sstevel@tonic-gate 		adr_short(&adr, &sz, 1);
11107c478bd9Sstevel@tonic-gate 
11117c478bd9Sstevel@tonic-gate 		token->len = (uchar_t)adr_count(&adr);
11127c478bd9Sstevel@tonic-gate 		m = au_getclr();
11137c478bd9Sstevel@tonic-gate 
11147c478bd9Sstevel@tonic-gate 		(void) au_append_buf(set, sz, m);
11157c478bd9Sstevel@tonic-gate 		(void) au_append_rec(token, m, AU_PACK);
11167c478bd9Sstevel@tonic-gate 		adr.adr_now += sz;
11177c478bd9Sstevel@tonic-gate 	}
11187c478bd9Sstevel@tonic-gate 
11197c478bd9Sstevel@tonic-gate 	full = priv_isfullset(pset);
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate 	if (full) {
11227c478bd9Sstevel@tonic-gate 		buf = "ALL";
11237c478bd9Sstevel@tonic-gate 		sz = strlen(buf) + 1;
11247c478bd9Sstevel@tonic-gate 	} else {
11257c478bd9Sstevel@tonic-gate 		q = buf = kmem_alloc(maxprivbytes, KM_SLEEP);
11267c478bd9Sstevel@tonic-gate 		*buf = '\0';
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate 		for (priv = 0; (pname = priv_getbynum(priv)) != NULL; priv++) {
11297c478bd9Sstevel@tonic-gate 			if (priv_ismember(pset, priv)) {
11307c478bd9Sstevel@tonic-gate 				if (q != buf)
11317c478bd9Sstevel@tonic-gate 					*q++ = ',';
11327c478bd9Sstevel@tonic-gate 				(void) strcpy(q, pname);
11337c478bd9Sstevel@tonic-gate 				q += strlen(q);
11347c478bd9Sstevel@tonic-gate 			}
11357c478bd9Sstevel@tonic-gate 		}
11367c478bd9Sstevel@tonic-gate 		sz = (q - buf) + 1;
11377c478bd9