xref: /illumos-gate/usr/src/uts/common/c2/audit_token.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * Support routines for building audit records.
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>		/* for rval */
35*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/mode.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/user.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/session.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/acl.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/ipc_impl.h>
43*7c478bd9Sstevel@tonic-gate #include <netinet/in_systm.h>
44*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
45*7c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
47*7c478bd9Sstevel@tonic-gate #include <net/route.h>
48*7c478bd9Sstevel@tonic-gate #include <netinet/in_pcb.h>
49*7c478bd9Sstevel@tonic-gate #include <c2/audit.h>
50*7c478bd9Sstevel@tonic-gate #include <c2/audit_kernel.h>
51*7c478bd9Sstevel@tonic-gate #include <c2/audit_record.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/model.h>		/* for model_t */
53*7c478bd9Sstevel@tonic-gate #include <sys/vmparam.h>	/* for USRSTACK/USRSTACK32 */
54*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h>		/* for sonode */
55*7c478bd9Sstevel@tonic-gate #include <sys/socketvar.h>	/* for sonode */
56*7c478bd9Sstevel@tonic-gate #include <sys/zone.h>
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate /*
59*7c478bd9Sstevel@tonic-gate  * These are the control tokens
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /*
63*7c478bd9Sstevel@tonic-gate  * au_to_header
64*7c478bd9Sstevel@tonic-gate  * returns:
65*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a header token.
66*7c478bd9Sstevel@tonic-gate  */
67*7c478bd9Sstevel@tonic-gate token_t *
68*7c478bd9Sstevel@tonic-gate au_to_header(int byte_count, short e_type, short e_mod)
69*7c478bd9Sstevel@tonic-gate {
70*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
71*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* au_membuf pointer */
72*7c478bd9Sstevel@tonic-gate #ifdef _LP64
73*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER64;	/* header for this token */
74*7c478bd9Sstevel@tonic-gate 	static int64_t zerotime[2];
75*7c478bd9Sstevel@tonic-gate #else
76*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER32;
77*7c478bd9Sstevel@tonic-gate 	static int32_t zerotime[2];
78*7c478bd9Sstevel@tonic-gate #endif
79*7c478bd9Sstevel@tonic-gate 	char version = TOKEN_VERSION;	/* version of token family */
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
84*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
85*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&byte_count, 1);	/* length of */
86*7c478bd9Sstevel@tonic-gate 							/* audit record */
87*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &version, 1);		/* version of audit tokens */
88*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &e_type, 1);		/* event ID */
89*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &e_mod, 1);		/* event ID modifier */
90*7c478bd9Sstevel@tonic-gate #ifdef _LP64
91*7c478bd9Sstevel@tonic-gate 	adr_int64(&adr, zerotime, 2);		/* time & date space */
92*7c478bd9Sstevel@tonic-gate #else
93*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, zerotime, 2);
94*7c478bd9Sstevel@tonic-gate #endif
95*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	return (m);
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate token_t *
101*7c478bd9Sstevel@tonic-gate au_to_header_ex(int byte_count, au_event_t e_type, au_emod_t e_mod)
102*7c478bd9Sstevel@tonic-gate {
103*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
104*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* au_membuf pointer */
105*7c478bd9Sstevel@tonic-gate 	au_kcontext_t	*kctx = SET_KCTX_PZ;
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate #ifdef _LP64
108*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER64_EX;	/* header for this token */
109*7c478bd9Sstevel@tonic-gate 	static int64_t zerotime[2];
110*7c478bd9Sstevel@tonic-gate #else
111*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_HEADER32_EX;
112*7c478bd9Sstevel@tonic-gate 	static int32_t zerotime[2];
113*7c478bd9Sstevel@tonic-gate #endif
114*7c478bd9Sstevel@tonic-gate 	char version = TOKEN_VERSION;	/* version of token family */
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
119*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token ID */
120*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&byte_count, 1);	/* length of */
121*7c478bd9Sstevel@tonic-gate 							/* audit record */
122*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &version, 1);		/* version of audit tokens */
123*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &e_type, 1);		/* event ID */
124*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &e_mod, 1);		/* event ID modifier */
125*7c478bd9Sstevel@tonic-gate 	adr_uint32(&adr, &kctx->auk_info.ai_termid.at_type, 1);
126*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)&kctx->auk_info.ai_termid.at_addr[0],
127*7c478bd9Sstevel@tonic-gate 	    (int)kctx->auk_info.ai_termid.at_type);
128*7c478bd9Sstevel@tonic-gate #ifdef _LP64
129*7c478bd9Sstevel@tonic-gate 	adr_int64(&adr, zerotime, 2);		/* time & date */
130*7c478bd9Sstevel@tonic-gate #else
131*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, zerotime, 2);
132*7c478bd9Sstevel@tonic-gate #endif
133*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	return (m);
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate  * au_to_trailer
140*7c478bd9Sstevel@tonic-gate  * returns:
141*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a trailer token.
142*7c478bd9Sstevel@tonic-gate  */
143*7c478bd9Sstevel@tonic-gate token_t *
144*7c478bd9Sstevel@tonic-gate au_to_trailer(int byte_count)
145*7c478bd9Sstevel@tonic-gate {
146*7c478bd9Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
147*7c478bd9Sstevel@tonic-gate 	token_t *m;				/* au_membuf pointer */
148*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_TRAILER;		/* header for this token */
149*7c478bd9Sstevel@tonic-gate 	short magic = (short)AUT_TRAILER_MAGIC; /* trailer magic number */
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
154*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);		/* token ID */
155*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &magic, 1);			/* magic number */
156*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&byte_count, 1);	/* length of */
157*7c478bd9Sstevel@tonic-gate 							/* audit record */
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	return (m);
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate /*
164*7c478bd9Sstevel@tonic-gate  * These are the data tokens
165*7c478bd9Sstevel@tonic-gate  */
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate /*
168*7c478bd9Sstevel@tonic-gate  * au_to_data
169*7c478bd9Sstevel@tonic-gate  * returns:
170*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a data token.
171*7c478bd9Sstevel@tonic-gate  */
172*7c478bd9Sstevel@tonic-gate token_t *
173*7c478bd9Sstevel@tonic-gate au_to_data(char unit_print, char unit_type, char unit_count, char *p)
174*7c478bd9Sstevel@tonic-gate {
175*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
176*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* au_membuf pointer */
177*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_DATA;	/* header for this token */
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate 	ASSERT(p != NULL);
180*7c478bd9Sstevel@tonic-gate 	ASSERT(unit_count != 0);
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate 	switch (unit_type) {
183*7c478bd9Sstevel@tonic-gate 	case AUR_SHORT:
184*7c478bd9Sstevel@tonic-gate 		if (sizeof (short) * unit_count >= AU_BUFSIZE)
185*7c478bd9Sstevel@tonic-gate 			return (au_to_text("au_to_data: unit count too big"));
186*7c478bd9Sstevel@tonic-gate 		break;
187*7c478bd9Sstevel@tonic-gate 	case AUR_INT32:
188*7c478bd9Sstevel@tonic-gate 		if (sizeof (int32_t) * unit_count >= AU_BUFSIZE)
189*7c478bd9Sstevel@tonic-gate 			return (au_to_text("au_to_data: unit count too big"));
190*7c478bd9Sstevel@tonic-gate 		break;
191*7c478bd9Sstevel@tonic-gate 	case AUR_INT64:
192*7c478bd9Sstevel@tonic-gate 		if (sizeof (int64_t) * unit_count >= AU_BUFSIZE)
193*7c478bd9Sstevel@tonic-gate 			return (au_to_text("au_to_data: unit count too big"));
194*7c478bd9Sstevel@tonic-gate 		break;
195*7c478bd9Sstevel@tonic-gate 	case AUR_BYTE:
196*7c478bd9Sstevel@tonic-gate 	default:
197*7c478bd9Sstevel@tonic-gate #ifdef _CHAR_IS_UNSIGNED
198*7c478bd9Sstevel@tonic-gate 		if (sizeof (char) * unit_count >= AU_BUFSIZE)
199*7c478bd9Sstevel@tonic-gate 			return (au_to_text("au_to_data: unit count too big"));
200*7c478bd9Sstevel@tonic-gate #endif
201*7c478bd9Sstevel@tonic-gate 		/*
202*7c478bd9Sstevel@tonic-gate 		 * we used to check for this:
203*7c478bd9Sstevel@tonic-gate 		 * sizeof (char) * (int)unit_count >= AU_BUFSIZE).
204*7c478bd9Sstevel@tonic-gate 		 * but the compiler is smart enough to see that
205*7c478bd9Sstevel@tonic-gate 		 * will never be >= AU_BUFSIZE, since that's 128
206*7c478bd9Sstevel@tonic-gate 		 * and unit_count maxes out at 127 (signed char),
207*7c478bd9Sstevel@tonic-gate 		 * and complain.
208*7c478bd9Sstevel@tonic-gate 		 */
209*7c478bd9Sstevel@tonic-gate 		break;
210*7c478bd9Sstevel@tonic-gate 	}
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
215*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
216*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &unit_print, 1);
217*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &unit_type, 1);
218*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &unit_count, 1);
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate 	switch (unit_type) {
221*7c478bd9Sstevel@tonic-gate 	case AUR_SHORT:
222*7c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)p, unit_count);
223*7c478bd9Sstevel@tonic-gate 		break;
224*7c478bd9Sstevel@tonic-gate 	case AUR_INT32:
225*7c478bd9Sstevel@tonic-gate 		adr_int32(&adr, (int32_t *)p, unit_count);
226*7c478bd9Sstevel@tonic-gate 		break;
227*7c478bd9Sstevel@tonic-gate 	case AUR_INT64:
228*7c478bd9Sstevel@tonic-gate 		adr_int64(&adr, (int64_t *)p, unit_count);
229*7c478bd9Sstevel@tonic-gate 		break;
230*7c478bd9Sstevel@tonic-gate 	case AUR_BYTE:
231*7c478bd9Sstevel@tonic-gate 	default:
232*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, p, unit_count);
233*7c478bd9Sstevel@tonic-gate 		break;
234*7c478bd9Sstevel@tonic-gate 	}
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate 	return (m);
239*7c478bd9Sstevel@tonic-gate }
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate /*
242*7c478bd9Sstevel@tonic-gate  * au_to_process
243*7c478bd9Sstevel@tonic-gate  * au_to_subject
244*7c478bd9Sstevel@tonic-gate  * returns:
245*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a process token.
246*7c478bd9Sstevel@tonic-gate  */
247*7c478bd9Sstevel@tonic-gate static token_t *au_to_any_process(char, uid_t, gid_t, uid_t, gid_t,
248*7c478bd9Sstevel@tonic-gate     pid_t, au_id_t, au_asid_t, const au_tid_addr_t *atid);
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate token_t *
251*7c478bd9Sstevel@tonic-gate au_to_process(uid_t uid, gid_t gid, uid_t ruid, gid_t rgid, pid_t pid,
252*7c478bd9Sstevel@tonic-gate     au_id_t auid, au_asid_t asid, const au_tid_addr_t *atid)
253*7c478bd9Sstevel@tonic-gate {
254*7c478bd9Sstevel@tonic-gate 	char data_header;
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate #ifdef _LP64
257*7c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6)
258*7c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS64_EX;
259*7c478bd9Sstevel@tonic-gate 	else
260*7c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS64;
261*7c478bd9Sstevel@tonic-gate #else
262*7c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6)
263*7c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS32_EX;
264*7c478bd9Sstevel@tonic-gate 	else
265*7c478bd9Sstevel@tonic-gate 		data_header = AUT_PROCESS32;
266*7c478bd9Sstevel@tonic-gate #endif
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 	return (au_to_any_process(data_header, uid, gid, ruid,
269*7c478bd9Sstevel@tonic-gate 	    rgid, pid, auid, asid, atid));
270*7c478bd9Sstevel@tonic-gate }
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate token_t *
273*7c478bd9Sstevel@tonic-gate au_to_subject(uid_t uid, gid_t gid, uid_t ruid, gid_t rgid, pid_t pid,
274*7c478bd9Sstevel@tonic-gate     au_id_t auid, au_asid_t asid, const au_tid_addr_t *atid)
275*7c478bd9Sstevel@tonic-gate {
276*7c478bd9Sstevel@tonic-gate 	char data_header;
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate #ifdef _LP64
279*7c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6)
280*7c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT64_EX;
281*7c478bd9Sstevel@tonic-gate 	else
282*7c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT64;
283*7c478bd9Sstevel@tonic-gate #else
284*7c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6)
285*7c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT32_EX;
286*7c478bd9Sstevel@tonic-gate 	else
287*7c478bd9Sstevel@tonic-gate 		data_header = AUT_SUBJECT32;
288*7c478bd9Sstevel@tonic-gate #endif
289*7c478bd9Sstevel@tonic-gate 	return (au_to_any_process(data_header, uid, gid, ruid,
290*7c478bd9Sstevel@tonic-gate 	    rgid, pid, auid, asid, atid));
291*7c478bd9Sstevel@tonic-gate }
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate static token_t *
295*7c478bd9Sstevel@tonic-gate au_to_any_process(char data_header,
296*7c478bd9Sstevel@tonic-gate     uid_t uid, gid_t gid, uid_t ruid, gid_t rgid, pid_t pid,
297*7c478bd9Sstevel@tonic-gate     au_id_t auid, au_asid_t asid, const au_tid_addr_t *atid)
298*7c478bd9Sstevel@tonic-gate {
299*7c478bd9Sstevel@tonic-gate 	token_t *m;	/* local au_membuf */
300*7c478bd9Sstevel@tonic-gate 	adr_t adr;	/* adr memory stream header */
301*7c478bd9Sstevel@tonic-gate 	int32_t value;
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
304*7c478bd9Sstevel@tonic-gate 
305*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
306*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
307*7c478bd9Sstevel@tonic-gate 	value = (int32_t)auid;
308*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
309*7c478bd9Sstevel@tonic-gate 	value = (int32_t)uid;
310*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
311*7c478bd9Sstevel@tonic-gate 	value = (int32_t)gid;
312*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
313*7c478bd9Sstevel@tonic-gate 	value = (int32_t)ruid;
314*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
315*7c478bd9Sstevel@tonic-gate 	value = (int32_t)rgid;
316*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
317*7c478bd9Sstevel@tonic-gate 	value = (int32_t)pid;
318*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
319*7c478bd9Sstevel@tonic-gate 	value = (int32_t)asid;
320*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
321*7c478bd9Sstevel@tonic-gate #ifdef _LP64
322*7c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(atid->at_port), 1);
323*7c478bd9Sstevel@tonic-gate #else
324*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(atid->at_port), 1);
325*7c478bd9Sstevel@tonic-gate #endif
326*7c478bd9Sstevel@tonic-gate 	if (atid->at_type == AU_IPv6) {
327*7c478bd9Sstevel@tonic-gate 		adr_uint32(&adr, (uint_t *)&atid->at_type, 1);
328*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&atid->at_addr[0], 16);
329*7c478bd9Sstevel@tonic-gate 	} else {
330*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&(atid->at_addr[0]), 4);
331*7c478bd9Sstevel@tonic-gate 	}
332*7c478bd9Sstevel@tonic-gate 
333*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate 	return (m);
336*7c478bd9Sstevel@tonic-gate }
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate /*
339*7c478bd9Sstevel@tonic-gate  * au_to_text
340*7c478bd9Sstevel@tonic-gate  * returns:
341*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a text token.
342*7c478bd9Sstevel@tonic-gate  */
343*7c478bd9Sstevel@tonic-gate token_t *
344*7c478bd9Sstevel@tonic-gate au_to_text(const char *text)
345*7c478bd9Sstevel@tonic-gate {
346*7c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
347*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
348*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_TEXT;	/* header for this token */
349*7c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate 	token = au_getclr();
352*7c478bd9Sstevel@tonic-gate 
353*7c478bd9Sstevel@tonic-gate 	bytes = (short)strlen(text) + 1;
354*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
355*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
356*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
357*7c478bd9Sstevel@tonic-gate 
358*7c478bd9Sstevel@tonic-gate 	token->len = (char)adr_count(&adr);
359*7c478bd9Sstevel@tonic-gate 	/*
360*7c478bd9Sstevel@tonic-gate 	 * Now attach the text
361*7c478bd9Sstevel@tonic-gate 	 */
362*7c478bd9Sstevel@tonic-gate 	(void) au_append_buf(text, bytes, token);
363*7c478bd9Sstevel@tonic-gate 
364*7c478bd9Sstevel@tonic-gate 	return (token);
365*7c478bd9Sstevel@tonic-gate }
366*7c478bd9Sstevel@tonic-gate 
367*7c478bd9Sstevel@tonic-gate /*
368*7c478bd9Sstevel@tonic-gate  * au_zonename_length
369*7c478bd9Sstevel@tonic-gate  * returns:
370*7c478bd9Sstevel@tonic-gate  * -	length of zonename token to be generated
371*7c478bd9Sstevel@tonic-gate  * -	zone name up to ZONENAME_MAX + 1 in length
372*7c478bd9Sstevel@tonic-gate  */
373*7c478bd9Sstevel@tonic-gate #define	ZONE_TOKEN_OVERHEAD 3
374*7c478bd9Sstevel@tonic-gate 	/*
375*7c478bd9Sstevel@tonic-gate 	 * the zone token is
376*7c478bd9Sstevel@tonic-gate 	 * token id (1 byte)
377*7c478bd9Sstevel@tonic-gate 	 * string length (2 bytes)
378*7c478bd9Sstevel@tonic-gate 	 * the string (strlen(zonename) + 1)
379*7c478bd9Sstevel@tonic-gate 	 */
380*7c478bd9Sstevel@tonic-gate size_t
381*7c478bd9Sstevel@tonic-gate au_zonename_length()
382*7c478bd9Sstevel@tonic-gate {
383*7c478bd9Sstevel@tonic-gate 	return (strlen(curproc->p_zone->zone_name) + 1 +
384*7c478bd9Sstevel@tonic-gate 	    ZONE_TOKEN_OVERHEAD);
385*7c478bd9Sstevel@tonic-gate }
386*7c478bd9Sstevel@tonic-gate 
387*7c478bd9Sstevel@tonic-gate /*
388*7c478bd9Sstevel@tonic-gate  * au_to_zonename
389*7c478bd9Sstevel@tonic-gate  *
390*7c478bd9Sstevel@tonic-gate  * A length of zero input to au_to_zonename means the length is not
391*7c478bd9Sstevel@tonic-gate  * pre-calculated.
392*7c478bd9Sstevel@tonic-gate  *
393*7c478bd9Sstevel@tonic-gate  * The caller is responsible for checking the AUDIT_ZONENAME policy
394*7c478bd9Sstevel@tonic-gate  * before calling au_zonename_length() and au_to_zonename().  If
395*7c478bd9Sstevel@tonic-gate  * the policy changes between the calls, no harm is done, so the
396*7c478bd9Sstevel@tonic-gate  * policy only needs to be checked once.
397*7c478bd9Sstevel@tonic-gate  *
398*7c478bd9Sstevel@tonic-gate  * returns:
399*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a zonename token; NULL if
400*7c478bd9Sstevel@tonic-gate  *	policy is off.
401*7c478bd9Sstevel@tonic-gate  *
402*7c478bd9Sstevel@tonic-gate  *	if the zonename token is generated at token generation close time,
403*7c478bd9Sstevel@tonic-gate  *	the length of the token is already known and it is ASSERTed that
404*7c478bd9Sstevel@tonic-gate  *	it has not changed.  If not precalculated, zone_length must be
405*7c478bd9Sstevel@tonic-gate  *	zero.
406*7c478bd9Sstevel@tonic-gate  */
407*7c478bd9Sstevel@tonic-gate token_t *
408*7c478bd9Sstevel@tonic-gate au_to_zonename(size_t zone_length)
409*7c478bd9Sstevel@tonic-gate {
410*7c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
411*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
412*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_ZONENAME;	/* header for this token */
413*7c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
414*7c478bd9Sstevel@tonic-gate 
415*7c478bd9Sstevel@tonic-gate 	token = au_getclr();
416*7c478bd9Sstevel@tonic-gate 
417*7c478bd9Sstevel@tonic-gate 	bytes = (short)strlen(curproc->p_zone->zone_name) + 1;
418*7c478bd9Sstevel@tonic-gate 	/*
419*7c478bd9Sstevel@tonic-gate 	 * If zone_length != 0, it was precalculated and is
420*7c478bd9Sstevel@tonic-gate 	 * the token length, not the string length.
421*7c478bd9Sstevel@tonic-gate 	 */
422*7c478bd9Sstevel@tonic-gate 	ASSERT((zone_length == 0) ||
423*7c478bd9Sstevel@tonic-gate 	    (zone_length == (bytes + ZONE_TOKEN_OVERHEAD)));
424*7c478bd9Sstevel@tonic-gate 
425*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
426*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
427*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate 	token->len = (char)adr_count(&adr);
430*7c478bd9Sstevel@tonic-gate 	(void) au_append_buf(curproc->p_zone->zone_name, bytes, token);
431*7c478bd9Sstevel@tonic-gate 
432*7c478bd9Sstevel@tonic-gate 	return (token);
433*7c478bd9Sstevel@tonic-gate }
434*7c478bd9Sstevel@tonic-gate 
435*7c478bd9Sstevel@tonic-gate /*
436*7c478bd9Sstevel@tonic-gate  * au_to_strings
437*7c478bd9Sstevel@tonic-gate  * returns:
438*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a strings array token.
439*7c478bd9Sstevel@tonic-gate  */
440*7c478bd9Sstevel@tonic-gate token_t *
441*7c478bd9Sstevel@tonic-gate au_to_strings(
442*7c478bd9Sstevel@tonic-gate 	char header,		/* token type */
443*7c478bd9Sstevel@tonic-gate 	const char *kstrp,	/* kernel string pointer */
444*7c478bd9Sstevel@tonic-gate 	ssize_t count)		/* count of arguments */
445*7c478bd9Sstevel@tonic-gate {
446*7c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
447*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
448*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
449*7c478bd9Sstevel@tonic-gate 	size_t len;
450*7c478bd9Sstevel@tonic-gate 	int32_t tlen;
451*7c478bd9Sstevel@tonic-gate 
452*7c478bd9Sstevel@tonic-gate 	token = au_getclr();
453*7c478bd9Sstevel@tonic-gate 
454*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
455*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &header, 1);
456*7c478bd9Sstevel@tonic-gate 	tlen = (int32_t)count;
457*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &tlen, 1);
458*7c478bd9Sstevel@tonic-gate 
459*7c478bd9Sstevel@tonic-gate 	token->len = (char)adr_count(&adr);
460*7c478bd9Sstevel@tonic-gate 
461*7c478bd9Sstevel@tonic-gate 	while (count-- > 0) {
462*7c478bd9Sstevel@tonic-gate 		m = au_getclr();
463*7c478bd9Sstevel@tonic-gate 		len = strlen(kstrp) + 1;
464*7c478bd9Sstevel@tonic-gate 		(void) au_append_buf(kstrp, len, m);
465*7c478bd9Sstevel@tonic-gate 		(void) au_append_rec((token_t *)token, (token_t *)m, AU_PACK);
466*7c478bd9Sstevel@tonic-gate 		kstrp += len;
467*7c478bd9Sstevel@tonic-gate 	}
468*7c478bd9Sstevel@tonic-gate 
469*7c478bd9Sstevel@tonic-gate 	return (token);
470*7c478bd9Sstevel@tonic-gate }
471*7c478bd9Sstevel@tonic-gate 
472*7c478bd9Sstevel@tonic-gate /*
473*7c478bd9Sstevel@tonic-gate  * au_to_exec_args
474*7c478bd9Sstevel@tonic-gate  * returns:
475*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a argv token.
476*7c478bd9Sstevel@tonic-gate  */
477*7c478bd9Sstevel@tonic-gate token_t *
478*7c478bd9Sstevel@tonic-gate au_to_exec_args(const char *kstrp, ssize_t argc)
479*7c478bd9Sstevel@tonic-gate {
480*7c478bd9Sstevel@tonic-gate 	return (au_to_strings(AUT_EXEC_ARGS, kstrp, argc));
481*7c478bd9Sstevel@tonic-gate }
482*7c478bd9Sstevel@tonic-gate 
483*7c478bd9Sstevel@tonic-gate /*
484*7c478bd9Sstevel@tonic-gate  * au_to_exec_env
485*7c478bd9Sstevel@tonic-gate  * returns:
486*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a arge token.
487*7c478bd9Sstevel@tonic-gate  */
488*7c478bd9Sstevel@tonic-gate token_t *
489*7c478bd9Sstevel@tonic-gate au_to_exec_env(const char *kstrp, ssize_t envc)
490*7c478bd9Sstevel@tonic-gate {
491*7c478bd9Sstevel@tonic-gate 	return (au_to_strings(AUT_EXEC_ENV, kstrp, envc));
492*7c478bd9Sstevel@tonic-gate }
493*7c478bd9Sstevel@tonic-gate 
494*7c478bd9Sstevel@tonic-gate /*
495*7c478bd9Sstevel@tonic-gate  * au_to_arg32
496*7c478bd9Sstevel@tonic-gate  *	char   n;	argument # being used
497*7c478bd9Sstevel@tonic-gate  *	char  *text;	text describing argument
498*7c478bd9Sstevel@tonic-gate  *	uint32_t v;	argument value
499*7c478bd9Sstevel@tonic-gate  * returns:
500*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing an argument token.
501*7c478bd9Sstevel@tonic-gate  */
502*7c478bd9Sstevel@tonic-gate token_t *
503*7c478bd9Sstevel@tonic-gate au_to_arg32(char n, char *text, uint32_t v)
504*7c478bd9Sstevel@tonic-gate {
505*7c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
506*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
507*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_ARG32;	/* header for this token */
508*7c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
509*7c478bd9Sstevel@tonic-gate 
510*7c478bd9Sstevel@tonic-gate 	token = au_getclr();
511*7c478bd9Sstevel@tonic-gate 
512*7c478bd9Sstevel@tonic-gate 	bytes = strlen(text) + 1;
513*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
514*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token type */
515*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &n, 1);			/* argument id */
516*7c478bd9Sstevel@tonic-gate 	adr_uint32(&adr, &v, 1);		/* argument value */
517*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
518*7c478bd9Sstevel@tonic-gate 
519*7c478bd9Sstevel@tonic-gate 	token->len = adr_count(&adr);
520*7c478bd9Sstevel@tonic-gate 	/*
521*7c478bd9Sstevel@tonic-gate 	 * Now add the description
522*7c478bd9Sstevel@tonic-gate 	 */
523*7c478bd9Sstevel@tonic-gate 	(void) au_append_buf(text, bytes, token);
524*7c478bd9Sstevel@tonic-gate 
525*7c478bd9Sstevel@tonic-gate 	return (token);
526*7c478bd9Sstevel@tonic-gate }
527*7c478bd9Sstevel@tonic-gate 
528*7c478bd9Sstevel@tonic-gate 
529*7c478bd9Sstevel@tonic-gate /*
530*7c478bd9Sstevel@tonic-gate  * au_to_arg64
531*7c478bd9Sstevel@tonic-gate  *	char		n;	argument # being used
532*7c478bd9Sstevel@tonic-gate  *	char		*text;	text describing argument
533*7c478bd9Sstevel@tonic-gate  *	uint64_t	v;	argument value
534*7c478bd9Sstevel@tonic-gate  * returns:
535*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing an argument token.
536*7c478bd9Sstevel@tonic-gate  */
537*7c478bd9Sstevel@tonic-gate token_t *
538*7c478bd9Sstevel@tonic-gate au_to_arg64(char n, char *text, uint64_t v)
539*7c478bd9Sstevel@tonic-gate {
540*7c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
541*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
542*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_ARG64;	/* header for this token */
543*7c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
544*7c478bd9Sstevel@tonic-gate 
545*7c478bd9Sstevel@tonic-gate 	token = au_getclr();
546*7c478bd9Sstevel@tonic-gate 
547*7c478bd9Sstevel@tonic-gate 	bytes = strlen(text) + 1;
548*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
549*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);	/* token type */
550*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &n, 1);			/* argument id */
551*7c478bd9Sstevel@tonic-gate 	adr_uint64(&adr, &v, 1);		/* argument value */
552*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
553*7c478bd9Sstevel@tonic-gate 
554*7c478bd9Sstevel@tonic-gate 	token->len = adr_count(&adr);
555*7c478bd9Sstevel@tonic-gate 	/*
556*7c478bd9Sstevel@tonic-gate 	 * Now the description
557*7c478bd9Sstevel@tonic-gate 	 */
558*7c478bd9Sstevel@tonic-gate 	(void) au_append_buf(text, bytes, token);
559*7c478bd9Sstevel@tonic-gate 
560*7c478bd9Sstevel@tonic-gate 	return (token);
561*7c478bd9Sstevel@tonic-gate }
562*7c478bd9Sstevel@tonic-gate 
563*7c478bd9Sstevel@tonic-gate 
564*7c478bd9Sstevel@tonic-gate /*
565*7c478bd9Sstevel@tonic-gate  * au_to_path
566*7c478bd9Sstevel@tonic-gate  * returns:
567*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a path token.
568*7c478bd9Sstevel@tonic-gate  */
569*7c478bd9Sstevel@tonic-gate token_t *
570*7c478bd9Sstevel@tonic-gate au_to_path(struct audit_path *app)
571*7c478bd9Sstevel@tonic-gate {
572*7c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
573*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
574*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
575*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_PATH;	/* header for this token */
576*7c478bd9Sstevel@tonic-gate 	short bytes;			/* length of string */
577*7c478bd9Sstevel@tonic-gate 	char *path = app->audp_sect[0];
578*7c478bd9Sstevel@tonic-gate 
579*7c478bd9Sstevel@tonic-gate 	bytes = (short)(app->audp_sect[1] - app->audp_sect[0]);
580*7c478bd9Sstevel@tonic-gate 
581*7c478bd9Sstevel@tonic-gate 	/*
582*7c478bd9Sstevel@tonic-gate 	 * generate path token header
583*7c478bd9Sstevel@tonic-gate 	 */
584*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
585*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
586*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
587*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
588*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
589*7c478bd9Sstevel@tonic-gate 
590*7c478bd9Sstevel@tonic-gate 	/* append path string */
591*7c478bd9Sstevel@tonic-gate 	token = m;
592*7c478bd9Sstevel@tonic-gate 	(void) au_append_buf(path, bytes, token);
593*7c478bd9Sstevel@tonic-gate 
594*7c478bd9Sstevel@tonic-gate 	if (app->audp_cnt > 1) {
595*7c478bd9Sstevel@tonic-gate 		/* generate attribute path strings token */
596*7c478bd9Sstevel@tonic-gate 		m = au_to_strings(AUT_XATPATH, app->audp_sect[1],
597*7c478bd9Sstevel@tonic-gate 		    app->audp_cnt - 1);
598*7c478bd9Sstevel@tonic-gate 
599*7c478bd9Sstevel@tonic-gate 		token = au_append_token(token, m);
600*7c478bd9Sstevel@tonic-gate 	}
601*7c478bd9Sstevel@tonic-gate 
602*7c478bd9Sstevel@tonic-gate 	return (token);
603*7c478bd9Sstevel@tonic-gate }
604*7c478bd9Sstevel@tonic-gate 
605*7c478bd9Sstevel@tonic-gate /*
606*7c478bd9Sstevel@tonic-gate  * au_to_ipc
607*7c478bd9Sstevel@tonic-gate  * returns:
608*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a System V IPC token.
609*7c478bd9Sstevel@tonic-gate  */
610*7c478bd9Sstevel@tonic-gate token_t *
611*7c478bd9Sstevel@tonic-gate au_to_ipc(char type, int id)
612*7c478bd9Sstevel@tonic-gate {
613*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
614*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
615*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_IPC;	/* header for this token */
616*7c478bd9Sstevel@tonic-gate 
617*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
618*7c478bd9Sstevel@tonic-gate 
619*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
620*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
621*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &type, 1);		/* type of IPC object */
622*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&id, 1);
623*7c478bd9Sstevel@tonic-gate 
624*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
625*7c478bd9Sstevel@tonic-gate 
626*7c478bd9Sstevel@tonic-gate 	return (m);
627*7c478bd9Sstevel@tonic-gate }
628*7c478bd9Sstevel@tonic-gate 
629*7c478bd9Sstevel@tonic-gate /*
630*7c478bd9Sstevel@tonic-gate  * au_to_return32
631*7c478bd9Sstevel@tonic-gate  * returns:
632*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a return value token.
633*7c478bd9Sstevel@tonic-gate  */
634*7c478bd9Sstevel@tonic-gate token_t *
635*7c478bd9Sstevel@tonic-gate au_to_return32(int error, int32_t rv)
636*7c478bd9Sstevel@tonic-gate {
637*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
638*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
639*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_RETURN32; /* header for this token */
640*7c478bd9Sstevel@tonic-gate 	int32_t val;
641*7c478bd9Sstevel@tonic-gate 	char ed = error;
642*7c478bd9Sstevel@tonic-gate 
643*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
644*7c478bd9Sstevel@tonic-gate 
645*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
646*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
647*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &ed, 1);
648*7c478bd9Sstevel@tonic-gate 
649*7c478bd9Sstevel@tonic-gate 	if (error) {
650*7c478bd9Sstevel@tonic-gate 		val = -1;
651*7c478bd9Sstevel@tonic-gate 		adr_int32(&adr, &val, 1);
652*7c478bd9Sstevel@tonic-gate 	} else {
653*7c478bd9Sstevel@tonic-gate 		adr_int32(&adr, &rv, 1);
654*7c478bd9Sstevel@tonic-gate 	}
655*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
656*7c478bd9Sstevel@tonic-gate 
657*7c478bd9Sstevel@tonic-gate 	return (m);
658*7c478bd9Sstevel@tonic-gate }
659*7c478bd9Sstevel@tonic-gate 
660*7c478bd9Sstevel@tonic-gate /*
661*7c478bd9Sstevel@tonic-gate  * au_to_return64
662*7c478bd9Sstevel@tonic-gate  * returns:
663*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a return value token.
664*7c478bd9Sstevel@tonic-gate  */
665*7c478bd9Sstevel@tonic-gate token_t *
666*7c478bd9Sstevel@tonic-gate au_to_return64(int error, int64_t rv)
667*7c478bd9Sstevel@tonic-gate {
668*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
669*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
670*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_RETURN64; /* header for this token */
671*7c478bd9Sstevel@tonic-gate 	int64_t val;
672*7c478bd9Sstevel@tonic-gate 	char ed = error;
673*7c478bd9Sstevel@tonic-gate 
674*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
675*7c478bd9Sstevel@tonic-gate 
676*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
677*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
678*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &ed, 1);
679*7c478bd9Sstevel@tonic-gate 
680*7c478bd9Sstevel@tonic-gate 	if (error) {
681*7c478bd9Sstevel@tonic-gate 		val = -1;
682*7c478bd9Sstevel@tonic-gate 		adr_int64(&adr, &val, 1);
683*7c478bd9Sstevel@tonic-gate 	} else {
684*7c478bd9Sstevel@tonic-gate 		adr_int64(&adr, &rv, 1);
685*7c478bd9Sstevel@tonic-gate 	}
686*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
687*7c478bd9Sstevel@tonic-gate 
688*7c478bd9Sstevel@tonic-gate 	return (m);
689*7c478bd9Sstevel@tonic-gate }
690*7c478bd9Sstevel@tonic-gate 
691*7c478bd9Sstevel@tonic-gate #ifdef	AU_MAY_USE_SOMEDAY
692*7c478bd9Sstevel@tonic-gate /*
693*7c478bd9Sstevel@tonic-gate  * au_to_opaque
694*7c478bd9Sstevel@tonic-gate  * returns:
695*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a opaque token.
696*7c478bd9Sstevel@tonic-gate  */
697*7c478bd9Sstevel@tonic-gate token_t *
698*7c478bd9Sstevel@tonic-gate au_to_opaque(short bytes, char *opaque)
699*7c478bd9Sstevel@tonic-gate {
700*7c478bd9Sstevel@tonic-gate 	token_t *token;			/* local au_membuf */
701*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
702*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_OPAQUE;	/* header for this token */
703*7c478bd9Sstevel@tonic-gate 
704*7c478bd9Sstevel@tonic-gate 	token = au_getclr();
705*7c478bd9Sstevel@tonic-gate 
706*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
707*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
708*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bytes, 1);
709*7c478bd9Sstevel@tonic-gate 
710*7c478bd9Sstevel@tonic-gate 	token->len = adr_count(&adr);
711*7c478bd9Sstevel@tonic-gate 
712*7c478bd9Sstevel@tonic-gate 	/*
713*7c478bd9Sstevel@tonic-gate 	 * Now attach the data
714*7c478bd9Sstevel@tonic-gate 	 */
715*7c478bd9Sstevel@tonic-gate 	(void) au_append_buf(opaque, bytes, token);
716*7c478bd9Sstevel@tonic-gate 
717*7c478bd9Sstevel@tonic-gate 	return (token);
718*7c478bd9Sstevel@tonic-gate }
719*7c478bd9Sstevel@tonic-gate #endif	/* AU_MAY_USE_SOMEDAY */
720*7c478bd9Sstevel@tonic-gate 
721*7c478bd9Sstevel@tonic-gate /*
722*7c478bd9Sstevel@tonic-gate  * au_to_ip
723*7c478bd9Sstevel@tonic-gate  * returns:
724*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a ip header token
725*7c478bd9Sstevel@tonic-gate  */
726*7c478bd9Sstevel@tonic-gate token_t *
727*7c478bd9Sstevel@tonic-gate au_to_ip(struct ip *ipp)
728*7c478bd9Sstevel@tonic-gate {
729*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
730*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
731*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_IP;	/* header for this token */
732*7c478bd9Sstevel@tonic-gate 
733*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
734*7c478bd9Sstevel@tonic-gate 
735*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
736*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
737*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)ipp, 2);
738*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&(ipp->ip_len), 3);
739*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)&(ipp->ip_ttl), 2);
740*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&(ipp->ip_sum), 1);
741*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(ipp->ip_src), 2);
742*7c478bd9Sstevel@tonic-gate 
743*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
744*7c478bd9Sstevel@tonic-gate 
745*7c478bd9Sstevel@tonic-gate 	return (m);
746*7c478bd9Sstevel@tonic-gate }
747*7c478bd9Sstevel@tonic-gate 
748*7c478bd9Sstevel@tonic-gate /*
749*7c478bd9Sstevel@tonic-gate  * au_to_iport
750*7c478bd9Sstevel@tonic-gate  * returns:
751*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a ip path token
752*7c478bd9Sstevel@tonic-gate  */
753*7c478bd9Sstevel@tonic-gate token_t *
754*7c478bd9Sstevel@tonic-gate au_to_iport(ushort_t iport)
755*7c478bd9Sstevel@tonic-gate {
756*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
757*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
758*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_IPORT;	/* header for this token */
759*7c478bd9Sstevel@tonic-gate 
760*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
761*7c478bd9Sstevel@tonic-gate 
762*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
763*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
764*7c478bd9Sstevel@tonic-gate 	adr_ushort(&adr, &iport, 1);
765*7c478bd9Sstevel@tonic-gate 
766*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
767*7c478bd9Sstevel@tonic-gate 
768*7c478bd9Sstevel@tonic-gate 	return (m);
769*7c478bd9Sstevel@tonic-gate }
770*7c478bd9Sstevel@tonic-gate 
771*7c478bd9Sstevel@tonic-gate /*
772*7c478bd9Sstevel@tonic-gate  * au_to_in_addr
773*7c478bd9Sstevel@tonic-gate  * returns:
774*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a ip path token
775*7c478bd9Sstevel@tonic-gate  */
776*7c478bd9Sstevel@tonic-gate token_t *
777*7c478bd9Sstevel@tonic-gate au_to_in_addr(struct in_addr *internet_addr)
778*7c478bd9Sstevel@tonic-gate {
779*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
780*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
781*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_IN_ADDR;	/* header for this token */
782*7c478bd9Sstevel@tonic-gate 
783*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
784*7c478bd9Sstevel@tonic-gate 
785*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
786*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
787*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)internet_addr, sizeof (struct in_addr));
788*7c478bd9Sstevel@tonic-gate 
789*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
790*7c478bd9Sstevel@tonic-gate 
791*7c478bd9Sstevel@tonic-gate 	return (m);
792*7c478bd9Sstevel@tonic-gate }
793*7c478bd9Sstevel@tonic-gate 
794*7c478bd9Sstevel@tonic-gate /*
795*7c478bd9Sstevel@tonic-gate  * au_to_in_addr_ex
796*7c478bd9Sstevel@tonic-gate  * returns:
797*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing an ipv6 token
798*7c478bd9Sstevel@tonic-gate  */
799*7c478bd9Sstevel@tonic-gate token_t *
800*7c478bd9Sstevel@tonic-gate au_to_in_addr_ex(int32_t *internet_addr)
801*7c478bd9Sstevel@tonic-gate {
802*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
803*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
804*7c478bd9Sstevel@tonic-gate 	char data_header_v4 = AUT_IN_ADDR;	/* header for v4 token */
805*7c478bd9Sstevel@tonic-gate 	char data_header_v6 = AUT_IN_ADDR_EX;	/* header for v6 token */
806*7c478bd9Sstevel@tonic-gate 	int32_t type = AU_IPv6;
807*7c478bd9Sstevel@tonic-gate 
808*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
809*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
810*7c478bd9Sstevel@tonic-gate 
811*7c478bd9Sstevel@tonic-gate 	if (IN6_IS_ADDR_V4MAPPED((in6_addr_t *)internet_addr)) {
812*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, &data_header_v4, 1);
813*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)internet_addr, sizeof (struct in_addr));
814*7c478bd9Sstevel@tonic-gate 	} else {
815*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, &data_header_v6, 1);
816*7c478bd9Sstevel@tonic-gate 		adr_int32(&adr, &type, 1);
817*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)internet_addr, sizeof (struct in6_addr));
818*7c478bd9Sstevel@tonic-gate 	}
819*7c478bd9Sstevel@tonic-gate 
820*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
821*7c478bd9Sstevel@tonic-gate 
822*7c478bd9Sstevel@tonic-gate 	return (m);
823*7c478bd9Sstevel@tonic-gate }
824*7c478bd9Sstevel@tonic-gate 
825*7c478bd9Sstevel@tonic-gate /*
826*7c478bd9Sstevel@tonic-gate  * The Modifier tokens
827*7c478bd9Sstevel@tonic-gate  */
828*7c478bd9Sstevel@tonic-gate 
829*7c478bd9Sstevel@tonic-gate /*
830*7c478bd9Sstevel@tonic-gate  * au_to_attr
831*7c478bd9Sstevel@tonic-gate  * returns:
832*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing an attribute token.
833*7c478bd9Sstevel@tonic-gate  */
834*7c478bd9Sstevel@tonic-gate token_t *
835*7c478bd9Sstevel@tonic-gate au_to_attr(struct vattr *attr)
836*7c478bd9Sstevel@tonic-gate {
837*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
838*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
839*7c478bd9Sstevel@tonic-gate #ifdef _LP64
840*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_ATTR64;	/* header for this token */
841*7c478bd9Sstevel@tonic-gate #else
842*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_ATTR32;
843*7c478bd9Sstevel@tonic-gate #endif
844*7c478bd9Sstevel@tonic-gate 	int32_t value;
845*7c478bd9Sstevel@tonic-gate 
846*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
847*7c478bd9Sstevel@tonic-gate 
848*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
849*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
850*7c478bd9Sstevel@tonic-gate 	value = (int32_t)attr->va_mode;
851*7c478bd9Sstevel@tonic-gate 	value |= (int32_t)(VTTOIF(attr->va_type));
852*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
853*7c478bd9Sstevel@tonic-gate 	value = (int32_t)attr->va_uid;
854*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
855*7c478bd9Sstevel@tonic-gate 	value = (int32_t)attr->va_gid;
856*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
857*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(attr->va_fsid), 1);
858*7c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(attr->va_nodeid), 1);
859*7c478bd9Sstevel@tonic-gate #ifdef _LP64
860*7c478bd9Sstevel@tonic-gate 	adr_int64(&adr, (int64_t *)&(attr->va_rdev), 1);
861*7c478bd9Sstevel@tonic-gate #else
862*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&(attr->va_rdev), 1);
863*7c478bd9Sstevel@tonic-gate #endif
864*7c478bd9Sstevel@tonic-gate 
865*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
866*7c478bd9Sstevel@tonic-gate 
867*7c478bd9Sstevel@tonic-gate 	return (m);
868*7c478bd9Sstevel@tonic-gate }
869*7c478bd9Sstevel@tonic-gate 
870*7c478bd9Sstevel@tonic-gate token_t *
871*7c478bd9Sstevel@tonic-gate au_to_acl(struct acl *aclp)
872*7c478bd9Sstevel@tonic-gate {
873*7c478bd9Sstevel@tonic-gate 	token_t *m;				/* local au_membuf */
874*7c478bd9Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
875*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_ACL;		/* header for this token */
876*7c478bd9Sstevel@tonic-gate 	int32_t value;
877*7c478bd9Sstevel@tonic-gate 
878*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
879*7c478bd9Sstevel@tonic-gate 
880*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
881*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
882*7c478bd9Sstevel@tonic-gate 
883*7c478bd9Sstevel@tonic-gate 	value = (int32_t)aclp->a_type;
884*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
885*7c478bd9Sstevel@tonic-gate 	value = (int32_t)aclp->a_id;
886*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
887*7c478bd9Sstevel@tonic-gate 	value = (int32_t)aclp->a_perm;
888*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
889*7c478bd9Sstevel@tonic-gate 
890*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
891*7c478bd9Sstevel@tonic-gate 	return (m);
892*7c478bd9Sstevel@tonic-gate }
893*7c478bd9Sstevel@tonic-gate 
894*7c478bd9Sstevel@tonic-gate /*
895*7c478bd9Sstevel@tonic-gate  * au_to_ipc_perm
896*7c478bd9Sstevel@tonic-gate  * returns:
897*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a System V IPC attribute token.
898*7c478bd9Sstevel@tonic-gate  */
899*7c478bd9Sstevel@tonic-gate token_t *
900*7c478bd9Sstevel@tonic-gate au_to_ipc_perm(struct kipc_perm *perm)
901*7c478bd9Sstevel@tonic-gate {
902*7c478bd9Sstevel@tonic-gate 	token_t *m;				/* local au_membuf */
903*7c478bd9Sstevel@tonic-gate 	adr_t adr;				/* adr memory stream header */
904*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_IPC_PERM;	/* header for this token */
905*7c478bd9Sstevel@tonic-gate 	int32_t value;
906*7c478bd9Sstevel@tonic-gate 
907*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
908*7c478bd9Sstevel@tonic-gate 
909*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
910*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
911*7c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_uid;
912*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
913*7c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_gid;
914*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
915*7c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_cuid;
916*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
917*7c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_cgid;
918*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
919*7c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_mode;
920*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
921*7c478bd9Sstevel@tonic-gate 	value = 0;			/* seq is now obsolete */
922*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
923*7c478bd9Sstevel@tonic-gate 	value = (int32_t)perm->ipc_key;
924*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &value, 1);
925*7c478bd9Sstevel@tonic-gate 
926*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
927*7c478bd9Sstevel@tonic-gate 
928*7c478bd9Sstevel@tonic-gate 	return (m);
929*7c478bd9Sstevel@tonic-gate }
930*7c478bd9Sstevel@tonic-gate 
931*7c478bd9Sstevel@tonic-gate #ifdef NOTYET
932*7c478bd9Sstevel@tonic-gate /*
933*7c478bd9Sstevel@tonic-gate  * au_to_label
934*7c478bd9Sstevel@tonic-gate  * returns:
935*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a label token.
936*7c478bd9Sstevel@tonic-gate  */
937*7c478bd9Sstevel@tonic-gate token_t *
938*7c478bd9Sstevel@tonic-gate au_to_label(bilabel_t *label)
939*7c478bd9Sstevel@tonic-gate {
940*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
941*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
942*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_LABEL;	/* header for this token */
943*7c478bd9Sstevel@tonic-gate 	short bs = sizeof (bilabel_t);
944*7c478bd9Sstevel@tonic-gate 
945*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
946*7c478bd9Sstevel@tonic-gate 
947*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
948*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
949*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &bs, 1);
950*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, (char *)label, bs);
951*7c478bd9Sstevel@tonic-gate 
952*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
953*7c478bd9Sstevel@tonic-gate 
954*7c478bd9Sstevel@tonic-gate 	return (m);
955*7c478bd9Sstevel@tonic-gate }
956*7c478bd9Sstevel@tonic-gate #endif	/* NOTYET */
957*7c478bd9Sstevel@tonic-gate 
958*7c478bd9Sstevel@tonic-gate token_t *
959*7c478bd9Sstevel@tonic-gate au_to_groups(const gid_t *crgroups, uint_t crngroups)
960*7c478bd9Sstevel@tonic-gate {
961*7c478bd9Sstevel@tonic-gate 	token_t *m;			/* local au_membuf */
962*7c478bd9Sstevel@tonic-gate 	adr_t adr;			/* adr memory stream header */
963*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_NEWGROUPS;	/* header for this token */
964*7c478bd9Sstevel@tonic-gate 	short n_groups;
965*7c478bd9Sstevel@tonic-gate 
966*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
967*7c478bd9Sstevel@tonic-gate 
968*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
969*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
970*7c478bd9Sstevel@tonic-gate 	n_groups = (short)crngroups;
971*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &n_groups, 1);
972*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)crgroups, (int)crngroups);
973*7c478bd9Sstevel@tonic-gate 
974*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
975*7c478bd9Sstevel@tonic-gate 
976*7c478bd9Sstevel@tonic-gate 	return (m);
977*7c478bd9Sstevel@tonic-gate }
978*7c478bd9Sstevel@tonic-gate 
979*7c478bd9Sstevel@tonic-gate /*
980*7c478bd9Sstevel@tonic-gate  * au_to_socket_ex
981*7c478bd9Sstevel@tonic-gate  * returns:
982*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a socket token.
983*7c478bd9Sstevel@tonic-gate  */
984*7c478bd9Sstevel@tonic-gate token_t *
985*7c478bd9Sstevel@tonic-gate au_to_socket_ex(short dom, short type, char *l, char *f)
986*7c478bd9Sstevel@tonic-gate {
987*7c478bd9Sstevel@tonic-gate 	adr_t adr;
988*7c478bd9Sstevel@tonic-gate 	token_t *m;
989*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_SOCKET_EX;
990*7c478bd9Sstevel@tonic-gate 	struct sockaddr_in6 *addr6;
991*7c478bd9Sstevel@tonic-gate 	struct sockaddr_in  *addr4;
992*7c478bd9Sstevel@tonic-gate 	short size;
993*7c478bd9Sstevel@tonic-gate 
994*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
995*7c478bd9Sstevel@tonic-gate 
996*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
997*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
998*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &dom, 1);		/* dom of socket */
999*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &type, 1);		/* type of socket */
1000*7c478bd9Sstevel@tonic-gate 
1001*7c478bd9Sstevel@tonic-gate 	if (dom == AF_INET6) {
1002*7c478bd9Sstevel@tonic-gate 		size = AU_IPv6;
1003*7c478bd9Sstevel@tonic-gate 		adr_short(&adr, &size, 1);	/* type of addresses */
1004*7c478bd9Sstevel@tonic-gate 		addr6 = (struct sockaddr_in6 *)l;
1005*7c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&addr6->sin6_port, 1);
1006*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&addr6->sin6_addr, size);
1007*7c478bd9Sstevel@tonic-gate 		addr6 = (struct sockaddr_in6 *)f;
1008*7c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&addr6->sin6_port, 1);
1009*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&addr6->sin6_addr, size);
1010*7c478bd9Sstevel@tonic-gate 	} else if (dom == AF_INET) {
1011*7c478bd9Sstevel@tonic-gate 		size = AU_IPv4;
1012*7c478bd9Sstevel@tonic-gate 		adr_short(&adr, &size, 1);	/* type of addresses */
1013*7c478bd9Sstevel@tonic-gate 		addr4 = (struct sockaddr_in *)l;
1014*7c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&addr4->sin_port, 1);
1015*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&addr4->sin_addr, size);
1016*7c478bd9Sstevel@tonic-gate 		addr4 = (struct sockaddr_in *)f;
1017*7c478bd9Sstevel@tonic-gate 		adr_short(&adr, (short *)&addr4->sin_port, 1);
1018*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, (char *)&addr4->sin_addr, size);
1019*7c478bd9Sstevel@tonic-gate 	}
1020*7c478bd9Sstevel@tonic-gate 
1021*7c478bd9Sstevel@tonic-gate 
1022*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
1023*7c478bd9Sstevel@tonic-gate 
1024*7c478bd9Sstevel@tonic-gate 	return (m);
1025*7c478bd9Sstevel@tonic-gate }
1026*7c478bd9Sstevel@tonic-gate 
1027*7c478bd9Sstevel@tonic-gate /*
1028*7c478bd9Sstevel@tonic-gate  * au_to_seq
1029*7c478bd9Sstevel@tonic-gate  * returns:
1030*7c478bd9Sstevel@tonic-gate  *	pointer to au_membuf chain containing a sequence token.
1031*7c478bd9Sstevel@tonic-gate  */
1032*7c478bd9Sstevel@tonic-gate token_t *
1033*7c478bd9Sstevel@tonic-gate au_to_seq()
1034*7c478bd9Sstevel@tonic-gate {
1035*7c478bd9Sstevel@tonic-gate 	adr_t adr;
1036*7c478bd9Sstevel@tonic-gate 	token_t *m;
1037*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_SEQ;
1038*7c478bd9Sstevel@tonic-gate 	static int32_t zerocount;
1039*7c478bd9Sstevel@tonic-gate 
1040*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
1041*7c478bd9Sstevel@tonic-gate 
1042*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
1043*7c478bd9Sstevel@tonic-gate 
1044*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
1045*7c478bd9Sstevel@tonic-gate 
1046*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, &zerocount, 1);
1047*7c478bd9Sstevel@tonic-gate 
1048*7c478bd9Sstevel@tonic-gate 	m->len = adr_count(&adr);
1049*7c478bd9Sstevel@tonic-gate 
1050*7c478bd9Sstevel@tonic-gate 	return (m);
1051*7c478bd9Sstevel@tonic-gate }
1052*7c478bd9Sstevel@tonic-gate 
1053*7c478bd9Sstevel@tonic-gate token_t *
1054*7c478bd9Sstevel@tonic-gate au_to_sock_inet(struct sockaddr_in *s_inet)
1055*7c478bd9Sstevel@tonic-gate {
1056*7c478bd9Sstevel@tonic-gate 	adr_t adr;
1057*7c478bd9Sstevel@tonic-gate 	token_t *m;
1058*7c478bd9Sstevel@tonic-gate 	char data_header = AUT_SOCKET;
1059*7c478bd9Sstevel@tonic-gate 
1060*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
1061*7c478bd9Sstevel@tonic-gate 
1062*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(m, char *));
1063*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
1064*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&s_inet->sin_family, 1);
1065*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, (short *)&s_inet->sin_port, 1);
1066*7c478bd9Sstevel@tonic-gate 
1067*7c478bd9Sstevel@tonic-gate 	/* remote addr */
1068*7c478bd9Sstevel@tonic-gate 	adr_int32(&adr, (int32_t *)&s_inet->sin_addr.s_addr, 1);
1069*7c478bd9Sstevel@tonic-gate 
1070*7c478bd9Sstevel@tonic-gate 	m->len = (uchar_t)adr_count(&adr);
1071*7c478bd9Sstevel@tonic-gate 
1072*7c478bd9Sstevel@tonic-gate 	return (m);
1073*7c478bd9Sstevel@tonic-gate }
1074*7c478bd9Sstevel@tonic-gate 
1075*7c478bd9Sstevel@tonic-gate extern int maxprivbytes;
1076*7c478bd9Sstevel@tonic-gate 
1077*7c478bd9Sstevel@tonic-gate token_t *
1078*7c478bd9Sstevel@tonic-gate au_to_privset(
1079*7c478bd9Sstevel@tonic-gate     const char *set,
1080*7c478bd9Sstevel@tonic-gate     const priv_set_t *pset,
1081*7c478bd9Sstevel@tonic-gate     char data_header,
1082*7c478bd9Sstevel@tonic-gate     int success)
1083*7c478bd9Sstevel@tonic-gate {
1084*7c478bd9Sstevel@tonic-gate 	token_t *token, *m;
1085*7c478bd9Sstevel@tonic-gate 	adr_t adr;
1086*7c478bd9Sstevel@tonic-gate 	int priv;
1087*7c478bd9Sstevel@tonic-gate 	const char *pname;
1088*7c478bd9Sstevel@tonic-gate 	char sf = (char)success;
1089*7c478bd9Sstevel@tonic-gate 	char *buf, *q;
1090*7c478bd9Sstevel@tonic-gate 	short sz;
1091*7c478bd9Sstevel@tonic-gate 	boolean_t full;
1092*7c478bd9Sstevel@tonic-gate 
1093*7c478bd9Sstevel@tonic-gate 	token = au_getclr();
1094*7c478bd9Sstevel@tonic-gate 
1095*7c478bd9Sstevel@tonic-gate 	adr_start(&adr, memtod(token, char *));
1096*7c478bd9Sstevel@tonic-gate 	adr_char(&adr, &data_header, 1);
1097*7c478bd9Sstevel@tonic-gate 	/*
1098*7c478bd9Sstevel@tonic-gate 	 * set is not used for AUT_UPRIV and sf (== success) is not
1099*7c478bd9Sstevel@tonic-gate 	 * used for AUT_PRIV
1100*7c478bd9Sstevel@tonic-gate 	 */
1101*7c478bd9Sstevel@tonic-gate 	if (data_header == AUT_UPRIV) {
1102*7c478bd9Sstevel@tonic-gate 		adr_char(&adr, &sf, 1);
1103*7c478bd9Sstevel@tonic-gate 	} else {
1104*7c478bd9Sstevel@tonic-gate 		sz = strlen(set) + 1;
1105*7c478bd9Sstevel@tonic-gate 		adr_short(&adr, &sz, 1);
1106*7c478bd9Sstevel@tonic-gate 
1107*7c478bd9Sstevel@tonic-gate 		token->len = (uchar_t)adr_count(&adr);
1108*7c478bd9Sstevel@tonic-gate 		m = au_getclr();
1109*7c478bd9Sstevel@tonic-gate 
1110*7c478bd9Sstevel@tonic-gate 		(void) au_append_buf(set, sz, m);
1111*7c478bd9Sstevel@tonic-gate 		(void) au_append_rec(token, m, AU_PACK);
1112*7c478bd9Sstevel@tonic-gate 		adr.adr_now += sz;
1113*7c478bd9Sstevel@tonic-gate 	}
1114*7c478bd9Sstevel@tonic-gate 
1115*7c478bd9Sstevel@tonic-gate 	full = priv_isfullset(pset);
1116*7c478bd9Sstevel@tonic-gate 
1117*7c478bd9Sstevel@tonic-gate 	if (full) {
1118*7c478bd9Sstevel@tonic-gate 		buf = "ALL";
1119*7c478bd9Sstevel@tonic-gate 		sz = strlen(buf) + 1;
1120*7c478bd9Sstevel@tonic-gate 	} else {
1121*7c478bd9Sstevel@tonic-gate 		q = buf = kmem_alloc(maxprivbytes, KM_SLEEP);
1122*7c478bd9Sstevel@tonic-gate 		*buf = '\0';
1123*7c478bd9Sstevel@tonic-gate 
1124*7c478bd9Sstevel@tonic-gate 		for (priv = 0; (pname = priv_getbynum(priv)) != NULL; priv++) {
1125*7c478bd9Sstevel@tonic-gate 			if (priv_ismember(pset, priv)) {
1126*7c478bd9Sstevel@tonic-gate 				if (q != buf)
1127*7c478bd9Sstevel@tonic-gate 					*q++ = ',';
1128*7c478bd9Sstevel@tonic-gate 				(void) strcpy(q, pname);
1129*7c478bd9Sstevel@tonic-gate 				q += strlen(q);
1130*7c478bd9Sstevel@tonic-gate 			}
1131*7c478bd9Sstevel@tonic-gate 		}
1132*7c478bd9Sstevel@tonic-gate 		sz = (q - buf) + 1;
1133*7c478bd9Sstevel@tonic-gate 	}
1134*7c478bd9Sstevel@tonic-gate 
1135*7c478bd9Sstevel@tonic-gate 	adr_short(&adr, &sz, 1);
1136*7c478bd9Sstevel@tonic-gate 	token->len = (uchar_t)adr_count(&adr);
1137*7c478bd9Sstevel@tonic-gate 
1138*7c478bd9Sstevel@tonic-gate 	m = au_getclr();
1139*7c478bd9Sstevel@tonic-gate 	(void) au_append_buf(buf, sz, m);
1140*7c478bd9Sstevel@tonic-gate 	(void) au_append_rec(token, m, AU_PACK);
1141*7c478bd9Sstevel@tonic-gate 
1142*7c478bd9Sstevel@tonic-gate 	if (!full)
1143*7c478bd9Sstevel@tonic-gate 		kmem_free(buf, maxprivbytes);
1144*7c478bd9Sstevel@tonic-gate 
1145*7c478bd9Sstevel@tonic-gate 	return (token);
1146*7c478bd9Sstevel@tonic-gate }
1147