xref: /illumos-gate/usr/src/cmd/praudit/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 #include <ctype.h>
30*7c478bd9Sstevel@tonic-gate #include <dirent.h>
31*7c478bd9Sstevel@tonic-gate #include <grp.h>
32*7c478bd9Sstevel@tonic-gate #include <libintl.h>
33*7c478bd9Sstevel@tonic-gate #include <limits.h>
34*7c478bd9Sstevel@tonic-gate #include <locale.h>
35*7c478bd9Sstevel@tonic-gate #include <pwd.h>
36*7c478bd9Sstevel@tonic-gate #include <stdio.h>
37*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
38*7c478bd9Sstevel@tonic-gate #include <string.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/file.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/uio.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/acl.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/errno.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/ipc.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/sem.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>
51*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
53*7c478bd9Sstevel@tonic-gate #include <rpc/types.h>
54*7c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
55*7c478bd9Sstevel@tonic-gate #include <rpc/auth_unix.h>
56*7c478bd9Sstevel@tonic-gate #include <rpc/svc.h>
57*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
58*7c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
59*7c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_quota.h>
60*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
61*7c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
62*7c478bd9Sstevel@tonic-gate #include <unistd.h>
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
65*7c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
66*7c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #ifdef	TSOL
69*7c478bd9Sstevel@tonic-gate #include <tsol/label.h>
70*7c478bd9Sstevel@tonic-gate #endif	/* TSOL */
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate #include "praudit.h"
73*7c478bd9Sstevel@tonic-gate #include "toktable.h"
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate #include <netdb.h>
76*7c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate static char *anchor_path(char *);
79*7c478bd9Sstevel@tonic-gate static char *collapse_path(char *);
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate /*
83*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
84*7c478bd9Sstevel@tonic-gate  * is_file_token:
85*7c478bd9Sstevel@tonic-gate  *		  Tests whether the specified token id represents a type
86*7c478bd9Sstevel@tonic-gate  *		  of file token.
87*7c478bd9Sstevel@tonic-gate  * return codes :  1 - tokenid is a file token type
88*7c478bd9Sstevel@tonic-gate  *		:  0 - otherwise
89*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
90*7c478bd9Sstevel@tonic-gate  */
91*7c478bd9Sstevel@tonic-gate int
92*7c478bd9Sstevel@tonic-gate is_file_token(int tokenid)
93*7c478bd9Sstevel@tonic-gate {
94*7c478bd9Sstevel@tonic-gate 	if ((tokenid == AUT_OTHER_FILE32) || (tokenid == AUT_OTHER_FILE64))
95*7c478bd9Sstevel@tonic-gate 		return (1);
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	return (0);
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate /*
101*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
102*7c478bd9Sstevel@tonic-gate  * is_header_token:
103*7c478bd9Sstevel@tonic-gate  *		  Tests whether the specified token id represents a type
104*7c478bd9Sstevel@tonic-gate  *		  of header token (signifying the start of a record).
105*7c478bd9Sstevel@tonic-gate  * return codes :  1 - tokenid is a header type
106*7c478bd9Sstevel@tonic-gate  *		:  0 - otherwise
107*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
108*7c478bd9Sstevel@tonic-gate  */
109*7c478bd9Sstevel@tonic-gate int
110*7c478bd9Sstevel@tonic-gate is_header_token(int tokenid)
111*7c478bd9Sstevel@tonic-gate {
112*7c478bd9Sstevel@tonic-gate 	if ((tokenid == AUT_OHEADER) || (tokenid == AUT_HEADER32) ||
113*7c478bd9Sstevel@tonic-gate 	    (tokenid == AUT_HEADER32_EX) || (tokenid == AUT_HEADER64) ||
114*7c478bd9Sstevel@tonic-gate 	    (tokenid == AUT_HEADER64_EX))
115*7c478bd9Sstevel@tonic-gate 		return (1);
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 	return (0);
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate /*
121*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
122*7c478bd9Sstevel@tonic-gate  * is_token:
123*7c478bd9Sstevel@tonic-gate  *		  Tests whether the specified token id represents a true
124*7c478bd9Sstevel@tonic-gate  *		  token, as opposed to a regular tag.
125*7c478bd9Sstevel@tonic-gate  * return codes :  1 - tokenid is a true token
126*7c478bd9Sstevel@tonic-gate  *		:  0 - otherwise
127*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
128*7c478bd9Sstevel@tonic-gate  */
129*7c478bd9Sstevel@tonic-gate int
130*7c478bd9Sstevel@tonic-gate is_token(int tokenid)
131*7c478bd9Sstevel@tonic-gate {
132*7c478bd9Sstevel@tonic-gate 	if ((tokenid > 0) && (tokenid <= MAXTOKEN))
133*7c478bd9Sstevel@tonic-gate 		return (1);
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	return (0);
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate /*
140*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
141*7c478bd9Sstevel@tonic-gate  * exit_token() 	: Process information label token and display contents
142*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
143*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
144*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the label token id has been retrieved
145*7c478bd9Sstevel@tonic-gate  *
146*7c478bd9Sstevel@tonic-gate  * Format of exit token:
147*7c478bd9Sstevel@tonic-gate  *	exit token id		adr_char
148*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
149*7c478bd9Sstevel@tonic-gate  */
150*7c478bd9Sstevel@tonic-gate int
151*7c478bd9Sstevel@tonic-gate exit_token(pr_context_t *context)
152*7c478bd9Sstevel@tonic-gate {
153*7c478bd9Sstevel@tonic-gate 	int	returnstat;
154*7c478bd9Sstevel@tonic-gate 	int	retval;
155*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ERRVAL)) != 0)
158*7c478bd9Sstevel@tonic-gate 		return (returnstat);
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int32(context, (int32_t *)&retval, 1)) == 0) {
161*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
162*7c478bd9Sstevel@tonic-gate 			char *emsg = strerror(retval);
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 			if (emsg == NULL)
165*7c478bd9Sstevel@tonic-gate 				uval.string_val = gettext("Unknown errno");
166*7c478bd9Sstevel@tonic-gate 			else
167*7c478bd9Sstevel@tonic-gate 				uval.string_val = gettext(emsg);
168*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
169*7c478bd9Sstevel@tonic-gate 		} else {
170*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_INT32;
171*7c478bd9Sstevel@tonic-gate 			uval.int32_val = retval;
172*7c478bd9Sstevel@tonic-gate 		}
173*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, 0);
174*7c478bd9Sstevel@tonic-gate 	}
175*7c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
176*7c478bd9Sstevel@tonic-gate 		returnstat = close_tag(context, TAG_ERRVAL);
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	return (process_tag(context, TAG_RETVAL, returnstat, 1));
179*7c478bd9Sstevel@tonic-gate }
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate /*
182*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------------
183*7c478bd9Sstevel@tonic-gate  * file_token()	: prints out seconds of time and other file name
184*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
185*7c478bd9Sstevel@tonic-gate  *		:  0 - successful, valid file token fields
186*7c478bd9Sstevel@tonic-gate  * At the time of entry, the file token ID has already been retrieved
187*7c478bd9Sstevel@tonic-gate  *
188*7c478bd9Sstevel@tonic-gate  * Format of file token:
189*7c478bd9Sstevel@tonic-gate  *	file token id		adr_char
190*7c478bd9Sstevel@tonic-gate  *	seconds of time		adr_u_int
191*7c478bd9Sstevel@tonic-gate  *	name of other file	adr_string
192*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------------
193*7c478bd9Sstevel@tonic-gate  */
194*7c478bd9Sstevel@tonic-gate int
195*7c478bd9Sstevel@tonic-gate file_token(pr_context_t *context)
196*7c478bd9Sstevel@tonic-gate {
197*7c478bd9Sstevel@tonic-gate 	int	returnstat;
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate 	returnstat = pa_utime32(context, 0, 0);		/* time from usecs */
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate 	/* other file name */
202*7c478bd9Sstevel@tonic-gate 	returnstat = pa_file_string(context, returnstat, 1);
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate 	return (returnstat);
205*7c478bd9Sstevel@tonic-gate }
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate int
208*7c478bd9Sstevel@tonic-gate file64_token(pr_context_t *context)
209*7c478bd9Sstevel@tonic-gate {
210*7c478bd9Sstevel@tonic-gate 	int	returnstat;
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	returnstat = pa_utime64(context, 0, 0);		/* time from usecs */
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate 	/* other file name */
215*7c478bd9Sstevel@tonic-gate 	returnstat = pa_file_string(context, returnstat, 1);
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate 	return (returnstat);
218*7c478bd9Sstevel@tonic-gate }
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate /*
221*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
222*7c478bd9Sstevel@tonic-gate  * header_token()	: Process record header token and display contents
223*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
224*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
225*7c478bd9Sstevel@tonic-gate  *			:  1 - warning, password entry not found
226*7c478bd9Sstevel@tonic-gate  *
227*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the header token id has been retrieved
228*7c478bd9Sstevel@tonic-gate  *
229*7c478bd9Sstevel@tonic-gate  * Format of header token:
230*7c478bd9Sstevel@tonic-gate  *	header token id 	adr_char
231*7c478bd9Sstevel@tonic-gate  * 	record byte count	adr_u_int
232*7c478bd9Sstevel@tonic-gate  *	event type		adr_u_short (printed either ASCII or raw)
233*7c478bd9Sstevel@tonic-gate  *	event class		adr_u_int   (printed either ASCII or raw)
234*7c478bd9Sstevel@tonic-gate  *	event action		adr_u_int
235*7c478bd9Sstevel@tonic-gate  *	if extended:		extended host name (IPv4/IPv6)
236*7c478bd9Sstevel@tonic-gate  *	seconds of time		adr_u_int   (printed either ASCII or raw)
237*7c478bd9Sstevel@tonic-gate  *	nanoseconds of time	adr_u_int
238*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
239*7c478bd9Sstevel@tonic-gate  */
240*7c478bd9Sstevel@tonic-gate int
241*7c478bd9Sstevel@tonic-gate header_token(pr_context_t *context)
242*7c478bd9Sstevel@tonic-gate {
243*7c478bd9Sstevel@tonic-gate 	int	returnstat;
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 	returnstat = pa_reclen(context, 0);		/* record byte */
246*7c478bd9Sstevel@tonic-gate 	/* version ID */
247*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
248*7c478bd9Sstevel@tonic-gate 	/* event type */
249*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
250*7c478bd9Sstevel@tonic-gate 	/* event modifier */
251*7c478bd9Sstevel@tonic-gate 	returnstat = pa_event_modifier(context, returnstat, 0);
252*7c478bd9Sstevel@tonic-gate 	/* time from nsec */
253*7c478bd9Sstevel@tonic-gate 	returnstat = pa_ntime32(context, returnstat, 1);
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 	return (returnstat);
256*7c478bd9Sstevel@tonic-gate }
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate int
259*7c478bd9Sstevel@tonic-gate header64_token(pr_context_t *context)
260*7c478bd9Sstevel@tonic-gate {
261*7c478bd9Sstevel@tonic-gate 	int	returnstat;
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	returnstat = pa_reclen(context, 0);		/* record byte */
264*7c478bd9Sstevel@tonic-gate 	/* version ID */
265*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
266*7c478bd9Sstevel@tonic-gate 	/* event type */
267*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
268*7c478bd9Sstevel@tonic-gate 	/* event modifier */
269*7c478bd9Sstevel@tonic-gate 	returnstat = pa_event_modifier(context, returnstat, 0);
270*7c478bd9Sstevel@tonic-gate 	/* time from nsec */
271*7c478bd9Sstevel@tonic-gate 	returnstat = pa_ntime64(context, returnstat, 1);
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 	return (returnstat);
274*7c478bd9Sstevel@tonic-gate }
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate int
277*7c478bd9Sstevel@tonic-gate header32_ex_token(pr_context_t *context)
278*7c478bd9Sstevel@tonic-gate {
279*7c478bd9Sstevel@tonic-gate 	int	returnstat;
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate 	returnstat = pa_reclen(context, 0);		/* record byte */
282*7c478bd9Sstevel@tonic-gate 	/* version ID */
283*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
284*7c478bd9Sstevel@tonic-gate 	/* event type */
285*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
286*7c478bd9Sstevel@tonic-gate 	/* event modifier */
287*7c478bd9Sstevel@tonic-gate 	returnstat = pa_event_modifier(context, returnstat, 0);
288*7c478bd9Sstevel@tonic-gate 	/* machine name */
289*7c478bd9Sstevel@tonic-gate 	returnstat = pa_hostname_ex(context, returnstat, 0);
290*7c478bd9Sstevel@tonic-gate 	/* time from nsec */
291*7c478bd9Sstevel@tonic-gate 	returnstat = pa_ntime32(context, returnstat, 1);
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate 	return (returnstat);
294*7c478bd9Sstevel@tonic-gate }
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate int
297*7c478bd9Sstevel@tonic-gate header64_ex_token(pr_context_t *context)
298*7c478bd9Sstevel@tonic-gate {
299*7c478bd9Sstevel@tonic-gate 	int	returnstat;
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate 	returnstat = pa_reclen(context, 0);		/* record byte */
302*7c478bd9Sstevel@tonic-gate 	/* version ID */
303*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
304*7c478bd9Sstevel@tonic-gate 	/* event type */
305*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
306*7c478bd9Sstevel@tonic-gate 	/* event modifier */
307*7c478bd9Sstevel@tonic-gate 	returnstat = pa_event_modifier(context, returnstat, 0);
308*7c478bd9Sstevel@tonic-gate 	/* machine name */
309*7c478bd9Sstevel@tonic-gate 	returnstat = pa_hostname_ex(context, returnstat, 0);
310*7c478bd9Sstevel@tonic-gate 	/* time from nsec */
311*7c478bd9Sstevel@tonic-gate 	returnstat = pa_ntime64(context, returnstat, 1);
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 	return (returnstat);
314*7c478bd9Sstevel@tonic-gate }
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate /*
317*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
318*7c478bd9Sstevel@tonic-gate  * trailer_token()	: Process record trailer token and display contents
319*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
320*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
321*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the trailer token id has already been
322*7c478bd9Sstevel@tonic-gate  * retrieved
323*7c478bd9Sstevel@tonic-gate  *
324*7c478bd9Sstevel@tonic-gate  * Format of trailer token:
325*7c478bd9Sstevel@tonic-gate  * 	trailer token id	adr_char
326*7c478bd9Sstevel@tonic-gate  * 	record sequence no	adr_u_short (should be AUT_TRAILER_MAGIC)
327*7c478bd9Sstevel@tonic-gate  *	record byte count	adr_u_int
328*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
329*7c478bd9Sstevel@tonic-gate  */
330*7c478bd9Sstevel@tonic-gate int
331*7c478bd9Sstevel@tonic-gate trailer_token(pr_context_t *context)
332*7c478bd9Sstevel@tonic-gate {
333*7c478bd9Sstevel@tonic-gate 	short	magic_number;
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate 	if (pr_adr_u_short(context, (ushort_t *)&magic_number, 1) < 0) {
336*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
337*7c478bd9Sstevel@tonic-gate 		    "praudit: Cannot retrieve trailer magic number\n"));
338*7c478bd9Sstevel@tonic-gate 		return (-1);
339*7c478bd9Sstevel@tonic-gate 	} else {
340*7c478bd9Sstevel@tonic-gate 		if (magic_number != AUT_TRAILER_MAGIC) {
341*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
342*7c478bd9Sstevel@tonic-gate 			    "praudit: Invalid trailer magic number\n"));
343*7c478bd9Sstevel@tonic-gate 			return (-1);
344*7c478bd9Sstevel@tonic-gate 		} else
345*7c478bd9Sstevel@tonic-gate 			/* Do not display trailer in XML mode */
346*7c478bd9Sstevel@tonic-gate 			if (context->format & PRF_XMLM) {
347*7c478bd9Sstevel@tonic-gate 				uint32_t	junk;
348*7c478bd9Sstevel@tonic-gate 				int		retstat;
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate 				retstat = pr_adr_u_int32(context, &junk, 1);
351*7c478bd9Sstevel@tonic-gate 				return (retstat);
352*7c478bd9Sstevel@tonic-gate 			} else {
353*7c478bd9Sstevel@tonic-gate 				return (pa_adr_u_int32(context, 0, 1));
354*7c478bd9Sstevel@tonic-gate 			}
355*7c478bd9Sstevel@tonic-gate 	}
356*7c478bd9Sstevel@tonic-gate }
357*7c478bd9Sstevel@tonic-gate 
358*7c478bd9Sstevel@tonic-gate /*
359*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
360*7c478bd9Sstevel@tonic-gate  * arbitrary_data_token():
361*7c478bd9Sstevel@tonic-gate  *			  Process arbitrary data token and display contents
362*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
363*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
364*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the arbitrary data token id has already
365*7c478bd9Sstevel@tonic-gate  * been retrieved
366*7c478bd9Sstevel@tonic-gate  *
367*7c478bd9Sstevel@tonic-gate  * Format of arbitrary data token:
368*7c478bd9Sstevel@tonic-gate  *	arbitrary data token id	adr char
369*7c478bd9Sstevel@tonic-gate  * 	how to print		adr_char
370*7c478bd9Sstevel@tonic-gate  *				From audit_record.h, this may be either:
371*7c478bd9Sstevel@tonic-gate  *				AUP_BINARY	binary
372*7c478bd9Sstevel@tonic-gate  *				AUP_OCTAL	octal
373*7c478bd9Sstevel@tonic-gate  *				AUP_DECIMAL	decimal
374*7c478bd9Sstevel@tonic-gate  *				AUP_HEX		hexadecimal
375*7c478bd9Sstevel@tonic-gate  *	basic unit		adr_char
376*7c478bd9Sstevel@tonic-gate  *				From audit_record.h, this may be either:
377*7c478bd9Sstevel@tonic-gate  *				AUR_BYTE	byte
378*7c478bd9Sstevel@tonic-gate  *				AUR_CHAR	char
379*7c478bd9Sstevel@tonic-gate  *				AUR_SHORT	short
380*7c478bd9Sstevel@tonic-gate  *				AUR_INT32	int32_t
381*7c478bd9Sstevel@tonic-gate  *				AUR_INT64	int64_t
382*7c478bd9Sstevel@tonic-gate  *	unit count		adr_char, specifying number of units of
383*7c478bd9Sstevel@tonic-gate  *				data in the "data items" parameter below
384*7c478bd9Sstevel@tonic-gate  *	data items		depends on basic unit
385*7c478bd9Sstevel@tonic-gate  *
386*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
387*7c478bd9Sstevel@tonic-gate  */
388*7c478bd9Sstevel@tonic-gate int
389*7c478bd9Sstevel@tonic-gate arbitrary_data_token(pr_context_t *context)
390*7c478bd9Sstevel@tonic-gate {
391*7c478bd9Sstevel@tonic-gate 	int	returnstat;
392*7c478bd9Sstevel@tonic-gate 	int	i;
393*7c478bd9Sstevel@tonic-gate 	char	c1;
394*7c478bd9Sstevel@tonic-gate 	short	c2;
395*7c478bd9Sstevel@tonic-gate 	int32_t	c3;
396*7c478bd9Sstevel@tonic-gate 	int64_t c4;
397*7c478bd9Sstevel@tonic-gate 	char	how_to_print, basic_unit, unit_count, fwid;
398*7c478bd9Sstevel@tonic-gate 	char	*p;
399*7c478bd9Sstevel@tonic-gate 	int	index = 0;
400*7c478bd9Sstevel@tonic-gate 	char	*pformat = "%*s";
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, &how_to_print, 1)) != 0)
405*7c478bd9Sstevel@tonic-gate 		return (returnstat);
406*7c478bd9Sstevel@tonic-gate 
407*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, &basic_unit, 1)) != 0)
408*7c478bd9Sstevel@tonic-gate 		return (returnstat);
409*7c478bd9Sstevel@tonic-gate 
410*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, &unit_count, 1)) != 0)
411*7c478bd9Sstevel@tonic-gate 		return (returnstat);
412*7c478bd9Sstevel@tonic-gate 
413*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
414*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
415*7c478bd9Sstevel@tonic-gate 		uval.string_val = htp2string(how_to_print);
416*7c478bd9Sstevel@tonic-gate 	} else {
417*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_INT32;
418*7c478bd9Sstevel@tonic-gate 		uval.int32_val = (int)how_to_print;
419*7c478bd9Sstevel@tonic-gate 	}
420*7c478bd9Sstevel@tonic-gate 
421*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ARBPRINT)) != 0)
422*7c478bd9Sstevel@tonic-gate 		return (returnstat);
423*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pa_print(context, &uval, 0)) < 0)
424*7c478bd9Sstevel@tonic-gate 		return (returnstat);
425*7c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_ARBPRINT)) != 0)
426*7c478bd9Sstevel@tonic-gate 		return (returnstat);
427*7c478bd9Sstevel@tonic-gate 
428*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
429*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
430*7c478bd9Sstevel@tonic-gate 		uval.string_val = bu2string(basic_unit);
431*7c478bd9Sstevel@tonic-gate 	} else {
432*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_INT32;
433*7c478bd9Sstevel@tonic-gate 		uval.int32_val = (int32_t)basic_unit;
434*7c478bd9Sstevel@tonic-gate 	}
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ARBTYPE)) != 0)
437*7c478bd9Sstevel@tonic-gate 		return (returnstat);
438*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pa_print(context, &uval, 0)) < 0)
439*7c478bd9Sstevel@tonic-gate 		return (returnstat);
440*7c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_ARBTYPE)) != 0)
441*7c478bd9Sstevel@tonic-gate 		return (returnstat);
442*7c478bd9Sstevel@tonic-gate 
443*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_INT32;
444*7c478bd9Sstevel@tonic-gate 	uval.int32_val = (int32_t)unit_count;
445*7c478bd9Sstevel@tonic-gate 
446*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ARBCOUNT)) != 0)
447*7c478bd9Sstevel@tonic-gate 		return (returnstat);
448*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pa_print(context, &uval, 1)) < 0)
449*7c478bd9Sstevel@tonic-gate 		return (returnstat);
450*7c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_ARBCOUNT)) != 0)
451*7c478bd9Sstevel@tonic-gate 		return (returnstat);
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate 	/* Done with attributes; force end of token open */
454*7c478bd9Sstevel@tonic-gate 	if ((returnstat = finish_open_tag(context)) != 0)
455*7c478bd9Sstevel@tonic-gate 		return (returnstat);
456*7c478bd9Sstevel@tonic-gate 
457*7c478bd9Sstevel@tonic-gate 	/* get the field width in case we need to format output */
458*7c478bd9Sstevel@tonic-gate 	fwid = findfieldwidth(basic_unit, how_to_print);
459*7c478bd9Sstevel@tonic-gate 	p = (char *)malloc(80);
460*7c478bd9Sstevel@tonic-gate 
461*7c478bd9Sstevel@tonic-gate 	/* now get the data items and print them */
462*7c478bd9Sstevel@tonic-gate 	for (i = 0; (i < unit_count); i++) {
463*7c478bd9Sstevel@tonic-gate 		switch (basic_unit) {
464*7c478bd9Sstevel@tonic-gate 			/* case AUR_BYTE: */
465*7c478bd9Sstevel@tonic-gate 		case AUR_CHAR:
466*7c478bd9Sstevel@tonic-gate 			if (pr_adr_char(context, &c1, 1) == 0)
467*7c478bd9Sstevel@tonic-gate 				(void) convert_char_to_string(how_to_print,
468*7c478bd9Sstevel@tonic-gate 					c1, p);
469*7c478bd9Sstevel@tonic-gate 			else {
470*7c478bd9Sstevel@tonic-gate 				free(p);
471*7c478bd9Sstevel@tonic-gate 				return (-1);
472*7c478bd9Sstevel@tonic-gate 			}
473*7c478bd9Sstevel@tonic-gate 			break;
474*7c478bd9Sstevel@tonic-gate 		case AUR_SHORT:
475*7c478bd9Sstevel@tonic-gate 			if (pr_adr_short(context, &c2, 1) == 0)
476*7c478bd9Sstevel@tonic-gate 				(void) convert_short_to_string(how_to_print,
477*7c478bd9Sstevel@tonic-gate 					c2, p);
478*7c478bd9Sstevel@tonic-gate 			else {
479*7c478bd9Sstevel@tonic-gate 				free(p);
480*7c478bd9Sstevel@tonic-gate 				return (-1);
481*7c478bd9Sstevel@tonic-gate 			}
482*7c478bd9Sstevel@tonic-gate 			break;
483*7c478bd9Sstevel@tonic-gate 		case AUR_INT32:
484*7c478bd9Sstevel@tonic-gate 			if (pr_adr_int32(context, &c3, 1) == 0)
485*7c478bd9Sstevel@tonic-gate 				(void) convert_int32_to_string(how_to_print,
486*7c478bd9Sstevel@tonic-gate 					c3, p);
487*7c478bd9Sstevel@tonic-gate 			else {
488*7c478bd9Sstevel@tonic-gate 				free(p);
489*7c478bd9Sstevel@tonic-gate 				return (-1);
490*7c478bd9Sstevel@tonic-gate 			}
491*7c478bd9Sstevel@tonic-gate 			break;
492*7c478bd9Sstevel@tonic-gate 		case AUR_INT64:
493*7c478bd9Sstevel@tonic-gate 			if (pr_adr_int64(context, &c4, 1) == 0)
494*7c478bd9Sstevel@tonic-gate 				(void) convert_int64_to_string(how_to_print,
495*7c478bd9Sstevel@tonic-gate 					c4, p);
496*7c478bd9Sstevel@tonic-gate 			else {
497*7c478bd9Sstevel@tonic-gate 				free(p);
498*7c478bd9Sstevel@tonic-gate 				return (-1);
499*7c478bd9Sstevel@tonic-gate 			}
500*7c478bd9Sstevel@tonic-gate 			break;
501*7c478bd9Sstevel@tonic-gate 		default:
502*7c478bd9Sstevel@tonic-gate 			free(p);
503*7c478bd9Sstevel@tonic-gate 			return (-1);
504*7c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
505*7c478bd9Sstevel@tonic-gate 		}
506*7c478bd9Sstevel@tonic-gate 
507*7c478bd9Sstevel@tonic-gate 		/*
508*7c478bd9Sstevel@tonic-gate 		 * At this point, we have successfully retrieved a data
509*7c478bd9Sstevel@tonic-gate 		 * item and converted it into an ASCII string pointed to
510*7c478bd9Sstevel@tonic-gate 		 * by p. If all output is to be printed on one line,
511*7c478bd9Sstevel@tonic-gate 		 * simply separate the data items by a space (or by the
512*7c478bd9Sstevel@tonic-gate 		 * delimiter if this is the last data item), otherwise, we
513*7c478bd9Sstevel@tonic-gate 		 * need to format the output before display.
514*7c478bd9Sstevel@tonic-gate 		 */
515*7c478bd9Sstevel@tonic-gate 		if (context->format & PRF_ONELINE) {
516*7c478bd9Sstevel@tonic-gate 			returnstat = pr_printf(context, "%s", p);
517*7c478bd9Sstevel@tonic-gate 			if ((returnstat >= 0) && (i == (unit_count - 1)))
518*7c478bd9Sstevel@tonic-gate 				returnstat = pr_printf(context, "%s",
519*7c478bd9Sstevel@tonic-gate 				    context->SEPARATOR);
520*7c478bd9Sstevel@tonic-gate 			else
521*7c478bd9Sstevel@tonic-gate 				returnstat = pr_putchar(context, ' ');
522*7c478bd9Sstevel@tonic-gate 		} else {	/* format output */
523*7c478bd9Sstevel@tonic-gate 			returnstat = pr_printf(context, pformat, fwid, p);
524*7c478bd9Sstevel@tonic-gate 			index += fwid;
525*7c478bd9Sstevel@tonic-gate 			if ((returnstat >= 0) &&
526*7c478bd9Sstevel@tonic-gate 			    (((index + fwid) > 75) ||
527*7c478bd9Sstevel@tonic-gate 			    (i == (unit_count - 1)))) {
528*7c478bd9Sstevel@tonic-gate 				returnstat = pr_putchar(context, '\n');
529*7c478bd9Sstevel@tonic-gate 				index = 0;
530*7c478bd9Sstevel@tonic-gate 			}
531*7c478bd9Sstevel@tonic-gate 		} /* else if PRF_ONELINE */
532*7c478bd9Sstevel@tonic-gate 		if (returnstat < 0) {
533*7c478bd9Sstevel@tonic-gate 			free(p);
534*7c478bd9Sstevel@tonic-gate 			return (returnstat);
535*7c478bd9Sstevel@tonic-gate 		}
536*7c478bd9Sstevel@tonic-gate 	}
537*7c478bd9Sstevel@tonic-gate 	free(p);
538*7c478bd9Sstevel@tonic-gate 
539*7c478bd9Sstevel@tonic-gate 	return (returnstat);
540*7c478bd9Sstevel@tonic-gate }
541*7c478bd9Sstevel@tonic-gate 
542*7c478bd9Sstevel@tonic-gate /*
543*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
544*7c478bd9Sstevel@tonic-gate  * opaque_token() 	: Process opaque token and display contents
545*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
546*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
547*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the opaque token id has already been
548*7c478bd9Sstevel@tonic-gate  * retrieved
549*7c478bd9Sstevel@tonic-gate  *
550*7c478bd9Sstevel@tonic-gate  * Format of opaque token:
551*7c478bd9Sstevel@tonic-gate  *	opaque token id		adr_char
552*7c478bd9Sstevel@tonic-gate  *	size			adr_short
553*7c478bd9Sstevel@tonic-gate  *	data			adr_char, size times
554*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
555*7c478bd9Sstevel@tonic-gate  */
556*7c478bd9Sstevel@tonic-gate int
557*7c478bd9Sstevel@tonic-gate opaque_token(pr_context_t *context)
558*7c478bd9Sstevel@tonic-gate {
559*7c478bd9Sstevel@tonic-gate 	int	returnstat;
560*7c478bd9Sstevel@tonic-gate 	short	size;
561*7c478bd9Sstevel@tonic-gate 	char	*charp;
562*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
563*7c478bd9Sstevel@tonic-gate 
564*7c478bd9Sstevel@tonic-gate 
565*7c478bd9Sstevel@tonic-gate 	/* print the size of the token */
566*7c478bd9Sstevel@tonic-gate 	if (pr_adr_short(context, &size, 1) == 0) {
567*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_SHORT;
568*7c478bd9Sstevel@tonic-gate 		uval.short_val = size;
569*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, 0);
570*7c478bd9Sstevel@tonic-gate 	} else
571*7c478bd9Sstevel@tonic-gate 		returnstat = -1;
572*7c478bd9Sstevel@tonic-gate 
573*7c478bd9Sstevel@tonic-gate 	/* now print out the data field in hexadecimal */
574*7c478bd9Sstevel@tonic-gate 	if (returnstat >= 0) {
575*7c478bd9Sstevel@tonic-gate 		/* try to allocate memory for the character string */
576*7c478bd9Sstevel@tonic-gate 		if ((charp = (char *)malloc(size * sizeof (char))) == NULL)
577*7c478bd9Sstevel@tonic-gate 			returnstat = -1;
578*7c478bd9Sstevel@tonic-gate 		else {
579*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pr_adr_char(context, charp,
580*7c478bd9Sstevel@tonic-gate 			    size)) == 0) {
581*7c478bd9Sstevel@tonic-gate 				/* print out in hexadecimal format */
582*7c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_STRING;
583*7c478bd9Sstevel@tonic-gate 				uval.string_val = hexconvert(charp, size, size);
584*7c478bd9Sstevel@tonic-gate 				if (uval.string_val) {
585*7c478bd9Sstevel@tonic-gate 					returnstat = pa_print(context,
586*7c478bd9Sstevel@tonic-gate 					    &uval, 1);
587*7c478bd9Sstevel@tonic-gate 					free(uval.string_val);
588*7c478bd9Sstevel@tonic-gate 				}
589*7c478bd9Sstevel@tonic-gate 			}
590*7c478bd9Sstevel@tonic-gate 			free(charp);
591*7c478bd9Sstevel@tonic-gate 		}
592*7c478bd9Sstevel@tonic-gate 	}
593*7c478bd9Sstevel@tonic-gate 
594*7c478bd9Sstevel@tonic-gate 	return (returnstat);
595*7c478bd9Sstevel@tonic-gate }
596*7c478bd9Sstevel@tonic-gate 
597*7c478bd9Sstevel@tonic-gate /*
598*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
599*7c478bd9Sstevel@tonic-gate  * path_token() 	: Process path token and display contents
600*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
601*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
602*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the path token id has been retrieved
603*7c478bd9Sstevel@tonic-gate  *
604*7c478bd9Sstevel@tonic-gate  * Format of path token:
605*7c478bd9Sstevel@tonic-gate  *	token id	adr_char
606*7c478bd9Sstevel@tonic-gate  *	path		adr_string
607*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
608*7c478bd9Sstevel@tonic-gate  */
609*7c478bd9Sstevel@tonic-gate int
610*7c478bd9Sstevel@tonic-gate path_token(pr_context_t *context)
611*7c478bd9Sstevel@tonic-gate {
612*7c478bd9Sstevel@tonic-gate 	char	*path;	/* path */
613*7c478bd9Sstevel@tonic-gate 	char	*apath;	/* anchored path */
614*7c478bd9Sstevel@tonic-gate 	char	*cpath;	/* collapsed path */
615*7c478bd9Sstevel@tonic-gate 	short	length;
616*7c478bd9Sstevel@tonic-gate 	int	returnstat;
617*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
618*7c478bd9Sstevel@tonic-gate 
619*7c478bd9Sstevel@tonic-gate 	/*
620*7c478bd9Sstevel@tonic-gate 	 * We need to know how much space to allocate for our string, so
621*7c478bd9Sstevel@tonic-gate 	 * read the length first, then call pr_adr_char to read those bytes.
622*7c478bd9Sstevel@tonic-gate 	 */
623*7c478bd9Sstevel@tonic-gate 	if (pr_adr_short(context, &length, 1) == 0) {
624*7c478bd9Sstevel@tonic-gate 		if ((path = (char *)malloc(length + 1)) == NULL) {
625*7c478bd9Sstevel@tonic-gate 			returnstat = -1;
626*7c478bd9Sstevel@tonic-gate 		} else if (pr_adr_char(context, path, length) == 0) {
627*7c478bd9Sstevel@tonic-gate 			path[length] = '\0';
628*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
629*7c478bd9Sstevel@tonic-gate 			if (*path != '/') {
630*7c478bd9Sstevel@tonic-gate 				apath = anchor_path(path);
631*7c478bd9Sstevel@tonic-gate 				free(path);
632*7c478bd9Sstevel@tonic-gate 			} else
633*7c478bd9Sstevel@tonic-gate 				apath = path;
634*7c478bd9Sstevel@tonic-gate 			cpath = collapse_path(apath);
635*7c478bd9Sstevel@tonic-gate 			uval.string_val = cpath;
636*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 1);
637*7c478bd9Sstevel@tonic-gate 			free(cpath);
638*7c478bd9Sstevel@tonic-gate 		} else {
639*7c478bd9Sstevel@tonic-gate 			free(path);
640*7c478bd9Sstevel@tonic-gate 			returnstat = -1;
641*7c478bd9Sstevel@tonic-gate 		}
642*7c478bd9Sstevel@tonic-gate 		return (returnstat);
643*7c478bd9Sstevel@tonic-gate 	} else
644*7c478bd9Sstevel@tonic-gate 		return (-1);
645*7c478bd9Sstevel@tonic-gate }
646*7c478bd9Sstevel@tonic-gate 
647*7c478bd9Sstevel@tonic-gate /*
648*7c478bd9Sstevel@tonic-gate  * anchor a path name with a slash
649*7c478bd9Sstevel@tonic-gate  */
650*7c478bd9Sstevel@tonic-gate char *
651*7c478bd9Sstevel@tonic-gate anchor_path(char *sp)
652*7c478bd9Sstevel@tonic-gate {
653*7c478bd9Sstevel@tonic-gate 	char	*dp; /* destination path */
654*7c478bd9Sstevel@tonic-gate 	char	*tp; /* temporary path */
655*7c478bd9Sstevel@tonic-gate 	size_t	len;
656*7c478bd9Sstevel@tonic-gate 
657*7c478bd9Sstevel@tonic-gate 	len = strlen(sp) + 2;
658*7c478bd9Sstevel@tonic-gate 	if ((dp = tp = (char *)calloc(1, len)) == (char *)0)
659*7c478bd9Sstevel@tonic-gate 		return ((char *)0);
660*7c478bd9Sstevel@tonic-gate 
661*7c478bd9Sstevel@tonic-gate 	*dp++ = '/';
662*7c478bd9Sstevel@tonic-gate 
663*7c478bd9Sstevel@tonic-gate 	(void) strlcpy(dp, sp, len);
664*7c478bd9Sstevel@tonic-gate 
665*7c478bd9Sstevel@tonic-gate 	return (tp);
666*7c478bd9Sstevel@tonic-gate }
667*7c478bd9Sstevel@tonic-gate 
668*7c478bd9Sstevel@tonic-gate /*
669*7c478bd9Sstevel@tonic-gate  * copy path to collapsed path.
670*7c478bd9Sstevel@tonic-gate  * collapsed path does not contain:
671*7c478bd9Sstevel@tonic-gate  *	successive slashes
672*7c478bd9Sstevel@tonic-gate  *	instances of dot-slash
673*7c478bd9Sstevel@tonic-gate  *	instances of dot-dot-slash
674*7c478bd9Sstevel@tonic-gate  * passed path must be anchored with a '/'
675*7c478bd9Sstevel@tonic-gate  */
676*7c478bd9Sstevel@tonic-gate char *
677*7c478bd9Sstevel@tonic-gate collapse_path(char *s)
678*7c478bd9Sstevel@tonic-gate {
679*7c478bd9Sstevel@tonic-gate 	int	id;	/* index of where we are in destination string */
680*7c478bd9Sstevel@tonic-gate 	int	is;		/* index of where we are in source string */
681*7c478bd9Sstevel@tonic-gate 	int	slashseen;	/* have we seen a slash */
682*7c478bd9Sstevel@tonic-gate 	int	ls;		/* length of source string */
683*7c478bd9Sstevel@tonic-gate 
684*7c478bd9Sstevel@tonic-gate 	ls = strlen(s) + 1;
685*7c478bd9Sstevel@tonic-gate 
686*7c478bd9Sstevel@tonic-gate 	slashseen = 0;
687*7c478bd9Sstevel@tonic-gate 	for (is = 0, id = 0; is < ls; is++) {
688*7c478bd9Sstevel@tonic-gate 		/* thats all folks, we've reached the end of input */
689*7c478bd9Sstevel@tonic-gate 		if (s[is] == '\0') {
690*7c478bd9Sstevel@tonic-gate 			if (id > 1 && s[id-1] == '/') {
691*7c478bd9Sstevel@tonic-gate 				--id;
692*7c478bd9Sstevel@tonic-gate 			}
693*7c478bd9Sstevel@tonic-gate 			s[id++] = '\0';
694*7c478bd9Sstevel@tonic-gate 			break;
695*7c478bd9Sstevel@tonic-gate 		}
696*7c478bd9Sstevel@tonic-gate 		/* previous character was a / */
697*7c478bd9Sstevel@tonic-gate 		if (slashseen) {
698*7c478bd9Sstevel@tonic-gate 			if (s[is] == '/')
699*7c478bd9Sstevel@tonic-gate 				continue;	/* another slash, ignore it */
700*7c478bd9Sstevel@tonic-gate 		} else if (s[is] == '/') {
701*7c478bd9Sstevel@tonic-gate 			/* we see a /, just copy it and try again */
702*7c478bd9Sstevel@tonic-gate 			slashseen = 1;
703*7c478bd9Sstevel@tonic-gate 			s[id++] = '/';
704*7c478bd9Sstevel@tonic-gate 			continue;
705*7c478bd9Sstevel@tonic-gate 		}
706*7c478bd9Sstevel@tonic-gate 		/* /./ seen */
707*7c478bd9Sstevel@tonic-gate 		if (s[is] == '.' && s[is+1] == '/') {
708*7c478bd9Sstevel@tonic-gate 			is += 1;
709*7c478bd9Sstevel@tonic-gate 			continue;
710*7c478bd9Sstevel@tonic-gate 		}
711*7c478bd9Sstevel@tonic-gate 		/* XXX/. seen */
712*7c478bd9Sstevel@tonic-gate 		if (s[is] == '.' && s[is+1] == '\0') {
713*7c478bd9Sstevel@tonic-gate 			if (id > 1)
714*7c478bd9Sstevel@tonic-gate 				id--;
715*7c478bd9Sstevel@tonic-gate 			continue;
716*7c478bd9Sstevel@tonic-gate 		}
717*7c478bd9Sstevel@tonic-gate 		/* XXX/.. seen */
718*7c478bd9Sstevel@tonic-gate 		if (s[is] == '.' && s[is+1] == '.' && s[is+2] == '\0') {
719*7c478bd9Sstevel@tonic-gate 			is += 1;
720*7c478bd9Sstevel@tonic-gate 			if (id > 0)
721*7c478bd9Sstevel@tonic-gate 				id--;
722*7c478bd9Sstevel@tonic-gate 			while (id > 0 && s[--id] != '/');
723*7c478bd9Sstevel@tonic-gate 			id++;
724*7c478bd9Sstevel@tonic-gate 			continue;
725*7c478bd9Sstevel@tonic-gate 		}
726*7c478bd9Sstevel@tonic-gate 		/* XXX/../ seen */
727*7c478bd9Sstevel@tonic-gate 		if (s[is] == '.' && s[is+1] == '.' && s[is+2] == '/') {
728*7c478bd9Sstevel@tonic-gate 			is += 2;
729*7c478bd9Sstevel@tonic-gate 			if (id > 0)
730*7c478bd9Sstevel@tonic-gate 				id--;
731*7c478bd9Sstevel@tonic-gate 			while (id > 0 && s[--id] != '/');
732*7c478bd9Sstevel@tonic-gate 			id++;
733*7c478bd9Sstevel@tonic-gate 			continue;
734*7c478bd9Sstevel@tonic-gate 		}
735*7c478bd9Sstevel@tonic-gate 		while (is < ls && (s[id++] = s[is++]) != '/');
736*7c478bd9Sstevel@tonic-gate 		is--;
737*7c478bd9Sstevel@tonic-gate 	}
738*7c478bd9Sstevel@tonic-gate 	return (s);
739*7c478bd9Sstevel@tonic-gate }
740*7c478bd9Sstevel@tonic-gate 
741*7c478bd9Sstevel@tonic-gate /*
742*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
743*7c478bd9Sstevel@tonic-gate  * cmd_token()		: Process cmd token and display contents
744*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
745*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
746*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the cmd token id has been retrieved
747*7c478bd9Sstevel@tonic-gate  *
748*7c478bd9Sstevel@tonic-gate  * Format of command token:
749*7c478bd9Sstevel@tonic-gate  *	token id	adr_char
750*7c478bd9Sstevel@tonic-gate  *	argc		adr_short
751*7c478bd9Sstevel@tonic-gate  *	N*argv[i]	adr_string (short, string)
752*7c478bd9Sstevel@tonic-gate  *	env cnt		adr_short
753*7c478bd9Sstevel@tonic-gate  *	N*arge[i]	adr_string (short, string)
754*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
755*7c478bd9Sstevel@tonic-gate  */
756*7c478bd9Sstevel@tonic-gate int
757*7c478bd9Sstevel@tonic-gate cmd_token(pr_context_t *context)
758*7c478bd9Sstevel@tonic-gate {
759*7c478bd9Sstevel@tonic-gate 	int	returnstat;
760*7c478bd9Sstevel@tonic-gate 	short num;
761*7c478bd9Sstevel@tonic-gate 
762*7c478bd9Sstevel@tonic-gate 	returnstat = pr_adr_short(context, &num, 1);
763*7c478bd9Sstevel@tonic-gate 	if (returnstat < 0)
764*7c478bd9Sstevel@tonic-gate 		return (returnstat);
765*7c478bd9Sstevel@tonic-gate 
766*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM)) {
767*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%s%s%d%s",
768*7c478bd9Sstevel@tonic-gate 		    (context->format & PRF_ONELINE) ? "" : gettext("argcnt"),
769*7c478bd9Sstevel@tonic-gate 		    (context->format & PRF_ONELINE) ? "" : context->SEPARATOR,
770*7c478bd9Sstevel@tonic-gate 		    num, context->SEPARATOR);
771*7c478bd9Sstevel@tonic-gate 		if (returnstat < 0)
772*7c478bd9Sstevel@tonic-gate 			return (returnstat);
773*7c478bd9Sstevel@tonic-gate 	}
774*7c478bd9Sstevel@tonic-gate 
775*7c478bd9Sstevel@tonic-gate 	for (; num > 0; num--) {
776*7c478bd9Sstevel@tonic-gate 		if ((returnstat = process_tag(context, TAG_ARGV,
777*7c478bd9Sstevel@tonic-gate 		    returnstat, 0)) < 0)
778*7c478bd9Sstevel@tonic-gate 			return (returnstat);
779*7c478bd9Sstevel@tonic-gate 	}
780*7c478bd9Sstevel@tonic-gate 
781*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_short(context, &num, 1)) < 0)
782*7c478bd9Sstevel@tonic-gate 		return (returnstat);
783*7c478bd9Sstevel@tonic-gate 
784*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM)) {
785*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%s%s%d%s",
786*7c478bd9Sstevel@tonic-gate 		    (context->format & PRF_ONELINE) ? "" : gettext("envcnt"),
787*7c478bd9Sstevel@tonic-gate 		    (context->format & PRF_ONELINE) ? "" : context->SEPARATOR,
788*7c478bd9Sstevel@tonic-gate 		    num, context->SEPARATOR);
789*7c478bd9Sstevel@tonic-gate 		if (returnstat < 0)
790*7c478bd9Sstevel@tonic-gate 			return (returnstat);
791*7c478bd9Sstevel@tonic-gate 	}
792*7c478bd9Sstevel@tonic-gate 
793*7c478bd9Sstevel@tonic-gate 	if ((num == 0) && !(context->format & PRF_XMLM)) {
794*7c478bd9Sstevel@tonic-gate 		returnstat = pr_putchar(context, '\n');
795*7c478bd9Sstevel@tonic-gate 		if (returnstat < 0)
796*7c478bd9Sstevel@tonic-gate 			return (returnstat);
797*7c478bd9Sstevel@tonic-gate 	}
798*7c478bd9Sstevel@tonic-gate 
799*7c478bd9Sstevel@tonic-gate 	for (; num > 1; num--) {
800*7c478bd9Sstevel@tonic-gate 		if ((returnstat = process_tag(context, TAG_ARGE,
801*7c478bd9Sstevel@tonic-gate 		    returnstat, 0)) < 0)
802*7c478bd9Sstevel@tonic-gate 			return (returnstat);
803*7c478bd9Sstevel@tonic-gate 	}
804*7c478bd9Sstevel@tonic-gate 	if (num)
805*7c478bd9Sstevel@tonic-gate 		returnstat = process_tag(context, TAG_ARGE, returnstat, 1);
806*7c478bd9Sstevel@tonic-gate 
807*7c478bd9Sstevel@tonic-gate 	return (returnstat);
808*7c478bd9Sstevel@tonic-gate 
809*7c478bd9Sstevel@tonic-gate }
810*7c478bd9Sstevel@tonic-gate 
811*7c478bd9Sstevel@tonic-gate /*
812*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
813*7c478bd9Sstevel@tonic-gate  * argument32_token()	: Process argument token and display contents
814*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
815*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
816*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the arg token id has been retrieved
817*7c478bd9Sstevel@tonic-gate  *
818*7c478bd9Sstevel@tonic-gate  * Format of argument token:
819*7c478bd9Sstevel@tonic-gate  *	current directory token id	adr_char
820*7c478bd9Sstevel@tonic-gate  *	argument number			adr_char
821*7c478bd9Sstevel@tonic-gate  *	argument value			adr_int32
822*7c478bd9Sstevel@tonic-gate  *	argument description		adr_string
823*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
824*7c478bd9Sstevel@tonic-gate  */
825*7c478bd9Sstevel@tonic-gate int
826*7c478bd9Sstevel@tonic-gate argument32_token(pr_context_t *context)
827*7c478bd9Sstevel@tonic-gate {
828*7c478bd9Sstevel@tonic-gate 	int	returnstat;
829*7c478bd9Sstevel@tonic-gate 
830*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_ARGNUM, 0, 0);
831*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_ARGVAL32, returnstat, 0);
832*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_ARGDESC, returnstat, 1);
833*7c478bd9Sstevel@tonic-gate 
834*7c478bd9Sstevel@tonic-gate 	return (returnstat);
835*7c478bd9Sstevel@tonic-gate 
836*7c478bd9Sstevel@tonic-gate }
837*7c478bd9Sstevel@tonic-gate 
838*7c478bd9Sstevel@tonic-gate /*
839*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
840*7c478bd9Sstevel@tonic-gate  * argument64_token()	: Process argument token and display contents
841*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
842*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
843*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the arg token id has been retrieved
844*7c478bd9Sstevel@tonic-gate  *
845*7c478bd9Sstevel@tonic-gate  * Format of 64 bit argument token:
846*7c478bd9Sstevel@tonic-gate  *	current directory token id	adr_char
847*7c478bd9Sstevel@tonic-gate  *	argument number			adr_char
848*7c478bd9Sstevel@tonic-gate  *	argument value			adr_int64
849*7c478bd9Sstevel@tonic-gate  *	argument description		adr_string
850*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
851*7c478bd9Sstevel@tonic-gate  */
852*7c478bd9Sstevel@tonic-gate int
853*7c478bd9Sstevel@tonic-gate argument64_token(pr_context_t *context)
854*7c478bd9Sstevel@tonic-gate {
855*7c478bd9Sstevel@tonic-gate 	int	returnstat;
856*7c478bd9Sstevel@tonic-gate 
857*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_ARGNUM, 0, 0);
858*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_ARGVAL64, returnstat, 0);
859*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_ARGDESC, returnstat, 1);
860*7c478bd9Sstevel@tonic-gate 
861*7c478bd9Sstevel@tonic-gate 	return (returnstat);
862*7c478bd9Sstevel@tonic-gate 
863*7c478bd9Sstevel@tonic-gate }
864*7c478bd9Sstevel@tonic-gate 
865*7c478bd9Sstevel@tonic-gate /*
866*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
867*7c478bd9Sstevel@tonic-gate  * process_token() 	: Process process token and display contents
868*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
869*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
870*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the process token id has been retrieved
871*7c478bd9Sstevel@tonic-gate  *
872*7c478bd9Sstevel@tonic-gate  * Format of process token:
873*7c478bd9Sstevel@tonic-gate  *	process token id	adr_char
874*7c478bd9Sstevel@tonic-gate  *	auid			adr_u_int32
875*7c478bd9Sstevel@tonic-gate  *	euid			adr_u_int32
876*7c478bd9Sstevel@tonic-gate  *	egid			adr_u_int32
877*7c478bd9Sstevel@tonic-gate  *	ruid			adr_u_int32
878*7c478bd9Sstevel@tonic-gate  *	egid			adr_u_int32
879*7c478bd9Sstevel@tonic-gate  *	pid			adr_u_int32
880*7c478bd9Sstevel@tonic-gate  *	sid			adr_u_int32
881*7c478bd9Sstevel@tonic-gate  *	tid			adr_u_int32, adr_u_int32
882*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
883*7c478bd9Sstevel@tonic-gate  */
884*7c478bd9Sstevel@tonic-gate int
885*7c478bd9Sstevel@tonic-gate process32_token(pr_context_t *context)
886*7c478bd9Sstevel@tonic-gate {
887*7c478bd9Sstevel@tonic-gate 	int	returnstat;
888*7c478bd9Sstevel@tonic-gate 
889*7c478bd9Sstevel@tonic-gate 		/* auid */
890*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_AUID, 0, 0);
891*7c478bd9Sstevel@tonic-gate 		/* uid */
892*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
893*7c478bd9Sstevel@tonic-gate 		/* gid */
894*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
895*7c478bd9Sstevel@tonic-gate 		/* ruid */
896*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RUID, returnstat, 0);
897*7c478bd9Sstevel@tonic-gate 		/* rgid */
898*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RGID, returnstat, 0);
899*7c478bd9Sstevel@tonic-gate 		/* pid */
900*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_PID, returnstat, 0);
901*7c478bd9Sstevel@tonic-gate 		/* sid */
902*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SID, returnstat, 0);
903*7c478bd9Sstevel@tonic-gate 		/* tid */
904*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TID32, returnstat, 1);
905*7c478bd9Sstevel@tonic-gate 
906*7c478bd9Sstevel@tonic-gate 	return (returnstat);
907*7c478bd9Sstevel@tonic-gate }
908*7c478bd9Sstevel@tonic-gate 
909*7c478bd9Sstevel@tonic-gate int
910*7c478bd9Sstevel@tonic-gate process64_token(pr_context_t *context)
911*7c478bd9Sstevel@tonic-gate {
912*7c478bd9Sstevel@tonic-gate 	int	returnstat;
913*7c478bd9Sstevel@tonic-gate 
914*7c478bd9Sstevel@tonic-gate 		/* auid */
915*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_AUID, 0, 0);
916*7c478bd9Sstevel@tonic-gate 		/* uid */
917*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
918*7c478bd9Sstevel@tonic-gate 		/* gid */
919*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
920*7c478bd9Sstevel@tonic-gate 		/* ruid */
921*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RUID, returnstat, 0);
922*7c478bd9Sstevel@tonic-gate 		/* rgid */
923*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RGID, returnstat, 0);
924*7c478bd9Sstevel@tonic-gate 		/* pid */
925*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_PID, returnstat, 0);
926*7c478bd9Sstevel@tonic-gate 		/* sid */
927*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SID, returnstat, 0);
928*7c478bd9Sstevel@tonic-gate 		/* tid */
929*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TID64, returnstat, 1);
930*7c478bd9Sstevel@tonic-gate 
931*7c478bd9Sstevel@tonic-gate 	return (returnstat);
932*7c478bd9Sstevel@tonic-gate }
933*7c478bd9Sstevel@tonic-gate 
934*7c478bd9Sstevel@tonic-gate /*
935*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
936*7c478bd9Sstevel@tonic-gate  * process_ex_token()	: Process process token and display contents
937*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
938*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
939*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the process token id has been retrieved
940*7c478bd9Sstevel@tonic-gate  *
941*7c478bd9Sstevel@tonic-gate  * Format of extended process token:
942*7c478bd9Sstevel@tonic-gate  *	process token id	adr_char
943*7c478bd9Sstevel@tonic-gate  *	auid			adr_u_int32
944*7c478bd9Sstevel@tonic-gate  *	euid			adr_u_int32
945*7c478bd9Sstevel@tonic-gate  *	egid			adr_u_int32
946*7c478bd9Sstevel@tonic-gate  *	ruid			adr_u_int32
947*7c478bd9Sstevel@tonic-gate  *	egid			adr_u_int32
948*7c478bd9Sstevel@tonic-gate  *	pid			adr_u_int32
949*7c478bd9Sstevel@tonic-gate  *	sid			adr_u_int32
950*7c478bd9Sstevel@tonic-gate  *	tid			adr_u_int32, adr_u_int32, 4*adr_u_int32
951*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
952*7c478bd9Sstevel@tonic-gate  */
953*7c478bd9Sstevel@tonic-gate int
954*7c478bd9Sstevel@tonic-gate process32_ex_token(pr_context_t *context)
955*7c478bd9Sstevel@tonic-gate {
956*7c478bd9Sstevel@tonic-gate 	int	returnstat;
957*7c478bd9Sstevel@tonic-gate 
958*7c478bd9Sstevel@tonic-gate 		/* auid */
959*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_AUID, 0, 0);
960*7c478bd9Sstevel@tonic-gate 		/* uid */
961*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
962*7c478bd9Sstevel@tonic-gate 		/* gid */
963*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
964*7c478bd9Sstevel@tonic-gate 		/* ruid */
965*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RUID, returnstat, 0);
966*7c478bd9Sstevel@tonic-gate 		/* rgid */
967*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RGID, returnstat, 0);
968*7c478bd9Sstevel@tonic-gate 		/* pid */
969*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_PID, returnstat, 0);
970*7c478bd9Sstevel@tonic-gate 		/* sid */
971*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SID, returnstat, 0);
972*7c478bd9Sstevel@tonic-gate 		/* tid */
973*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TID32_EX, returnstat, 1);
974*7c478bd9Sstevel@tonic-gate 
975*7c478bd9Sstevel@tonic-gate 	return (returnstat);
976*7c478bd9Sstevel@tonic-gate }
977*7c478bd9Sstevel@tonic-gate 
978*7c478bd9Sstevel@tonic-gate int
979*7c478bd9Sstevel@tonic-gate process64_ex_token(pr_context_t *context)
980*7c478bd9Sstevel@tonic-gate {
981*7c478bd9Sstevel@tonic-gate 	int	returnstat;
982*7c478bd9Sstevel@tonic-gate 
983*7c478bd9Sstevel@tonic-gate 		/* auid */
984*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_AUID, 0, 0);
985*7c478bd9Sstevel@tonic-gate 		/* uid */
986*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
987*7c478bd9Sstevel@tonic-gate 		/* gid */
988*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
989*7c478bd9Sstevel@tonic-gate 		/* ruid */
990*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RUID, returnstat, 0);
991*7c478bd9Sstevel@tonic-gate 		/* rgid */
992*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RGID, returnstat, 0);
993*7c478bd9Sstevel@tonic-gate 		/* pid */
994*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_PID, returnstat, 0);
995*7c478bd9Sstevel@tonic-gate 		/* sid */
996*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SID, returnstat, 0);
997*7c478bd9Sstevel@tonic-gate 		/* tid */
998*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TID64_EX, returnstat, 1);
999*7c478bd9Sstevel@tonic-gate 
1000*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1001*7c478bd9Sstevel@tonic-gate }
1002*7c478bd9Sstevel@tonic-gate 
1003*7c478bd9Sstevel@tonic-gate /*
1004*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1005*7c478bd9Sstevel@tonic-gate  * return_value32_token(): Process return value and display contents
1006*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
1007*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1008*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the return value token id has been retrieved
1009*7c478bd9Sstevel@tonic-gate  *
1010*7c478bd9Sstevel@tonic-gate  * Format of return value token:
1011*7c478bd9Sstevel@tonic-gate  * 	return value token id	adr_char
1012*7c478bd9Sstevel@tonic-gate  *	error number		adr_char
1013*7c478bd9Sstevel@tonic-gate  *	return value		adr_int32
1014*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1015*7c478bd9Sstevel@tonic-gate  */
1016*7c478bd9Sstevel@tonic-gate int
1017*7c478bd9Sstevel@tonic-gate return_value32_token(pr_context_t *context)
1018*7c478bd9Sstevel@tonic-gate {
1019*7c478bd9Sstevel@tonic-gate 	int		returnstat;
1020*7c478bd9Sstevel@tonic-gate 	uchar_t		number;
1021*7c478bd9Sstevel@tonic-gate 	int32_t		value;
1022*7c478bd9Sstevel@tonic-gate 	char		pb[512];    /* print buffer */
1023*7c478bd9Sstevel@tonic-gate 	uval_t		uval;
1024*7c478bd9Sstevel@tonic-gate 	bool_t		used_ret_val = 0;
1025*7c478bd9Sstevel@tonic-gate 
1026*7c478bd9Sstevel@tonic-gate 	/*
1027*7c478bd9Sstevel@tonic-gate 	 * Every audit record generated contains a return token.
1028*7c478bd9Sstevel@tonic-gate 	 *
1029*7c478bd9Sstevel@tonic-gate 	 * The return token is a special token. It indicates the success
1030*7c478bd9Sstevel@tonic-gate 	 * or failure of the event that contains it.
1031*7c478bd9Sstevel@tonic-gate 	 * The return32 token contains two pieces of data:
1032*7c478bd9Sstevel@tonic-gate 	 *
1033*7c478bd9Sstevel@tonic-gate 	 * 	char	number;
1034*7c478bd9Sstevel@tonic-gate 	 * 	int32_t	return_value;
1035*7c478bd9Sstevel@tonic-gate 	 *
1036*7c478bd9Sstevel@tonic-gate 	 * For audit records generated by the kernel:
1037*7c478bd9Sstevel@tonic-gate 	 * The kernel always puts a positive value in "number".
1038*7c478bd9Sstevel@tonic-gate 	 * Upon success "number" is 0.
1039*7c478bd9Sstevel@tonic-gate 	 * Upon failure "number" is a positive errno value that is less than
1040*7c478bd9Sstevel@tonic-gate 	 * sys_nerr.
1041*7c478bd9Sstevel@tonic-gate 	 *
1042*7c478bd9Sstevel@tonic-gate 	 * For audit records generated at the user level:
1043*7c478bd9Sstevel@tonic-gate 	 * Upon success "number" is 0.
1044*7c478bd9Sstevel@tonic-gate 	 * Upon failure "number" is -1.
1045*7c478bd9Sstevel@tonic-gate 	 *
1046*7c478bd9Sstevel@tonic-gate 	 * For both kernel and user land the value of "return_value" is
1047*7c478bd9Sstevel@tonic-gate 	 * arbitrary. For the kernel it contains the return value of
1048*7c478bd9Sstevel@tonic-gate 	 * the system call. For user land it contains an arbitrary return
1049*7c478bd9Sstevel@tonic-gate 	 * value if it is less than ADT_FAIL_VALUE; ADT_FAIL_VALUE
1050*7c478bd9Sstevel@tonic-gate 	 * and above are messages defined in adt_event.h.   ADT_FAIL_PAM and
1051*7c478bd9Sstevel@tonic-gate 	 * above are messages from pam_strerror().  No interpretation is done
1052*7c478bd9Sstevel@tonic-gate 	 * on "return_value" if it is outside the range of ADT_FAIL_VALUE_* or
1053*7c478bd9Sstevel@tonic-gate 	 * ADT_FAIL_PAM values.
1054*7c478bd9Sstevel@tonic-gate 	 */
1055*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ERRVAL)) != 0)
1056*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1057*7c478bd9Sstevel@tonic-gate 
1058*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_char(context, &number, 1)) == 0) {
1059*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
1060*7c478bd9Sstevel@tonic-gate 			used_ret_val = 1;
1061*7c478bd9Sstevel@tonic-gate 			pa_error(number, pb, sizeof (pb));
1062*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
1063*7c478bd9Sstevel@tonic-gate 			uval.string_val = pb;
1064*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pa_print(context, &uval, 0)) != 0)
1065*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1066*7c478bd9Sstevel@tonic-gate 			if ((returnstat = close_tag(context, TAG_ERRVAL)) != 0)
1067*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1068*7c478bd9Sstevel@tonic-gate 			if ((returnstat = open_tag(context, TAG_RETVAL)) != 0)
1069*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1070*7c478bd9Sstevel@tonic-gate 
1071*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pr_adr_int32(
1072*7c478bd9Sstevel@tonic-gate 			    context, &value, 1)) != 0)
1073*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1074*7c478bd9Sstevel@tonic-gate 
1075*7c478bd9Sstevel@tonic-gate 			pa_retval(value, pb, sizeof (pb));
1076*7c478bd9Sstevel@tonic-gate 		} else {
1077*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_INT32;
1078*7c478bd9Sstevel@tonic-gate 			if ((char)number == -1)
1079*7c478bd9Sstevel@tonic-gate 				uval.int32_val = -1;
1080*7c478bd9Sstevel@tonic-gate 			else
1081*7c478bd9Sstevel@tonic-gate 				uval.int32_val = number;
1082*7c478bd9Sstevel@tonic-gate 		}
1083*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, used_ret_val);
1084*7c478bd9Sstevel@tonic-gate 	}
1085*7c478bd9Sstevel@tonic-gate 	if (used_ret_val) {
1086*7c478bd9Sstevel@tonic-gate 		if (returnstat == 0)
1087*7c478bd9Sstevel@tonic-gate 			returnstat = close_tag(context, TAG_RETVAL);
1088*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1089*7c478bd9Sstevel@tonic-gate 	}
1090*7c478bd9Sstevel@tonic-gate 	if (!returnstat)
1091*7c478bd9Sstevel@tonic-gate 		if (returnstat = close_tag(context, TAG_ERRVAL))
1092*7c478bd9Sstevel@tonic-gate 			return (returnstat);
1093*7c478bd9Sstevel@tonic-gate 
1094*7c478bd9Sstevel@tonic-gate 	return (process_tag(context, TAG_RETVAL, returnstat, 1));
1095*7c478bd9Sstevel@tonic-gate }
1096*7c478bd9Sstevel@tonic-gate 
1097*7c478bd9Sstevel@tonic-gate /*
1098*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1099*7c478bd9Sstevel@tonic-gate  * return_value64_token(): Process return value and display contents
1100*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
1101*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1102*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the return value token id has been retrieved
1103*7c478bd9Sstevel@tonic-gate  *
1104*7c478bd9Sstevel@tonic-gate  * Format of return value token:
1105*7c478bd9Sstevel@tonic-gate  * 	return value token id	adr_char
1106*7c478bd9Sstevel@tonic-gate  *	error number		adr_char
1107*7c478bd9Sstevel@tonic-gate  *	return value		adr_int64
1108*7c478bd9Sstevel@tonic-gate  *
1109*7c478bd9Sstevel@tonic-gate  * HOWEVER, the 64 bit return value is a concatenation of two
1110*7c478bd9Sstevel@tonic-gate  * 32 bit return values; the first of which is the same as is
1111*7c478bd9Sstevel@tonic-gate  * carried in the return32 token.  The second 32 bits are ignored
1112*7c478bd9Sstevel@tonic-gate  * here so that the displayed return token will have the same
1113*7c478bd9Sstevel@tonic-gate  * number whether the application is 32 or 64 bits.
1114*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1115*7c478bd9Sstevel@tonic-gate  */
1116*7c478bd9Sstevel@tonic-gate int
1117*7c478bd9Sstevel@tonic-gate return_value64_token(pr_context_t *context)
1118*7c478bd9Sstevel@tonic-gate {
1119*7c478bd9Sstevel@tonic-gate 	int		returnstat;
1120*7c478bd9Sstevel@tonic-gate 	uchar_t		number;
1121*7c478bd9Sstevel@tonic-gate 	rval_t		rval;
1122*7c478bd9Sstevel@tonic-gate 	char		pb[512];    /* print buffer */
1123*7c478bd9Sstevel@tonic-gate 	uval_t		uval;
1124*7c478bd9Sstevel@tonic-gate 
1125*7c478bd9Sstevel@tonic-gate 	/*
1126*7c478bd9Sstevel@tonic-gate 	 * Every audit record generated contains a return token.
1127*7c478bd9Sstevel@tonic-gate 	 *
1128*7c478bd9Sstevel@tonic-gate 	 * The return token is a special token. It indicates the success
1129*7c478bd9Sstevel@tonic-gate 	 * or failure of the event that contains it.
1130*7c478bd9Sstevel@tonic-gate 	 * The return64 token contains two pieces of data:
1131*7c478bd9Sstevel@tonic-gate 	 *
1132*7c478bd9Sstevel@tonic-gate 	 * 	char	number;
1133*7c478bd9Sstevel@tonic-gate 	 * 	int64_t	return_value;
1134*7c478bd9Sstevel@tonic-gate 	 *
1135*7c478bd9Sstevel@tonic-gate 	 * For audit records generated by the kernel:
1136*7c478bd9Sstevel@tonic-gate 	 * The kernel always puts a positive value in "number".
1137*7c478bd9Sstevel@tonic-gate 	 * Upon success "number" is 0.
1138*7c478bd9Sstevel@tonic-gate 	 * Upon failure "number" is a positive errno value that is less than
1139*7c478bd9Sstevel@tonic-gate 	 * sys_nerr.
1140*7c478bd9Sstevel@tonic-gate 	 *
1141*7c478bd9Sstevel@tonic-gate 	 * For audit records generated at the user level:
1142*7c478bd9Sstevel@tonic-gate 	 * Upon success "number" is 0.
1143*7c478bd9Sstevel@tonic-gate 	 * Upon failure "number" is -1.
1144*7c478bd9Sstevel@tonic-gate 	 *
1145*7c478bd9Sstevel@tonic-gate 	 * For both kernel and user land the value of "return_value" is
1146*7c478bd9Sstevel@tonic-gate 	 * arbitrary. For the kernel it contains the return value of
1147*7c478bd9Sstevel@tonic-gate 	 * the system call. For user land it contains an arbitrary return
1148*7c478bd9Sstevel@tonic-gate 	 * value if it is less than ADT_FAIL_VALUE; ADT_FAIL_VALUE
1149*7c478bd9Sstevel@tonic-gate 	 * and above are messages defined in adt_event.h.   ADT_FAIL_PAM and
1150*7c478bd9Sstevel@tonic-gate 	 * above are messages from pam_strerror().  No interpretation is done
1151*7c478bd9Sstevel@tonic-gate 	 * on "return_value" if it is outside the range of ADT_FAIL_VALUE_* or
1152*7c478bd9Sstevel@tonic-gate 	 * ADT_FAIL_PAM values.
1153*7c478bd9Sstevel@tonic-gate 	 *
1154*7c478bd9Sstevel@tonic-gate 	 * The 64 bit return value consists of two 32bit parts; for
1155*7c478bd9Sstevel@tonic-gate 	 * system calls, the first part is the value returned by the
1156*7c478bd9Sstevel@tonic-gate 	 * system call and the second part depends on the system call
1157*7c478bd9Sstevel@tonic-gate 	 * implementation.  In most cases, the second part is either 0
1158*7c478bd9Sstevel@tonic-gate 	 * or garbage; because of that, it is omitted from the praudit
1159*7c478bd9Sstevel@tonic-gate 	 * output.
1160*7c478bd9Sstevel@tonic-gate 	 */
1161*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ERRVAL)) != 0)
1162*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1163*7c478bd9Sstevel@tonic-gate 
1164*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_char(context, &number, 1)) == 0) {
1165*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
1166*7c478bd9Sstevel@tonic-gate 			pa_error(number, pb, sizeof (pb));
1167*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
1168*7c478bd9Sstevel@tonic-gate 			uval.string_val = pb;
1169*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pa_print(context, &uval, 0)) != 0)
1170*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1171*7c478bd9Sstevel@tonic-gate 
1172*7c478bd9Sstevel@tonic-gate 			if ((returnstat = close_tag(context, TAG_ERRVAL)) != 0)
1173*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1174*7c478bd9Sstevel@tonic-gate 			if ((returnstat = open_tag(context, TAG_RETVAL)) != 0)
1175*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1176*7c478bd9Sstevel@tonic-gate 
1177*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pr_adr_int64(context,
1178*7c478bd9Sstevel@tonic-gate 			    &rval.r_vals, 1)) != 0)
1179*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1180*7c478bd9Sstevel@tonic-gate 			pa_retval(rval.r_val1, pb, sizeof (pb));
1181*7c478bd9Sstevel@tonic-gate 		} else {
1182*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_INT32;
1183*7c478bd9Sstevel@tonic-gate 			if ((char)number == -1)
1184*7c478bd9Sstevel@tonic-gate 				uval.int32_val = -1;
1185*7c478bd9Sstevel@tonic-gate 			else
1186*7c478bd9Sstevel@tonic-gate 				uval.int32_val = number;
1187*7c478bd9Sstevel@tonic-gate 
1188*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pa_print(context, &uval, 0)) != 0)
1189*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1190*7c478bd9Sstevel@tonic-gate 
1191*7c478bd9Sstevel@tonic-gate 			if ((returnstat = close_tag(context, TAG_ERRVAL)) != 0)
1192*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1193*7c478bd9Sstevel@tonic-gate 			if ((returnstat = open_tag(context, TAG_RETVAL)) != 0)
1194*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1195*7c478bd9Sstevel@tonic-gate 
1196*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pr_adr_int64(context,
1197*7c478bd9Sstevel@tonic-gate 			    &rval.r_vals, 1)) != 0)
1198*7c478bd9Sstevel@tonic-gate 				return (returnstat);
1199*7c478bd9Sstevel@tonic-gate 			uval.int32_val = rval.r_val1;
1200*7c478bd9Sstevel@tonic-gate 		}
1201*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, 1);
1202*7c478bd9Sstevel@tonic-gate 	} else {
1203*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1204*7c478bd9Sstevel@tonic-gate 	}
1205*7c478bd9Sstevel@tonic-gate 
1206*7c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
1207*7c478bd9Sstevel@tonic-gate 		returnstat = close_tag(context, TAG_RETVAL);
1208*7c478bd9Sstevel@tonic-gate 
1209*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1210*7c478bd9Sstevel@tonic-gate }
1211*7c478bd9Sstevel@tonic-gate 
1212*7c478bd9Sstevel@tonic-gate /*
1213*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1214*7c478bd9Sstevel@tonic-gate  * subject32_token()	: Process subject token and display contents
1215*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
1216*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1217*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the subject token id has been retrieved
1218*7c478bd9Sstevel@tonic-gate  *
1219*7c478bd9Sstevel@tonic-gate  * Format of subject token:
1220*7c478bd9Sstevel@tonic-gate  *	subject token id	adr_char
1221*7c478bd9Sstevel@tonic-gate  *	auid			adr_u_int32
1222*7c478bd9Sstevel@tonic-gate  *	euid			adr_u_int32
1223*7c478bd9Sstevel@tonic-gate  *	egid			adr_u_int32
1224*7c478bd9Sstevel@tonic-gate  *	ruid			adr_u_int32
1225*7c478bd9Sstevel@tonic-gate  *	egid			adr_u_int32
1226*7c478bd9Sstevel@tonic-gate  *	pid			adr_u_int32
1227*7c478bd9Sstevel@tonic-gate  *	sid			adr_u_int32
1228*7c478bd9Sstevel@tonic-gate  *	tid			adr_u_int32, adr_u_int32
1229*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1230*7c478bd9Sstevel@tonic-gate  */
1231*7c478bd9Sstevel@tonic-gate int
1232*7c478bd9Sstevel@tonic-gate subject32_token(pr_context_t *context)
1233*7c478bd9Sstevel@tonic-gate {
1234*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1235*7c478bd9Sstevel@tonic-gate 
1236*7c478bd9Sstevel@tonic-gate 		/* auid */
1237*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_AUID, 0, 0);
1238*7c478bd9Sstevel@tonic-gate 		/* uid */
1239*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
1240*7c478bd9Sstevel@tonic-gate 		/* gid */
1241*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
1242*7c478bd9Sstevel@tonic-gate 		/* ruid */
1243*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1244*7c478bd9Sstevel@tonic-gate 		/* rgid */
1245*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1246*7c478bd9Sstevel@tonic-gate 		/* pid */
1247*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_PID, returnstat, 0);
1248*7c478bd9Sstevel@tonic-gate 		/* sid */
1249*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SID, returnstat, 0);
1250*7c478bd9Sstevel@tonic-gate 		/* tid */
1251*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TID32, returnstat, 1);
1252*7c478bd9Sstevel@tonic-gate 
1253*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1254*7c478bd9Sstevel@tonic-gate }
1255*7c478bd9Sstevel@tonic-gate 
1256*7c478bd9Sstevel@tonic-gate int
1257*7c478bd9Sstevel@tonic-gate subject64_token(pr_context_t *context)
1258*7c478bd9Sstevel@tonic-gate {
1259*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1260*7c478bd9Sstevel@tonic-gate 
1261*7c478bd9Sstevel@tonic-gate 		/* auid */
1262*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_AUID, 0, 0);
1263*7c478bd9Sstevel@tonic-gate 		/* uid */
1264*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
1265*7c478bd9Sstevel@tonic-gate 		/* gid */
1266*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
1267*7c478bd9Sstevel@tonic-gate 		/* ruid */
1268*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1269*7c478bd9Sstevel@tonic-gate 		/* rgid */
1270*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1271*7c478bd9Sstevel@tonic-gate 		/* pid */
1272*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_PID, returnstat, 0);
1273*7c478bd9Sstevel@tonic-gate 		/* sid */
1274*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SID, returnstat, 0);
1275*7c478bd9Sstevel@tonic-gate 		/* tid */
1276*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TID64, returnstat, 1);
1277*7c478bd9Sstevel@tonic-gate 
1278*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1279*7c478bd9Sstevel@tonic-gate }
1280*7c478bd9Sstevel@tonic-gate 
1281*7c478bd9Sstevel@tonic-gate /*
1282*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1283*7c478bd9Sstevel@tonic-gate  * subject_ex_token(): Process subject token and display contents
1284*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
1285*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1286*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the subject token id has been retrieved
1287*7c478bd9Sstevel@tonic-gate  *
1288*7c478bd9Sstevel@tonic-gate  * Format of extended subject token:
1289*7c478bd9Sstevel@tonic-gate  *	subject token id	adr_char
1290*7c478bd9Sstevel@tonic-gate  *	auid			adr_u_int32
1291*7c478bd9Sstevel@tonic-gate  *	euid			adr_u_int32
1292*7c478bd9Sstevel@tonic-gate  *	egid			adr_u_int32
1293*7c478bd9Sstevel@tonic-gate  *	ruid			adr_u_int32
1294*7c478bd9Sstevel@tonic-gate  *	egid			adr_u_int32
1295*7c478bd9Sstevel@tonic-gate  *	pid			adr_u_int32
1296*7c478bd9Sstevel@tonic-gate  *	sid			adr_u_int32
1297*7c478bd9Sstevel@tonic-gate  *	tid			adr_u_int32, adr_u_int32
1298*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1299*7c478bd9Sstevel@tonic-gate  */
1300*7c478bd9Sstevel@tonic-gate int
1301*7c478bd9Sstevel@tonic-gate subject32_ex_token(pr_context_t *context)
1302*7c478bd9Sstevel@tonic-gate {
1303*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1304*7c478bd9Sstevel@tonic-gate 
1305*7c478bd9Sstevel@tonic-gate 		/* auid */
1306*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_AUID, 0, 0);
1307*7c478bd9Sstevel@tonic-gate 		/* uid */
1308*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
1309*7c478bd9Sstevel@tonic-gate 		/* gid */
1310*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
1311*7c478bd9Sstevel@tonic-gate 		/* ruid */
1312*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1313*7c478bd9Sstevel@tonic-gate 		/* rgid */
1314*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1315*7c478bd9Sstevel@tonic-gate 		/* pid */
1316*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_PID, returnstat, 0);
1317*7c478bd9Sstevel@tonic-gate 		/* sid */
1318*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SID, returnstat, 0);
1319*7c478bd9Sstevel@tonic-gate 		/* tid */
1320*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TID32_EX, returnstat, 1);
1321*7c478bd9Sstevel@tonic-gate 
1322*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1323*7c478bd9Sstevel@tonic-gate }
1324*7c478bd9Sstevel@tonic-gate 
1325*7c478bd9Sstevel@tonic-gate int
1326*7c478bd9Sstevel@tonic-gate subject64_ex_token(pr_context_t *context)
1327*7c478bd9Sstevel@tonic-gate {
1328*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1329*7c478bd9Sstevel@tonic-gate 
1330*7c478bd9Sstevel@tonic-gate 		/* auid */
1331*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_AUID, 0, 0);
1332*7c478bd9Sstevel@tonic-gate 		/* uid */
1333*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
1334*7c478bd9Sstevel@tonic-gate 		/* gid */
1335*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
1336*7c478bd9Sstevel@tonic-gate 		/* ruid */
1337*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1338*7c478bd9Sstevel@tonic-gate 		/* rgid */
1339*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1340*7c478bd9Sstevel@tonic-gate 		/* pid */
1341*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_PID, returnstat, 0);
1342*7c478bd9Sstevel@tonic-gate 		/* sid */
1343*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SID, returnstat, 0);
1344*7c478bd9Sstevel@tonic-gate 		/* tid */
1345*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_TID64_EX, returnstat, 1);
1346*7c478bd9Sstevel@tonic-gate 
1347*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1348*7c478bd9Sstevel@tonic-gate }
1349*7c478bd9Sstevel@tonic-gate 
1350*7c478bd9Sstevel@tonic-gate /*
1351*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1352*7c478bd9Sstevel@tonic-gate  * s5_IPC_token()	: Process System V IPC token and display contents
1353*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
1354*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1355*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the System V IPC id has been retrieved
1356*7c478bd9Sstevel@tonic-gate  *
1357*7c478bd9Sstevel@tonic-gate  * Format of System V IPC token:
1358*7c478bd9Sstevel@tonic-gate  *	System V IPC token id	adr_char
1359*7c478bd9Sstevel@tonic-gate  *	object id		adr_int32
1360*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1361*7c478bd9Sstevel@tonic-gate  */
1362*7c478bd9Sstevel@tonic-gate int
1363*7c478bd9Sstevel@tonic-gate s5_IPC_token(pr_context_t *context)
1364*7c478bd9Sstevel@tonic-gate {
1365*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1366*7c478bd9Sstevel@tonic-gate 	uchar_t ipctype;
1367*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1368*7c478bd9Sstevel@tonic-gate 
1369*7c478bd9Sstevel@tonic-gate 	/*
1370*7c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
1371*7c478bd9Sstevel@tonic-gate 	 * These names refer to the type of System V IPC object:
1372*7c478bd9Sstevel@tonic-gate 	 * message queue, semaphore, shared memory.
1373*7c478bd9Sstevel@tonic-gate 	 */
1374*7c478bd9Sstevel@tonic-gate 
1375*7c478bd9Sstevel@tonic-gate 	if (pr_adr_u_char(context, &ipctype, 1) == 0) {
1376*7c478bd9Sstevel@tonic-gate 		if ((returnstat = open_tag(context, TAG_IPCTYPE)) != 0)
1377*7c478bd9Sstevel@tonic-gate 			return (returnstat);
1378*7c478bd9Sstevel@tonic-gate 
1379*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
1380*7c478bd9Sstevel@tonic-gate 			/* print in ASCII form */
1381*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
1382*7c478bd9Sstevel@tonic-gate 			switch (ipctype) {
1383*7c478bd9Sstevel@tonic-gate 			case AT_IPC_MSG:
1384*7c478bd9Sstevel@tonic-gate 				uval.string_val = gettext("msg");
1385*7c478bd9Sstevel@tonic-gate 				break;
1386*7c478bd9Sstevel@tonic-gate 			case AT_IPC_SEM:
1387*7c478bd9Sstevel@tonic-gate 				uval.string_val = gettext("sem");
1388*7c478bd9Sstevel@tonic-gate 				break;
1389*7c478bd9Sstevel@tonic-gate 			case AT_IPC_SHM:
1390*7c478bd9Sstevel@tonic-gate 				uval.string_val = gettext("shm");
1391*7c478bd9Sstevel@tonic-gate 				break;
1392*7c478bd9Sstevel@tonic-gate 			}
1393*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
1394*7c478bd9Sstevel@tonic-gate 		}
1395*7c478bd9Sstevel@tonic-gate 		/* print in integer form */
1396*7c478bd9Sstevel@tonic-gate 		if ((context->format & PRF_RAWM) || (returnstat == 1)) {
1397*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_BYTE;
1398*7c478bd9Sstevel@tonic-gate 			uval.char_val = ipctype;
1399*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
1400*7c478bd9Sstevel@tonic-gate 		}
1401*7c478bd9Sstevel@tonic-gate 		if ((returnstat = close_tag(context, TAG_IPCTYPE)) != 0)
1402*7c478bd9Sstevel@tonic-gate 			return (returnstat);
1403*7c478bd9Sstevel@tonic-gate 
1404*7c478bd9Sstevel@tonic-gate 		/* next get and print ipc id */
1405*7c478bd9Sstevel@tonic-gate 		return (process_tag(context, TAG_IPCID, returnstat, 1));
1406*7c478bd9Sstevel@tonic-gate 	} else {
1407*7c478bd9Sstevel@tonic-gate 		/* cannot retrieve ipc type */
1408*7c478bd9Sstevel@tonic-gate 		return (-1);
1409*7c478bd9Sstevel@tonic-gate 	}
1410*7c478bd9Sstevel@tonic-gate }
1411*7c478bd9Sstevel@tonic-gate 
1412*7c478bd9Sstevel@tonic-gate /*
1413*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1414*7c478bd9Sstevel@tonic-gate  * text_token()	: Process text token and display contents
1415*7c478bd9Sstevel@tonic-gate  * return codes	: -1 - error
1416*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1417*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the text token id has been retrieved
1418*7c478bd9Sstevel@tonic-gate  *
1419*7c478bd9Sstevel@tonic-gate  * Format of text token:
1420*7c478bd9Sstevel@tonic-gate  *	text token id		adr_char
1421*7c478bd9Sstevel@tonic-gate  * 	text			adr_string
1422*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1423*7c478bd9Sstevel@tonic-gate  */
1424*7c478bd9Sstevel@tonic-gate int
1425*7c478bd9Sstevel@tonic-gate text_token(pr_context_t *context)
1426*7c478bd9Sstevel@tonic-gate {
1427*7c478bd9Sstevel@tonic-gate 	return (pa_adr_string(context, 0, 1));
1428*7c478bd9Sstevel@tonic-gate }
1429*7c478bd9Sstevel@tonic-gate 
1430*7c478bd9Sstevel@tonic-gate /*
1431*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1432*7c478bd9Sstevel@tonic-gate  * tid_token()		: Process a generic terminal id token / AUT_TID
1433*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
1434*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1435*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the token id has been retrieved
1436*7c478bd9Sstevel@tonic-gate  *
1437*7c478bd9Sstevel@tonic-gate  * Format of tid token:
1438*7c478bd9Sstevel@tonic-gate  *	ip token id	adr_char
1439*7c478bd9Sstevel@tonic-gate  *	terminal type	adr_char
1440*7c478bd9Sstevel@tonic-gate  *  terminal type = AU_IPADR:
1441*7c478bd9Sstevel@tonic-gate  *	remote port:	adr_short
1442*7c478bd9Sstevel@tonic-gate  *	local port:	adr_short
1443*7c478bd9Sstevel@tonic-gate  *	IP type:	adt_int32 -- AU_IPv4 or AU_IPv6
1444*7c478bd9Sstevel@tonic-gate  *	address:	adr_int32 if IPv4, else 4 * adr_int32
1445*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1446*7c478bd9Sstevel@tonic-gate  */
1447*7c478bd9Sstevel@tonic-gate int
1448*7c478bd9Sstevel@tonic-gate tid_token(pr_context_t *context)
1449*7c478bd9Sstevel@tonic-gate {
1450*7c478bd9Sstevel@tonic-gate 	int		returnstat;
1451*7c478bd9Sstevel@tonic-gate 	uchar_t		type;
1452*7c478bd9Sstevel@tonic-gate 	uval_t		uval;
1453*7c478bd9Sstevel@tonic-gate 
1454*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_char(context, &type, 1)) != 0)
1455*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1456*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
1457*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_TID_TYPE)) != 0)
1458*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1459*7c478bd9Sstevel@tonic-gate 
1460*7c478bd9Sstevel@tonic-gate 	switch (type) {
1461*7c478bd9Sstevel@tonic-gate 	default:
1462*7c478bd9Sstevel@tonic-gate 		return (-1);	/* other than IP type is not implemented */
1463*7c478bd9Sstevel@tonic-gate 	case AU_IPADR:
1464*7c478bd9Sstevel@tonic-gate 		uval.string_val = "ip";
1465*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, 0);
1466*7c478bd9Sstevel@tonic-gate 		returnstat = close_tag(context, TAG_TID_TYPE);
1467*7c478bd9Sstevel@tonic-gate 		returnstat = open_tag(context, TAG_IP);
1468*7c478bd9Sstevel@tonic-gate 		returnstat = process_tag(context, TAG_IP_REMOTE, returnstat, 0);
1469*7c478bd9Sstevel@tonic-gate 		returnstat = process_tag(context, TAG_IP_LOCAL, returnstat, 0);
1470*7c478bd9Sstevel@tonic-gate 		returnstat = process_tag(context, TAG_IP_ADR, returnstat, 1);
1471*7c478bd9Sstevel@tonic-gate 		returnstat = close_tag(context, TAG_IP);
1472*7c478bd9Sstevel@tonic-gate 		break;
1473*7c478bd9Sstevel@tonic-gate 	}
1474*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1475*7c478bd9Sstevel@tonic-gate }
1476*7c478bd9Sstevel@tonic-gate 
1477*7c478bd9Sstevel@tonic-gate /*
1478*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1479*7c478bd9Sstevel@tonic-gate  * ip_addr_token() 	: Process ip token and display contents
1480*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
1481*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1482*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the ip token id has been retrieved
1483*7c478bd9Sstevel@tonic-gate  *
1484*7c478bd9Sstevel@tonic-gate  * Format of ip address token:
1485*7c478bd9Sstevel@tonic-gate  *	ip token id	adr_char
1486*7c478bd9Sstevel@tonic-gate  *	address		adr_int32 (printed in hex)
1487*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1488*7c478bd9Sstevel@tonic-gate  */
1489*7c478bd9Sstevel@tonic-gate 
1490*7c478bd9Sstevel@tonic-gate int
1491*7c478bd9Sstevel@tonic-gate ip_addr_token(pr_context_t *context)
1492*7c478bd9Sstevel@tonic-gate {
1493*7c478bd9Sstevel@tonic-gate 	return (pa_hostname(context, 0, 1));
1494*7c478bd9Sstevel@tonic-gate }
1495*7c478bd9Sstevel@tonic-gate 
1496*7c478bd9Sstevel@tonic-gate int
1497*7c478bd9Sstevel@tonic-gate ip_addr_ex_token(pr_context_t *context)
1498*7c478bd9Sstevel@tonic-gate {
1499*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1500*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[16];
1501*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_type;
1502*7c478bd9Sstevel@tonic-gate 	struct in_addr	ia;
1503*7c478bd9Sstevel@tonic-gate 	char		*ipstring;
1504*7c478bd9Sstevel@tonic-gate 	char		buf[256];
1505*7c478bd9Sstevel@tonic-gate 	uval_t		uval;
1506*7c478bd9Sstevel@tonic-gate 
1507*7c478bd9Sstevel@tonic-gate 	/* get address type */
1508*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
1509*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1510*7c478bd9Sstevel@tonic-gate 
1511*7c478bd9Sstevel@tonic-gate 	/* legal address types are either AU_IPv4 or AU_IPv6 only */
1512*7c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
1513*7c478bd9Sstevel@tonic-gate 		return (-1);
1514*7c478bd9Sstevel@tonic-gate 
1515*7c478bd9Sstevel@tonic-gate 	/* get address (4/16) */
1516*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
1517*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1518*7c478bd9Sstevel@tonic-gate 
1519*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
1520*7c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {
1521*7c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
1522*7c478bd9Sstevel@tonic-gate 
1523*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
1524*7c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], buf, sizeof (buf));
1525*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, 1));
1526*7c478bd9Sstevel@tonic-gate 		}
1527*7c478bd9Sstevel@tonic-gate 
1528*7c478bd9Sstevel@tonic-gate 		ia.s_addr = ip_addr[0];
1529*7c478bd9Sstevel@tonic-gate 		if ((ipstring = inet_ntoa(ia)) == NULL)
1530*7c478bd9Sstevel@tonic-gate 			return (-1);
1531*7c478bd9Sstevel@tonic-gate 
1532*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%s", ipstring);
1533*7c478bd9Sstevel@tonic-gate 
1534*7c478bd9Sstevel@tonic-gate 	} else {
1535*7c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
1536*7c478bd9Sstevel@tonic-gate 
1537*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
1538*7c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, buf, sizeof (buf));
1539*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, 1));
1540*7c478bd9Sstevel@tonic-gate 		}
1541*7c478bd9Sstevel@tonic-gate 
1542*7c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *) ip_addr, buf,
1543*7c478bd9Sstevel@tonic-gate 		    sizeof (buf));
1544*7c478bd9Sstevel@tonic-gate 
1545*7c478bd9Sstevel@tonic-gate 	}
1546*7c478bd9Sstevel@tonic-gate 
1547*7c478bd9Sstevel@tonic-gate 	return (pa_print(context, &uval, 1));
1548*7c478bd9Sstevel@tonic-gate }
1549*7c478bd9Sstevel@tonic-gate 
1550*7c478bd9Sstevel@tonic-gate /*
1551*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1552*7c478bd9Sstevel@tonic-gate  * ip_token()		: Process ip header token and display contents
1553*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
1554*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1555*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the ip token id has been retrieved
1556*7c478bd9Sstevel@tonic-gate  *
1557*7c478bd9Sstevel@tonic-gate  * Format of ip header token:
1558*7c478bd9Sstevel@tonic-gate  *	ip header token id	adr_char
1559*7c478bd9Sstevel@tonic-gate  *	version			adr_char (printed in hex)
1560*7c478bd9Sstevel@tonic-gate  *	type of service		adr_char (printed in hex)
1561*7c478bd9Sstevel@tonic-gate  *	length			adr_short
1562*7c478bd9Sstevel@tonic-gate  *	id			adr_u_short
1563*7c478bd9Sstevel@tonic-gate  *	offset			adr_u_short
1564*7c478bd9Sstevel@tonic-gate  *	ttl			adr_char (printed in hex)
1565*7c478bd9Sstevel@tonic-gate  *	protocol		adr_char (printed in hex)
1566*7c478bd9Sstevel@tonic-gate  *	checksum		adr_u_short
1567*7c478bd9Sstevel@tonic-gate  *	source address		adr_int32 (printed in hex)
1568*7c478bd9Sstevel@tonic-gate  *	destination address	adr_int32 (printed in hex)
1569*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1570*7c478bd9Sstevel@tonic-gate  */
1571*7c478bd9Sstevel@tonic-gate int
1572*7c478bd9Sstevel@tonic-gate ip_token(pr_context_t *context)
1573*7c478bd9Sstevel@tonic-gate {
1574*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1575*7c478bd9Sstevel@tonic-gate 
1576*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPVERS, 0, 0);
1577*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPSERV, returnstat, 0);
1578*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPLEN, returnstat, 0);
1579*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPID, returnstat, 0);
1580*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPOFFS, returnstat, 0);
1581*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPTTL, returnstat, 0);
1582*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPPROTO, returnstat, 0);
1583*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPCKSUM, returnstat, 0);
1584*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPSRC, returnstat, 0);
1585*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_IPDEST, returnstat, 1);
1586*7c478bd9Sstevel@tonic-gate 
1587*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1588*7c478bd9Sstevel@tonic-gate }
1589*7c478bd9Sstevel@tonic-gate 
1590*7c478bd9Sstevel@tonic-gate /*
1591*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1592*7c478bd9Sstevel@tonic-gate  * iport_token() 	: Process ip port address token and display contents
1593*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
1594*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1595*7c478bd9Sstevel@tonic-gate  * NOTE: At time of call, the ip port address token id has been retrieved
1596*7c478bd9Sstevel@tonic-gate  *
1597*7c478bd9Sstevel@tonic-gate  * Format of ip port token:
1598*7c478bd9Sstevel@tonic-gate  *	ip port address token id	adr_char
1599*7c478bd9Sstevel@tonic-gate  *	port address			adr_short (in hex)
1600*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1601*7c478bd9Sstevel@tonic-gate  */
1602*7c478bd9Sstevel@tonic-gate int
1603*7c478bd9Sstevel@tonic-gate iport_token(pr_context_t *context)
1604*7c478bd9Sstevel@tonic-gate {
1605*7c478bd9Sstevel@tonic-gate 	return (pa_adr_shorthex(context, 0, 1));
1606*7c478bd9Sstevel@tonic-gate }
1607*7c478bd9Sstevel@tonic-gate 
1608*7c478bd9Sstevel@tonic-gate /*
1609*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1610*7c478bd9Sstevel@tonic-gate  * socket_token() 	: Process socket token and display contents
1611*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
1612*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1613*7c478bd9Sstevel@tonic-gate  * NOTE: At time of call, the socket token id has been retrieved
1614*7c478bd9Sstevel@tonic-gate  *
1615*7c478bd9Sstevel@tonic-gate  * Format of socket token:
1616*7c478bd9Sstevel@tonic-gate  *	ip socket token id		adr_char
1617*7c478bd9Sstevel@tonic-gate  *	socket type			adr_short (in hex)
1618*7c478bd9Sstevel@tonic-gate  *	foreign port			adr_short (in hex)
1619*7c478bd9Sstevel@tonic-gate  *	foreign internet address	adr_hostname/adr_int32 (in ascii/hex)
1620*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1621*7c478bd9Sstevel@tonic-gate  *
1622*7c478bd9Sstevel@tonic-gate  * Note: local port and local internet address have been removed for 5.x
1623*7c478bd9Sstevel@tonic-gate  */
1624*7c478bd9Sstevel@tonic-gate int
1625*7c478bd9Sstevel@tonic-gate socket_token(pr_context_t *context)
1626*7c478bd9Sstevel@tonic-gate {
1627*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1628*7c478bd9Sstevel@tonic-gate 
1629*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SOCKTYPE, 0, 0);
1630*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SOCKPORT, returnstat, 0);
1631*7c478bd9Sstevel@tonic-gate 	if (returnstat != 0)
1632*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1633*7c478bd9Sstevel@tonic-gate 
1634*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_SOCKADDR)) != 0)
1635*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1636*7c478bd9Sstevel@tonic-gate 
1637*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pa_hostname(context, returnstat, 1)) != 0)
1638*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1639*7c478bd9Sstevel@tonic-gate 
1640*7c478bd9Sstevel@tonic-gate 	return (close_tag(context, TAG_SOCKADDR));
1641*7c478bd9Sstevel@tonic-gate }
1642*7c478bd9Sstevel@tonic-gate 
1643*7c478bd9Sstevel@tonic-gate /*
1644*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1645*7c478bd9Sstevel@tonic-gate  * socket_ex_token()	: Process socket token and display contents
1646*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
1647*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1648*7c478bd9Sstevel@tonic-gate  * NOTE: At time of call, the extended socket token id has been retrieved
1649*7c478bd9Sstevel@tonic-gate  *
1650*7c478bd9Sstevel@tonic-gate  * Format of extended socket token:
1651*7c478bd9Sstevel@tonic-gate  *	token id			adr_char
1652*7c478bd9Sstevel@tonic-gate  *	socket domain			adr_short (in hex)
1653*7c478bd9Sstevel@tonic-gate  *	socket type			adr_short (in hex)
1654*7c478bd9Sstevel@tonic-gate  *	IP address type			adr_short (in hex) [not displayed]
1655*7c478bd9Sstevel@tonic-gate  *	local port			adr_short (in hex)
1656*7c478bd9Sstevel@tonic-gate  *	local internet address		adr_hostname/adr_int32 (in ascii/hex)
1657*7c478bd9Sstevel@tonic-gate  *	foreign port			adr_short (in hex)
1658*7c478bd9Sstevel@tonic-gate  *	foreign internet address	adr_hostname/adr_int32 (in ascii/hex)
1659*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1660*7c478bd9Sstevel@tonic-gate  *
1661*7c478bd9Sstevel@tonic-gate  * Note: local port and local internet address have been removed for 5.x
1662*7c478bd9Sstevel@tonic-gate  */
1663*7c478bd9Sstevel@tonic-gate int
1664*7c478bd9Sstevel@tonic-gate socket_ex_token(pr_context_t *context)
1665*7c478bd9Sstevel@tonic-gate {
1666*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1667*7c478bd9Sstevel@tonic-gate 
1668*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SOCKEXDOM, 0, 0);
1669*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SOCKEXTYPE, returnstat, 0);
1670*7c478bd9Sstevel@tonic-gate 	returnstat = pa_hostname_so(context, returnstat, 1);
1671*7c478bd9Sstevel@tonic-gate 
1672*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1673*7c478bd9Sstevel@tonic-gate }
1674*7c478bd9Sstevel@tonic-gate 
1675*7c478bd9Sstevel@tonic-gate /*
1676*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1677*7c478bd9Sstevel@tonic-gate  * sequence_token()	: Process sequence token and display contents
1678*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
1679*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1680*7c478bd9Sstevel@tonic-gate  * NOTE: At time of call, the socket token id has been retrieved
1681*7c478bd9Sstevel@tonic-gate  *
1682*7c478bd9Sstevel@tonic-gate  * Format of sequence token:
1683*7c478bd9Sstevel@tonic-gate  *	sequence token id		adr_char
1684*7c478bd9Sstevel@tonic-gate  *	sequence number 		adr_u_int32 (in hex)
1685*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1686*7c478bd9Sstevel@tonic-gate  */
1687*7c478bd9Sstevel@tonic-gate int
1688*7c478bd9Sstevel@tonic-gate sequence_token(pr_context_t *context)
1689*7c478bd9Sstevel@tonic-gate {
1690*7c478bd9Sstevel@tonic-gate 	return (process_tag(context, TAG_SEQNUM, 0, 1));
1691*7c478bd9Sstevel@tonic-gate }
1692*7c478bd9Sstevel@tonic-gate 
1693*7c478bd9Sstevel@tonic-gate /*
1694*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1695*7c478bd9Sstevel@tonic-gate  * acl_token()	: Process access control list term
1696*7c478bd9Sstevel@tonic-gate  * return codes	: -1 - error
1697*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1698*7c478bd9Sstevel@tonic-gate  *
1699*7c478bd9Sstevel@tonic-gate  * Format of acl token:
1700*7c478bd9Sstevel@tonic-gate  *	token id	adr_char
1701*7c478bd9Sstevel@tonic-gate  *	term type	adr_u_int32
1702*7c478bd9Sstevel@tonic-gate  *	term value	adr_u_int32 (depends on type)
1703*7c478bd9Sstevel@tonic-gate  *	file mode	adr_u_int (in octal)
1704*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1705*7c478bd9Sstevel@tonic-gate  */
1706*7c478bd9Sstevel@tonic-gate int
1707*7c478bd9Sstevel@tonic-gate acl_token(pr_context_t *context)
1708*7c478bd9Sstevel@tonic-gate {
1709*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1710*7c478bd9Sstevel@tonic-gate 
1711*7c478bd9Sstevel@tonic-gate 	returnstat = pa_pw_uid_gr_gid(context, 0, 0);
1712*7c478bd9Sstevel@tonic-gate 
1713*7c478bd9Sstevel@tonic-gate 	return (process_tag(context, TAG_MODE, returnstat, 1));
1714*7c478bd9Sstevel@tonic-gate }
1715*7c478bd9Sstevel@tonic-gate 
1716*7c478bd9Sstevel@tonic-gate /*
1717*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1718*7c478bd9Sstevel@tonic-gate  * attribute_token()	: Process attribute token and display contents
1719*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
1720*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1721*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the attribute token id has been retrieved
1722*7c478bd9Sstevel@tonic-gate  *
1723*7c478bd9Sstevel@tonic-gate  * Format of attribute token:
1724*7c478bd9Sstevel@tonic-gate  *	attribute token id	adr_char
1725*7c478bd9Sstevel@tonic-gate  * 	mode			adr_u_int (printed in octal)
1726*7c478bd9Sstevel@tonic-gate  *	uid			adr_u_int
1727*7c478bd9Sstevel@tonic-gate  *	gid			adr_u_int
1728*7c478bd9Sstevel@tonic-gate  *	file system id		adr_int
1729*7c478bd9Sstevel@tonic-gate  *
1730*7c478bd9Sstevel@tonic-gate  *	node id			adr_int		(attribute_token
1731*7c478bd9Sstevel@tonic-gate  *						 pre SunOS 5.7)
1732*7c478bd9Sstevel@tonic-gate  *	device			adr_u_int
1733*7c478bd9Sstevel@tonic-gate  * or
1734*7c478bd9Sstevel@tonic-gate  *	node id			adr_int64	(attribute32_token)
1735*7c478bd9Sstevel@tonic-gate  *	device			adr_u_int
1736*7c478bd9Sstevel@tonic-gate  * or
1737*7c478bd9Sstevel@tonic-gate  *	node id			adr_int64	(attribute64_token)
1738*7c478bd9Sstevel@tonic-gate  *	device			adr_u_int64
1739*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1740*7c478bd9Sstevel@tonic-gate  */
1741*7c478bd9Sstevel@tonic-gate int
1742*7c478bd9Sstevel@tonic-gate attribute_token(pr_context_t *context)
1743*7c478bd9Sstevel@tonic-gate {
1744*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1745*7c478bd9Sstevel@tonic-gate 
1746*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_MODE, 0, 0);
1747*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
1748*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
1749*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_FSID, returnstat, 0);
1750*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_NODEID32, returnstat, 0);
1751*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_DEVICE32, returnstat, 1);
1752*7c478bd9Sstevel@tonic-gate 
1753*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1754*7c478bd9Sstevel@tonic-gate }
1755*7c478bd9Sstevel@tonic-gate 
1756*7c478bd9Sstevel@tonic-gate int
1757*7c478bd9Sstevel@tonic-gate attribute32_token(pr_context_t *context)
1758*7c478bd9Sstevel@tonic-gate {
1759*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1760*7c478bd9Sstevel@tonic-gate 
1761*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_MODE, 0, 0);
1762*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
1763*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
1764*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_FSID, returnstat, 0);
1765*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_NODEID64, returnstat, 0);
1766*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_DEVICE32, returnstat, 1);
1767*7c478bd9Sstevel@tonic-gate 
1768*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1769*7c478bd9Sstevel@tonic-gate }
1770*7c478bd9Sstevel@tonic-gate 
1771*7c478bd9Sstevel@tonic-gate int
1772*7c478bd9Sstevel@tonic-gate attribute64_token(pr_context_t *context)
1773*7c478bd9Sstevel@tonic-gate {
1774*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1775*7c478bd9Sstevel@tonic-gate 
1776*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_MODE, 0, 0);
1777*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, returnstat, 0);
1778*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
1779*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_FSID, returnstat, 0);
1780*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_NODEID64, returnstat, 0);
1781*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_DEVICE64, returnstat, 1);
1782*7c478bd9Sstevel@tonic-gate 
1783*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1784*7c478bd9Sstevel@tonic-gate }
1785*7c478bd9Sstevel@tonic-gate 
1786*7c478bd9Sstevel@tonic-gate /*
1787*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1788*7c478bd9Sstevel@tonic-gate  * group_token() 	: Process group token and display contents
1789*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
1790*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1791*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the group token id has been retrieved
1792*7c478bd9Sstevel@tonic-gate  *
1793*7c478bd9Sstevel@tonic-gate  * Format of group token:
1794*7c478bd9Sstevel@tonic-gate  *	group token id		adr_char
1795*7c478bd9Sstevel@tonic-gate  *	group list		adr_long, 16 times
1796*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1797*7c478bd9Sstevel@tonic-gate  */
1798*7c478bd9Sstevel@tonic-gate int
1799*7c478bd9Sstevel@tonic-gate group_token(pr_context_t *context)
1800*7c478bd9Sstevel@tonic-gate {
1801*7c478bd9Sstevel@tonic-gate 	int	returnstat = 0;
1802*7c478bd9Sstevel@tonic-gate 	int	i;
1803*7c478bd9Sstevel@tonic-gate 
1804*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < NGROUPS_MAX - 1; i++) {
1805*7c478bd9Sstevel@tonic-gate 		if ((returnstat = process_tag(context, TAG_GROUPID,
1806*7c478bd9Sstevel@tonic-gate 		    returnstat, 0)) < 0)
1807*7c478bd9Sstevel@tonic-gate 			return (returnstat);
1808*7c478bd9Sstevel@tonic-gate 	}
1809*7c478bd9Sstevel@tonic-gate 
1810*7c478bd9Sstevel@tonic-gate 	return (process_tag(context, TAG_GROUPID, returnstat, 1));
1811*7c478bd9Sstevel@tonic-gate }
1812*7c478bd9Sstevel@tonic-gate 
1813*7c478bd9Sstevel@tonic-gate /*
1814*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1815*7c478bd9Sstevel@tonic-gate  * newgroup_token() 	: Process group token and display contents
1816*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
1817*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1818*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the group token id has been retrieved
1819*7c478bd9Sstevel@tonic-gate  *
1820*7c478bd9Sstevel@tonic-gate  * Format of new group token:
1821*7c478bd9Sstevel@tonic-gate  *	group token id		adr_char
1822*7c478bd9Sstevel@tonic-gate  *	group number		adr_short
1823*7c478bd9Sstevel@tonic-gate  *	group list		adr_int32, group number times
1824*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1825*7c478bd9Sstevel@tonic-gate  */
1826*7c478bd9Sstevel@tonic-gate int
1827*7c478bd9Sstevel@tonic-gate newgroup_token(pr_context_t *context)
1828*7c478bd9Sstevel@tonic-gate {
1829*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1830*7c478bd9Sstevel@tonic-gate 	int	i, num;
1831*7c478bd9Sstevel@tonic-gate 	short	n_groups;
1832*7c478bd9Sstevel@tonic-gate 
1833*7c478bd9Sstevel@tonic-gate 	returnstat = pr_adr_short(context, &n_groups, 1);
1834*7c478bd9Sstevel@tonic-gate 	if (returnstat != 0)
1835*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1836*7c478bd9Sstevel@tonic-gate 
1837*7c478bd9Sstevel@tonic-gate 	num = (int)n_groups;
1838*7c478bd9Sstevel@tonic-gate 	if (num == 0) {
1839*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_XMLM)) {
1840*7c478bd9Sstevel@tonic-gate 			/* sigh, have to put out a '\n' */
1841*7c478bd9Sstevel@tonic-gate 			returnstat = pr_putchar(context, '\n');
1842*7c478bd9Sstevel@tonic-gate 		}
1843*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1844*7c478bd9Sstevel@tonic-gate 	}
1845*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < num - 1; i++) {
1846*7c478bd9Sstevel@tonic-gate 		if ((returnstat = process_tag(context, TAG_GROUPID,
1847*7c478bd9Sstevel@tonic-gate 		    returnstat, 0)) < 0)
1848*7c478bd9Sstevel@tonic-gate 			return (returnstat);
1849*7c478bd9Sstevel@tonic-gate 	}
1850*7c478bd9Sstevel@tonic-gate 
1851*7c478bd9Sstevel@tonic-gate 	return (process_tag(context, TAG_GROUPID, returnstat, 1));
1852*7c478bd9Sstevel@tonic-gate }
1853*7c478bd9Sstevel@tonic-gate 
1854*7c478bd9Sstevel@tonic-gate static int
1855*7c478bd9Sstevel@tonic-gate string_token_common(pr_context_t *context, int tag)
1856*7c478bd9Sstevel@tonic-gate {
1857*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1858*7c478bd9Sstevel@tonic-gate 	int	num;
1859*7c478bd9Sstevel@tonic-gate 
1860*7c478bd9Sstevel@tonic-gate 	returnstat = pr_adr_int32(context, (int32_t *)&num, 1);
1861*7c478bd9Sstevel@tonic-gate 	if (returnstat != 0)
1862*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1863*7c478bd9Sstevel@tonic-gate 
1864*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM)) {
1865*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%d%s", num,
1866*7c478bd9Sstevel@tonic-gate 		    context->SEPARATOR);
1867*7c478bd9Sstevel@tonic-gate 		if (returnstat != 0)
1868*7c478bd9Sstevel@tonic-gate 			return (returnstat);
1869*7c478bd9Sstevel@tonic-gate 	}
1870*7c478bd9Sstevel@tonic-gate 
1871*7c478bd9Sstevel@tonic-gate 	if (num == 0)
1872*7c478bd9Sstevel@tonic-gate 		return (0);
1873*7c478bd9Sstevel@tonic-gate 
1874*7c478bd9Sstevel@tonic-gate 	for (; num > 1; num--) {
1875*7c478bd9Sstevel@tonic-gate 		if ((returnstat = (process_tag(context, tag,
1876*7c478bd9Sstevel@tonic-gate 		    returnstat, 0))) < 0)
1877*7c478bd9Sstevel@tonic-gate 			return (returnstat);
1878*7c478bd9Sstevel@tonic-gate 	}
1879*7c478bd9Sstevel@tonic-gate 
1880*7c478bd9Sstevel@tonic-gate 	return (process_tag(context, tag, returnstat, 1));
1881*7c478bd9Sstevel@tonic-gate }
1882*7c478bd9Sstevel@tonic-gate 
1883*7c478bd9Sstevel@tonic-gate int
1884*7c478bd9Sstevel@tonic-gate path_attr_token(pr_context_t *context)
1885*7c478bd9Sstevel@tonic-gate {
1886*7c478bd9Sstevel@tonic-gate 	return (string_token_common(context, TAG_XAT));
1887*7c478bd9Sstevel@tonic-gate }
1888*7c478bd9Sstevel@tonic-gate 
1889*7c478bd9Sstevel@tonic-gate int
1890*7c478bd9Sstevel@tonic-gate exec_args_token(pr_context_t *context)
1891*7c478bd9Sstevel@tonic-gate {
1892*7c478bd9Sstevel@tonic-gate 	return (string_token_common(context, TAG_ARG));
1893*7c478bd9Sstevel@tonic-gate }
1894*7c478bd9Sstevel@tonic-gate 
1895*7c478bd9Sstevel@tonic-gate int
1896*7c478bd9Sstevel@tonic-gate exec_env_token(pr_context_t *context)
1897*7c478bd9Sstevel@tonic-gate {
1898*7c478bd9Sstevel@tonic-gate 	return (string_token_common(context, TAG_ENV));
1899*7c478bd9Sstevel@tonic-gate }
1900*7c478bd9Sstevel@tonic-gate 
1901*7c478bd9Sstevel@tonic-gate /*
1902*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1903*7c478bd9Sstevel@tonic-gate  * s5_IPC_perm_token() : Process System V IPC permission token and display
1904*7c478bd9Sstevel@tonic-gate  *			 contents
1905*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
1906*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1907*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the System V IPC permission token id
1908*7c478bd9Sstevel@tonic-gate  * has been retrieved
1909*7c478bd9Sstevel@tonic-gate  *
1910*7c478bd9Sstevel@tonic-gate  * Format of System V IPC permission token:
1911*7c478bd9Sstevel@tonic-gate  *	System V IPC permission token id	adr_char
1912*7c478bd9Sstevel@tonic-gate  * 	uid					adr_u_int32
1913*7c478bd9Sstevel@tonic-gate  *	gid					adr_u_int32
1914*7c478bd9Sstevel@tonic-gate  *	cuid					adr_u_int32
1915*7c478bd9Sstevel@tonic-gate  *	cgid					adr_u_int32
1916*7c478bd9Sstevel@tonic-gate  *	mode					adr_u_int32
1917*7c478bd9Sstevel@tonic-gate  *	seq					adr_u_int32
1918*7c478bd9Sstevel@tonic-gate  *	key					adr_int32
1919*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1920*7c478bd9Sstevel@tonic-gate  */
1921*7c478bd9Sstevel@tonic-gate int
1922*7c478bd9Sstevel@tonic-gate s5_IPC_perm_token(pr_context_t *context)
1923*7c478bd9Sstevel@tonic-gate {
1924*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1925*7c478bd9Sstevel@tonic-gate 
1926*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_UID, 0, 0);
1927*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_GID, returnstat, 0);
1928*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_CUID, returnstat, 0);
1929*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_CGID, returnstat, 0);
1930*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_MODE, returnstat, 0);
1931*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SEQ, returnstat, 0);
1932*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_KEY, returnstat, 1);
1933*7c478bd9Sstevel@tonic-gate 
1934*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1935*7c478bd9Sstevel@tonic-gate }
1936*7c478bd9Sstevel@tonic-gate 
1937*7c478bd9Sstevel@tonic-gate /*
1938*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1939*7c478bd9Sstevel@tonic-gate  * host_token()	: Process host token and display contents
1940*7c478bd9Sstevel@tonic-gate  * return codes	: -1 - error
1941*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1942*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the host token id has been retrieved
1943*7c478bd9Sstevel@tonic-gate  *
1944*7c478bd9Sstevel@tonic-gate  * Format of host token:
1945*7c478bd9Sstevel@tonic-gate  *	host token id		adr_char
1946*7c478bd9Sstevel@tonic-gate  *	hostid			adr_u_int32
1947*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1948*7c478bd9Sstevel@tonic-gate  */
1949*7c478bd9Sstevel@tonic-gate int
1950*7c478bd9Sstevel@tonic-gate host_token(pr_context_t *context)
1951*7c478bd9Sstevel@tonic-gate {
1952*7c478bd9Sstevel@tonic-gate 	return (pa_hostname(context, 0, 1));
1953*7c478bd9Sstevel@tonic-gate }
1954*7c478bd9Sstevel@tonic-gate 
1955*7c478bd9Sstevel@tonic-gate /*
1956*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1957*7c478bd9Sstevel@tonic-gate  * liaison_token()	: Process liaison token and display contents
1958*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
1959*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
1960*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the liaison token id has been retrieved
1961*7c478bd9Sstevel@tonic-gate  *
1962*7c478bd9Sstevel@tonic-gate  * Format of liaison token:
1963*7c478bd9Sstevel@tonic-gate  *	liaison token id	adr_char
1964*7c478bd9Sstevel@tonic-gate  *	liaison			adr_u_int32
1965*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1966*7c478bd9Sstevel@tonic-gate  */
1967*7c478bd9Sstevel@tonic-gate int
1968*7c478bd9Sstevel@tonic-gate liaison_token(pr_context_t *context)
1969*7c478bd9Sstevel@tonic-gate {
1970*7c478bd9Sstevel@tonic-gate 	return (pa_liaison(context, 0, 1));
1971*7c478bd9Sstevel@tonic-gate }
1972*7c478bd9Sstevel@tonic-gate 
1973*7c478bd9Sstevel@tonic-gate /*
1974*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1975*7c478bd9Sstevel@tonic-gate  * useofauth_token(): Process useofauth token and display contents
1976*7c478bd9Sstevel@tonic-gate  * return codes	: -1 - error
1977*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1978*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the uauth token id has been retrieved
1979*7c478bd9Sstevel@tonic-gate  *
1980*7c478bd9Sstevel@tonic-gate  * Format of useofauth token:
1981*7c478bd9Sstevel@tonic-gate  *	uauth token id		adr_char
1982*7c478bd9Sstevel@tonic-gate  * 	uauth			adr_string
1983*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1984*7c478bd9Sstevel@tonic-gate  */
1985*7c478bd9Sstevel@tonic-gate int
1986*7c478bd9Sstevel@tonic-gate useofauth_token(pr_context_t *context)
1987*7c478bd9Sstevel@tonic-gate {
1988*7c478bd9Sstevel@tonic-gate 	return (pa_adr_string(context, 0, 1));
1989*7c478bd9Sstevel@tonic-gate }
1990*7c478bd9Sstevel@tonic-gate 
1991*7c478bd9Sstevel@tonic-gate /*
1992*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1993*7c478bd9Sstevel@tonic-gate  * zonename_token(): Process zonename token and display contents
1994*7c478bd9Sstevel@tonic-gate  * return codes	: -1 - error
1995*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1996*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the zonename token id has been retrieved
1997*7c478bd9Sstevel@tonic-gate  *
1998*7c478bd9Sstevel@tonic-gate  * Format of zonename token:
1999*7c478bd9Sstevel@tonic-gate  *	zonename token id	adr_char
2000*7c478bd9Sstevel@tonic-gate  * 	zone name		adr_string
2001*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2002*7c478bd9Sstevel@tonic-gate  */
2003*7c478bd9Sstevel@tonic-gate int
2004*7c478bd9Sstevel@tonic-gate zonename_token(pr_context_t *context)
2005*7c478bd9Sstevel@tonic-gate {
2006*7c478bd9Sstevel@tonic-gate 	return (process_tag(context, TAG_ZONENAME, 0, 1));
2007*7c478bd9Sstevel@tonic-gate }
2008*7c478bd9Sstevel@tonic-gate 
2009*7c478bd9Sstevel@tonic-gate /*
2010*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2011*7c478bd9Sstevel@tonic-gate  * xatom_token()	: Process Xatom token and display contents in hex.
2012*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
2013*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
2014*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the xatom token id has been retrieved
2015*7c478bd9Sstevel@tonic-gate  *
2016*7c478bd9Sstevel@tonic-gate  * Format of xatom token:
2017*7c478bd9Sstevel@tonic-gate  *	token id		adr_char
2018*7c478bd9Sstevel@tonic-gate  * 	length			adr_short
2019*7c478bd9Sstevel@tonic-gate  * 	atom			adr_char length times
2020*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2021*7c478bd9Sstevel@tonic-gate  */
2022*7c478bd9Sstevel@tonic-gate int
2023*7c478bd9Sstevel@tonic-gate xatom_token(pr_context_t *context)
2024*7c478bd9Sstevel@tonic-gate {
2025*7c478bd9Sstevel@tonic-gate 	return (pa_adr_string(context, 0, 1));
2026*7c478bd9Sstevel@tonic-gate }
2027*7c478bd9Sstevel@tonic-gate 
2028*7c478bd9Sstevel@tonic-gate int
2029*7c478bd9Sstevel@tonic-gate xcolormap_token(pr_context_t *context)
2030*7c478bd9Sstevel@tonic-gate {
2031*7c478bd9Sstevel@tonic-gate 	return (pa_xgeneric(context));
2032*7c478bd9Sstevel@tonic-gate }
2033*7c478bd9Sstevel@tonic-gate 
2034*7c478bd9Sstevel@tonic-gate int
2035*7c478bd9Sstevel@tonic-gate xcursor_token(pr_context_t *context)
2036*7c478bd9Sstevel@tonic-gate {
2037*7c478bd9Sstevel@tonic-gate 	return (pa_xgeneric(context));
2038*7c478bd9Sstevel@tonic-gate }
2039*7c478bd9Sstevel@tonic-gate 
2040*7c478bd9Sstevel@tonic-gate int
2041*7c478bd9Sstevel@tonic-gate xfont_token(pr_context_t *context)
2042*7c478bd9Sstevel@tonic-gate {
2043*7c478bd9Sstevel@tonic-gate 	return (pa_xgeneric(context));
2044*7c478bd9Sstevel@tonic-gate }
2045*7c478bd9Sstevel@tonic-gate 
2046*7c478bd9Sstevel@tonic-gate int
2047*7c478bd9Sstevel@tonic-gate xgc_token(pr_context_t *context)
2048*7c478bd9Sstevel@tonic-gate {
2049*7c478bd9Sstevel@tonic-gate 	return (pa_xgeneric(context));
2050*7c478bd9Sstevel@tonic-gate }
2051*7c478bd9Sstevel@tonic-gate 
2052*7c478bd9Sstevel@tonic-gate int
2053*7c478bd9Sstevel@tonic-gate xpixmap_token(pr_context_t *context)
2054*7c478bd9Sstevel@tonic-gate {
2055*7c478bd9Sstevel@tonic-gate 	return (pa_xgeneric(context));
2056*7c478bd9Sstevel@tonic-gate }
2057*7c478bd9Sstevel@tonic-gate 
2058*7c478bd9Sstevel@tonic-gate int
2059*7c478bd9Sstevel@tonic-gate xwindow_token(pr_context_t *context)
2060*7c478bd9Sstevel@tonic-gate {
2061*7c478bd9Sstevel@tonic-gate 	return (pa_xgeneric(context));
2062*7c478bd9Sstevel@tonic-gate }
2063*7c478bd9Sstevel@tonic-gate 
2064*7c478bd9Sstevel@tonic-gate /*
2065*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2066*7c478bd9Sstevel@tonic-gate  * xproperty_token(): Process Xproperty token and display contents
2067*7c478bd9Sstevel@tonic-gate  *
2068*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
2069*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
2070*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the xproperty token id has been retrieved
2071*7c478bd9Sstevel@tonic-gate  *
2072*7c478bd9Sstevel@tonic-gate  * Format of xproperty token:
2073*7c478bd9Sstevel@tonic-gate  *	token id		adr_char
2074*7c478bd9Sstevel@tonic-gate  *	XID			adr_u_int32
2075*7c478bd9Sstevel@tonic-gate  *	creator UID		adr_u_int32
2076*7c478bd9Sstevel@tonic-gate  *	text			adr_text
2077*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2078*7c478bd9Sstevel@tonic-gate  */
2079*7c478bd9Sstevel@tonic-gate int
2080*7c478bd9Sstevel@tonic-gate xproperty_token(pr_context_t *context)
2081*7c478bd9Sstevel@tonic-gate {
2082*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2083*7c478bd9Sstevel@tonic-gate 
2084*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_XID, 0, 0);
2085*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_XCUID, returnstat, 0);
2086*7c478bd9Sstevel@tonic-gate 
2087*7c478bd9Sstevel@tonic-gate 	/* Done with attributes; force end of token open */
2088*7c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
2089*7c478bd9Sstevel@tonic-gate 		returnstat = finish_open_tag(context);
2090*7c478bd9Sstevel@tonic-gate 
2091*7c478bd9Sstevel@tonic-gate 	returnstat = pa_adr_string(context, returnstat, 1);
2092*7c478bd9Sstevel@tonic-gate 
2093*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2094*7c478bd9Sstevel@tonic-gate }
2095*7c478bd9Sstevel@tonic-gate 
2096*7c478bd9Sstevel@tonic-gate /*
2097*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2098*7c478bd9Sstevel@tonic-gate  * xselect_token(): Process Xselect token and display contents in hex
2099*7c478bd9Sstevel@tonic-gate  *
2100*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
2101*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
2102*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the xselect token id has been retrieved
2103*7c478bd9Sstevel@tonic-gate  *
2104*7c478bd9Sstevel@tonic-gate  * Format of xselect token
2105*7c478bd9Sstevel@tonic-gate  *	text token id		adr_char
2106*7c478bd9Sstevel@tonic-gate  * 	property text		adr_string
2107*7c478bd9Sstevel@tonic-gate  * 	property type		adr_string
2108*7c478bd9Sstevel@tonic-gate  * 	property data		adr_string
2109*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2110*7c478bd9Sstevel@tonic-gate  */
2111*7c478bd9Sstevel@tonic-gate int
2112*7c478bd9Sstevel@tonic-gate xselect_token(pr_context_t *context)
2113*7c478bd9Sstevel@tonic-gate {
2114*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2115*7c478bd9Sstevel@tonic-gate 
2116*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_XSELTEXT, 0, 0);
2117*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_XSELTYPE, returnstat, 0);
2118*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_XSELDATA, returnstat, 1);
2119*7c478bd9Sstevel@tonic-gate 
2120*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2121*7c478bd9Sstevel@tonic-gate }
2122*7c478bd9Sstevel@tonic-gate 
2123*7c478bd9Sstevel@tonic-gate /*
2124*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2125*7c478bd9Sstevel@tonic-gate  * xclient_token(): Process Xclient token and display contents in hex.
2126*7c478bd9Sstevel@tonic-gate  *
2127*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
2128*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
2129*7c478bd9Sstevel@tonic-gate  *
2130*7c478bd9Sstevel@tonic-gate  * Format of xclient token:
2131*7c478bd9Sstevel@tonic-gate  *	token id		adr_char
2132*7c478bd9Sstevel@tonic-gate  * 	client			adr_int32
2133*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2134*7c478bd9Sstevel@tonic-gate  */
2135*7c478bd9Sstevel@tonic-gate int
2136*7c478bd9Sstevel@tonic-gate xclient_token(pr_context_t *context)
2137*7c478bd9Sstevel@tonic-gate {
2138*7c478bd9Sstevel@tonic-gate 	return (pa_adr_int32(context, 0, 1));
2139*7c478bd9Sstevel@tonic-gate }
2140*7c478bd9Sstevel@tonic-gate 
2141*7c478bd9Sstevel@tonic-gate /*
2142*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2143*7c478bd9Sstevel@tonic-gate  * slabel_token() 	: Process sensitivity label token and display contents
2144*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
2145*7c478bd9Sstevel@tonic-gate  *			: 0 - successful
2146*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the slabel token id has been retrieved
2147*7c478bd9Sstevel@tonic-gate  *
2148*7c478bd9Sstevel@tonic-gate  * Format of sensitivity label token:
2149*7c478bd9Sstevel@tonic-gate  *	slabel token id		adr_char
2150*7c478bd9Sstevel@tonic-gate  *	label			adr_char, sizeof (bslabel_t) bytes
2151*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2152*7c478bd9Sstevel@tonic-gate  */
2153*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2154*7c478bd9Sstevel@tonic-gate int
2155*7c478bd9Sstevel@tonic-gate slabel_token(pr_context_t *context)
2156*7c478bd9Sstevel@tonic-gate {
2157*7c478bd9Sstevel@tonic-gate #ifdef	TSOL
2158*7c478bd9Sstevel@tonic-gate 	bslabel_t label;
2159*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2160*7c478bd9Sstevel@tonic-gate 	int	s;
2161*7c478bd9Sstevel@tonic-gate 	char	strbuf[2048];
2162*7c478bd9Sstevel@tonic-gate 	char	*sp = strbuf;
2163*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2164*7c478bd9Sstevel@tonic-gate 
2165*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&label,
2166*7c478bd9Sstevel@tonic-gate 	    sizeof (label))) == 0) {
2167*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
2168*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
2169*7c478bd9Sstevel@tonic-gate 			/* print in ASCII form using bltos */
2170*7c478bd9Sstevel@tonic-gate 			s = bsltos(&label, &sp, sizeof (strbuf), 0);
2171*7c478bd9Sstevel@tonic-gate 			if (s > 0) {
2172*7c478bd9Sstevel@tonic-gate 				uval.string_val = sp;
2173*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, 1);
2174*7c478bd9Sstevel@tonic-gate 			} else /* cannot convert to string */
2175*7c478bd9Sstevel@tonic-gate 				returnstat = 1;
2176*7c478bd9Sstevel@tonic-gate 		}
2177*7c478bd9Sstevel@tonic-gate 		/* print in hexadecimal form */
2178*7c478bd9Sstevel@tonic-gate 		if ((context->format & PRF_RAWM) || (returnstat == 1)) {
2179*7c478bd9Sstevel@tonic-gate 			uval.string_val = hexconvert((char *)&label,
2180*7c478bd9Sstevel@tonic-gate 			    sizeof (bslabel_t), sizeof (bslabel_t));
2181*7c478bd9Sstevel@tonic-gate 			if (uval.string_val) {
2182*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, 1);
2183*7c478bd9Sstevel@tonic-gate 				free(uval.string_val);
2184*7c478bd9Sstevel@tonic-gate 			}
2185*7c478bd9Sstevel@tonic-gate 		}
2186*7c478bd9Sstevel@tonic-gate 	}
2187*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2188*7c478bd9Sstevel@tonic-gate #else	/* !TSOL */
2189*7c478bd9Sstevel@tonic-gate 	return (-1);
2190*7c478bd9Sstevel@tonic-gate #endif	/* TSOL */
2191*7c478bd9Sstevel@tonic-gate }
2192*7c478bd9Sstevel@tonic-gate 
2193*7c478bd9Sstevel@tonic-gate /*
2194*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2195*7c478bd9Sstevel@tonic-gate  * useofpriv_token() : Process priv token and display contents
2196*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
2197*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
2198*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the useofpriv token id has been retrieved
2199*7c478bd9Sstevel@tonic-gate  *
2200*7c478bd9Sstevel@tonic-gate  * Format of useofpriv token:
2201*7c478bd9Sstevel@tonic-gate  *	useofpriv token id	adr_char
2202*7c478bd9Sstevel@tonic-gate  *	success/failure flag	adr_char
2203*7c478bd9Sstevel@tonic-gate  *	priv			adr_int32 (Trusted Solaris)
2204*7c478bd9Sstevel@tonic-gate  *	priv_set		'\0' separated privileges.
2205*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2206*7c478bd9Sstevel@tonic-gate  */
2207*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2208*7c478bd9Sstevel@tonic-gate int
2209*7c478bd9Sstevel@tonic-gate useofpriv_token(pr_context_t *context)
2210*7c478bd9Sstevel@tonic-gate {
2211*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2212*7c478bd9Sstevel@tonic-gate 	char	sf;
2213*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2214*7c478bd9Sstevel@tonic-gate 
2215*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, &sf, 1)) != 0) {
2216*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2217*7c478bd9Sstevel@tonic-gate 	}
2218*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
2219*7c478bd9Sstevel@tonic-gate 		/* print in ASCII form */
2220*7c478bd9Sstevel@tonic-gate 
2221*7c478bd9Sstevel@tonic-gate 		if ((returnstat = open_tag(context, TAG_RESULT)) != 0)
2222*7c478bd9Sstevel@tonic-gate 			return (returnstat);
2223*7c478bd9Sstevel@tonic-gate 
2224*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
2225*7c478bd9Sstevel@tonic-gate 		if (sf) {
2226*7c478bd9Sstevel@tonic-gate 			uval.string_val = gettext("successful use of priv");
2227*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
2228*7c478bd9Sstevel@tonic-gate 		} else {
2229*7c478bd9Sstevel@tonic-gate 			uval.string_val = gettext("failed use of priv");
2230*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
2231*7c478bd9Sstevel@tonic-gate 		}
2232*7c478bd9Sstevel@tonic-gate 		if (returnstat == 0)
2233*7c478bd9Sstevel@tonic-gate 			returnstat = close_tag(context, TAG_RESULT);
2234*7c478bd9Sstevel@tonic-gate 
2235*7c478bd9Sstevel@tonic-gate 		/* Done with attributes; force end of token open */
2236*7c478bd9Sstevel@tonic-gate 		if (returnstat == 0)
2237*7c478bd9Sstevel@tonic-gate 			returnstat = finish_open_tag(context);
2238*7c478bd9Sstevel@tonic-gate 	} else {
2239*7c478bd9Sstevel@tonic-gate 		/* print in hexadecimal form */
2240*7c478bd9Sstevel@tonic-gate 		if ((returnstat = open_tag(context, TAG_RESULT)) != 0)
2241*7c478bd9Sstevel@tonic-gate 			return (returnstat);
2242*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_SHORT;
2243*7c478bd9Sstevel@tonic-gate 		uval.short_val = sf;
2244*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, 0);
2245*7c478bd9Sstevel@tonic-gate 		if (returnstat == 0)
2246*7c478bd9Sstevel@tonic-gate 			returnstat = close_tag(context, TAG_RESULT);
2247*7c478bd9Sstevel@tonic-gate 
2248*7c478bd9Sstevel@tonic-gate 		/* Done with attributes; force end of token open */
2249*7c478bd9Sstevel@tonic-gate 		if (returnstat == 0)
2250*7c478bd9Sstevel@tonic-gate 			returnstat = finish_open_tag(context);
2251*7c478bd9Sstevel@tonic-gate 	}
2252*7c478bd9Sstevel@tonic-gate 	return (pa_adr_string(context, 0, 1));
2253*7c478bd9Sstevel@tonic-gate }
2254*7c478bd9Sstevel@tonic-gate 
2255*7c478bd9Sstevel@tonic-gate /*
2256*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2257*7c478bd9Sstevel@tonic-gate  * privilege_token()	: Process privilege token and display contents
2258*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
2259*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
2260*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the privilege token id has been retrieved
2261*7c478bd9Sstevel@tonic-gate  *
2262*7c478bd9Sstevel@tonic-gate  * Format of privilege token:
2263*7c478bd9Sstevel@tonic-gate  *	privilege token id	adr_char
2264*7c478bd9Sstevel@tonic-gate  *	privilege type		adr_string
2265*7c478bd9Sstevel@tonic-gate  *	privilege		adr_string
2266*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2267*7c478bd9Sstevel@tonic-gate  */
2268*7c478bd9Sstevel@tonic-gate int
2269*7c478bd9Sstevel@tonic-gate privilege_token(pr_context_t *context)
2270*7c478bd9Sstevel@tonic-gate {
2271*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2272*7c478bd9Sstevel@tonic-gate 
2273*7c478bd9Sstevel@tonic-gate 	/* privilege type: */
2274*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_SETTYPE, 0, 0);
2275*7c478bd9Sstevel@tonic-gate 
2276*7c478bd9Sstevel@tonic-gate 	/* Done with attributes; force end of token open */
2277*7c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
2278*7c478bd9Sstevel@tonic-gate 		returnstat = finish_open_tag(context);
2279*7c478bd9Sstevel@tonic-gate 
2280*7c478bd9Sstevel@tonic-gate 	/* privilege: */
2281*7c478bd9Sstevel@tonic-gate 	return (pa_adr_string(context, returnstat, 1));
2282*7c478bd9Sstevel@tonic-gate }
2283*7c478bd9Sstevel@tonic-gate 
2284*7c478bd9Sstevel@tonic-gate /*
2285*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2286*7c478bd9Sstevel@tonic-gate  * ilabel_token() 	: Process information label token and display contents
2287*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
2288*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
2289*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the ilabel token id has been retrieved
2290*7c478bd9Sstevel@tonic-gate  *
2291*7c478bd9Sstevel@tonic-gate  * Format of information label token:
2292*7c478bd9Sstevel@tonic-gate  *	label token id		adr_char
2293*7c478bd9Sstevel@tonic-gate  *	label			adr_opaque, sizeof (bilabel_t) bytes
2294*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2295*7c478bd9Sstevel@tonic-gate  */
2296*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2297*7c478bd9Sstevel@tonic-gate int
2298*7c478bd9Sstevel@tonic-gate ilabel_token(pr_context_t *context)
2299*7c478bd9Sstevel@tonic-gate {
2300*7c478bd9Sstevel@tonic-gate #ifdef	TSOL
2301*7c478bd9Sstevel@tonic-gate 	bilabel_t label;
2302*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2303*7c478bd9Sstevel@tonic-gate 	int	s;
2304*7c478bd9Sstevel@tonic-gate 	char	strbuf[2048];
2305*7c478bd9Sstevel@tonic-gate 	char	*sp = strbuf;
2306*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2307*7c478bd9Sstevel@tonic-gate 
2308*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&label,
2309*7c478bd9Sstevel@tonic-gate 	    sizeof (label))) == 0) {
2310*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
2311*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
2312*7c478bd9Sstevel@tonic-gate 			/* print in ASCII form using bltos */
2313*7c478bd9Sstevel@tonic-gate 			s = biltos(&label, &sp, sizeof (strbuf), 0);
2314*7c478bd9Sstevel@tonic-gate 			if (s > 0) {
2315*7c478bd9Sstevel@tonic-gate 				uval.string_val = sp;
2316*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, 1);
2317*7c478bd9Sstevel@tonic-gate 			} else /* cannot convert to string */
2318*7c478bd9Sstevel@tonic-gate 				returnstat = 1;
2319*7c478bd9Sstevel@tonic-gate 		}
2320*7c478bd9Sstevel@tonic-gate 		/* print in hexadecimal form */
2321*7c478bd9Sstevel@tonic-gate 		if ((context->format & PRF_RAWM) || (returnstat == 1)) {
2322*7c478bd9Sstevel@tonic-gate 			uval.string_val = hexconvert((char *)&label,
2323*7c478bd9Sstevel@tonic-gate 			    sizeof (bilabel_t), sizeof (bilabel_t));
2324*7c478bd9Sstevel@tonic-gate 			if (uval.string_val) {
2325*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, 1);
2326*7c478bd9Sstevel@tonic-gate 				free(uval.string_val);
2327*7c478bd9Sstevel@tonic-gate 			}
2328*7c478bd9Sstevel@tonic-gate 		}
2329*7c478bd9Sstevel@tonic-gate 	}
2330*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2331*7c478bd9Sstevel@tonic-gate #else	/* !TSOL */
2332*7c478bd9Sstevel@tonic-gate 	return (-1);
2333*7c478bd9Sstevel@tonic-gate #endif	/* TSOL */
2334*7c478bd9Sstevel@tonic-gate }
2335*7c478bd9Sstevel@tonic-gate 
2336*7c478bd9Sstevel@tonic-gate /*
2337*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2338*7c478bd9Sstevel@tonic-gate  * clearance_token()	: Process clearance token and display contents
2339*7c478bd9Sstevel@tonic-gate  * return codes 	: -1 - error
2340*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
2341*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the clearance token id has been retrieved
2342*7c478bd9Sstevel@tonic-gate  *
2343*7c478bd9Sstevel@tonic-gate  * Format of clearance token:
2344*7c478bd9Sstevel@tonic-gate  *	clearance token id	adr_char
2345*7c478bd9Sstevel@tonic-gate  *	clearance		adr_char, sizeof (bclear_t) bytes
2346*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2347*7c478bd9Sstevel@tonic-gate  */
2348*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2349*7c478bd9Sstevel@tonic-gate int
2350*7c478bd9Sstevel@tonic-gate clearance_token(pr_context_t *context)
2351*7c478bd9Sstevel@tonic-gate {
2352*7c478bd9Sstevel@tonic-gate #ifdef	TSOL
2353*7c478bd9Sstevel@tonic-gate 	bclear_t clearance;
2354*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2355*7c478bd9Sstevel@tonic-gate 	int	s;
2356*7c478bd9Sstevel@tonic-gate 	char	strbuf[2048];
2357*7c478bd9Sstevel@tonic-gate 	char	*sp = strbuf;
2358*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2359*7c478bd9Sstevel@tonic-gate 
2360*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&clearance,
2361*7c478bd9Sstevel@tonic-gate 	    sizeof (clearance))) == 0) {
2362*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
2363*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
2364*7c478bd9Sstevel@tonic-gate 			/* print in ASCII form using bltos */
2365*7c478bd9Sstevel@tonic-gate 			s = bcleartos(&clearance, &sp, sizeof (strbuf),
2366*7c478bd9Sstevel@tonic-gate 			    SHORT_WORDS);
2367*7c478bd9Sstevel@tonic-gate 			if (s > 0) {
2368*7c478bd9Sstevel@tonic-gate 				uval.string_val = sp;
2369*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, 1);
2370*7c478bd9Sstevel@tonic-gate 			} else /* cannot convert to string */
2371*7c478bd9Sstevel@tonic-gate 				returnstat = 1;
2372*7c478bd9Sstevel@tonic-gate 		}
2373*7c478bd9Sstevel@tonic-gate 		/* print in hexadecimal form */
2374*7c478bd9Sstevel@tonic-gate 		if ((context->format & PRF_RAWM) || (returnstat == 1)) {
2375*7c478bd9Sstevel@tonic-gate 			uval.string_val = hexconvert((char *)&clearance,
2376*7c478bd9Sstevel@tonic-gate 			    sizeof (bclear_t), sizeof (bclear_t));
2377*7c478bd9Sstevel@tonic-gate 			if (uval.string_val) {
2378*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, 1);
2379*7c478bd9Sstevel@tonic-gate 				free(uval.string_val);
2380*7c478bd9Sstevel@tonic-gate 			}
2381*7c478bd9Sstevel@tonic-gate 		}
2382*7c478bd9Sstevel@tonic-gate 	}
2383*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2384*7c478bd9Sstevel@tonic-gate #else	/* !TSOL */
2385*7c478bd9Sstevel@tonic-gate 	return (-1);
2386*7c478bd9Sstevel@tonic-gate #endif	/* TSOL */
2387*7c478bd9Sstevel@tonic-gate }
2388