xref: /titanic_41/usr/src/cmd/praudit/format.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #define	_REENTRANT
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #include <ctype.h>
32*7c478bd9Sstevel@tonic-gate #include <errno.h>
33*7c478bd9Sstevel@tonic-gate #include <grp.h>
34*7c478bd9Sstevel@tonic-gate #include <libintl.h>
35*7c478bd9Sstevel@tonic-gate #include <netdb.h>
36*7c478bd9Sstevel@tonic-gate #include <time.h>
37*7c478bd9Sstevel@tonic-gate #include <pwd.h>
38*7c478bd9Sstevel@tonic-gate #include <stdio.h>
39*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
40*7c478bd9Sstevel@tonic-gate #include <string.h>
41*7c478bd9Sstevel@tonic-gate #include <wchar.h>
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
46*7c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
47*7c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
48*7c478bd9Sstevel@tonic-gate #include <security/pam_appl.h>
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
51*7c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate #include "praudit.h"
55*7c478bd9Sstevel@tonic-gate #include "toktable.h"
56*7c478bd9Sstevel@tonic-gate #include "adt_xlate.h"
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate static void	convertascii(char *p, char *c, int size);
59*7c478bd9Sstevel@tonic-gate static int	convertbinary(char *p, char *c, int size);
60*7c478bd9Sstevel@tonic-gate static void	eventmodifier2string(ushort_t emodifier, char *modstring,
61*7c478bd9Sstevel@tonic-gate     size_t modlen);
62*7c478bd9Sstevel@tonic-gate static int	do_mtime32(pr_context_t *context, int status, int flag,
63*7c478bd9Sstevel@tonic-gate     uint32_t scale);
64*7c478bd9Sstevel@tonic-gate static int	do_mtime64(pr_context_t *context, int status, int flag,
65*7c478bd9Sstevel@tonic-gate     uint64_t scale);
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate /*
68*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------
69*7c478bd9Sstevel@tonic-gate  * field widths for arbitrary data token type
70*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------
71*7c478bd9Sstevel@tonic-gate  */
72*7c478bd9Sstevel@tonic-gate static struct fw {
73*7c478bd9Sstevel@tonic-gate 	char	basic_unit;
74*7c478bd9Sstevel@tonic-gate 	struct {
75*7c478bd9Sstevel@tonic-gate 		char	print_base;
76*7c478bd9Sstevel@tonic-gate 		int	field_width;
77*7c478bd9Sstevel@tonic-gate 	} pwidth[5];
78*7c478bd9Sstevel@tonic-gate } fwidth[] = {
79*7c478bd9Sstevel@tonic-gate 	/* character data type, 8 bits */
80*7c478bd9Sstevel@tonic-gate 		AUR_CHAR,	AUP_BINARY,	12,
81*7c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	 6,
82*7c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	 6,
83*7c478bd9Sstevel@tonic-gate 				AUP_HEX,	 6,
84*7c478bd9Sstevel@tonic-gate 				AUP_STRING,	 4,
85*7c478bd9Sstevel@tonic-gate 		AUR_BYTE,	AUP_BINARY,	12,
86*7c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	 6,
87*7c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	 6,
88*7c478bd9Sstevel@tonic-gate 				AUP_HEX,	 6,
89*7c478bd9Sstevel@tonic-gate 				AUP_STRING,	 4,
90*7c478bd9Sstevel@tonic-gate 		AUR_SHORT,	AUP_BINARY,	20,
91*7c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	10,
92*7c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	10,
93*7c478bd9Sstevel@tonic-gate 				AUP_HEX,	 8,
94*7c478bd9Sstevel@tonic-gate 				AUP_STRING,	 6,
95*7c478bd9Sstevel@tonic-gate 		AUR_INT32,	AUP_BINARY,	36,
96*7c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	18,
97*7c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	18,
98*7c478bd9Sstevel@tonic-gate 				AUP_HEX,	12,
99*7c478bd9Sstevel@tonic-gate 				AUP_STRING,	10,
100*7c478bd9Sstevel@tonic-gate 		AUR_INT64,	AUP_BINARY,	68,
101*7c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	34,
102*7c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	34,
103*7c478bd9Sstevel@tonic-gate 				AUP_HEX,	20,
104*7c478bd9Sstevel@tonic-gate 				AUP_STRING,	20};
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate static int	numwidthentries = sizeof (fwidth)
108*7c478bd9Sstevel@tonic-gate 			/ sizeof (struct fw);
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate /*
112*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
113*7c478bd9Sstevel@tonic-gate  * do_newline:
114*7c478bd9Sstevel@tonic-gate  *		  Print a newline, if needed according to various formatting
115*7c478bd9Sstevel@tonic-gate  *		  rules.
116*7c478bd9Sstevel@tonic-gate  * return codes :   0 - success
117*7c478bd9Sstevel@tonic-gate  *		:  -1 - error
118*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
119*7c478bd9Sstevel@tonic-gate  */
120*7c478bd9Sstevel@tonic-gate int
121*7c478bd9Sstevel@tonic-gate do_newline(pr_context_t *context, int flag)
122*7c478bd9Sstevel@tonic-gate {
123*7c478bd9Sstevel@tonic-gate 	int	retstat = 0;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_ONELINE) && (flag == 1))
126*7c478bd9Sstevel@tonic-gate 		retstat = pr_putchar(context, '\n');
127*7c478bd9Sstevel@tonic-gate 	else if (!(context->format & PRF_XMLM))
128*7c478bd9Sstevel@tonic-gate 		retstat = pr_printf(context, "%s", context->SEPARATOR);
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	return (retstat);
131*7c478bd9Sstevel@tonic-gate }
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate int
134*7c478bd9Sstevel@tonic-gate open_tag(pr_context_t *context, int tagnum)
135*7c478bd9Sstevel@tonic-gate {
136*7c478bd9Sstevel@tonic-gate 	int		err = 0;
137*7c478bd9Sstevel@tonic-gate 	token_desc_t	*tag;
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 	/* no-op if not doing XML format */
140*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM))
141*7c478bd9Sstevel@tonic-gate 		return (0);
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 	tag = &tokentable[tagnum];
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 	/*
146*7c478bd9Sstevel@tonic-gate 	 * First if needed do an implicit finish of a pending open for an
147*7c478bd9Sstevel@tonic-gate 	 * extended tag.  I.e., for the extended tag xxx:
148*7c478bd9Sstevel@tonic-gate 	 *	<xxx a=".." b=".."> ...  </xxx>
149*7c478bd9Sstevel@tonic-gate 	 * -- insert a close bracket after the last attribute
150*7c478bd9Sstevel@tonic-gate 	 * (in other words, when the 1st non-attribute is opened while
151*7c478bd9Sstevel@tonic-gate 	 * this is pending). Note that only one tag could be pending at
152*7c478bd9Sstevel@tonic-gate 	 * a given time -- it couldn't be nested.
153*7c478bd9Sstevel@tonic-gate 	 */
154*7c478bd9Sstevel@tonic-gate 	if (context->pending_flag && (tag->t_type != T_ATTRIBUTE)) {
155*7c478bd9Sstevel@tonic-gate 		/* complete pending extended open */
156*7c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, '>');
157*7c478bd9Sstevel@tonic-gate 		if (err != 0)
158*7c478bd9Sstevel@tonic-gate 			return (err);
159*7c478bd9Sstevel@tonic-gate 		context->pending_flag = 0;
160*7c478bd9Sstevel@tonic-gate 	}
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	if (is_header_token(tagnum) || is_file_token(tagnum)) {
163*7c478bd9Sstevel@tonic-gate 		/* File token or new record on new line */
164*7c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, '\n');
165*7c478bd9Sstevel@tonic-gate 	} else if (is_token(tagnum)) {
166*7c478bd9Sstevel@tonic-gate 		/* Each token on new line if possible */
167*7c478bd9Sstevel@tonic-gate 		err = do_newline(context, 1);
168*7c478bd9Sstevel@tonic-gate 	}
169*7c478bd9Sstevel@tonic-gate 	if (err != 0)
170*7c478bd9Sstevel@tonic-gate 		return (err);
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 	switch (tag->t_type) {
173*7c478bd9Sstevel@tonic-gate 	case T_ATTRIBUTE:
174*7c478bd9Sstevel@tonic-gate 		err = pr_printf(context, " %s=\"", tag->t_tagname);
175*7c478bd9Sstevel@tonic-gate 		break;
176*7c478bd9Sstevel@tonic-gate 	case T_ELEMENT:
177*7c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "<%s>", tag->t_tagname);
178*7c478bd9Sstevel@tonic-gate 		break;
179*7c478bd9Sstevel@tonic-gate 	case T_ENCLOSED:
180*7c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "<%s", tag->t_tagname);
181*7c478bd9Sstevel@tonic-gate 		break;
182*7c478bd9Sstevel@tonic-gate 	case T_EXTENDED:
183*7c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "<%s", tag->t_tagname);
184*7c478bd9Sstevel@tonic-gate 		if (err == 0)
185*7c478bd9Sstevel@tonic-gate 			context->pending_flag = tagnum;
186*7c478bd9Sstevel@tonic-gate 		break;
187*7c478bd9Sstevel@tonic-gate 	default:
188*7c478bd9Sstevel@tonic-gate 		break;
189*7c478bd9Sstevel@tonic-gate 	}
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	if (is_header_token(tagnum) && (err == 0))
192*7c478bd9Sstevel@tonic-gate 		context->current_rec = tagnum;	/* set start of new record */
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 	return (err);
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate /*
198*7c478bd9Sstevel@tonic-gate  * Do an implicit close of a record when needed.
199*7c478bd9Sstevel@tonic-gate  */
200*7c478bd9Sstevel@tonic-gate int
201*7c478bd9Sstevel@tonic-gate check_close_rec(pr_context_t *context, int tagnum)
202*7c478bd9Sstevel@tonic-gate {
203*7c478bd9Sstevel@tonic-gate 	int	err = 0;
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	/* no-op if not doing XML format */
206*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM))
207*7c478bd9Sstevel@tonic-gate 		return (0);
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 	/*
210*7c478bd9Sstevel@tonic-gate 	 * If we're opening a header or the file token (i.e., starting a new
211*7c478bd9Sstevel@tonic-gate 	 * record), if there's a current record in progress do an implicit
212*7c478bd9Sstevel@tonic-gate 	 * close of it.
213*7c478bd9Sstevel@tonic-gate 	 */
214*7c478bd9Sstevel@tonic-gate 	if ((is_header_token(tagnum) || is_file_token(tagnum)) &&
215*7c478bd9Sstevel@tonic-gate 	    context->current_rec) {
216*7c478bd9Sstevel@tonic-gate 		err = do_newline(context, 1);
217*7c478bd9Sstevel@tonic-gate 		if (err == 0)
218*7c478bd9Sstevel@tonic-gate 			err = close_tag(context, context->current_rec);
219*7c478bd9Sstevel@tonic-gate 	}
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 	return (err);
222*7c478bd9Sstevel@tonic-gate }
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate /*
225*7c478bd9Sstevel@tonic-gate  * explicit finish of a pending open for an extended tag.
226*7c478bd9Sstevel@tonic-gate  */
227*7c478bd9Sstevel@tonic-gate int
228*7c478bd9Sstevel@tonic-gate finish_open_tag(pr_context_t *context)
229*7c478bd9Sstevel@tonic-gate {
230*7c478bd9Sstevel@tonic-gate 	int	err = 0;
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate 	/* no-op if not doing XML format */
233*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM))
234*7c478bd9Sstevel@tonic-gate 		return (0);
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 	if (context->pending_flag) {
237*7c478bd9Sstevel@tonic-gate 		/* complete pending extended open */
238*7c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, '>');
239*7c478bd9Sstevel@tonic-gate 		if (err == 0)
240*7c478bd9Sstevel@tonic-gate 			context->pending_flag = 0;
241*7c478bd9Sstevel@tonic-gate 	}
242*7c478bd9Sstevel@tonic-gate 	return (err);
243*7c478bd9Sstevel@tonic-gate }
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate int
246*7c478bd9Sstevel@tonic-gate close_tag(pr_context_t *context, int tagnum)
247*7c478bd9Sstevel@tonic-gate {
248*7c478bd9Sstevel@tonic-gate 	int		err = 0;
249*7c478bd9Sstevel@tonic-gate 	token_desc_t	*tag;
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 	/* no-op if not doing XML format */
252*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM))
253*7c478bd9Sstevel@tonic-gate 		return (0);
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 	tag = &tokentable[tagnum];
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate 	switch (tag->t_type) {
258*7c478bd9Sstevel@tonic-gate 	case T_ATTRIBUTE:
259*7c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, '\"');
260*7c478bd9Sstevel@tonic-gate 		break;
261*7c478bd9Sstevel@tonic-gate 	case T_ELEMENT:
262*7c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "</%s>", tag->t_tagname);
263*7c478bd9Sstevel@tonic-gate 		break;
264*7c478bd9Sstevel@tonic-gate 	case T_ENCLOSED:
265*7c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "/>");
266*7c478bd9Sstevel@tonic-gate 		break;
267*7c478bd9Sstevel@tonic-gate 	case T_EXTENDED:
268*7c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "</%s>", tag->t_tagname);
269*7c478bd9Sstevel@tonic-gate 		break;
270*7c478bd9Sstevel@tonic-gate 	default:
271*7c478bd9Sstevel@tonic-gate 		break;
272*7c478bd9Sstevel@tonic-gate 	}
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate 	if (is_header_token(tagnum) && (err == 0))
275*7c478bd9Sstevel@tonic-gate 		context->current_rec = 0;	/* closing rec; none current */
276*7c478bd9Sstevel@tonic-gate 
277*7c478bd9Sstevel@tonic-gate 	return (err);
278*7c478bd9Sstevel@tonic-gate }
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate /*
281*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
282*7c478bd9Sstevel@tonic-gate  * process_tag:
283*7c478bd9Sstevel@tonic-gate  *		  Calls the routine corresponding to the tag
284*7c478bd9Sstevel@tonic-gate  *		  Note that to use this mechanism, all such routines must
285*7c478bd9Sstevel@tonic-gate  *		  take 2 ints for their parameters; the first of these is
286*7c478bd9Sstevel@tonic-gate  *		  the current status.
287*7c478bd9Sstevel@tonic-gate  *
288*7c478bd9Sstevel@tonic-gate  *		  flag = 1 for newline / delimiter, else 0
289*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
290*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
291*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
292*7c478bd9Sstevel@tonic-gate  */
293*7c478bd9Sstevel@tonic-gate int
294*7c478bd9Sstevel@tonic-gate process_tag(pr_context_t *context, int tagnum, int status, int flag)
295*7c478bd9Sstevel@tonic-gate {
296*7c478bd9Sstevel@tonic-gate 	int retstat;
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate 	retstat = status;
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate 	if (retstat)
301*7c478bd9Sstevel@tonic-gate 		return (retstat);
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	if ((tagnum > 0) && (tagnum <= MAXTAG) &&
304*7c478bd9Sstevel@tonic-gate 	    (tokentable[tagnum].func != NOFUNC)) {
305*7c478bd9Sstevel@tonic-gate 		retstat = open_tag(context, tagnum);
306*7c478bd9Sstevel@tonic-gate 		if (!retstat)
307*7c478bd9Sstevel@tonic-gate 			retstat = (*tokentable[tagnum].func)(context, status,
308*7c478bd9Sstevel@tonic-gate 			    flag);
309*7c478bd9Sstevel@tonic-gate 		if (!retstat)
310*7c478bd9Sstevel@tonic-gate 			retstat = close_tag(context, tagnum);
311*7c478bd9Sstevel@tonic-gate 		return (retstat);
312*7c478bd9Sstevel@tonic-gate 	}
313*7c478bd9Sstevel@tonic-gate 	/* here if token id is not in table */
314*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("praudit: No code associated with "
315*7c478bd9Sstevel@tonic-gate 	    "tag id %d\n"), tagnum);
316*7c478bd9Sstevel@tonic-gate 	return (0);
317*7c478bd9Sstevel@tonic-gate }
318*7c478bd9Sstevel@tonic-gate 
319*7c478bd9Sstevel@tonic-gate void
320*7c478bd9Sstevel@tonic-gate get_Hname(uint32_t addr, char *buf, size_t buflen)
321*7c478bd9Sstevel@tonic-gate {
322*7c478bd9Sstevel@tonic-gate 	extern char	*inet_ntoa(const struct in_addr);
323*7c478bd9Sstevel@tonic-gate 	struct hostent *phe;
324*7c478bd9Sstevel@tonic-gate 	struct in_addr ia;
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate 	phe = gethostbyaddr((const char *)&addr, 4, AF_INET);
327*7c478bd9Sstevel@tonic-gate 	if (phe == (struct hostent *)0) {
328*7c478bd9Sstevel@tonic-gate 		ia.s_addr = addr;
329*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, buflen, "%s", inet_ntoa(ia));
330*7c478bd9Sstevel@tonic-gate 		return;
331*7c478bd9Sstevel@tonic-gate 	}
332*7c478bd9Sstevel@tonic-gate 	ia.s_addr = addr;
333*7c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, buflen, "%s", phe->h_name);
334*7c478bd9Sstevel@tonic-gate }
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate void
337*7c478bd9Sstevel@tonic-gate get_Hname_ex(uint32_t *addr, char *buf, size_t buflen)
338*7c478bd9Sstevel@tonic-gate {
339*7c478bd9Sstevel@tonic-gate 	struct hostent *phe;
340*7c478bd9Sstevel@tonic-gate 	int err;
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate 	phe = getipnodebyaddr((const void *)addr, 16, AF_INET6, &err);
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate 	if (phe == (struct hostent *)0) {
345*7c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *)addr, buf, buflen);
346*7c478bd9Sstevel@tonic-gate 	} else
347*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, buflen, "%s", phe->h_name);
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate 	if (phe)
350*7c478bd9Sstevel@tonic-gate 		freehostent(phe);
351*7c478bd9Sstevel@tonic-gate }
352*7c478bd9Sstevel@tonic-gate 
353*7c478bd9Sstevel@tonic-gate int
354*7c478bd9Sstevel@tonic-gate pa_hostname(pr_context_t *context, int status, int flag)
355*7c478bd9Sstevel@tonic-gate {
356*7c478bd9Sstevel@tonic-gate 	int	returnstat;
357*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr;
358*7c478bd9Sstevel@tonic-gate 	struct in_addr ia;
359*7c478bd9Sstevel@tonic-gate 	uval_t uval;
360*7c478bd9Sstevel@tonic-gate 	char	buf[256];
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate 	if (status <  0)
363*7c478bd9Sstevel@tonic-gate 		return (status);
364*7c478bd9Sstevel@tonic-gate 
365*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0)
366*7c478bd9Sstevel@tonic-gate 		return (returnstat);
367*7c478bd9Sstevel@tonic-gate 
368*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
369*7c478bd9Sstevel@tonic-gate 
370*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
371*7c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
372*7c478bd9Sstevel@tonic-gate 		get_Hname(ip_addr, buf, sizeof (buf));
373*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
374*7c478bd9Sstevel@tonic-gate 	} else {
375*7c478bd9Sstevel@tonic-gate 		ia.s_addr = ip_addr;
376*7c478bd9Sstevel@tonic-gate 		if ((uval.string_val = inet_ntoa(ia)) == NULL)
377*7c478bd9Sstevel@tonic-gate 			return (-1);
378*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
379*7c478bd9Sstevel@tonic-gate 	}
380*7c478bd9Sstevel@tonic-gate 	return (returnstat);
381*7c478bd9Sstevel@tonic-gate }
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate int
384*7c478bd9Sstevel@tonic-gate pa_hostname_ex(pr_context_t *context, int status, int flag)
385*7c478bd9Sstevel@tonic-gate {
386*7c478bd9Sstevel@tonic-gate 	int	returnstat;
387*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_type;
388*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[4];
389*7c478bd9Sstevel@tonic-gate 	struct in_addr ia;
390*7c478bd9Sstevel@tonic-gate 	char buf[256];
391*7c478bd9Sstevel@tonic-gate 	uval_t uval;
392*7c478bd9Sstevel@tonic-gate 
393*7c478bd9Sstevel@tonic-gate 	if (status <  0)
394*7c478bd9Sstevel@tonic-gate 		return (status);
395*7c478bd9Sstevel@tonic-gate 
396*7c478bd9Sstevel@tonic-gate 	/* get ip type */
397*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int32(context, (int32_t *)&ip_type, 1)) != 0)
398*7c478bd9Sstevel@tonic-gate 		return (returnstat);
399*7c478bd9Sstevel@tonic-gate 
400*7c478bd9Sstevel@tonic-gate 	/* only IPv4 and IPv6 addresses are legal */
401*7c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
402*7c478bd9Sstevel@tonic-gate 		return (-1);
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 	/* get ip address */
405*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
406*7c478bd9Sstevel@tonic-gate 			return (returnstat);
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_HOSTID)) != 0)
409*7c478bd9Sstevel@tonic-gate 		return (returnstat);
410*7c478bd9Sstevel@tonic-gate 
411*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
412*7c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {		/* ipv4 address */
413*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
414*7c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
415*7c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], buf, sizeof (buf));
416*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
417*7c478bd9Sstevel@tonic-gate 		} else {
418*7c478bd9Sstevel@tonic-gate 			ia.s_addr = ip_addr[0];
419*7c478bd9Sstevel@tonic-gate 			if ((uval.string_val = inet_ntoa(ia)) == NULL)
420*7c478bd9Sstevel@tonic-gate 				return (-1);
421*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
422*7c478bd9Sstevel@tonic-gate 		}
423*7c478bd9Sstevel@tonic-gate 	} else if (ip_type == AU_IPv6) {	/* IPv6 addresss (128 bits) */
424*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
425*7c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
426*7c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, buf, sizeof (buf));
427*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
428*7c478bd9Sstevel@tonic-gate 		} else {
429*7c478bd9Sstevel@tonic-gate 			uval.string_val = (char *)buf;
430*7c478bd9Sstevel@tonic-gate 			(void) inet_ntop(AF_INET6, (void *)ip_addr, buf,
431*7c478bd9Sstevel@tonic-gate 			    sizeof (buf));
432*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
433*7c478bd9Sstevel@tonic-gate 		}
434*7c478bd9Sstevel@tonic-gate 	}
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate 	if (returnstat != 0)
437*7c478bd9Sstevel@tonic-gate 		return (returnstat);
438*7c478bd9Sstevel@tonic-gate 	return (close_tag(context, TAG_HOSTID));
439*7c478bd9Sstevel@tonic-gate }
440*7c478bd9Sstevel@tonic-gate 
441*7c478bd9Sstevel@tonic-gate int
442*7c478bd9Sstevel@tonic-gate pa_hostname_so(pr_context_t *context, int status, int flag)
443*7c478bd9Sstevel@tonic-gate {
444*7c478bd9Sstevel@tonic-gate 	int		returnstat;
445*7c478bd9Sstevel@tonic-gate 	short		ip_type;
446*7c478bd9Sstevel@tonic-gate 	ushort_t	ip_port;
447*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[4];
448*7c478bd9Sstevel@tonic-gate 	struct in_addr ia;
449*7c478bd9Sstevel@tonic-gate 	char buf[256];
450*7c478bd9Sstevel@tonic-gate 	uval_t uval;
451*7c478bd9Sstevel@tonic-gate 
452*7c478bd9Sstevel@tonic-gate 	if (status <  0)
453*7c478bd9Sstevel@tonic-gate 		return (status);
454*7c478bd9Sstevel@tonic-gate 
455*7c478bd9Sstevel@tonic-gate 	/* get ip type */
456*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_short(context, &ip_type, 1)) != 0)
457*7c478bd9Sstevel@tonic-gate 		return (returnstat);
458*7c478bd9Sstevel@tonic-gate 
459*7c478bd9Sstevel@tonic-gate 	/* only IPv4 and IPv6 addresses are legal */
460*7c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
461*7c478bd9Sstevel@tonic-gate 		return (-1);
462*7c478bd9Sstevel@tonic-gate 
463*7c478bd9Sstevel@tonic-gate 	/* get local ip port */
464*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_short(context, &ip_port, 1)) != 0)
465*7c478bd9Sstevel@tonic-gate 		return (returnstat);
466*7c478bd9Sstevel@tonic-gate 
467*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_SOCKEXLPORT)) != 0)
468*7c478bd9Sstevel@tonic-gate 		return (returnstat);
469*7c478bd9Sstevel@tonic-gate 
470*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
471*7c478bd9Sstevel@tonic-gate 	uval.string_val = hexconvert((char *)&ip_port, sizeof (ip_port),
472*7c478bd9Sstevel@tonic-gate 	    sizeof (ip_port));
473*7c478bd9Sstevel@tonic-gate 	if (uval.string_val) {
474*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, 0);
475*7c478bd9Sstevel@tonic-gate 		free(uval.string_val);
476*7c478bd9Sstevel@tonic-gate 	} else
477*7c478bd9Sstevel@tonic-gate 		returnstat = -1;
478*7c478bd9Sstevel@tonic-gate 	if (returnstat)
479*7c478bd9Sstevel@tonic-gate 		return (returnstat);
480*7c478bd9Sstevel@tonic-gate 
481*7c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_SOCKEXLPORT)) != 0)
482*7c478bd9Sstevel@tonic-gate 		return (returnstat);
483*7c478bd9Sstevel@tonic-gate 
484*7c478bd9Sstevel@tonic-gate 	/* get local ip address */
485*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
486*7c478bd9Sstevel@tonic-gate 			return (returnstat);
487*7c478bd9Sstevel@tonic-gate 
488*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_SOCKEXLADDR)) != 0)
489*7c478bd9Sstevel@tonic-gate 		return (returnstat);
490*7c478bd9Sstevel@tonic-gate 
491*7c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {		/* ipv4 address */
492*7c478bd9Sstevel@tonic-gate 
493*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
494*7c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
495*7c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], buf, sizeof (buf));
496*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
497*7c478bd9Sstevel@tonic-gate 		} else {
498*7c478bd9Sstevel@tonic-gate 			ia.s_addr = ip_addr[0];
499*7c478bd9Sstevel@tonic-gate 			if ((uval.string_val = inet_ntoa(ia)) == NULL)
500*7c478bd9Sstevel@tonic-gate 				return (-1);
501*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
502*7c478bd9Sstevel@tonic-gate 		}
503*7c478bd9Sstevel@tonic-gate 
504*7c478bd9Sstevel@tonic-gate 	} else if (ip_type == AU_IPv6) {	/* IPv6 addresss (128 bits) */
505*7c478bd9Sstevel@tonic-gate 
506*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
507*7c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
508*7c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, buf, sizeof (buf));
509*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
510*7c478bd9Sstevel@tonic-gate 		} else {
511*7c478bd9Sstevel@tonic-gate 			uval.string_val = (char *)buf;
512*7c478bd9Sstevel@tonic-gate 			(void) inet_ntop(AF_INET6, (void *)ip_addr, buf,
513*7c478bd9Sstevel@tonic-gate 			    sizeof (buf));
514*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
515*7c478bd9Sstevel@tonic-gate 		}
516*7c478bd9Sstevel@tonic-gate 	} else
517*7c478bd9Sstevel@tonic-gate 		returnstat = -1;
518*7c478bd9Sstevel@tonic-gate 
519*7c478bd9Sstevel@tonic-gate 	if (returnstat)
520*7c478bd9Sstevel@tonic-gate 		return (returnstat);
521*7c478bd9Sstevel@tonic-gate 
522*7c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_SOCKEXLADDR)) != 0)
523*7c478bd9Sstevel@tonic-gate 		return (returnstat);
524*7c478bd9Sstevel@tonic-gate 
525*7c478bd9Sstevel@tonic-gate 	/* get foreign ip port */
526*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_short(context, &ip_port, 1)) != 0)
527*7c478bd9Sstevel@tonic-gate 		return (returnstat);
528*7c478bd9Sstevel@tonic-gate 
529*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_SOCKEXFPORT)) != 0)
530*7c478bd9Sstevel@tonic-gate 		return (returnstat);
531*7c478bd9Sstevel@tonic-gate 
532*7c478bd9Sstevel@tonic-gate 	uval.string_val = hexconvert((char *)&ip_port, sizeof (ip_port),
533*7c478bd9Sstevel@tonic-gate 	    sizeof (ip_port));
534*7c478bd9Sstevel@tonic-gate 	if (uval.string_val) {
535*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, 0);
536*7c478bd9Sstevel@tonic-gate 		free(uval.string_val);
537*7c478bd9Sstevel@tonic-gate 	} else
538*7c478bd9Sstevel@tonic-gate 		returnstat = -1;
539*7c478bd9Sstevel@tonic-gate 
540*7c478bd9Sstevel@tonic-gate 	if (returnstat)
541*7c478bd9Sstevel@tonic-gate 		return (returnstat);
542*7c478bd9Sstevel@tonic-gate 
543*7c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_SOCKEXFPORT)) != 0)
544*7c478bd9Sstevel@tonic-gate 		return (returnstat);
545*7c478bd9Sstevel@tonic-gate 
546*7c478bd9Sstevel@tonic-gate 	/* get foreign ip address */
547*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
548*7c478bd9Sstevel@tonic-gate 			return (returnstat);
549*7c478bd9Sstevel@tonic-gate 
550*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_SOCKEXFADDR)) != 0)
551*7c478bd9Sstevel@tonic-gate 		return (returnstat);
552*7c478bd9Sstevel@tonic-gate 
553*7c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {		/* ipv4 address */
554*7c478bd9Sstevel@tonic-gate 
555*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
556*7c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
557*7c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], buf, sizeof (buf));
558*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
559*7c478bd9Sstevel@tonic-gate 		} else {
560*7c478bd9Sstevel@tonic-gate 			ia.s_addr = ip_addr[0];
561*7c478bd9Sstevel@tonic-gate 			if ((uval.string_val = inet_ntoa(ia)) == NULL)
562*7c478bd9Sstevel@tonic-gate 				return (-1);
563*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
564*7c478bd9Sstevel@tonic-gate 		}
565*7c478bd9Sstevel@tonic-gate 
566*7c478bd9Sstevel@tonic-gate 	} else if (ip_type == AU_IPv6) {	/* IPv6 addresss (128 bits) */
567*7c478bd9Sstevel@tonic-gate 
568*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
569*7c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
570*7c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, buf, sizeof (buf));
571*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
572*7c478bd9Sstevel@tonic-gate 		} else {
573*7c478bd9Sstevel@tonic-gate 			uval.string_val = (char *)buf;
574*7c478bd9Sstevel@tonic-gate 			(void) inet_ntop(AF_INET6, (void *)ip_addr, buf,
575*7c478bd9Sstevel@tonic-gate 			    sizeof (buf));
576*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
577*7c478bd9Sstevel@tonic-gate 		}
578*7c478bd9Sstevel@tonic-gate 	} else
579*7c478bd9Sstevel@tonic-gate 		returnstat = -1;
580*7c478bd9Sstevel@tonic-gate 
581*7c478bd9Sstevel@tonic-gate 	if (returnstat)
582*7c478bd9Sstevel@tonic-gate 		return (returnstat);
583*7c478bd9Sstevel@tonic-gate 
584*7c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_SOCKEXFADDR)) != 0)
585*7c478bd9Sstevel@tonic-gate 		return (returnstat);
586*7c478bd9Sstevel@tonic-gate 
587*7c478bd9Sstevel@tonic-gate 	return (returnstat);
588*7c478bd9Sstevel@tonic-gate }
589*7c478bd9Sstevel@tonic-gate 
590*7c478bd9Sstevel@tonic-gate 
591*7c478bd9Sstevel@tonic-gate #define	NBITSMAJOR64	32	/* # of major device bits in 64-bit Solaris */
592*7c478bd9Sstevel@tonic-gate #define	NBITSMINOR64	32	/* # of minor device bits in 64-bit Solaris */
593*7c478bd9Sstevel@tonic-gate #define	MAXMAJ64	0xfffffffful	/* max major value */
594*7c478bd9Sstevel@tonic-gate #define	MAXMIN64	0xfffffffful	/* max minor value */
595*7c478bd9Sstevel@tonic-gate 
596*7c478bd9Sstevel@tonic-gate #define	NBITSMAJOR32	14	/* # of SVR4 major device bits */
597*7c478bd9Sstevel@tonic-gate #define	NBITSMINOR32	18	/* # of SVR4 minor device bits */
598*7c478bd9Sstevel@tonic-gate #define	NMAXMAJ32	0x3fff	/* SVR4 max major value */
599*7c478bd9Sstevel@tonic-gate #define	NMAXMIN32	0x3ffff	/* MAX minor for 3b2 software drivers. */
600*7c478bd9Sstevel@tonic-gate 
601*7c478bd9Sstevel@tonic-gate 
602*7c478bd9Sstevel@tonic-gate static int32_t
603*7c478bd9Sstevel@tonic-gate minor_64(uint64_t dev)
604*7c478bd9Sstevel@tonic-gate {
605*7c478bd9Sstevel@tonic-gate 	if (dev == NODEV) {
606*7c478bd9Sstevel@tonic-gate 		errno = EINVAL;
607*7c478bd9Sstevel@tonic-gate 		return (NODEV);
608*7c478bd9Sstevel@tonic-gate 	}
609*7c478bd9Sstevel@tonic-gate 	return (int32_t)(dev & MAXMIN64);
610*7c478bd9Sstevel@tonic-gate }
611*7c478bd9Sstevel@tonic-gate 
612*7c478bd9Sstevel@tonic-gate static int32_t
613*7c478bd9Sstevel@tonic-gate major_64(uint64_t dev)
614*7c478bd9Sstevel@tonic-gate {
615*7c478bd9Sstevel@tonic-gate 	uint32_t maj;
616*7c478bd9Sstevel@tonic-gate 
617*7c478bd9Sstevel@tonic-gate 	maj = (uint32_t)(dev >> NBITSMINOR64);
618*7c478bd9Sstevel@tonic-gate 
619*7c478bd9Sstevel@tonic-gate 	if (dev == NODEV || maj > MAXMAJ64) {
620*7c478bd9Sstevel@tonic-gate 		errno = EINVAL;
621*7c478bd9Sstevel@tonic-gate 		return (NODEV);
622*7c478bd9Sstevel@tonic-gate 	}
623*7c478bd9Sstevel@tonic-gate 	return (int32_t)(maj);
624*7c478bd9Sstevel@tonic-gate }
625*7c478bd9Sstevel@tonic-gate 
626*7c478bd9Sstevel@tonic-gate static int32_t
627*7c478bd9Sstevel@tonic-gate minor_32(uint32_t dev)
628*7c478bd9Sstevel@tonic-gate {
629*7c478bd9Sstevel@tonic-gate 	if (dev == NODEV) {
630*7c478bd9Sstevel@tonic-gate 		errno = EINVAL;
631*7c478bd9Sstevel@tonic-gate 		return (NODEV);
632*7c478bd9Sstevel@tonic-gate 	}
633*7c478bd9Sstevel@tonic-gate 	return (int32_t)(dev & MAXMIN32);
634*7c478bd9Sstevel@tonic-gate }
635*7c478bd9Sstevel@tonic-gate 
636*7c478bd9Sstevel@tonic-gate static int32_t
637*7c478bd9Sstevel@tonic-gate major_32(uint32_t dev)
638*7c478bd9Sstevel@tonic-gate {
639*7c478bd9Sstevel@tonic-gate 	uint32_t maj;
640*7c478bd9Sstevel@tonic-gate 
641*7c478bd9Sstevel@tonic-gate 	maj = (uint32_t)(dev >> NBITSMINOR32);
642*7c478bd9Sstevel@tonic-gate 
643*7c478bd9Sstevel@tonic-gate 	if (dev == NODEV || maj > MAXMAJ32) {
644*7c478bd9Sstevel@tonic-gate 		errno = EINVAL;
645*7c478bd9Sstevel@tonic-gate 		return (NODEV);
646*7c478bd9Sstevel@tonic-gate 	}
647*7c478bd9Sstevel@tonic-gate 	return (int32_t)(maj);
648*7c478bd9Sstevel@tonic-gate }
649*7c478bd9Sstevel@tonic-gate 
650*7c478bd9Sstevel@tonic-gate 
651*7c478bd9Sstevel@tonic-gate /*
652*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
653*7c478bd9Sstevel@tonic-gate  * pa_tid() 	: Process terminal id and display contents
654*7c478bd9Sstevel@tonic-gate  * return codes	: -1 - error
655*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
656*7c478bd9Sstevel@tonic-gate  *
657*7c478bd9Sstevel@tonic-gate  *	terminal id port		adr_int32
658*7c478bd9Sstevel@tonic-gate  *	terminal id machine		adr_int32
659*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
660*7c478bd9Sstevel@tonic-gate  */
661*7c478bd9Sstevel@tonic-gate int
662*7c478bd9Sstevel@tonic-gate pa_tid32(pr_context_t *context, int status, int flag)
663*7c478bd9Sstevel@tonic-gate {
664*7c478bd9Sstevel@tonic-gate 	int	returnstat;
665*7c478bd9Sstevel@tonic-gate 	int32_t dev_maj_min;
666*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr;
667*7c478bd9Sstevel@tonic-gate 	struct in_addr ia;
668*7c478bd9Sstevel@tonic-gate 	char	*ipstring;
669*7c478bd9Sstevel@tonic-gate 	char	buf[256];
670*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
671*7c478bd9Sstevel@tonic-gate 
672*7c478bd9Sstevel@tonic-gate 	if (status <  0)
673*7c478bd9Sstevel@tonic-gate 		return (status);
674*7c478bd9Sstevel@tonic-gate 
675*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int32(context, &dev_maj_min, 1)) != 0)
676*7c478bd9Sstevel@tonic-gate 		return (returnstat);
677*7c478bd9Sstevel@tonic-gate 
678*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0)
679*7c478bd9Sstevel@tonic-gate 		return (returnstat);
680*7c478bd9Sstevel@tonic-gate 
681*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
682*7c478bd9Sstevel@tonic-gate 	uval.string_val = buf;
683*7c478bd9Sstevel@tonic-gate 
684*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
685*7c478bd9Sstevel@tonic-gate 		char	hostname[256];
686*7c478bd9Sstevel@tonic-gate 
687*7c478bd9Sstevel@tonic-gate 		get_Hname(ip_addr, hostname, sizeof (hostname));
688*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
689*7c478bd9Sstevel@tonic-gate 			major_32(dev_maj_min),
690*7c478bd9Sstevel@tonic-gate 			minor_32(dev_maj_min),
691*7c478bd9Sstevel@tonic-gate 			hostname);
692*7c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
693*7c478bd9Sstevel@tonic-gate 	}
694*7c478bd9Sstevel@tonic-gate 
695*7c478bd9Sstevel@tonic-gate 	ia.s_addr = ip_addr;
696*7c478bd9Sstevel@tonic-gate 	if ((ipstring = inet_ntoa(ia)) == NULL)
697*7c478bd9Sstevel@tonic-gate 		return (-1);
698*7c478bd9Sstevel@tonic-gate 
699*7c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf), "%d %d %s",
700*7c478bd9Sstevel@tonic-gate 		major_32(dev_maj_min),
701*7c478bd9Sstevel@tonic-gate 		minor_32(dev_maj_min),
702*7c478bd9Sstevel@tonic-gate 		ipstring);
703*7c478bd9Sstevel@tonic-gate 
704*7c478bd9Sstevel@tonic-gate 	return (pa_print(context, &uval, flag));
705*7c478bd9Sstevel@tonic-gate }
706*7c478bd9Sstevel@tonic-gate 
707*7c478bd9Sstevel@tonic-gate int
708*7c478bd9Sstevel@tonic-gate pa_tid32_ex(pr_context_t *context, int status, int flag)
709*7c478bd9Sstevel@tonic-gate {
710*7c478bd9Sstevel@tonic-gate 	int		returnstat;
711*7c478bd9Sstevel@tonic-gate 	int32_t		dev_maj_min;
712*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[16];
713*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_type;
714*7c478bd9Sstevel@tonic-gate 	struct in_addr	ia;
715*7c478bd9Sstevel@tonic-gate 	char		*ipstring;
716*7c478bd9Sstevel@tonic-gate 	char		hostname[256];
717*7c478bd9Sstevel@tonic-gate 	char		buf[256];
718*7c478bd9Sstevel@tonic-gate 	char		tbuf[256];
719*7c478bd9Sstevel@tonic-gate 	uval_t		uval;
720*7c478bd9Sstevel@tonic-gate 
721*7c478bd9Sstevel@tonic-gate 	if (status <  0)
722*7c478bd9Sstevel@tonic-gate 		return (status);
723*7c478bd9Sstevel@tonic-gate 
724*7c478bd9Sstevel@tonic-gate 	/* get port info */
725*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int32(context, &dev_maj_min, 1)) != 0)
726*7c478bd9Sstevel@tonic-gate 		return (returnstat);
727*7c478bd9Sstevel@tonic-gate 
728*7c478bd9Sstevel@tonic-gate 	/* get address type */
729*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
730*7c478bd9Sstevel@tonic-gate 		return (returnstat);
731*7c478bd9Sstevel@tonic-gate 
732*7c478bd9Sstevel@tonic-gate 	/* legal address types are either AU_IPv4 or AU_IPv6 only */
733*7c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
734*7c478bd9Sstevel@tonic-gate 		return (-1);
735*7c478bd9Sstevel@tonic-gate 
736*7c478bd9Sstevel@tonic-gate 	/* get address (4/16) */
737*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
738*7c478bd9Sstevel@tonic-gate 		return (returnstat);
739*7c478bd9Sstevel@tonic-gate 
740*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
741*7c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {
742*7c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
743*7c478bd9Sstevel@tonic-gate 
744*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
745*7c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], hostname, sizeof (hostname));
746*7c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%d %d %s",
747*7c478bd9Sstevel@tonic-gate 				major_32(dev_maj_min),
748*7c478bd9Sstevel@tonic-gate 				minor_32(dev_maj_min),
749*7c478bd9Sstevel@tonic-gate 				hostname);
750*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
751*7c478bd9Sstevel@tonic-gate 		}
752*7c478bd9Sstevel@tonic-gate 
753*7c478bd9Sstevel@tonic-gate 		ia.s_addr = ip_addr[0];
754*7c478bd9Sstevel@tonic-gate 		if ((ipstring = inet_ntoa(ia)) == NULL)
755*7c478bd9Sstevel@tonic-gate 			return (-1);
756*7c478bd9Sstevel@tonic-gate 
757*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
758*7c478bd9Sstevel@tonic-gate 			major_32(dev_maj_min),
759*7c478bd9Sstevel@tonic-gate 			minor_32(dev_maj_min),
760*7c478bd9Sstevel@tonic-gate 			ipstring);
761*7c478bd9Sstevel@tonic-gate 
762*7c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
763*7c478bd9Sstevel@tonic-gate 	} else {
764*7c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
765*7c478bd9Sstevel@tonic-gate 
766*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
767*7c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, hostname, sizeof (hostname));
768*7c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%d %d %s",
769*7c478bd9Sstevel@tonic-gate 				major_32(dev_maj_min),
770*7c478bd9Sstevel@tonic-gate 				minor_32(dev_maj_min),
771*7c478bd9Sstevel@tonic-gate 				hostname);
772*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
773*7c478bd9Sstevel@tonic-gate 		}
774*7c478bd9Sstevel@tonic-gate 
775*7c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf,
776*7c478bd9Sstevel@tonic-gate 		    sizeof (tbuf));
777*7c478bd9Sstevel@tonic-gate 
778*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
779*7c478bd9Sstevel@tonic-gate 			major_32(dev_maj_min),
780*7c478bd9Sstevel@tonic-gate 			minor_32(dev_maj_min),
781*7c478bd9Sstevel@tonic-gate 			tbuf);
782*7c478bd9Sstevel@tonic-gate 
783*7c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
784*7c478bd9Sstevel@tonic-gate 	}
785*7c478bd9Sstevel@tonic-gate }
786*7c478bd9Sstevel@tonic-gate 
787*7c478bd9Sstevel@tonic-gate int
788*7c478bd9Sstevel@tonic-gate pa_ip_addr(pr_context_t *context, int status, int flag)
789*7c478bd9Sstevel@tonic-gate {
790*7c478bd9Sstevel@tonic-gate 	int		returnstat;
791*7c478bd9Sstevel@tonic-gate 	uval_t		uval;
792*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[4];
793*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_type;
794*7c478bd9Sstevel@tonic-gate 	struct in_addr	ia;
795*7c478bd9Sstevel@tonic-gate 	char		*ipstring;
796*7c478bd9Sstevel@tonic-gate 	char		hostname[256];
797*7c478bd9Sstevel@tonic-gate 	char		buf[256];
798*7c478bd9Sstevel@tonic-gate 	char		tbuf[256];
799*7c478bd9Sstevel@tonic-gate 
800*7c478bd9Sstevel@tonic-gate 	if (status <  0)
801*7c478bd9Sstevel@tonic-gate 		return (status);
802*7c478bd9Sstevel@tonic-gate 
803*7c478bd9Sstevel@tonic-gate 	/* get address type */
804*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
805*7c478bd9Sstevel@tonic-gate 		return (returnstat);
806*7c478bd9Sstevel@tonic-gate 
807*7c478bd9Sstevel@tonic-gate 	/* legal address type is AU_IPv4 or AU_IPv6 */
808*7c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
809*7c478bd9Sstevel@tonic-gate 		return (-1);
810*7c478bd9Sstevel@tonic-gate 
811*7c478bd9Sstevel@tonic-gate 	/* get address (4/16) */
812*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
813*7c478bd9Sstevel@tonic-gate 		return (returnstat);
814*7c478bd9Sstevel@tonic-gate 
815*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
816*7c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {
817*7c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
818*7c478bd9Sstevel@tonic-gate 
819*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
820*7c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], hostname, sizeof (hostname));
821*7c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%s",
822*7c478bd9Sstevel@tonic-gate 				hostname);
823*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
824*7c478bd9Sstevel@tonic-gate 		}
825*7c478bd9Sstevel@tonic-gate 
826*7c478bd9Sstevel@tonic-gate 		ia.s_addr = ip_addr[0];
827*7c478bd9Sstevel@tonic-gate 		if ((ipstring = inet_ntoa(ia)) == NULL)
828*7c478bd9Sstevel@tonic-gate 			return (-1);
829*7c478bd9Sstevel@tonic-gate 
830*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%s",
831*7c478bd9Sstevel@tonic-gate 			ipstring);
832*7c478bd9Sstevel@tonic-gate 
833*7c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
834*7c478bd9Sstevel@tonic-gate 	} else {
835*7c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
836*7c478bd9Sstevel@tonic-gate 
837*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
838*7c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, hostname, sizeof (hostname));
839*7c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%s",
840*7c478bd9Sstevel@tonic-gate 			    hostname);
841*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
842*7c478bd9Sstevel@tonic-gate 		}
843*7c478bd9Sstevel@tonic-gate 
844*7c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf,
845*7c478bd9Sstevel@tonic-gate 		    sizeof (tbuf));
846*7c478bd9Sstevel@tonic-gate 
847*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%s", tbuf);
848*7c478bd9Sstevel@tonic-gate 
849*7c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
850*7c478bd9Sstevel@tonic-gate 	}
851*7c478bd9Sstevel@tonic-gate 
852*7c478bd9Sstevel@tonic-gate }
853*7c478bd9Sstevel@tonic-gate 
854*7c478bd9Sstevel@tonic-gate int
855*7c478bd9Sstevel@tonic-gate pa_tid64(pr_context_t *context, int status, int flag)
856*7c478bd9Sstevel@tonic-gate {
857*7c478bd9Sstevel@tonic-gate 	int	returnstat;
858*7c478bd9Sstevel@tonic-gate 	int64_t dev_maj_min;
859*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr;
860*7c478bd9Sstevel@tonic-gate 	struct in_addr ia;
861*7c478bd9Sstevel@tonic-gate 	char	*ipstring;
862*7c478bd9Sstevel@tonic-gate 	char	buf[256];
863*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
864*7c478bd9Sstevel@tonic-gate 
865*7c478bd9Sstevel@tonic-gate 	if (status <  0)
866*7c478bd9Sstevel@tonic-gate 		return (status);
867*7c478bd9Sstevel@tonic-gate 
868*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0)
869*7c478bd9Sstevel@tonic-gate 		return (returnstat);
870*7c478bd9Sstevel@tonic-gate 
871*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0)
872*7c478bd9Sstevel@tonic-gate 		return (returnstat);
873*7c478bd9Sstevel@tonic-gate 
874*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
875*7c478bd9Sstevel@tonic-gate 	uval.string_val = buf;
876*7c478bd9Sstevel@tonic-gate 
877*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
878*7c478bd9Sstevel@tonic-gate 		char	hostname[256];
879*7c478bd9Sstevel@tonic-gate 
880*7c478bd9Sstevel@tonic-gate 		get_Hname(ip_addr, hostname, sizeof (hostname));
881*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
882*7c478bd9Sstevel@tonic-gate 			major_64(dev_maj_min),
883*7c478bd9Sstevel@tonic-gate 			minor_64(dev_maj_min),
884*7c478bd9Sstevel@tonic-gate 			hostname);
885*7c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
886*7c478bd9Sstevel@tonic-gate 	}
887*7c478bd9Sstevel@tonic-gate 
888*7c478bd9Sstevel@tonic-gate 	ia.s_addr = ip_addr;
889*7c478bd9Sstevel@tonic-gate 	if ((ipstring = inet_ntoa(ia)) == NULL)
890*7c478bd9Sstevel@tonic-gate 		return (-1);
891*7c478bd9Sstevel@tonic-gate 
892*7c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf), "%d %d %s",
893*7c478bd9Sstevel@tonic-gate 		major_64(dev_maj_min),
894*7c478bd9Sstevel@tonic-gate 		minor_64(dev_maj_min),
895*7c478bd9Sstevel@tonic-gate 		ipstring);
896*7c478bd9Sstevel@tonic-gate 
897*7c478bd9Sstevel@tonic-gate 	return (pa_print(context, &uval, flag));
898*7c478bd9Sstevel@tonic-gate }
899*7c478bd9Sstevel@tonic-gate 
900*7c478bd9Sstevel@tonic-gate int
901*7c478bd9Sstevel@tonic-gate pa_tid64_ex(pr_context_t *context, int status, int flag)
902*7c478bd9Sstevel@tonic-gate {
903*7c478bd9Sstevel@tonic-gate 	int		returnstat;
904*7c478bd9Sstevel@tonic-gate 	int64_t		dev_maj_min;
905*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[4];
906*7c478bd9Sstevel@tonic-gate 	uint32_t	ip_type;
907*7c478bd9Sstevel@tonic-gate 	struct in_addr	ia;
908*7c478bd9Sstevel@tonic-gate 	char		*ipstring;
909*7c478bd9Sstevel@tonic-gate 	char		hostname[256];
910*7c478bd9Sstevel@tonic-gate 	char		buf[256];
911*7c478bd9Sstevel@tonic-gate 	char		tbuf[256];
912*7c478bd9Sstevel@tonic-gate 	uval_t		uval;
913*7c478bd9Sstevel@tonic-gate 
914*7c478bd9Sstevel@tonic-gate 	if (status <  0)
915*7c478bd9Sstevel@tonic-gate 		return (status);
916*7c478bd9Sstevel@tonic-gate 
917*7c478bd9Sstevel@tonic-gate 	/* get port info */
918*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0)
919*7c478bd9Sstevel@tonic-gate 		return (returnstat);
920*7c478bd9Sstevel@tonic-gate 
921*7c478bd9Sstevel@tonic-gate 	/* get address type */
922*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
923*7c478bd9Sstevel@tonic-gate 		return (returnstat);
924*7c478bd9Sstevel@tonic-gate 
925*7c478bd9Sstevel@tonic-gate 	/* legal address types are either AU_IPv4 or AU_IPv6 only */
926*7c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
927*7c478bd9Sstevel@tonic-gate 		return (-1);
928*7c478bd9Sstevel@tonic-gate 
929*7c478bd9Sstevel@tonic-gate 	/* get address (4/16) */
930*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&ip_addr, ip_type)) != 0)
931*7c478bd9Sstevel@tonic-gate 		return (returnstat);
932*7c478bd9Sstevel@tonic-gate 
933*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
934*7c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {
935*7c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
936*7c478bd9Sstevel@tonic-gate 
937*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
938*7c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], hostname, sizeof (hostname));
939*7c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
940*7c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%d %d %s",
941*7c478bd9Sstevel@tonic-gate 				major_64(dev_maj_min),
942*7c478bd9Sstevel@tonic-gate 				minor_64(dev_maj_min),
943*7c478bd9Sstevel@tonic-gate 				hostname);
944*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
945*7c478bd9Sstevel@tonic-gate 		}
946*7c478bd9Sstevel@tonic-gate 
947*7c478bd9Sstevel@tonic-gate 		ia.s_addr = ip_addr[0];
948*7c478bd9Sstevel@tonic-gate 		if ((ipstring = inet_ntoa(ia)) == NULL)
949*7c478bd9Sstevel@tonic-gate 			return (-1);
950*7c478bd9Sstevel@tonic-gate 
951*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
952*7c478bd9Sstevel@tonic-gate 			major_64(dev_maj_min),
953*7c478bd9Sstevel@tonic-gate 			minor_64(dev_maj_min),
954*7c478bd9Sstevel@tonic-gate 			ipstring);
955*7c478bd9Sstevel@tonic-gate 
956*7c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
957*7c478bd9Sstevel@tonic-gate 	} else {
958*7c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
959*7c478bd9Sstevel@tonic-gate 
960*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
961*7c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, hostname, sizeof (hostname));
962*7c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%d %d %s",
963*7c478bd9Sstevel@tonic-gate 				major_64(dev_maj_min),
964*7c478bd9Sstevel@tonic-gate 				minor_64(dev_maj_min),
965*7c478bd9Sstevel@tonic-gate 				hostname);
966*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
967*7c478bd9Sstevel@tonic-gate 		}
968*7c478bd9Sstevel@tonic-gate 
969*7c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *)ip_addr, tbuf,
970*7c478bd9Sstevel@tonic-gate 		    sizeof (tbuf));
971*7c478bd9Sstevel@tonic-gate 
972*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
973*7c478bd9Sstevel@tonic-gate 			major_64(dev_maj_min),
974*7c478bd9Sstevel@tonic-gate 			minor_64(dev_maj_min),
975*7c478bd9Sstevel@tonic-gate 			tbuf);
976*7c478bd9Sstevel@tonic-gate 
977*7c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
978*7c478bd9Sstevel@tonic-gate 	}
979*7c478bd9Sstevel@tonic-gate }
980*7c478bd9Sstevel@tonic-gate 
981*7c478bd9Sstevel@tonic-gate 
982*7c478bd9Sstevel@tonic-gate /*
983*7c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------
984*7c478bd9Sstevel@tonic-gate  * findfieldwidth:
985*7c478bd9Sstevel@tonic-gate  * Returns the field width based on the basic unit and print mode.
986*7c478bd9Sstevel@tonic-gate  * This routine is called to determine the field width for the
987*7c478bd9Sstevel@tonic-gate  * data items in the arbitrary data token where the tokens are
988*7c478bd9Sstevel@tonic-gate  * to be printed in more than one line.  The field width can be
989*7c478bd9Sstevel@tonic-gate  * found in the fwidth structure.
990*7c478bd9Sstevel@tonic-gate  *
991*7c478bd9Sstevel@tonic-gate  * Input parameters:
992*7c478bd9Sstevel@tonic-gate  * basicunit	Can be one of AUR_CHAR, AUR_BYTE, AUR_SHORT,
993*7c478bd9Sstevel@tonic-gate  *		AUR_INT32, or AUR_INT64
994*7c478bd9Sstevel@tonic-gate  * howtoprint	Print mode. Can be one of AUP_BINARY, AUP_OCTAL,
995*7c478bd9Sstevel@tonic-gate  *		AUP_DECIMAL, or AUP_HEX.
996*7c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------
997*7c478bd9Sstevel@tonic-gate  */
998*7c478bd9Sstevel@tonic-gate int
999*7c478bd9Sstevel@tonic-gate findfieldwidth(char basicunit, char howtoprint)
1000*7c478bd9Sstevel@tonic-gate {
1001*7c478bd9Sstevel@tonic-gate 	int	i, j;
1002*7c478bd9Sstevel@tonic-gate 
1003*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < numwidthentries; i++) {
1004*7c478bd9Sstevel@tonic-gate 		if (fwidth[i].basic_unit == basicunit) {
1005*7c478bd9Sstevel@tonic-gate 			for (j = 0; j <= 4; j++) {
1006*7c478bd9Sstevel@tonic-gate 				if (fwidth[i].pwidth[j].print_base ==
1007*7c478bd9Sstevel@tonic-gate 					howtoprint)
1008*7c478bd9Sstevel@tonic-gate 				return (fwidth[i].pwidth[j].field_width);
1009*7c478bd9Sstevel@tonic-gate 			}
1010*7c478bd9Sstevel@tonic-gate 			/*
1011*7c478bd9Sstevel@tonic-gate 			 * if we got here, then we didn't get what we were after
1012*7c478bd9Sstevel@tonic-gate 			 */
1013*7c478bd9Sstevel@tonic-gate 			return (0);
1014*7c478bd9Sstevel@tonic-gate 		}
1015*7c478bd9Sstevel@tonic-gate 	}
1016*7c478bd9Sstevel@tonic-gate 	/* if we got here, we didn't get what we wanted either */
1017*7c478bd9Sstevel@tonic-gate 	return (0);
1018*7c478bd9Sstevel@tonic-gate }
1019*7c478bd9Sstevel@tonic-gate 
1020*7c478bd9Sstevel@tonic-gate 
1021*7c478bd9Sstevel@tonic-gate /*
1022*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1023*7c478bd9Sstevel@tonic-gate  * pa_cmd: Retrieves the cmd item from the input stream.
1024*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1025*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1026*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1027*7c478bd9Sstevel@tonic-gate  */
1028*7c478bd9Sstevel@tonic-gate int
1029*7c478bd9Sstevel@tonic-gate pa_cmd(pr_context_t *context, int status, int flag)
1030*7c478bd9Sstevel@tonic-gate {
1031*7c478bd9Sstevel@tonic-gate 	char	*cmd;  /* cmd */
1032*7c478bd9Sstevel@tonic-gate 	short	length;
1033*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1034*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1035*7c478bd9Sstevel@tonic-gate 
1036*7c478bd9Sstevel@tonic-gate 	/*
1037*7c478bd9Sstevel@tonic-gate 	 * We need to know how much space to allocate for our string, so
1038*7c478bd9Sstevel@tonic-gate 	 * read the length first, then call pr_adr_char to read those bytes.
1039*7c478bd9Sstevel@tonic-gate 	 */
1040*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1041*7c478bd9Sstevel@tonic-gate 		if (pr_adr_short(context, &length, 1) == 0) {
1042*7c478bd9Sstevel@tonic-gate 			if ((cmd = (char *)malloc(length + 1)) == NULL)
1043*7c478bd9Sstevel@tonic-gate 				return (-1);
1044*7c478bd9Sstevel@tonic-gate 			if (pr_adr_char(context, cmd, length) == 0) {
1045*7c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_STRING;
1046*7c478bd9Sstevel@tonic-gate 				uval.string_val = cmd;
1047*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
1048*7c478bd9Sstevel@tonic-gate 			} else {
1049*7c478bd9Sstevel@tonic-gate 				returnstat = -1;
1050*7c478bd9Sstevel@tonic-gate 			}
1051*7c478bd9Sstevel@tonic-gate 			free(cmd);
1052*7c478bd9Sstevel@tonic-gate 			return (returnstat);
1053*7c478bd9Sstevel@tonic-gate 		} else
1054*7c478bd9Sstevel@tonic-gate 			return (-1);
1055*7c478bd9Sstevel@tonic-gate 	} else
1056*7c478bd9Sstevel@tonic-gate 		return (status);
1057*7c478bd9Sstevel@tonic-gate }
1058*7c478bd9Sstevel@tonic-gate 
1059*7c478bd9Sstevel@tonic-gate 
1060*7c478bd9Sstevel@tonic-gate 
1061*7c478bd9Sstevel@tonic-gate /*
1062*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1063*7c478bd9Sstevel@tonic-gate  * pa_adr_byte	: Issues pr_adr_char to retrieve the next ADR item from
1064*7c478bd9Sstevel@tonic-gate  *		  the input stream pointed to by audit_adr, and prints it
1065*7c478bd9Sstevel@tonic-gate  *		  as an integer if status >= 0
1066*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1067*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1068*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1069*7c478bd9Sstevel@tonic-gate  */
1070*7c478bd9Sstevel@tonic-gate int
1071*7c478bd9Sstevel@tonic-gate pa_adr_byte(pr_context_t *context, int status, int flag)
1072*7c478bd9Sstevel@tonic-gate {
1073*7c478bd9Sstevel@tonic-gate 	char	c;
1074*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1075*7c478bd9Sstevel@tonic-gate 
1076*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1077*7c478bd9Sstevel@tonic-gate 		if (pr_adr_char(context, &c, 1) == 0) {
1078*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_BYTE;
1079*7c478bd9Sstevel@tonic-gate 			uval.char_val = c;
1080*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
1081*7c478bd9Sstevel@tonic-gate 		} else
1082*7c478bd9Sstevel@tonic-gate 			return (-1);
1083*7c478bd9Sstevel@tonic-gate 	} else
1084*7c478bd9Sstevel@tonic-gate 		return (status);
1085*7c478bd9Sstevel@tonic-gate }
1086*7c478bd9Sstevel@tonic-gate 
1087*7c478bd9Sstevel@tonic-gate /*
1088*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1089*7c478bd9Sstevel@tonic-gate  * pa_adr_charhex: Issues pr_adr_char to retrieve the next ADR item from
1090*7c478bd9Sstevel@tonic-gate  *			the input stream pointed to by audit_adr, and prints it
1091*7c478bd9Sstevel@tonic-gate  *			in hexadecimal if status >= 0
1092*7c478bd9Sstevel@tonic-gate  * return codes  : -1 - error
1093*7c478bd9Sstevel@tonic-gate  *		 :  0 - successful
1094*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1095*7c478bd9Sstevel@tonic-gate  */
1096*7c478bd9Sstevel@tonic-gate int
1097*7c478bd9Sstevel@tonic-gate pa_adr_charhex(pr_context_t *context, int status, int flag)
1098*7c478bd9Sstevel@tonic-gate {
1099*7c478bd9Sstevel@tonic-gate 	char	p[2];
1100*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1101*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1102*7c478bd9Sstevel@tonic-gate 
1103*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1104*7c478bd9Sstevel@tonic-gate 		p[0] = p[1] = 0;
1105*7c478bd9Sstevel@tonic-gate 
1106*7c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_char(context, p, 1)) == 0) {
1107*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
1108*7c478bd9Sstevel@tonic-gate 			uval.string_val = hexconvert(p, sizeof (char),
1109*7c478bd9Sstevel@tonic-gate 			    sizeof (char));
1110*7c478bd9Sstevel@tonic-gate 			if (uval.string_val) {
1111*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
1112*7c478bd9Sstevel@tonic-gate 				free(uval.string_val);
1113*7c478bd9Sstevel@tonic-gate 			}
1114*7c478bd9Sstevel@tonic-gate 		}
1115*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1116*7c478bd9Sstevel@tonic-gate 	} else
1117*7c478bd9Sstevel@tonic-gate 		return (status);
1118*7c478bd9Sstevel@tonic-gate }
1119*7c478bd9Sstevel@tonic-gate 
1120*7c478bd9Sstevel@tonic-gate /*
1121*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1122*7c478bd9Sstevel@tonic-gate  * pa_adr_int32	: Issues pr_adr_int32 to retrieve the next ADR item from the
1123*7c478bd9Sstevel@tonic-gate  *		  input stream pointed to by audit_adr, and prints it
1124*7c478bd9Sstevel@tonic-gate  *		  if status >= 0
1125*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1126*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1127*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1128*7c478bd9Sstevel@tonic-gate  */
1129*7c478bd9Sstevel@tonic-gate int
1130*7c478bd9Sstevel@tonic-gate pa_adr_int32(pr_context_t *context, int status, int flag)
1131*7c478bd9Sstevel@tonic-gate {
1132*7c478bd9Sstevel@tonic-gate 	int32_t	c;
1133*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1134*7c478bd9Sstevel@tonic-gate 
1135*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1136*7c478bd9Sstevel@tonic-gate 		if (pr_adr_int32(context, &c, 1) == 0) {
1137*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_INT32;
1138*7c478bd9Sstevel@tonic-gate 			uval.int32_val = c;
1139*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
1140*7c478bd9Sstevel@tonic-gate 		} else
1141*7c478bd9Sstevel@tonic-gate 			return (-1);
1142*7c478bd9Sstevel@tonic-gate 	} else
1143*7c478bd9Sstevel@tonic-gate 		return (status);
1144*7c478bd9Sstevel@tonic-gate }
1145*7c478bd9Sstevel@tonic-gate 
1146*7c478bd9Sstevel@tonic-gate 
1147*7c478bd9Sstevel@tonic-gate 
1148*7c478bd9Sstevel@tonic-gate 
1149*7c478bd9Sstevel@tonic-gate /*
1150*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1151*7c478bd9Sstevel@tonic-gate  * pa_adr_int64	: Issues pr_adr_int64 to retrieve the next ADR item from the
1152*7c478bd9Sstevel@tonic-gate  *		  input stream pointed to by audit_adr, and prints it
1153*7c478bd9Sstevel@tonic-gate  *		  if status >= 0
1154*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1155*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1156*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1157*7c478bd9Sstevel@tonic-gate  */
1158*7c478bd9Sstevel@tonic-gate int
1159*7c478bd9Sstevel@tonic-gate pa_adr_int64(pr_context_t *context, int status, int flag)
1160*7c478bd9Sstevel@tonic-gate {
1161*7c478bd9Sstevel@tonic-gate 	int64_t	c;
1162*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1163*7c478bd9Sstevel@tonic-gate 
1164*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1165*7c478bd9Sstevel@tonic-gate 		if (pr_adr_int64(context, &c, 1) == 0) {
1166*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_INT64;
1167*7c478bd9Sstevel@tonic-gate 			uval.int64_val = c;
1168*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
1169*7c478bd9Sstevel@tonic-gate 		} else
1170*7c478bd9Sstevel@tonic-gate 			return (-1);
1171*7c478bd9Sstevel@tonic-gate 	} else
1172*7c478bd9Sstevel@tonic-gate 		return (status);
1173*7c478bd9Sstevel@tonic-gate }
1174*7c478bd9Sstevel@tonic-gate 
1175*7c478bd9Sstevel@tonic-gate /*
1176*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1177*7c478bd9Sstevel@tonic-gate  * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the
1178*7c478bd9Sstevel@tonic-gate  *			input stream pointed to by audit_adr, and prints it
1179*7c478bd9Sstevel@tonic-gate  *			in hexadecimal if status >= 0
1180*7c478bd9Sstevel@tonic-gate  * return codes  : -1 - error
1181*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1182*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1183*7c478bd9Sstevel@tonic-gate  */
1184*7c478bd9Sstevel@tonic-gate int
1185*7c478bd9Sstevel@tonic-gate pa_adr_int32hex(pr_context_t *context, int status, int flag)
1186*7c478bd9Sstevel@tonic-gate {
1187*7c478bd9Sstevel@tonic-gate 	int32_t	l;
1188*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1189*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1190*7c478bd9Sstevel@tonic-gate 
1191*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1192*7c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_int32(context, &l, 1)) == 0) {
1193*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_HEX32;
1194*7c478bd9Sstevel@tonic-gate 			uval.int32_val = l;
1195*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
1196*7c478bd9Sstevel@tonic-gate 		}
1197*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1198*7c478bd9Sstevel@tonic-gate 	} else
1199*7c478bd9Sstevel@tonic-gate 		return (status);
1200*7c478bd9Sstevel@tonic-gate }
1201*7c478bd9Sstevel@tonic-gate 
1202*7c478bd9Sstevel@tonic-gate /*
1203*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1204*7c478bd9Sstevel@tonic-gate  * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the
1205*7c478bd9Sstevel@tonic-gate  *			input stream pointed to by audit_adr, and prints it
1206*7c478bd9Sstevel@tonic-gate  *			in hexadecimal if status >= 0
1207*7c478bd9Sstevel@tonic-gate  * return codes  : -1 - error
1208*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1209*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1210*7c478bd9Sstevel@tonic-gate  */
1211*7c478bd9Sstevel@tonic-gate int
1212*7c478bd9Sstevel@tonic-gate pa_adr_int64hex(pr_context_t *context, int status, int flag)
1213*7c478bd9Sstevel@tonic-gate {
1214*7c478bd9Sstevel@tonic-gate 	int64_t	l;
1215*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1216*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1217*7c478bd9Sstevel@tonic-gate 
1218*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1219*7c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_int64(context, &l, 1)) == 0) {
1220*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_HEX64;
1221*7c478bd9Sstevel@tonic-gate 			uval.int64_val = l;
1222*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
1223*7c478bd9Sstevel@tonic-gate 		}
1224*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1225*7c478bd9Sstevel@tonic-gate 	} else
1226*7c478bd9Sstevel@tonic-gate 		return (status);
1227*7c478bd9Sstevel@tonic-gate }
1228*7c478bd9Sstevel@tonic-gate 
1229*7c478bd9Sstevel@tonic-gate 
1230*7c478bd9Sstevel@tonic-gate /*
1231*7c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
1232*7c478bd9Sstevel@tonic-gate  * bu2string: Maps a print basic unit type to a string.
1233*7c478bd9Sstevel@tonic-gate  * returns  : The string mapping or "unknown basic unit type".
1234*7c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
1235*7c478bd9Sstevel@tonic-gate  */
1236*7c478bd9Sstevel@tonic-gate char *
1237*7c478bd9Sstevel@tonic-gate bu2string(char basic_unit)
1238*7c478bd9Sstevel@tonic-gate {
1239*7c478bd9Sstevel@tonic-gate 	register int	i;
1240*7c478bd9Sstevel@tonic-gate 
1241*7c478bd9Sstevel@tonic-gate 	struct bu_map_ent {
1242*7c478bd9Sstevel@tonic-gate 		char	basic_unit;
1243*7c478bd9Sstevel@tonic-gate 		char	*string;
1244*7c478bd9Sstevel@tonic-gate 	};
1245*7c478bd9Sstevel@tonic-gate 
1246*7c478bd9Sstevel@tonic-gate 	/*
1247*7c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
1248*7c478bd9Sstevel@tonic-gate 	 * These names are data units when displaying the arbitrary data
1249*7c478bd9Sstevel@tonic-gate 	 * token.
1250*7c478bd9Sstevel@tonic-gate 	 */
1251*7c478bd9Sstevel@tonic-gate 
1252*7c478bd9Sstevel@tonic-gate 	static struct bu_map_ent bu_map[] = {
1253*7c478bd9Sstevel@tonic-gate 				{ AUR_BYTE, "byte" },
1254*7c478bd9Sstevel@tonic-gate 				{ AUR_CHAR, "char" },
1255*7c478bd9Sstevel@tonic-gate 				{ AUR_SHORT, "short" },
1256*7c478bd9Sstevel@tonic-gate 				{ AUR_INT32, "int32" },
1257*7c478bd9Sstevel@tonic-gate 				{ AUR_INT64, "int64" } 	};
1258*7c478bd9Sstevel@tonic-gate 
1259*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < sizeof (bu_map) / sizeof (struct bu_map_ent); i++)
1260*7c478bd9Sstevel@tonic-gate 		if (basic_unit == bu_map[i].basic_unit)
1261*7c478bd9Sstevel@tonic-gate 			return (gettext(bu_map[i].string));
1262*7c478bd9Sstevel@tonic-gate 
1263*7c478bd9Sstevel@tonic-gate 	return (gettext("unknown basic unit type"));
1264*7c478bd9Sstevel@tonic-gate }
1265*7c478bd9Sstevel@tonic-gate 
1266*7c478bd9Sstevel@tonic-gate 
1267*7c478bd9Sstevel@tonic-gate /*
1268*7c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
1269*7c478bd9Sstevel@tonic-gate  * eventmodifier2string: Maps event modifier flags to a readable string.
1270*7c478bd9Sstevel@tonic-gate  * returns: The string mapping or "none".
1271*7c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
1272*7c478bd9Sstevel@tonic-gate  */
1273*7c478bd9Sstevel@tonic-gate static void
1274*7c478bd9Sstevel@tonic-gate eventmodifier2string(ushort_t emodifier, char *modstring, size_t modlen)
1275*7c478bd9Sstevel@tonic-gate {
1276*7c478bd9Sstevel@tonic-gate 	register int	i, j;
1277*7c478bd9Sstevel@tonic-gate 
1278*7c478bd9Sstevel@tonic-gate 	struct em_map_ent {
1279*7c478bd9Sstevel@tonic-gate 		int	mask;
1280*7c478bd9Sstevel@tonic-gate 		char	*string;
1281*7c478bd9Sstevel@tonic-gate 	};
1282*7c478bd9Sstevel@tonic-gate 
1283*7c478bd9Sstevel@tonic-gate 	/*
1284*7c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
1285*7c478bd9Sstevel@tonic-gate 	 * These abbreviations represent the event modifier field of the
1286*7c478bd9Sstevel@tonic-gate 	 * header token.  To gain a better understanding of each modifier,
1287*7c478bd9Sstevel@tonic-gate 	 * read the SunShield BSM Guide, part no. 802-1965-xx.
1288*7c478bd9Sstevel@tonic-gate 	 */
1289*7c478bd9Sstevel@tonic-gate 
1290*7c478bd9Sstevel@tonic-gate 	static struct em_map_ent em_map[] = {
1291*7c478bd9Sstevel@tonic-gate 		{ (int)PAD_READ,	"rd" },	/* data read from object */
1292*7c478bd9Sstevel@tonic-gate 		{ (int)PAD_WRITE,	"wr" },	/* data written to object */
1293*7c478bd9Sstevel@tonic-gate #ifdef TSOL
1294*7c478bd9Sstevel@tonic-gate 		{ (int)PAD_SPRIVUSE,	"sp" },	/* successfully used priv */
1295*7c478bd9Sstevel@tonic-gate 		{ (int)PAD_FPRIVUSE,	"fp" },	/* failed use of priv */
1296*7c478bd9Sstevel@tonic-gate #endif
1297*7c478bd9Sstevel@tonic-gate 		{ (int)PAD_NONATTR,	"na" },	/* non-attributable event */
1298*7c478bd9Sstevel@tonic-gate 		{ (int)PAD_FAILURE,	"fe" }	/* fail audit event */
1299*7c478bd9Sstevel@tonic-gate 	};
1300*7c478bd9Sstevel@tonic-gate 
1301*7c478bd9Sstevel@tonic-gate 	modstring[0] = '\0';
1302*7c478bd9Sstevel@tonic-gate 
1303*7c478bd9Sstevel@tonic-gate 	for (i = 0, j = 0; i < sizeof (em_map) / sizeof (struct em_map_ent);
1304*7c478bd9Sstevel@tonic-gate 	    i++) {
1305*7c478bd9Sstevel@tonic-gate 		if ((int)emodifier & em_map[i].mask) {
1306*7c478bd9Sstevel@tonic-gate 			if (j++)
1307*7c478bd9Sstevel@tonic-gate 				(void) strlcat(modstring, ":", modlen);
1308*7c478bd9Sstevel@tonic-gate 			(void) strlcat(modstring, em_map[i].string, modlen);
1309*7c478bd9Sstevel@tonic-gate 		}
1310*7c478bd9Sstevel@tonic-gate 	}
1311*7c478bd9Sstevel@tonic-gate }
1312*7c478bd9Sstevel@tonic-gate 
1313*7c478bd9Sstevel@tonic-gate 
1314*7c478bd9Sstevel@tonic-gate /*
1315*7c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------
1316*7c478bd9Sstevel@tonic-gate  * convert_char_to_string:
1317*7c478bd9Sstevel@tonic-gate  *   Converts a byte to string depending on the print mode
1318*7c478bd9Sstevel@tonic-gate  * input	: printmode, which may be one of AUP_BINARY,
1319*7c478bd9Sstevel@tonic-gate  *		  AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
1320*7c478bd9Sstevel@tonic-gate  *		  c, which is the byte to convert
1321*7c478bd9Sstevel@tonic-gate  * output	: p, which is a pointer to the location where
1322*7c478bd9Sstevel@tonic-gate  *		  the resulting string is to be stored
1323*7c478bd9Sstevel@tonic-gate  *  ----------------------------------------------------------
1324*7c478bd9Sstevel@tonic-gate  */
1325*7c478bd9Sstevel@tonic-gate 
1326*7c478bd9Sstevel@tonic-gate int
1327*7c478bd9Sstevel@tonic-gate convert_char_to_string(char printmode, char c, char *p)
1328*7c478bd9Sstevel@tonic-gate {
1329*7c478bd9Sstevel@tonic-gate 	union {
1330*7c478bd9Sstevel@tonic-gate 		char	c1[4];
1331*7c478bd9Sstevel@tonic-gate 		int	c2;
1332*7c478bd9Sstevel@tonic-gate 	} dat;
1333*7c478bd9Sstevel@tonic-gate 
1334*7c478bd9Sstevel@tonic-gate 	dat.c2 = 0;
1335*7c478bd9Sstevel@tonic-gate 	dat.c1[3] = c;
1336*7c478bd9Sstevel@tonic-gate 
1337*7c478bd9Sstevel@tonic-gate 	if (printmode == AUP_BINARY)
1338*7c478bd9Sstevel@tonic-gate 		(void) convertbinary(p, &c, sizeof (char));
1339*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_OCTAL)
1340*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%o", (int)dat.c2);
1341*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_DECIMAL)
1342*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%d", c);
1343*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_HEX)
1344*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "0x%x", (int)dat.c2);
1345*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_STRING)
1346*7c478bd9Sstevel@tonic-gate 		convertascii(p, &c, sizeof (char));
1347*7c478bd9Sstevel@tonic-gate 	return (0);
1348*7c478bd9Sstevel@tonic-gate }
1349*7c478bd9Sstevel@tonic-gate 
1350*7c478bd9Sstevel@tonic-gate /*
1351*7c478bd9Sstevel@tonic-gate  * --------------------------------------------------------------
1352*7c478bd9Sstevel@tonic-gate  * convert_short_to_string:
1353*7c478bd9Sstevel@tonic-gate  * Converts a short integer to string depending on the print mode
1354*7c478bd9Sstevel@tonic-gate  * input	: printmode, which may be one of AUP_BINARY,
1355*7c478bd9Sstevel@tonic-gate  *		AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
1356*7c478bd9Sstevel@tonic-gate  *		c, which is the short integer to convert
1357*7c478bd9Sstevel@tonic-gate  * output	: p, which is a pointer to the location where
1358*7c478bd9Sstevel@tonic-gate  *		the resulting string is to be stored
1359*7c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------------
1360*7c478bd9Sstevel@tonic-gate  */
1361*7c478bd9Sstevel@tonic-gate int
1362*7c478bd9Sstevel@tonic-gate convert_short_to_string(char printmode, short c, char *p)
1363*7c478bd9Sstevel@tonic-gate {
1364*7c478bd9Sstevel@tonic-gate 	union {
1365*7c478bd9Sstevel@tonic-gate 		short	c1[2];
1366*7c478bd9Sstevel@tonic-gate 		int	c2;
1367*7c478bd9Sstevel@tonic-gate 	} dat;
1368*7c478bd9Sstevel@tonic-gate 
1369*7c478bd9Sstevel@tonic-gate 	dat.c2 = 0;
1370*7c478bd9Sstevel@tonic-gate 	dat.c1[1] = c;
1371*7c478bd9Sstevel@tonic-gate 
1372*7c478bd9Sstevel@tonic-gate 	if (printmode == AUP_BINARY)
1373*7c478bd9Sstevel@tonic-gate 		(void) convertbinary(p, (char *)&c, sizeof (short));
1374*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_OCTAL)
1375*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%o", (int)dat.c2);
1376*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_DECIMAL)
1377*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%hd", c);
1378*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_HEX)
1379*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "0x%x", (int)dat.c2);
1380*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_STRING)
1381*7c478bd9Sstevel@tonic-gate 		convertascii(p, (char *)&c, sizeof (short));
1382*7c478bd9Sstevel@tonic-gate 	return (0);
1383*7c478bd9Sstevel@tonic-gate }
1384*7c478bd9Sstevel@tonic-gate 
1385*7c478bd9Sstevel@tonic-gate /*
1386*7c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------
1387*7c478bd9Sstevel@tonic-gate  * convert_int32_to_string:
1388*7c478bd9Sstevel@tonic-gate  * Converts a integer to string depending on the print mode
1389*7c478bd9Sstevel@tonic-gate  * input	: printmode, which may be one of AUP_BINARY,
1390*7c478bd9Sstevel@tonic-gate  *		AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
1391*7c478bd9Sstevel@tonic-gate  *		c, which is the integer to convert
1392*7c478bd9Sstevel@tonic-gate  * output	: p, which is a pointer to the location where
1393*7c478bd9Sstevel@tonic-gate  *		the resulting string is to be stored
1394*7c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------
1395*7c478bd9Sstevel@tonic-gate  */
1396*7c478bd9Sstevel@tonic-gate int
1397*7c478bd9Sstevel@tonic-gate convert_int32_to_string(char printmode, int32_t c, char *p)
1398*7c478bd9Sstevel@tonic-gate {
1399*7c478bd9Sstevel@tonic-gate 	if (printmode == AUP_BINARY)
1400*7c478bd9Sstevel@tonic-gate 		(void) convertbinary(p, (char *)&c, sizeof (int32_t));
1401*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_OCTAL)
1402*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%o", c);
1403*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_DECIMAL)
1404*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%d", c);
1405*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_HEX)
1406*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "0x%x", c);
1407*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_STRING)
1408*7c478bd9Sstevel@tonic-gate 		convertascii(p, (char *)&c, sizeof (int));
1409*7c478bd9Sstevel@tonic-gate 	return (0);
1410*7c478bd9Sstevel@tonic-gate }
1411*7c478bd9Sstevel@tonic-gate 
1412*7c478bd9Sstevel@tonic-gate /*
1413*7c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------
1414*7c478bd9Sstevel@tonic-gate  * convert_int64_to_string:
1415*7c478bd9Sstevel@tonic-gate  * Converts a integer to string depending on the print mode
1416*7c478bd9Sstevel@tonic-gate  * input	: printmode, which may be one of AUP_BINARY,
1417*7c478bd9Sstevel@tonic-gate  *		AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
1418*7c478bd9Sstevel@tonic-gate  *		c, which is the integer to convert
1419*7c478bd9Sstevel@tonic-gate  * output	: p, which is a pointer to the location where
1420*7c478bd9Sstevel@tonic-gate  *		the resulting string is to be stored
1421*7c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------
1422*7c478bd9Sstevel@tonic-gate  */
1423*7c478bd9Sstevel@tonic-gate int
1424*7c478bd9Sstevel@tonic-gate convert_int64_to_string(char printmode, int64_t c, char *p)
1425*7c478bd9Sstevel@tonic-gate {
1426*7c478bd9Sstevel@tonic-gate 	if (printmode == AUP_BINARY)
1427*7c478bd9Sstevel@tonic-gate 		(void) convertbinary(p, (char *)&c, sizeof (int64_t));
1428*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_OCTAL)
1429*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%"PRIo64, c);
1430*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_DECIMAL)
1431*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%"PRId64, c);
1432*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_HEX)
1433*7c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "0x%"PRIx64, c);
1434*7c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_STRING)
1435*7c478bd9Sstevel@tonic-gate 		convertascii(p, (char *)&c, sizeof (int64_t));
1436*7c478bd9Sstevel@tonic-gate 	return (0);
1437*7c478bd9Sstevel@tonic-gate }
1438*7c478bd9Sstevel@tonic-gate 
1439*7c478bd9Sstevel@tonic-gate 
1440*7c478bd9Sstevel@tonic-gate /*
1441*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------
1442*7c478bd9Sstevel@tonic-gate  * convertbinary:
1443*7c478bd9Sstevel@tonic-gate  * Converts a unit c of 'size' bytes long into a binary string
1444*7c478bd9Sstevel@tonic-gate  * and returns it into the position pointed to by p
1445*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
1446*7c478bd9Sstevel@tonic-gate  */
1447*7c478bd9Sstevel@tonic-gate int
1448*7c478bd9Sstevel@tonic-gate convertbinary(char *p, char *c, int size)
1449*7c478bd9Sstevel@tonic-gate {
1450*7c478bd9Sstevel@tonic-gate 	char	*s, *t, *ss;
1451*7c478bd9Sstevel@tonic-gate 	int	i, j;
1452*7c478bd9Sstevel@tonic-gate 
1453*7c478bd9Sstevel@tonic-gate 	if ((s = (char *)malloc(8 * size + 1)) == NULL)
1454*7c478bd9Sstevel@tonic-gate 		return (0);
1455*7c478bd9Sstevel@tonic-gate 
1456*7c478bd9Sstevel@tonic-gate 	ss = s;
1457*7c478bd9Sstevel@tonic-gate 
1458*7c478bd9Sstevel@tonic-gate 	/* first convert to binary */
1459*7c478bd9Sstevel@tonic-gate 	t = s;
1460*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
1461*7c478bd9Sstevel@tonic-gate 		for (j = 0; j < 8; j++)
1462*7c478bd9Sstevel@tonic-gate 			(void) sprintf(t++, "%d", ((*c >> (7 - j)) & (0x01)));
1463*7c478bd9Sstevel@tonic-gate 		c++;
1464*7c478bd9Sstevel@tonic-gate 	}
1465*7c478bd9Sstevel@tonic-gate 	*t = '\0';
1466*7c478bd9Sstevel@tonic-gate 
1467*7c478bd9Sstevel@tonic-gate 	/* now string leading zero's if any */
1468*7c478bd9Sstevel@tonic-gate 	j = strlen(s) - 1;
1469*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < j; i++) {
1470*7c478bd9Sstevel@tonic-gate 		if (*s != '0')
1471*7c478bd9Sstevel@tonic-gate 			break;
1472*7c478bd9Sstevel@tonic-gate 			else
1473*7c478bd9Sstevel@tonic-gate 			s++;
1474*7c478bd9Sstevel@tonic-gate 	}
1475*7c478bd9Sstevel@tonic-gate 
1476*7c478bd9Sstevel@tonic-gate 	/* now copy the contents of s to p */
1477*7c478bd9Sstevel@tonic-gate 	t = p;
1478*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < (8 * size + 1); i++) {
1479*7c478bd9Sstevel@tonic-gate 		if (*s == '\0') {
1480*7c478bd9Sstevel@tonic-gate 			*t = '\0';
1481*7c478bd9Sstevel@tonic-gate 			break;
1482*7c478bd9Sstevel@tonic-gate 		}
1483*7c478bd9Sstevel@tonic-gate 		*t++ = *s++;
1484*7c478bd9Sstevel@tonic-gate 	}
1485*7c478bd9Sstevel@tonic-gate 	free(ss);
1486*7c478bd9Sstevel@tonic-gate 
1487*7c478bd9Sstevel@tonic-gate 	return (1);
1488*7c478bd9Sstevel@tonic-gate }
1489*7c478bd9Sstevel@tonic-gate 
1490*7c478bd9Sstevel@tonic-gate 
1491*7c478bd9Sstevel@tonic-gate static char hex[] = "0123456789abcdef";
1492*7c478bd9Sstevel@tonic-gate /*
1493*7c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
1494*7c478bd9Sstevel@tonic-gate  * hexconvert	: Converts a string of (size) bytes to hexadecimal, and
1495*7c478bd9Sstevel@tonic-gate  *		returns the hexadecimal string.
1496*7c478bd9Sstevel@tonic-gate  * returns	: - NULL if memory cannot be allocated for the string, or
1497*7c478bd9Sstevel@tonic-gate  *		- pointer to the hexadecimal string if successful
1498*7c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
1499*7c478bd9Sstevel@tonic-gate  */
1500*7c478bd9Sstevel@tonic-gate char *
1501*7c478bd9Sstevel@tonic-gate hexconvert(char *c, int size, int chunk)
1502*7c478bd9Sstevel@tonic-gate {
1503*7c478bd9Sstevel@tonic-gate 	register char	*s, *t;
1504*7c478bd9Sstevel@tonic-gate 	register int	i, j, k;
1505*7c478bd9Sstevel@tonic-gate 	int	numchunks;
1506*7c478bd9Sstevel@tonic-gate 	int	leftovers;
1507*7c478bd9Sstevel@tonic-gate 
1508*7c478bd9Sstevel@tonic-gate 	if (size <= 0)
1509*7c478bd9Sstevel@tonic-gate 		return (NULL);
1510*7c478bd9Sstevel@tonic-gate 
1511*7c478bd9Sstevel@tonic-gate 	if ((s = (char *)malloc((size * 5) + 1)) == NULL)
1512*7c478bd9Sstevel@tonic-gate 		return (NULL);
1513*7c478bd9Sstevel@tonic-gate 
1514*7c478bd9Sstevel@tonic-gate 	if (chunk > size || chunk <= 0)
1515*7c478bd9Sstevel@tonic-gate 		chunk = size;
1516*7c478bd9Sstevel@tonic-gate 
1517*7c478bd9Sstevel@tonic-gate 	numchunks = size / chunk;
1518*7c478bd9Sstevel@tonic-gate 	leftovers = size % chunk;
1519*7c478bd9Sstevel@tonic-gate 
1520*7c478bd9Sstevel@tonic-gate 	t = s;
1521*7c478bd9Sstevel@tonic-gate 	for (i = j = 0; i < numchunks; i++) {
1522*7c478bd9Sstevel@tonic-gate 		if (j++) {
1523*7c478bd9Sstevel@tonic-gate 			*t++ = ' ';
1524*7c478bd9Sstevel@tonic-gate 		}
1525*7c478bd9Sstevel@tonic-gate 		*t++ = '0';
1526*7c478bd9Sstevel@tonic-gate 		*t++ = 'x';
1527*7c478bd9Sstevel@tonic-gate 		for (k = 0; k < chunk; k++) {
1528*7c478bd9Sstevel@tonic-gate 			*t++ = hex[(uint_t)((uchar_t)*c >> 4)];
1529*7c478bd9Sstevel@tonic-gate 			*t++ = hex[(uint_t)((uchar_t)*c & 0xF)];
1530*7c478bd9Sstevel@tonic-gate 			c++;
1531*7c478bd9Sstevel@tonic-gate 		}
1532*7c478bd9Sstevel@tonic-gate 	}
1533*7c478bd9Sstevel@tonic-gate 
1534*7c478bd9Sstevel@tonic-gate 	if (leftovers) {
1535*7c478bd9Sstevel@tonic-gate 		*t++ = ' ';
1536*7c478bd9Sstevel@tonic-gate 		*t++ = '0';
1537*7c478bd9Sstevel@tonic-gate 		*t++ = 'x';
1538*7c478bd9Sstevel@tonic-gate 		for (i = 0; i < leftovers; i++) {
1539*7c478bd9Sstevel@tonic-gate 			*t++ = hex[(uint_t)((uchar_t)*c >> 4)];
1540*7c478bd9Sstevel@tonic-gate 			*t++ = hex[(uint_t)((uchar_t)*c & 0xF)];
1541*7c478bd9Sstevel@tonic-gate 			c++;
1542*7c478bd9Sstevel@tonic-gate 		}
1543*7c478bd9Sstevel@tonic-gate 	}
1544*7c478bd9Sstevel@tonic-gate 
1545*7c478bd9Sstevel@tonic-gate 	*t = '\0';
1546*7c478bd9Sstevel@tonic-gate 	return (s);
1547*7c478bd9Sstevel@tonic-gate }
1548*7c478bd9Sstevel@tonic-gate 
1549*7c478bd9Sstevel@tonic-gate 
1550*7c478bd9Sstevel@tonic-gate /*
1551*7c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
1552*7c478bd9Sstevel@tonic-gate  * htp2string: Maps a print suggestion to a string.
1553*7c478bd9Sstevel@tonic-gate  * returns   : The string mapping or "unknown print suggestion".
1554*7c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
1555*7c478bd9Sstevel@tonic-gate  */
1556*7c478bd9Sstevel@tonic-gate char *
1557*7c478bd9Sstevel@tonic-gate htp2string(char print_sugg)
1558*7c478bd9Sstevel@tonic-gate {
1559*7c478bd9Sstevel@tonic-gate 	register int	i;
1560*7c478bd9Sstevel@tonic-gate 
1561*7c478bd9Sstevel@tonic-gate 	struct htp_map_ent {
1562*7c478bd9Sstevel@tonic-gate 		char	print_sugg;
1563*7c478bd9Sstevel@tonic-gate 		char	*print_string;
1564*7c478bd9Sstevel@tonic-gate 	};
1565*7c478bd9Sstevel@tonic-gate 
1566*7c478bd9Sstevel@tonic-gate 	/*
1567*7c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
1568*7c478bd9Sstevel@tonic-gate 	 * These names are data types when displaying the arbitrary data
1569*7c478bd9Sstevel@tonic-gate 	 * token.
1570*7c478bd9Sstevel@tonic-gate 	 */
1571*7c478bd9Sstevel@tonic-gate 
1572*7c478bd9Sstevel@tonic-gate 	static struct htp_map_ent htp_map[] = {
1573*7c478bd9Sstevel@tonic-gate 				{ AUP_BINARY, "binary" },
1574*7c478bd9Sstevel@tonic-gate 				{ AUP_OCTAL, "octal" },
1575*7c478bd9Sstevel@tonic-gate 				{ AUP_DECIMAL, "decimal" },
1576*7c478bd9Sstevel@tonic-gate 				{ AUP_HEX, "hexadecimal" },
1577*7c478bd9Sstevel@tonic-gate 				{ AUP_STRING, "string" } 	};
1578*7c478bd9Sstevel@tonic-gate 
1579*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < sizeof (htp_map) / sizeof (struct htp_map_ent); i++)
1580*7c478bd9Sstevel@tonic-gate 		if (print_sugg == htp_map[i].print_sugg)
1581*7c478bd9Sstevel@tonic-gate 			return (gettext(htp_map[i].print_string));
1582*7c478bd9Sstevel@tonic-gate 
1583*7c478bd9Sstevel@tonic-gate 	return (gettext("unknown print suggestion"));
1584*7c478bd9Sstevel@tonic-gate }
1585*7c478bd9Sstevel@tonic-gate 
1586*7c478bd9Sstevel@tonic-gate /*
1587*7c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------------
1588*7c478bd9Sstevel@tonic-gate  * pa_adr_short: Issues pr_adr_short to retrieve the next ADR item from the
1589*7c478bd9Sstevel@tonic-gate  *		input stream pointed to by audit_adr, and prints it
1590*7c478bd9Sstevel@tonic-gate  *		if status >= 0
1591*7c478bd9Sstevel@tonic-gate  * return codes: -1 - error
1592*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1593*7c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------------
1594*7c478bd9Sstevel@tonic-gate  */
1595*7c478bd9Sstevel@tonic-gate int
1596*7c478bd9Sstevel@tonic-gate pa_adr_short(pr_context_t *context, int status, int flag)
1597*7c478bd9Sstevel@tonic-gate {
1598*7c478bd9Sstevel@tonic-gate 	short	c;
1599*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1600*7c478bd9Sstevel@tonic-gate 
1601*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1602*7c478bd9Sstevel@tonic-gate 		if (pr_adr_short(context, &c, 1) == 0) {
1603*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_SHORT;
1604*7c478bd9Sstevel@tonic-gate 			uval.short_val = c;
1605*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
1606*7c478bd9Sstevel@tonic-gate 		} else
1607*7c478bd9Sstevel@tonic-gate 			return (-1);
1608*7c478bd9Sstevel@tonic-gate 	} else
1609*7c478bd9Sstevel@tonic-gate 		return (status);
1610*7c478bd9Sstevel@tonic-gate }
1611*7c478bd9Sstevel@tonic-gate 
1612*7c478bd9Sstevel@tonic-gate /*
1613*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1614*7c478bd9Sstevel@tonic-gate  * pa_adr_shorthex: Issues pr_adr_short to retrieve the next ADR item from the
1615*7c478bd9Sstevel@tonic-gate  *			input stream pointed to by audit_adr, and prints it
1616*7c478bd9Sstevel@tonic-gate  *			in hexadecimal if status >= 0
1617*7c478bd9Sstevel@tonic-gate  * return codes  : -1 - error
1618*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1619*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1620*7c478bd9Sstevel@tonic-gate  */
1621*7c478bd9Sstevel@tonic-gate int
1622*7c478bd9Sstevel@tonic-gate pa_adr_shorthex(pr_context_t *context, int status, int flag)
1623*7c478bd9Sstevel@tonic-gate {
1624*7c478bd9Sstevel@tonic-gate 	short	s;
1625*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1626*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1627*7c478bd9Sstevel@tonic-gate 
1628*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1629*7c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_short(context, &s, 1)) == 0) {
1630*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
1631*7c478bd9Sstevel@tonic-gate 			uval.string_val = hexconvert((char *)&s, sizeof (s),
1632*7c478bd9Sstevel@tonic-gate 			    sizeof (s));
1633*7c478bd9Sstevel@tonic-gate 			if (uval.string_val) {
1634*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
1635*7c478bd9Sstevel@tonic-gate 				free(uval.string_val);
1636*7c478bd9Sstevel@tonic-gate 			}
1637*7c478bd9Sstevel@tonic-gate 		}
1638*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1639*7c478bd9Sstevel@tonic-gate 	} else
1640*7c478bd9Sstevel@tonic-gate 		return (status);
1641*7c478bd9Sstevel@tonic-gate }
1642*7c478bd9Sstevel@tonic-gate 
1643*7c478bd9Sstevel@tonic-gate 
1644*7c478bd9Sstevel@tonic-gate /*
1645*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1646*7c478bd9Sstevel@tonic-gate  * pa_adr_string: Retrieves a string from the input stream and prints it
1647*7c478bd9Sstevel@tonic-gate  *		  if status >= 0
1648*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1649*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1650*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1651*7c478bd9Sstevel@tonic-gate  */
1652*7c478bd9Sstevel@tonic-gate int
1653*7c478bd9Sstevel@tonic-gate pa_adr_string(pr_context_t *context, int status, int flag)
1654*7c478bd9Sstevel@tonic-gate {
1655*7c478bd9Sstevel@tonic-gate 	char	*c;
1656*7c478bd9Sstevel@tonic-gate 	char	*p;
1657*7c478bd9Sstevel@tonic-gate 	short	length;
1658*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1659*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1660*7c478bd9Sstevel@tonic-gate 
1661*7c478bd9Sstevel@tonic-gate 	/*
1662*7c478bd9Sstevel@tonic-gate 	 * We need to know how much space to allocate for our string, so
1663*7c478bd9Sstevel@tonic-gate 	 * read the length first, then call pr_adr_char to read those bytes.
1664*7c478bd9Sstevel@tonic-gate 	 */
1665*7c478bd9Sstevel@tonic-gate 	if (status < 0)
1666*7c478bd9Sstevel@tonic-gate 		return (status);
1667*7c478bd9Sstevel@tonic-gate 
1668*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_short(context, &length, 1)) != 0)
1669*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1670*7c478bd9Sstevel@tonic-gate 	if ((c = (char *)malloc(length + 1)) == NULL)
1671*7c478bd9Sstevel@tonic-gate 		return (-1);
1672*7c478bd9Sstevel@tonic-gate 	if ((p = (char *)malloc((length * 2) + 1)) == NULL) {
1673*7c478bd9Sstevel@tonic-gate 		free(c);
1674*7c478bd9Sstevel@tonic-gate 		return (-1);
1675*7c478bd9Sstevel@tonic-gate 	}
1676*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, c, length)) != 0) {
1677*7c478bd9Sstevel@tonic-gate 		free(c);
1678*7c478bd9Sstevel@tonic-gate 		free(p);
1679*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1680*7c478bd9Sstevel@tonic-gate 	}
1681*7c478bd9Sstevel@tonic-gate 	convertascii(p, c, length - 1);
1682*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
1683*7c478bd9Sstevel@tonic-gate 	uval.string_val = p;
1684*7c478bd9Sstevel@tonic-gate 	returnstat = pa_print(context, &uval, flag);
1685*7c478bd9Sstevel@tonic-gate 	free(c);
1686*7c478bd9Sstevel@tonic-gate 	free(p);
1687*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1688*7c478bd9Sstevel@tonic-gate }
1689*7c478bd9Sstevel@tonic-gate 
1690*7c478bd9Sstevel@tonic-gate /*
1691*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1692*7c478bd9Sstevel@tonic-gate  * pa_file_string: Retrieves a file string from the input stream and prints it
1693*7c478bd9Sstevel@tonic-gate  *		  if status >= 0
1694*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1695*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1696*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1697*7c478bd9Sstevel@tonic-gate  */
1698*7c478bd9Sstevel@tonic-gate int
1699*7c478bd9Sstevel@tonic-gate pa_file_string(pr_context_t *context, int status, int flag)
1700*7c478bd9Sstevel@tonic-gate {
1701*7c478bd9Sstevel@tonic-gate 	char	*c;
1702*7c478bd9Sstevel@tonic-gate 	char	*p;
1703*7c478bd9Sstevel@tonic-gate 	short	length;
1704*7c478bd9Sstevel@tonic-gate 	int	returnstat;
1705*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1706*7c478bd9Sstevel@tonic-gate 
1707*7c478bd9Sstevel@tonic-gate 	/*
1708*7c478bd9Sstevel@tonic-gate 	 * We need to know how much space to allocate for our string, so
1709*7c478bd9Sstevel@tonic-gate 	 * read the length first, then call pr_adr_char to read those bytes.
1710*7c478bd9Sstevel@tonic-gate 	 */
1711*7c478bd9Sstevel@tonic-gate 	if (status < 0)
1712*7c478bd9Sstevel@tonic-gate 		return (status);
1713*7c478bd9Sstevel@tonic-gate 
1714*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_short(context, &length, 1)) != 0)
1715*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1716*7c478bd9Sstevel@tonic-gate 	if ((c = (char *)malloc(length + 1)) == NULL)
1717*7c478bd9Sstevel@tonic-gate 		return (-1);
1718*7c478bd9Sstevel@tonic-gate 	if ((p = (char *)malloc((length * 2) + 1)) == NULL) {
1719*7c478bd9Sstevel@tonic-gate 		free(c);
1720*7c478bd9Sstevel@tonic-gate 		return (-1);
1721*7c478bd9Sstevel@tonic-gate 	}
1722*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, c, length)) != 0) {
1723*7c478bd9Sstevel@tonic-gate 		free(c);
1724*7c478bd9Sstevel@tonic-gate 		free(p);
1725*7c478bd9Sstevel@tonic-gate 		return (returnstat);
1726*7c478bd9Sstevel@tonic-gate 	}
1727*7c478bd9Sstevel@tonic-gate 
1728*7c478bd9Sstevel@tonic-gate 	if (is_file_token(context->tokenid))
1729*7c478bd9Sstevel@tonic-gate 		context->audit_rec_len += length;
1730*7c478bd9Sstevel@tonic-gate 
1731*7c478bd9Sstevel@tonic-gate 	convertascii(p, c, length - 1);
1732*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
1733*7c478bd9Sstevel@tonic-gate 	uval.string_val = p;
1734*7c478bd9Sstevel@tonic-gate 
1735*7c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
1736*7c478bd9Sstevel@tonic-gate 		returnstat = finish_open_tag(context);
1737*7c478bd9Sstevel@tonic-gate 
1738*7c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
1739*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
1740*7c478bd9Sstevel@tonic-gate 
1741*7c478bd9Sstevel@tonic-gate 	free(c);
1742*7c478bd9Sstevel@tonic-gate 	free(p);
1743*7c478bd9Sstevel@tonic-gate 	return (returnstat);
1744*7c478bd9Sstevel@tonic-gate }
1745*7c478bd9Sstevel@tonic-gate 
1746*7c478bd9Sstevel@tonic-gate static int
1747*7c478bd9Sstevel@tonic-gate pa_putstr_xml(pr_context_t *context, int printable, char *str, size_t len)
1748*7c478bd9Sstevel@tonic-gate {
1749*7c478bd9Sstevel@tonic-gate 	int	err;
1750*7c478bd9Sstevel@tonic-gate 
1751*7c478bd9Sstevel@tonic-gate 	if (!printable) {
1752*7c478bd9Sstevel@tonic-gate 		/*
1753*7c478bd9Sstevel@tonic-gate 		 * Unprintable chars should always be converted to the
1754*7c478bd9Sstevel@tonic-gate 		 * visible form. If there are unprintable characters which
1755*7c478bd9Sstevel@tonic-gate 		 * require special treatment in xml, those should be
1756*7c478bd9Sstevel@tonic-gate 		 * handled here.
1757*7c478bd9Sstevel@tonic-gate 		 */
1758*7c478bd9Sstevel@tonic-gate 		do {
1759*7c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "\\%03o",
1760*7c478bd9Sstevel@tonic-gate 				(unsigned char)*str++);
1761*7c478bd9Sstevel@tonic-gate 		} while (err == 0 && --len != 0);
1762*7c478bd9Sstevel@tonic-gate 		return (err);
1763*7c478bd9Sstevel@tonic-gate 	}
1764*7c478bd9Sstevel@tonic-gate 	/* printable characters */
1765*7c478bd9Sstevel@tonic-gate 	if (len == 1) {
1766*7c478bd9Sstevel@tonic-gate 		/*
1767*7c478bd9Sstevel@tonic-gate 		 * check for the special chars only when char size was 1
1768*7c478bd9Sstevel@tonic-gate 		 * ie, ignore special chars appear in the middle of multibyte
1769*7c478bd9Sstevel@tonic-gate 		 * sequence.
1770*7c478bd9Sstevel@tonic-gate 		 */
1771*7c478bd9Sstevel@tonic-gate 
1772*7c478bd9Sstevel@tonic-gate 		/* Escape for XML */
1773*7c478bd9Sstevel@tonic-gate 		switch (*str) {
1774*7c478bd9Sstevel@tonic-gate 		case '&':
1775*7c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&amp;");
1776*7c478bd9Sstevel@tonic-gate 			break;
1777*7c478bd9Sstevel@tonic-gate 
1778*7c478bd9Sstevel@tonic-gate 		case '<':
1779*7c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&lt;");
1780*7c478bd9Sstevel@tonic-gate 			break;
1781*7c478bd9Sstevel@tonic-gate 
1782*7c478bd9Sstevel@tonic-gate 		case '>':
1783*7c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&gt;");
1784*7c478bd9Sstevel@tonic-gate 			break;
1785*7c478bd9Sstevel@tonic-gate 
1786*7c478bd9Sstevel@tonic-gate 		case '\"':
1787*7c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&quot;");
1788*7c478bd9Sstevel@tonic-gate 			break;
1789*7c478bd9Sstevel@tonic-gate 
1790*7c478bd9Sstevel@tonic-gate 		case '\'':
1791*7c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&apos;");
1792*7c478bd9Sstevel@tonic-gate 			break;
1793*7c478bd9Sstevel@tonic-gate 
1794*7c478bd9Sstevel@tonic-gate 		default:
1795*7c478bd9Sstevel@tonic-gate 			err = pr_putchar(context, *str);
1796*7c478bd9Sstevel@tonic-gate 			break;
1797*7c478bd9Sstevel@tonic-gate 		}
1798*7c478bd9Sstevel@tonic-gate 		return (err);
1799*7c478bd9Sstevel@tonic-gate 	}
1800*7c478bd9Sstevel@tonic-gate 	do {
1801*7c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, *str++);
1802*7c478bd9Sstevel@tonic-gate 	} while (err == 0 && --len != 0);
1803*7c478bd9Sstevel@tonic-gate 	return (err);
1804*7c478bd9Sstevel@tonic-gate }
1805*7c478bd9Sstevel@tonic-gate 
1806*7c478bd9Sstevel@tonic-gate static int
1807*7c478bd9Sstevel@tonic-gate pa_putstr(pr_context_t *context, int printable, char *str, size_t len)
1808*7c478bd9Sstevel@tonic-gate {
1809*7c478bd9Sstevel@tonic-gate 	int	err;
1810*7c478bd9Sstevel@tonic-gate 
1811*7c478bd9Sstevel@tonic-gate 	if (context->format & PRF_XMLM)
1812*7c478bd9Sstevel@tonic-gate 		return (pa_putstr_xml(context, printable, str, len));
1813*7c478bd9Sstevel@tonic-gate 
1814*7c478bd9Sstevel@tonic-gate 	if (!printable) {
1815*7c478bd9Sstevel@tonic-gate 		do {
1816*7c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "\\%03o",
1817*7c478bd9Sstevel@tonic-gate 				(unsigned char)*str++);
1818*7c478bd9Sstevel@tonic-gate 		} while (err == 0 && --len != 0);
1819*7c478bd9Sstevel@tonic-gate 		return (err);
1820*7c478bd9Sstevel@tonic-gate 	}
1821*7c478bd9Sstevel@tonic-gate 	do {
1822*7c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, *str++);
1823*7c478bd9Sstevel@tonic-gate 	} while (err == 0 && --len != 0);
1824*7c478bd9Sstevel@tonic-gate 	return (err);
1825*7c478bd9Sstevel@tonic-gate }
1826*7c478bd9Sstevel@tonic-gate 
1827*7c478bd9Sstevel@tonic-gate int
1828*7c478bd9Sstevel@tonic-gate pa_string(pr_context_t *context, int status, int flag)
1829*7c478bd9Sstevel@tonic-gate {
1830*7c478bd9Sstevel@tonic-gate 	int	rstat, wstat;
1831*7c478bd9Sstevel@tonic-gate 	int	i, printable, eos;
1832*7c478bd9Sstevel@tonic-gate 	int	mlen, rlen;
1833*7c478bd9Sstevel@tonic-gate 	int	mbmax = MB_CUR_MAX;
1834*7c478bd9Sstevel@tonic-gate 	wchar_t	wc;
1835*7c478bd9Sstevel@tonic-gate 	char	mbuf[MB_LEN_MAX + 1];
1836*7c478bd9Sstevel@tonic-gate 	char	c;
1837*7c478bd9Sstevel@tonic-gate 
1838*7c478bd9Sstevel@tonic-gate 	if (status < 0)
1839*7c478bd9Sstevel@tonic-gate 		return (status);
1840*7c478bd9Sstevel@tonic-gate 
1841*7c478bd9Sstevel@tonic-gate 	rstat = wstat = 0;
1842*7c478bd9Sstevel@tonic-gate 
1843*7c478bd9Sstevel@tonic-gate 	if (mbmax == 1) {
1844*7c478bd9Sstevel@tonic-gate 		while (wstat == 0) {
1845*7c478bd9Sstevel@tonic-gate 			if ((rstat = pr_adr_char(context, &c, 1)) < 0)
1846*7c478bd9Sstevel@tonic-gate 				break;
1847*7c478bd9Sstevel@tonic-gate 			if (c == '\0')
1848*7c478bd9Sstevel@tonic-gate 				break;
1849*7c478bd9Sstevel@tonic-gate 			printable = isprint((unsigned char)c);
1850*7c478bd9Sstevel@tonic-gate 			wstat = pa_putstr(context, printable, &c, 1);
1851*7c478bd9Sstevel@tonic-gate 		}
1852*7c478bd9Sstevel@tonic-gate 		goto done;
1853*7c478bd9Sstevel@tonic-gate 	}
1854*7c478bd9Sstevel@tonic-gate 
1855*7c478bd9Sstevel@tonic-gate 	mlen = eos = 0;
1856*7c478bd9Sstevel@tonic-gate 	while (wstat == 0) {
1857*7c478bd9Sstevel@tonic-gate 		rlen = 0;
1858*7c478bd9Sstevel@tonic-gate 		do {
1859*7c478bd9Sstevel@tonic-gate 			if (!eos) {
1860*7c478bd9Sstevel@tonic-gate 				rstat = pr_adr_char(context, &c, 1);
1861*7c478bd9Sstevel@tonic-gate 				if (rstat != 0 || c == '\0')
1862*7c478bd9Sstevel@tonic-gate 					eos = 1;
1863*7c478bd9Sstevel@tonic-gate 				else
1864*7c478bd9Sstevel@tonic-gate 					mbuf[mlen++] = c;
1865*7c478bd9Sstevel@tonic-gate 			}
1866*7c478bd9Sstevel@tonic-gate 			rlen = mbtowc(&wc, mbuf, mlen);
1867*7c478bd9Sstevel@tonic-gate 		} while (!eos && mlen < mbmax && rlen <= 0);
1868*7c478bd9Sstevel@tonic-gate 
1869*7c478bd9Sstevel@tonic-gate 		if (mlen == 0)
1870*7c478bd9Sstevel@tonic-gate 			break;	/* end of string */
1871*7c478bd9Sstevel@tonic-gate 
1872*7c478bd9Sstevel@tonic-gate 		if (rlen <= 0) { /* no good sequence */
1873*7c478bd9Sstevel@tonic-gate 			rlen = 1;
1874*7c478bd9Sstevel@tonic-gate 			printable = 0;
1875*7c478bd9Sstevel@tonic-gate 		} else {
1876*7c478bd9Sstevel@tonic-gate 			printable = iswprint(wc);
1877*7c478bd9Sstevel@tonic-gate 		}
1878*7c478bd9Sstevel@tonic-gate 		wstat = pa_putstr(context, printable, mbuf, rlen);
1879*7c478bd9Sstevel@tonic-gate 		mlen -= rlen;
1880*7c478bd9Sstevel@tonic-gate 		if (mlen > 0) {
1881*7c478bd9Sstevel@tonic-gate 			for (i = 0; i < mlen; i++)
1882*7c478bd9Sstevel@tonic-gate 				mbuf[i] = mbuf[rlen + i];
1883*7c478bd9Sstevel@tonic-gate 		}
1884*7c478bd9Sstevel@tonic-gate 	}
1885*7c478bd9Sstevel@tonic-gate 
1886*7c478bd9Sstevel@tonic-gate done:
1887*7c478bd9Sstevel@tonic-gate 	if (wstat == 0)
1888*7c478bd9Sstevel@tonic-gate 		wstat = do_newline(context, flag);
1889*7c478bd9Sstevel@tonic-gate 
1890*7c478bd9Sstevel@tonic-gate 	if (wstat == 0 && context->data_mode == FILEMODE)
1891*7c478bd9Sstevel@tonic-gate 		(void) fflush(stdout);
1892*7c478bd9Sstevel@tonic-gate 
1893*7c478bd9Sstevel@tonic-gate 	return ((rstat != 0 || wstat != 0) ? -1 : 0);
1894*7c478bd9Sstevel@tonic-gate }
1895*7c478bd9Sstevel@tonic-gate 
1896*7c478bd9Sstevel@tonic-gate /*
1897*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1898*7c478bd9Sstevel@tonic-gate  * pa_adr_u_int32: Issues pr_adr_u_int32 to retrieve the next ADR item from
1899*7c478bd9Sstevel@tonic-gate  *		  the input stream pointed to by audit_adr, and prints it
1900*7c478bd9Sstevel@tonic-gate  *		  if status = 0
1901*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1902*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1903*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1904*7c478bd9Sstevel@tonic-gate  */
1905*7c478bd9Sstevel@tonic-gate 
1906*7c478bd9Sstevel@tonic-gate 
1907*7c478bd9Sstevel@tonic-gate int
1908*7c478bd9Sstevel@tonic-gate pa_adr_u_int32(pr_context_t *context, int status, int flag)
1909*7c478bd9Sstevel@tonic-gate {
1910*7c478bd9Sstevel@tonic-gate 	uint32_t c;
1911*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1912*7c478bd9Sstevel@tonic-gate 
1913*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1914*7c478bd9Sstevel@tonic-gate 		if (pr_adr_u_int32(context, &c, 1) == 0) {
1915*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
1916*7c478bd9Sstevel@tonic-gate 			uval.uint32_val = c;
1917*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
1918*7c478bd9Sstevel@tonic-gate 		} else
1919*7c478bd9Sstevel@tonic-gate 			return (-1);
1920*7c478bd9Sstevel@tonic-gate 	} else
1921*7c478bd9Sstevel@tonic-gate 		return (status);
1922*7c478bd9Sstevel@tonic-gate }
1923*7c478bd9Sstevel@tonic-gate 
1924*7c478bd9Sstevel@tonic-gate 
1925*7c478bd9Sstevel@tonic-gate 
1926*7c478bd9Sstevel@tonic-gate /*
1927*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1928*7c478bd9Sstevel@tonic-gate  * pa_adr_u_int64: Issues pr_adr_u_int64 to retrieve the next ADR item from the
1929*7c478bd9Sstevel@tonic-gate  *		  input stream pointed to by audit_adr, and prints it
1930*7c478bd9Sstevel@tonic-gate  *		  if status = 0
1931*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1932*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1933*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1934*7c478bd9Sstevel@tonic-gate  */
1935*7c478bd9Sstevel@tonic-gate int
1936*7c478bd9Sstevel@tonic-gate pa_adr_u_int64(pr_context_t *context, int status, int flag)
1937*7c478bd9Sstevel@tonic-gate {
1938*7c478bd9Sstevel@tonic-gate 	uint64_t c;
1939*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1940*7c478bd9Sstevel@tonic-gate 
1941*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1942*7c478bd9Sstevel@tonic-gate 		if (pr_adr_u_int64(context, &c, 1) == 0) {
1943*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT64;
1944*7c478bd9Sstevel@tonic-gate 			uval.uint64_val = c;
1945*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
1946*7c478bd9Sstevel@tonic-gate 		} else
1947*7c478bd9Sstevel@tonic-gate 			return (-1);
1948*7c478bd9Sstevel@tonic-gate 	} else
1949*7c478bd9Sstevel@tonic-gate 		return (status);
1950*7c478bd9Sstevel@tonic-gate }
1951*7c478bd9Sstevel@tonic-gate 
1952*7c478bd9Sstevel@tonic-gate 
1953*7c478bd9Sstevel@tonic-gate /*
1954*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1955*7c478bd9Sstevel@tonic-gate  * pa_adr_u_short: Issues pr_adr_u_short to retrieve the next ADR item from
1956*7c478bd9Sstevel@tonic-gate  *			the input stream pointed to by audit_adr, and prints it
1957*7c478bd9Sstevel@tonic-gate  *			if status = 0
1958*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1959*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1960*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1961*7c478bd9Sstevel@tonic-gate  */
1962*7c478bd9Sstevel@tonic-gate int
1963*7c478bd9Sstevel@tonic-gate pa_adr_u_short(pr_context_t *context, int status, int flag)
1964*7c478bd9Sstevel@tonic-gate {
1965*7c478bd9Sstevel@tonic-gate 	ushort_t c;
1966*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1967*7c478bd9Sstevel@tonic-gate 
1968*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1969*7c478bd9Sstevel@tonic-gate 		if (pr_adr_u_short(context, &c, 1) == 0) {
1970*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_USHORT;
1971*7c478bd9Sstevel@tonic-gate 			uval.ushort_val = c;
1972*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
1973*7c478bd9Sstevel@tonic-gate 		} else
1974*7c478bd9Sstevel@tonic-gate 			return (-1);
1975*7c478bd9Sstevel@tonic-gate 	} else
1976*7c478bd9Sstevel@tonic-gate 		return (status);
1977*7c478bd9Sstevel@tonic-gate }
1978*7c478bd9Sstevel@tonic-gate 
1979*7c478bd9Sstevel@tonic-gate /*
1980*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1981*7c478bd9Sstevel@tonic-gate  * pa_reclen: Issues pr_adr_u_long to retrieve the length of the record
1982*7c478bd9Sstevel@tonic-gate  *		  from the input stream pointed to by audit_adr,
1983*7c478bd9Sstevel@tonic-gate  *		  and prints it (unless format is XML) if status = 0
1984*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
1985*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
1986*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1987*7c478bd9Sstevel@tonic-gate  */
1988*7c478bd9Sstevel@tonic-gate int
1989*7c478bd9Sstevel@tonic-gate pa_reclen(pr_context_t *context, int status)
1990*7c478bd9Sstevel@tonic-gate {
1991*7c478bd9Sstevel@tonic-gate 	uint32_t c;
1992*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
1993*7c478bd9Sstevel@tonic-gate 
1994*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
1995*7c478bd9Sstevel@tonic-gate 		if ((int)pr_adr_u_int32(context, &c, 1) == 0) {
1996*7c478bd9Sstevel@tonic-gate 			context->audit_rec_len = c;
1997*7c478bd9Sstevel@tonic-gate 
1998*7c478bd9Sstevel@tonic-gate 			/* Don't print this for XML format */
1999*7c478bd9Sstevel@tonic-gate 			if (context->format & PRF_XMLM) {
2000*7c478bd9Sstevel@tonic-gate 				return (0);
2001*7c478bd9Sstevel@tonic-gate 			} else {
2002*7c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_UINT32;
2003*7c478bd9Sstevel@tonic-gate 				uval.uint32_val = c;
2004*7c478bd9Sstevel@tonic-gate 				return (pa_print(context, &uval, 0));
2005*7c478bd9Sstevel@tonic-gate 			}
2006*7c478bd9Sstevel@tonic-gate 		} else
2007*7c478bd9Sstevel@tonic-gate 			return (-1);
2008*7c478bd9Sstevel@tonic-gate 	} else
2009*7c478bd9Sstevel@tonic-gate 		return (status);
2010*7c478bd9Sstevel@tonic-gate }
2011*7c478bd9Sstevel@tonic-gate 
2012*7c478bd9Sstevel@tonic-gate /*
2013*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2014*7c478bd9Sstevel@tonic-gate  * pa_mode	: Issues pr_adr_u_short to retrieve the next ADR item from
2015*7c478bd9Sstevel@tonic-gate  *		the input stream pointed to by audit_adr, and prints it
2016*7c478bd9Sstevel@tonic-gate  *		in octal if status = 0
2017*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2018*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
2019*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2020*7c478bd9Sstevel@tonic-gate  */
2021*7c478bd9Sstevel@tonic-gate int
2022*7c478bd9Sstevel@tonic-gate pa_mode(pr_context_t *context, int status, int flag)
2023*7c478bd9Sstevel@tonic-gate {
2024*7c478bd9Sstevel@tonic-gate 	uint32_t c;
2025*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2026*7c478bd9Sstevel@tonic-gate 
2027*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
2028*7c478bd9Sstevel@tonic-gate 		if (pr_adr_u_int32(context, &c, 1) == 0) {
2029*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_LOCT;
2030*7c478bd9Sstevel@tonic-gate 			uval.uint32_val = c;
2031*7c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
2032*7c478bd9Sstevel@tonic-gate 		} else
2033*7c478bd9Sstevel@tonic-gate 			return (-1);
2034*7c478bd9Sstevel@tonic-gate 	} else
2035*7c478bd9Sstevel@tonic-gate 		return (status);
2036*7c478bd9Sstevel@tonic-gate }
2037*7c478bd9Sstevel@tonic-gate 
2038*7c478bd9Sstevel@tonic-gate 
2039*7c478bd9Sstevel@tonic-gate /*
2040*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2041*7c478bd9Sstevel@tonic-gate  * pa_pw_uid()	: Issues pr_adr_u_int32 to reads uid from input stream
2042*7c478bd9Sstevel@tonic-gate  *		pointed to by audit_adr, and displays it in either
2043*7c478bd9Sstevel@tonic-gate  *		raw form or its ASCII representation, if status >= 0.
2044*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2045*7c478bd9Sstevel@tonic-gate  * 		:  1 - warning, passwd entry not found
2046*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
2047*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2048*7c478bd9Sstevel@tonic-gate  */
2049*7c478bd9Sstevel@tonic-gate int
2050*7c478bd9Sstevel@tonic-gate pa_pw_uid(pr_context_t *context, int status, int flag)
2051*7c478bd9Sstevel@tonic-gate {
2052*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2053*7c478bd9Sstevel@tonic-gate 	struct passwd *pw;
2054*7c478bd9Sstevel@tonic-gate 	uint32_t uid;
2055*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2056*7c478bd9Sstevel@tonic-gate 
2057*7c478bd9Sstevel@tonic-gate 	if (status < 0)
2058*7c478bd9Sstevel@tonic-gate 		return (status);
2059*7c478bd9Sstevel@tonic-gate 
2060*7c478bd9Sstevel@tonic-gate 	if (pr_adr_u_int32(context, &uid, 1) != 0)
2061*7c478bd9Sstevel@tonic-gate 		/* cannot retrieve uid */
2062*7c478bd9Sstevel@tonic-gate 		return (-1);
2063*7c478bd9Sstevel@tonic-gate 
2064*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
2065*7c478bd9Sstevel@tonic-gate 		/* get password file entry */
2066*7c478bd9Sstevel@tonic-gate 		if ((pw = getpwuid(uid)) == NULL) {
2067*7c478bd9Sstevel@tonic-gate 			returnstat = 1;
2068*7c478bd9Sstevel@tonic-gate 		} else {
2069*7c478bd9Sstevel@tonic-gate 			/* print in ASCII form */
2070*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
2071*7c478bd9Sstevel@tonic-gate 			uval.string_val = pw->pw_name;
2072*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
2073*7c478bd9Sstevel@tonic-gate 		}
2074*7c478bd9Sstevel@tonic-gate 	}
2075*7c478bd9Sstevel@tonic-gate 	/* print in integer form */
2076*7c478bd9Sstevel@tonic-gate 	if ((context->format & PRF_RAWM) || (returnstat == 1)) {
2077*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_INT32;
2078*7c478bd9Sstevel@tonic-gate 		uval.int32_val = uid;
2079*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
2080*7c478bd9Sstevel@tonic-gate 	}
2081*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2082*7c478bd9Sstevel@tonic-gate }
2083*7c478bd9Sstevel@tonic-gate 
2084*7c478bd9Sstevel@tonic-gate 
2085*7c478bd9Sstevel@tonic-gate /*
2086*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2087*7c478bd9Sstevel@tonic-gate  * pa_gr_uid()	: Issues pr_adr_u_int32 to reads group uid from input stream
2088*7c478bd9Sstevel@tonic-gate  *			pointed to by audit_adr, and displays it in either
2089*7c478bd9Sstevel@tonic-gate  *			raw form or its ASCII representation, if status >= 0.
2090*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2091*7c478bd9Sstevel@tonic-gate  * 		:  1 - warning, passwd entry not found
2092*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
2093*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2094*7c478bd9Sstevel@tonic-gate  */
2095*7c478bd9Sstevel@tonic-gate int
2096*7c478bd9Sstevel@tonic-gate pa_gr_uid(pr_context_t *context, int status, int flag)
2097*7c478bd9Sstevel@tonic-gate {
2098*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2099*7c478bd9Sstevel@tonic-gate 	struct group *gr;
2100*7c478bd9Sstevel@tonic-gate 	uint32_t gid;
2101*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2102*7c478bd9Sstevel@tonic-gate 
2103*7c478bd9Sstevel@tonic-gate 	if (status < 0)
2104*7c478bd9Sstevel@tonic-gate 		return (status);
2105*7c478bd9Sstevel@tonic-gate 
2106*7c478bd9Sstevel@tonic-gate 	if (pr_adr_u_int32(context, &gid, 1) != 0)
2107*7c478bd9Sstevel@tonic-gate 		/* cannot retrieve gid */
2108*7c478bd9Sstevel@tonic-gate 		return (-1);
2109*7c478bd9Sstevel@tonic-gate 
2110*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
2111*7c478bd9Sstevel@tonic-gate 		/* get group file entry */
2112*7c478bd9Sstevel@tonic-gate 		if ((gr = getgrgid(gid)) == NULL) {
2113*7c478bd9Sstevel@tonic-gate 			returnstat = 1;
2114*7c478bd9Sstevel@tonic-gate 		} else {
2115*7c478bd9Sstevel@tonic-gate 			/* print in ASCII form */
2116*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
2117*7c478bd9Sstevel@tonic-gate 			uval.string_val = gr->gr_name;
2118*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
2119*7c478bd9Sstevel@tonic-gate 		}
2120*7c478bd9Sstevel@tonic-gate 	}
2121*7c478bd9Sstevel@tonic-gate 	/* print in integer form */
2122*7c478bd9Sstevel@tonic-gate 	if ((context->format & PRF_RAWM) || (returnstat == 1)) {
2123*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_INT32;
2124*7c478bd9Sstevel@tonic-gate 		uval.int32_val = gid;
2125*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
2126*7c478bd9Sstevel@tonic-gate 	}
2127*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2128*7c478bd9Sstevel@tonic-gate }
2129*7c478bd9Sstevel@tonic-gate 
2130*7c478bd9Sstevel@tonic-gate 
2131*7c478bd9Sstevel@tonic-gate /*
2132*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2133*7c478bd9Sstevel@tonic-gate  * pa_pw_uid_gr_gid()	: Issues pr_adr_u_int32 to reads uid or group uid
2134*7c478bd9Sstevel@tonic-gate  *			from input stream
2135*7c478bd9Sstevel@tonic-gate  *			pointed to by audit_adr, and displays it in either
2136*7c478bd9Sstevel@tonic-gate  *			raw form or its ASCII representation, if status >= 0.
2137*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2138*7c478bd9Sstevel@tonic-gate  * 		:  1 - warning, passwd entry not found
2139*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
2140*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2141*7c478bd9Sstevel@tonic-gate  */
2142*7c478bd9Sstevel@tonic-gate int
2143*7c478bd9Sstevel@tonic-gate pa_pw_uid_gr_gid(pr_context_t *context, int status, int flag)
2144*7c478bd9Sstevel@tonic-gate {
2145*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2146*7c478bd9Sstevel@tonic-gate 	uint32_t	value;
2147*7c478bd9Sstevel@tonic-gate 	uval_t		uval;
2148*7c478bd9Sstevel@tonic-gate 
2149*7c478bd9Sstevel@tonic-gate 	if (status < 0)
2150*7c478bd9Sstevel@tonic-gate 		return (status);
2151*7c478bd9Sstevel@tonic-gate 
2152*7c478bd9Sstevel@tonic-gate 	/* get value of a_type */
2153*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &value, 1)) != 0)
2154*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2155*7c478bd9Sstevel@tonic-gate 
2156*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ACLTYPE)) != 0)
2157*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2158*7c478bd9Sstevel@tonic-gate 
2159*7c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_UINT32;
2160*7c478bd9Sstevel@tonic-gate 	uval.uint32_val = value;
2161*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pa_print(context, &uval, flag)) != 0)
2162*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2163*7c478bd9Sstevel@tonic-gate 
2164*7c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_ACLTYPE)) != 0)
2165*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2166*7c478bd9Sstevel@tonic-gate 
2167*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ACLVAL)) != 0)
2168*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2169*7c478bd9Sstevel@tonic-gate 	/*
2170*7c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
2171*7c478bd9Sstevel@tonic-gate 	 * The "mask" and "other" strings refer to the class mask
2172*7c478bd9Sstevel@tonic-gate 	 * and other (or world) entries in an ACL.
2173*7c478bd9Sstevel@tonic-gate 	 * The "unrecognized" string refers to an unrecognized ACL
2174*7c478bd9Sstevel@tonic-gate 	 * entry.
2175*7c478bd9Sstevel@tonic-gate 	 */
2176*7c478bd9Sstevel@tonic-gate 	switch (value) {
2177*7c478bd9Sstevel@tonic-gate 		case USER_OBJ:
2178*7c478bd9Sstevel@tonic-gate 		case USER:
2179*7c478bd9Sstevel@tonic-gate 			returnstat = pa_pw_uid(context, returnstat, flag);
2180*7c478bd9Sstevel@tonic-gate 			break;
2181*7c478bd9Sstevel@tonic-gate 		case GROUP_OBJ:
2182*7c478bd9Sstevel@tonic-gate 		case GROUP:
2183*7c478bd9Sstevel@tonic-gate 			returnstat = pa_gr_uid(context, returnstat, flag);
2184*7c478bd9Sstevel@tonic-gate 			break;
2185*7c478bd9Sstevel@tonic-gate 		case CLASS_OBJ:
2186*7c478bd9Sstevel@tonic-gate 		    returnstat = pr_adr_u_int32(context, &value, 1);
2187*7c478bd9Sstevel@tonic-gate 		    if (returnstat != 0)
2188*7c478bd9Sstevel@tonic-gate 			return (returnstat);
2189*7c478bd9Sstevel@tonic-gate 
2190*7c478bd9Sstevel@tonic-gate 		    if (!(context->format & PRF_RAWM)) {
2191*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
2192*7c478bd9Sstevel@tonic-gate 			uval.string_val = gettext("mask");
2193*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
2194*7c478bd9Sstevel@tonic-gate 		    } else {
2195*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
2196*7c478bd9Sstevel@tonic-gate 			uval.uint32_val = value;
2197*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pa_print(context, &uval, flag)) != 0)
2198*7c478bd9Sstevel@tonic-gate 				return (returnstat);
2199*7c478bd9Sstevel@tonic-gate 		    }
2200*7c478bd9Sstevel@tonic-gate 		    break;
2201*7c478bd9Sstevel@tonic-gate 		case OTHER_OBJ:
2202*7c478bd9Sstevel@tonic-gate 		    returnstat = pr_adr_u_int32(context, &value, 1);
2203*7c478bd9Sstevel@tonic-gate 		    if (returnstat != 0)
2204*7c478bd9Sstevel@tonic-gate 			return (returnstat);
2205*7c478bd9Sstevel@tonic-gate 
2206*7c478bd9Sstevel@tonic-gate 		    if (!(context->format & PRF_RAWM)) {
2207*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
2208*7c478bd9Sstevel@tonic-gate 			uval.string_val = gettext("other");
2209*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
2210*7c478bd9Sstevel@tonic-gate 		    } else {
2211*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
2212*7c478bd9Sstevel@tonic-gate 			uval.uint32_val = value;
2213*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pa_print(context, &uval, flag)) != 0)
2214*7c478bd9Sstevel@tonic-gate 				return (returnstat);
2215*7c478bd9Sstevel@tonic-gate 		    }
2216*7c478bd9Sstevel@tonic-gate 		    break;
2217*7c478bd9Sstevel@tonic-gate 		default:
2218*7c478bd9Sstevel@tonic-gate 		    returnstat = pr_adr_u_int32(context, &value, 1);
2219*7c478bd9Sstevel@tonic-gate 		    if (returnstat != 0)
2220*7c478bd9Sstevel@tonic-gate 			return (returnstat);
2221*7c478bd9Sstevel@tonic-gate 
2222*7c478bd9Sstevel@tonic-gate 		    if (!(context->format & PRF_RAWM)) {
2223*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
2224*7c478bd9Sstevel@tonic-gate 			uval.string_val = gettext("unrecognized");
2225*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
2226*7c478bd9Sstevel@tonic-gate 		    } else {
2227*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
2228*7c478bd9Sstevel@tonic-gate 			uval.uint32_val = value;
2229*7c478bd9Sstevel@tonic-gate 			if ((returnstat = pa_print(context, &uval, flag)) != 0)
2230*7c478bd9Sstevel@tonic-gate 				return (returnstat);
2231*7c478bd9Sstevel@tonic-gate 		    }
2232*7c478bd9Sstevel@tonic-gate 	}
2233*7c478bd9Sstevel@tonic-gate 
2234*7c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_ACLVAL)) != 0)
2235*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2236*7c478bd9Sstevel@tonic-gate 
2237*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2238*7c478bd9Sstevel@tonic-gate }
2239*7c478bd9Sstevel@tonic-gate 
2240*7c478bd9Sstevel@tonic-gate 
2241*7c478bd9Sstevel@tonic-gate /*
2242*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2243*7c478bd9Sstevel@tonic-gate  * pa_event_modifier(): Issues pr_adr_u_short to retrieve the next ADR item from
2244*7c478bd9Sstevel@tonic-gate  *		  the input stream pointed to by audit_adr.  This is the
2245*7c478bd9Sstevel@tonic-gate  *		  event type, and is displayed in hex;
2246*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2247*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
2248*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2249*7c478bd9Sstevel@tonic-gate  */
2250*7c478bd9Sstevel@tonic-gate int
2251*7c478bd9Sstevel@tonic-gate pa_event_modifier(pr_context_t *context, int status,  int flag)
2252*7c478bd9Sstevel@tonic-gate {
2253*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2254*7c478bd9Sstevel@tonic-gate 	ushort_t emodifier;
2255*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2256*7c478bd9Sstevel@tonic-gate 	char	modstring[64];
2257*7c478bd9Sstevel@tonic-gate 
2258*7c478bd9Sstevel@tonic-gate 	if (status < 0)
2259*7c478bd9Sstevel@tonic-gate 		return (status);
2260*7c478bd9Sstevel@tonic-gate 
2261*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_short(context, &emodifier, 1)) != 0)
2262*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2263*7c478bd9Sstevel@tonic-gate 
2264*7c478bd9Sstevel@tonic-gate 	/* For XML, only print when modifier is non-zero */
2265*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM) || (emodifier != 0)) {
2266*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
2267*7c478bd9Sstevel@tonic-gate 
2268*7c478bd9Sstevel@tonic-gate 		returnstat = open_tag(context, TAG_EVMOD);
2269*7c478bd9Sstevel@tonic-gate 
2270*7c478bd9Sstevel@tonic-gate 		if (returnstat >= 0) {
2271*7c478bd9Sstevel@tonic-gate 			if (!(context->format & PRF_RAWM)) {
2272*7c478bd9Sstevel@tonic-gate 				eventmodifier2string(emodifier, modstring,
2273*7c478bd9Sstevel@tonic-gate 				    sizeof (modstring));
2274*7c478bd9Sstevel@tonic-gate 				uval.string_val = modstring;
2275*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
2276*7c478bd9Sstevel@tonic-gate 			} else {
2277*7c478bd9Sstevel@tonic-gate 				uval.string_val = hexconvert((char *)&emodifier,
2278*7c478bd9Sstevel@tonic-gate 				    sizeof (emodifier), sizeof (emodifier));
2279*7c478bd9Sstevel@tonic-gate 				if (uval.string_val) {
2280*7c478bd9Sstevel@tonic-gate 					returnstat = pa_print(context, &uval,
2281*7c478bd9Sstevel@tonic-gate 					    flag);
2282*7c478bd9Sstevel@tonic-gate 					free(uval.string_val);
2283*7c478bd9Sstevel@tonic-gate 				}
2284*7c478bd9Sstevel@tonic-gate 			}
2285*7c478bd9Sstevel@tonic-gate 		}
2286*7c478bd9Sstevel@tonic-gate 		if (returnstat >= 0)
2287*7c478bd9Sstevel@tonic-gate 			returnstat = close_tag(context, TAG_EVMOD);
2288*7c478bd9Sstevel@tonic-gate 	}
2289*7c478bd9Sstevel@tonic-gate 
2290*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2291*7c478bd9Sstevel@tonic-gate }
2292*7c478bd9Sstevel@tonic-gate 
2293*7c478bd9Sstevel@tonic-gate 
2294*7c478bd9Sstevel@tonic-gate /*
2295*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2296*7c478bd9Sstevel@tonic-gate  * pa_event_type(): Issues pr_adr_u_short to retrieve the next ADR item from
2297*7c478bd9Sstevel@tonic-gate  *		  the input stream pointed to by audit_adr.  This is the
2298*7c478bd9Sstevel@tonic-gate  *		  event type, and is displayed in either raw or
2299*7c478bd9Sstevel@tonic-gate  *		  ASCII form as appropriate
2300*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2301*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
2302*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2303*7c478bd9Sstevel@tonic-gate  */
2304*7c478bd9Sstevel@tonic-gate int
2305*7c478bd9Sstevel@tonic-gate pa_event_type(pr_context_t *context, int status,  int flag)
2306*7c478bd9Sstevel@tonic-gate {
2307*7c478bd9Sstevel@tonic-gate 	ushort_t etype;
2308*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2309*7c478bd9Sstevel@tonic-gate 	au_event_ent_t *p_event = NULL;
2310*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2311*7c478bd9Sstevel@tonic-gate 
2312*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
2313*7c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_u_short(context, &etype, 1)) == 0) {
2314*7c478bd9Sstevel@tonic-gate 			if (!(context->format & PRF_RAWM)) {
2315*7c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_STRING;
2316*7c478bd9Sstevel@tonic-gate 				if (context->format & PRF_NOCACHE) {
2317*7c478bd9Sstevel@tonic-gate 					p_event = getauevnum(etype);
2318*7c478bd9Sstevel@tonic-gate 				} else {
2319*7c478bd9Sstevel@tonic-gate 					(void) cacheauevent(&p_event, etype);
2320*7c478bd9Sstevel@tonic-gate 				}
2321*7c478bd9Sstevel@tonic-gate 				if (p_event != NULL) {
2322*7c478bd9Sstevel@tonic-gate 					if (context->format & PRF_SHORTM)
2323*7c478bd9Sstevel@tonic-gate 						uval.string_val =
2324*7c478bd9Sstevel@tonic-gate 						    p_event->ae_name;
2325*7c478bd9Sstevel@tonic-gate 					else
2326*7c478bd9Sstevel@tonic-gate 						uval.string_val =
2327*7c478bd9Sstevel@tonic-gate 						    p_event->ae_desc;
2328*7c478bd9Sstevel@tonic-gate 				} else {
2329*7c478bd9Sstevel@tonic-gate 					uval.string_val =
2330*7c478bd9Sstevel@tonic-gate 					    gettext("invalid event number");
2331*7c478bd9Sstevel@tonic-gate 				}
2332*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
2333*7c478bd9Sstevel@tonic-gate 			} else {
2334*7c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_USHORT;
2335*7c478bd9Sstevel@tonic-gate 				uval.ushort_val = etype;
2336*7c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
2337*7c478bd9Sstevel@tonic-gate 			}
2338*7c478bd9Sstevel@tonic-gate 		}
2339*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2340*7c478bd9Sstevel@tonic-gate 	} else
2341*7c478bd9Sstevel@tonic-gate 		return (status);
2342*7c478bd9Sstevel@tonic-gate 
2343*7c478bd9Sstevel@tonic-gate }
2344*7c478bd9Sstevel@tonic-gate 
2345*7c478bd9Sstevel@tonic-gate 
2346*7c478bd9Sstevel@tonic-gate /*
2347*7c478bd9Sstevel@tonic-gate  * Print time from struct timeval to millisecond resolution.
2348*7c478bd9Sstevel@tonic-gate  *
2349*7c478bd9Sstevel@tonic-gate  *	typedef long	time_t;		time of day in seconds
2350*7c478bd9Sstevel@tonic-gate  *	typedef	long	useconds_t;	signed # of microseconds
2351*7c478bd9Sstevel@tonic-gate  *
2352*7c478bd9Sstevel@tonic-gate  * struct timeval {
2353*7c478bd9Sstevel@tonic-gate  *	time_t		tv_sec;		seconds
2354*7c478bd9Sstevel@tonic-gate  *	suseconds_t	tv_usec;	and microseconds
2355*7c478bd9Sstevel@tonic-gate  * };
2356*7c478bd9Sstevel@tonic-gate  */
2357*7c478bd9Sstevel@tonic-gate 
2358*7c478bd9Sstevel@tonic-gate int
2359*7c478bd9Sstevel@tonic-gate pa_utime32(pr_context_t *context, int status, int flag)
2360*7c478bd9Sstevel@tonic-gate {
2361*7c478bd9Sstevel@tonic-gate 	uint32_t scale = 1000;		/* usec to msec */
2362*7c478bd9Sstevel@tonic-gate 
2363*7c478bd9Sstevel@tonic-gate 	return (do_mtime32(context, status, flag, scale));
2364*7c478bd9Sstevel@tonic-gate }
2365*7c478bd9Sstevel@tonic-gate 
2366*7c478bd9Sstevel@tonic-gate /*
2367*7c478bd9Sstevel@tonic-gate  * Print time from timestruc_t to millisecond resolution.
2368*7c478bd9Sstevel@tonic-gate  *
2369*7c478bd9Sstevel@tonic-gate  *	typedef struct timespec timestruct_t;
2370*7c478bd9Sstevel@tonic-gate  * struct timespec{
2371*7c478bd9Sstevel@tonic-gate  *	time_t	tv_sec;		seconds
2372*7c478bd9Sstevel@tonic-gate  *	long	tv_nsec;	and nanoseconds
2373*7c478bd9Sstevel@tonic-gate  * };
2374*7c478bd9Sstevel@tonic-gate  */
2375*7c478bd9Sstevel@tonic-gate int
2376*7c478bd9Sstevel@tonic-gate pa_ntime32(pr_context_t *context, int status, int flag)
2377*7c478bd9Sstevel@tonic-gate {
2378*7c478bd9Sstevel@tonic-gate 	uint32_t scale = 1000000;	/* nsec to msec */
2379*7c478bd9Sstevel@tonic-gate 
2380*7c478bd9Sstevel@tonic-gate 	return (do_mtime32(context, status, flag, scale));
2381*7c478bd9Sstevel@tonic-gate }
2382*7c478bd9Sstevel@tonic-gate 
2383*7c478bd9Sstevel@tonic-gate /*
2384*7c478bd9Sstevel@tonic-gate  * Format the timezone +/- HH:MM and terminate the string
2385*7c478bd9Sstevel@tonic-gate  * Note tm and tv_sec are the same time.
2386*7c478bd9Sstevel@tonic-gate  * Too bad strftime won't produce an ISO 8601 time zone numeric
2387*7c478bd9Sstevel@tonic-gate  */
2388*7c478bd9Sstevel@tonic-gate 
2389*7c478bd9Sstevel@tonic-gate #define	MINS	(24L * 60)
2390*7c478bd9Sstevel@tonic-gate static void
2391*7c478bd9Sstevel@tonic-gate tzone(struct tm *tm, time_t *tv_sec, char *p)
2392*7c478bd9Sstevel@tonic-gate {
2393*7c478bd9Sstevel@tonic-gate 	struct tm *gmt;
2394*7c478bd9Sstevel@tonic-gate 	int min_off;
2395*7c478bd9Sstevel@tonic-gate 
2396*7c478bd9Sstevel@tonic-gate 	gmt = gmtime(tv_sec);
2397*7c478bd9Sstevel@tonic-gate 
2398*7c478bd9Sstevel@tonic-gate 	min_off = ((tm->tm_hour - gmt->tm_hour) * 60) +
2399*7c478bd9Sstevel@tonic-gate 	    (tm->tm_min - gmt->tm_min);
2400*7c478bd9Sstevel@tonic-gate 
2401*7c478bd9Sstevel@tonic-gate 	if (tm->tm_year < gmt->tm_year)		/* cross new year */
2402*7c478bd9Sstevel@tonic-gate 		min_off -= MINS;
2403*7c478bd9Sstevel@tonic-gate 	else if (tm->tm_year > gmt->tm_year)
2404*7c478bd9Sstevel@tonic-gate 		min_off += MINS;
2405*7c478bd9Sstevel@tonic-gate 	else if (tm->tm_yday < gmt->tm_yday)	/* cross dateline */
2406*7c478bd9Sstevel@tonic-gate 		min_off -= MINS;
2407*7c478bd9Sstevel@tonic-gate 	else if (tm->tm_yday > gmt->tm_yday)
2408*7c478bd9Sstevel@tonic-gate 		min_off += MINS;
2409*7c478bd9Sstevel@tonic-gate 
2410*7c478bd9Sstevel@tonic-gate 	if (min_off < 0) {
2411*7c478bd9Sstevel@tonic-gate 		min_off = -min_off;
2412*7c478bd9Sstevel@tonic-gate 		*p++ = '-';
2413*7c478bd9Sstevel@tonic-gate 	} else {
2414*7c478bd9Sstevel@tonic-gate 		*p++ = '+';
2415*7c478bd9Sstevel@tonic-gate 	}
2416*7c478bd9Sstevel@tonic-gate 
2417*7c478bd9Sstevel@tonic-gate 	*p++ = min_off / 600 + '0';		/* 10s of hours */
2418*7c478bd9Sstevel@tonic-gate 	min_off = min_off - min_off / 600 * 600;
2419*7c478bd9Sstevel@tonic-gate 	*p++ = min_off / 60 % 10 + '0';		/* hours */
2420*7c478bd9Sstevel@tonic-gate 	min_off = min_off - min_off / 60 * 60;
2421*7c478bd9Sstevel@tonic-gate 	*p++ = ':';
2422*7c478bd9Sstevel@tonic-gate 	*p++ = min_off / 10 + '0';		/* 10s of minutes */
2423*7c478bd9Sstevel@tonic-gate 	*p++ = min_off % 10 + '0';		/* minutes */
2424*7c478bd9Sstevel@tonic-gate 	*p = '\0';
2425*7c478bd9Sstevel@tonic-gate }
2426*7c478bd9Sstevel@tonic-gate 
2427*7c478bd9Sstevel@tonic-gate /*
2428*7c478bd9Sstevel@tonic-gate  * Format the milliseconds in place in the string.
2429*7c478bd9Sstevel@tonic-gate  * Borrowed from strftime.c:itoa()
2430*7c478bd9Sstevel@tonic-gate  */
2431*7c478bd9Sstevel@tonic-gate static void
2432*7c478bd9Sstevel@tonic-gate msec32(uint32_t msec, char *p)
2433*7c478bd9Sstevel@tonic-gate {
2434*7c478bd9Sstevel@tonic-gate 	*p++ = msec / 100 + '0';
2435*7c478bd9Sstevel@tonic-gate 	msec  = msec - msec / 100 * 100;
2436*7c478bd9Sstevel@tonic-gate 	*p++ = msec / 10 + '0';
2437*7c478bd9Sstevel@tonic-gate 	*p++ = msec % 10 +'0';
2438*7c478bd9Sstevel@tonic-gate }
2439*7c478bd9Sstevel@tonic-gate 
2440*7c478bd9Sstevel@tonic-gate /*
2441*7c478bd9Sstevel@tonic-gate  * Format time and print relative to scale factor from micro/nano seconds.
2442*7c478bd9Sstevel@tonic-gate  */
2443*7c478bd9Sstevel@tonic-gate static int
2444*7c478bd9Sstevel@tonic-gate do_mtime32(pr_context_t *context, int status, int flag, uint32_t scale)
2445*7c478bd9Sstevel@tonic-gate {
2446*7c478bd9Sstevel@tonic-gate 	uint32_t t32;
2447*7c478bd9Sstevel@tonic-gate 	time_t tv_sec;
2448*7c478bd9Sstevel@tonic-gate 	struct tm tm;
2449*7c478bd9Sstevel@tonic-gate 	char	time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")];
2450*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2451*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2452*7c478bd9Sstevel@tonic-gate 
2453*7c478bd9Sstevel@tonic-gate 	if (status < 0)
2454*7c478bd9Sstevel@tonic-gate 		return (status);
2455*7c478bd9Sstevel@tonic-gate 
2456*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ISO)) != 0)
2457*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2458*7c478bd9Sstevel@tonic-gate 
2459*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context,
2460*7c478bd9Sstevel@tonic-gate 	    (uint32_t *)&tv_sec, 1)) != 0)
2461*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2462*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &t32, 1)) == 0) {
2463*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
2464*7c478bd9Sstevel@tonic-gate 			(void) localtime_r(&tv_sec, &tm);
2465*7c478bd9Sstevel@tonic-gate 			(void) strftime(time_created,
2466*7c478bd9Sstevel@tonic-gate 			    sizeof ("YYYY-MM-DD HH:MM:SS.xxx "),
2467*7c478bd9Sstevel@tonic-gate 			    "%Y-%m-%d %H:%M:%S.xxx ", &tm);
2468*7c478bd9Sstevel@tonic-gate 			msec32(t32/scale,
2469*7c478bd9Sstevel@tonic-gate 			    &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]);
2470*7c478bd9Sstevel@tonic-gate 			tzone(&tm, &tv_sec,
2471*7c478bd9Sstevel@tonic-gate 			    &time_created[
2472*7c478bd9Sstevel@tonic-gate 			    sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]);
2473*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
2474*7c478bd9Sstevel@tonic-gate 			uval.string_val = time_created;
2475*7c478bd9Sstevel@tonic-gate 		} else {
2476*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
2477*7c478bd9Sstevel@tonic-gate 			uval.uint32_val = (uint32_t)tv_sec;
2478*7c478bd9Sstevel@tonic-gate 			(void) pa_print(context, &uval, 0);
2479*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
2480*7c478bd9Sstevel@tonic-gate 			uval.uint32_val = t32;
2481*7c478bd9Sstevel@tonic-gate 		}
2482*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
2483*7c478bd9Sstevel@tonic-gate 	}
2484*7c478bd9Sstevel@tonic-gate 
2485*7c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
2486*7c478bd9Sstevel@tonic-gate 		return (close_tag(context, TAG_ISO));
2487*7c478bd9Sstevel@tonic-gate 	else
2488*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2489*7c478bd9Sstevel@tonic-gate }
2490*7c478bd9Sstevel@tonic-gate 
2491*7c478bd9Sstevel@tonic-gate /*
2492*7c478bd9Sstevel@tonic-gate  * Print time from struct timeval to millisecond resolution.
2493*7c478bd9Sstevel@tonic-gate  *
2494*7c478bd9Sstevel@tonic-gate  *	typedef long	time_t;		time of day in seconds
2495*7c478bd9Sstevel@tonic-gate  *	typedef	long	useconds_t;	signed # of microseconds
2496*7c478bd9Sstevel@tonic-gate  *
2497*7c478bd9Sstevel@tonic-gate  * struct timeval {
2498*7c478bd9Sstevel@tonic-gate  *	time_t		tv_sec;		seconds
2499*7c478bd9Sstevel@tonic-gate  *	suseconds_t	tv_usec;	and microseconds
2500*7c478bd9Sstevel@tonic-gate  * };
2501*7c478bd9Sstevel@tonic-gate  */
2502*7c478bd9Sstevel@tonic-gate 
2503*7c478bd9Sstevel@tonic-gate int
2504*7c478bd9Sstevel@tonic-gate pa_utime64(pr_context_t *context, int status, int flag)
2505*7c478bd9Sstevel@tonic-gate {
2506*7c478bd9Sstevel@tonic-gate 	uint64_t scale = 1000;		/* usec to msec */
2507*7c478bd9Sstevel@tonic-gate 
2508*7c478bd9Sstevel@tonic-gate 	return (do_mtime64(context, status, flag, scale));
2509*7c478bd9Sstevel@tonic-gate }
2510*7c478bd9Sstevel@tonic-gate 
2511*7c478bd9Sstevel@tonic-gate /*
2512*7c478bd9Sstevel@tonic-gate  * Print time from timestruc_t to millisecond resolution.
2513*7c478bd9Sstevel@tonic-gate  *
2514*7c478bd9Sstevel@tonic-gate  *	typedef struct timespec timestruct_t;
2515*7c478bd9Sstevel@tonic-gate  * struct timespec{
2516*7c478bd9Sstevel@tonic-gate  *	time_t	tv_sec;		seconds
2517*7c478bd9Sstevel@tonic-gate  *	long	tv_nsec;	and nanoseconds
2518*7c478bd9Sstevel@tonic-gate  * };
2519*7c478bd9Sstevel@tonic-gate  */
2520*7c478bd9Sstevel@tonic-gate int
2521*7c478bd9Sstevel@tonic-gate pa_ntime64(pr_context_t *context, int status, int flag)
2522*7c478bd9Sstevel@tonic-gate {
2523*7c478bd9Sstevel@tonic-gate 	uint64_t scale = 1000000;	/* nsec to msec */
2524*7c478bd9Sstevel@tonic-gate 
2525*7c478bd9Sstevel@tonic-gate 	return (do_mtime64(context, status, flag, scale));
2526*7c478bd9Sstevel@tonic-gate }
2527*7c478bd9Sstevel@tonic-gate 
2528*7c478bd9Sstevel@tonic-gate /*
2529*7c478bd9Sstevel@tonic-gate  * Format the milliseconds in place in the string.
2530*7c478bd9Sstevel@tonic-gate  * Borrowed from strftime.c:itoa()
2531*7c478bd9Sstevel@tonic-gate  */
2532*7c478bd9Sstevel@tonic-gate static void
2533*7c478bd9Sstevel@tonic-gate msec64(uint64_t msec, char *p)
2534*7c478bd9Sstevel@tonic-gate {
2535*7c478bd9Sstevel@tonic-gate 	*p++ = msec / 100 + '0';
2536*7c478bd9Sstevel@tonic-gate 	msec = msec - msec / 100 * 100;
2537*7c478bd9Sstevel@tonic-gate 	*p++ = msec / 10 + '0';
2538*7c478bd9Sstevel@tonic-gate 	*p++ = msec % 10 +'0';
2539*7c478bd9Sstevel@tonic-gate }
2540*7c478bd9Sstevel@tonic-gate 
2541*7c478bd9Sstevel@tonic-gate /*
2542*7c478bd9Sstevel@tonic-gate  * Format time and print relative to scale factor from micro/nano seconds.
2543*7c478bd9Sstevel@tonic-gate  */
2544*7c478bd9Sstevel@tonic-gate static int
2545*7c478bd9Sstevel@tonic-gate do_mtime64(pr_context_t *context, int status, int flag, uint64_t scale)
2546*7c478bd9Sstevel@tonic-gate {
2547*7c478bd9Sstevel@tonic-gate 	uint64_t t64_sec;
2548*7c478bd9Sstevel@tonic-gate 	uint64_t t64_msec;
2549*7c478bd9Sstevel@tonic-gate 	time_t tv_sec;
2550*7c478bd9Sstevel@tonic-gate 	struct tm tm;
2551*7c478bd9Sstevel@tonic-gate 	char	time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")];
2552*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2553*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2554*7c478bd9Sstevel@tonic-gate 
2555*7c478bd9Sstevel@tonic-gate 	if (status < 0)
2556*7c478bd9Sstevel@tonic-gate 		return (status);
2557*7c478bd9Sstevel@tonic-gate 
2558*7c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ISO)) != 0)
2559*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2560*7c478bd9Sstevel@tonic-gate 
2561*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int64(context, &t64_sec, 1)) != 0)
2562*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2563*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int64(context, &t64_msec, 1)) == 0) {
2564*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
2565*7c478bd9Sstevel@tonic-gate #ifndef	_LP64
2566*7c478bd9Sstevel@tonic-gate 			/*
2567*7c478bd9Sstevel@tonic-gate 			 * N.B.
2568*7c478bd9Sstevel@tonic-gate 			 * This fails for years from 2038
2569*7c478bd9Sstevel@tonic-gate 			 * The Y2K+38 problem
2570*7c478bd9Sstevel@tonic-gate 			 */
2571*7c478bd9Sstevel@tonic-gate #endif	/* !_LP64 */
2572*7c478bd9Sstevel@tonic-gate 			tv_sec = (time_t)t64_sec;
2573*7c478bd9Sstevel@tonic-gate 			(void) localtime_r(&tv_sec, &tm);
2574*7c478bd9Sstevel@tonic-gate 			(void) strftime(time_created,
2575*7c478bd9Sstevel@tonic-gate 			    sizeof ("YYYY-MM-DD HH:MM:SS.xxx "),
2576*7c478bd9Sstevel@tonic-gate 			    "%Y-%m-%d %H:%M:%S.xxx ", &tm);
2577*7c478bd9Sstevel@tonic-gate 			msec64(t64_msec/scale,
2578*7c478bd9Sstevel@tonic-gate 			    &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]);
2579*7c478bd9Sstevel@tonic-gate 			tzone(&tm, &tv_sec,
2580*7c478bd9Sstevel@tonic-gate 			    &time_created[
2581*7c478bd9Sstevel@tonic-gate 			    sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]);
2582*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
2583*7c478bd9Sstevel@tonic-gate 			uval.string_val = time_created;
2584*7c478bd9Sstevel@tonic-gate 		} else {
2585*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT64;
2586*7c478bd9Sstevel@tonic-gate 			uval.uint64_val = t64_sec;
2587*7c478bd9Sstevel@tonic-gate 			(void) pa_print(context, &uval, 0);
2588*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT64;
2589*7c478bd9Sstevel@tonic-gate 			uval.uint64_val = t64_msec;
2590*7c478bd9Sstevel@tonic-gate 		}
2591*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
2592*7c478bd9Sstevel@tonic-gate 	}
2593*7c478bd9Sstevel@tonic-gate 
2594*7c478bd9Sstevel@tonic-gate 	if (returnstat < 0)
2595*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2596*7c478bd9Sstevel@tonic-gate 
2597*7c478bd9Sstevel@tonic-gate 	return (close_tag(context, TAG_ISO));
2598*7c478bd9Sstevel@tonic-gate }
2599*7c478bd9Sstevel@tonic-gate 
2600*7c478bd9Sstevel@tonic-gate /*
2601*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2602*7c478bd9Sstevel@tonic-gate  * pa_error()   :  convert the return token error code.
2603*7c478bd9Sstevel@tonic-gate  *
2604*7c478bd9Sstevel@tonic-gate  * output	: buf string representing return token error code.
2605*7c478bd9Sstevel@tonic-gate  *
2606*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2607*7c478bd9Sstevel@tonic-gate  */
2608*7c478bd9Sstevel@tonic-gate void
2609*7c478bd9Sstevel@tonic-gate pa_error(const uchar_t err, char *buf, size_t buflen)
2610*7c478bd9Sstevel@tonic-gate {
2611*7c478bd9Sstevel@tonic-gate 	if (err == 0) {
2612*7c478bd9Sstevel@tonic-gate 		(void) strlcpy(buf, gettext("success"), buflen);
2613*7c478bd9Sstevel@tonic-gate 	} else if ((char)err == -1) {
2614*7c478bd9Sstevel@tonic-gate 		(void) strlcpy(buf, gettext("failure"), buflen);
2615*7c478bd9Sstevel@tonic-gate 	} else {
2616*7c478bd9Sstevel@tonic-gate 		char *emsg = strerror(err);
2617*7c478bd9Sstevel@tonic-gate 
2618*7c478bd9Sstevel@tonic-gate 		if (emsg != NULL) {
2619*7c478bd9Sstevel@tonic-gate 			(void) strlcpy(buf, gettext("failure: "), buflen);
2620*7c478bd9Sstevel@tonic-gate 			(void) strlcat(buf, emsg, buflen);
2621*7c478bd9Sstevel@tonic-gate 		} else {
2622*7c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, buflen, "%s%d",
2623*7c478bd9Sstevel@tonic-gate 			    gettext("failure: "), err);
2624*7c478bd9Sstevel@tonic-gate 		}
2625*7c478bd9Sstevel@tonic-gate 	}
2626*7c478bd9Sstevel@tonic-gate }
2627*7c478bd9Sstevel@tonic-gate 
2628*7c478bd9Sstevel@tonic-gate /*
2629*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2630*7c478bd9Sstevel@tonic-gate  * pa_retval()   :  convert the return token return value code.
2631*7c478bd9Sstevel@tonic-gate  *
2632*7c478bd9Sstevel@tonic-gate  * output	: buf string representing return token error code.
2633*7c478bd9Sstevel@tonic-gate  *
2634*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2635*7c478bd9Sstevel@tonic-gate  */
2636*7c478bd9Sstevel@tonic-gate void
2637*7c478bd9Sstevel@tonic-gate pa_retval(const int32_t retval, char *buf, size_t buflen)
2638*7c478bd9Sstevel@tonic-gate {
2639*7c478bd9Sstevel@tonic-gate 	struct msg_text	*msglist = &adt_msg_text[ADT_LIST_FAIL_VALUE];
2640*7c478bd9Sstevel@tonic-gate 
2641*7c478bd9Sstevel@tonic-gate 	if ((retval + msglist->ml_offset >= msglist->ml_min_index) &&
2642*7c478bd9Sstevel@tonic-gate 	    (retval + msglist->ml_offset <= msglist->ml_max_index)) {
2643*7c478bd9Sstevel@tonic-gate 
2644*7c478bd9Sstevel@tonic-gate 		(void) strlcpy(buf,
2645*7c478bd9Sstevel@tonic-gate 		    gettext(msglist->ml_msg_list[retval + msglist->ml_offset]),
2646*7c478bd9Sstevel@tonic-gate 		    buflen);
2647*7c478bd9Sstevel@tonic-gate 	} else if ((retval >= ADT_FAIL_PAM) &&
2648*7c478bd9Sstevel@tonic-gate 	    (retval < ADT_FAIL_PAM + PAM_TOTAL_ERRNUM))
2649*7c478bd9Sstevel@tonic-gate 		(void) strlcpy(buf, pam_strerror(NULL, retval - ADT_FAIL_PAM),
2650*7c478bd9Sstevel@tonic-gate 		    buflen);
2651*7c478bd9Sstevel@tonic-gate 	else
2652*7c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, buflen, "%d", retval);
2653*7c478bd9Sstevel@tonic-gate }
2654*7c478bd9Sstevel@tonic-gate 
2655*7c478bd9Sstevel@tonic-gate 
2656*7c478bd9Sstevel@tonic-gate /*
2657*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2658*7c478bd9Sstevel@tonic-gate  * pa_printstr()	:  print a given string, translating unprintables
2659*7c478bd9Sstevel@tonic-gate  *			:  as needed.
2660*7c478bd9Sstevel@tonic-gate  */
2661*7c478bd9Sstevel@tonic-gate static int
2662*7c478bd9Sstevel@tonic-gate pa_printstr(pr_context_t *context, char *str)
2663*7c478bd9Sstevel@tonic-gate {
2664*7c478bd9Sstevel@tonic-gate 	int	err = 0;
2665*7c478bd9Sstevel@tonic-gate 	int	len, printable;
2666*7c478bd9Sstevel@tonic-gate 	int	mbmax = MB_CUR_MAX;
2667*7c478bd9Sstevel@tonic-gate 	wchar_t	wc;
2668*7c478bd9Sstevel@tonic-gate 	char	c;
2669*7c478bd9Sstevel@tonic-gate 
2670*7c478bd9Sstevel@tonic-gate 	if (mbmax == 1) {
2671*7c478bd9Sstevel@tonic-gate 		/* fast path */
2672*7c478bd9Sstevel@tonic-gate 		while (err == 0 && *str != '\0') {
2673*7c478bd9Sstevel@tonic-gate 			c = *str++;
2674*7c478bd9Sstevel@tonic-gate 			printable = isprint((unsigned char)c);
2675*7c478bd9Sstevel@tonic-gate 			err = pa_putstr(context, printable, &c, 1);
2676*7c478bd9Sstevel@tonic-gate 		}
2677*7c478bd9Sstevel@tonic-gate 		return (err);
2678*7c478bd9Sstevel@tonic-gate 	}
2679*7c478bd9Sstevel@tonic-gate 	while (err == 0 && *str != '\0') {
2680*7c478bd9Sstevel@tonic-gate 		len = mbtowc(&wc, str, mbmax);
2681*7c478bd9Sstevel@tonic-gate 		if (len <= 0) {
2682*7c478bd9Sstevel@tonic-gate 			len = 1;
2683*7c478bd9Sstevel@tonic-gate 			printable = 0;
2684*7c478bd9Sstevel@tonic-gate 		} else {
2685*7c478bd9Sstevel@tonic-gate 			printable = iswprint(wc);
2686*7c478bd9Sstevel@tonic-gate 		}
2687*7c478bd9Sstevel@tonic-gate 		err = pa_putstr(context, printable, str, len);
2688*7c478bd9Sstevel@tonic-gate 		str += len;
2689*7c478bd9Sstevel@tonic-gate 	}
2690*7c478bd9Sstevel@tonic-gate 	return (err);
2691*7c478bd9Sstevel@tonic-gate }
2692*7c478bd9Sstevel@tonic-gate 
2693*7c478bd9Sstevel@tonic-gate /*
2694*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2695*7c478bd9Sstevel@tonic-gate  * pa_print()	:  print as one str or formatted for easy reading.
2696*7c478bd9Sstevel@tonic-gate  * 		: flag - indicates whether to output a new line for
2697*7c478bd9Sstevel@tonic-gate  *		: multi-line output.
2698*7c478bd9Sstevel@tonic-gate  * 		:		= 0; no new line
2699*7c478bd9Sstevel@tonic-gate  *		:		= 1; new line if regular output
2700*7c478bd9Sstevel@tonic-gate  * output	: The audit record information is displayed in the
2701*7c478bd9Sstevel@tonic-gate  *		  type specified by uvaltype and value specified in
2702*7c478bd9Sstevel@tonic-gate  *		  uval.  The printing of the delimiter or newline is
2703*7c478bd9Sstevel@tonic-gate  *		  determined by PRF_ONELINE, and the flag value,
2704*7c478bd9Sstevel@tonic-gate  *		  as follows:
2705*7c478bd9Sstevel@tonic-gate  *			+--------+------+------+-----------------+
2706*7c478bd9Sstevel@tonic-gate  *			|ONELINE | flag | last | Action          |
2707*7c478bd9Sstevel@tonic-gate  *			+--------+------+------+-----------------+
2708*7c478bd9Sstevel@tonic-gate  *			|    Y   |   Y  |   T  | print new line  |
2709*7c478bd9Sstevel@tonic-gate  *			|    Y   |   Y  |   F  | print delimiter |
2710*7c478bd9Sstevel@tonic-gate  *			|    Y   |   N  |   T  | print new line  |
2711*7c478bd9Sstevel@tonic-gate  *			|    Y   |   N  |   F  | print delimiter |
2712*7c478bd9Sstevel@tonic-gate  *			|    N   |   Y  |   T  | print new line  |
2713*7c478bd9Sstevel@tonic-gate  *			|    N   |   Y  |   F  | print new line  |
2714*7c478bd9Sstevel@tonic-gate  *			|    N   |   N  |   T  | print new line  |
2715*7c478bd9Sstevel@tonic-gate  *			|    N   |   N  |   F  | print delimiter |
2716*7c478bd9Sstevel@tonic-gate  *			+--------+------+------+-----------------+
2717*7c478bd9Sstevel@tonic-gate  *
2718*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2719*7c478bd9Sstevel@tonic-gate  *		0 - successful
2720*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2721*7c478bd9Sstevel@tonic-gate  */
2722*7c478bd9Sstevel@tonic-gate int
2723*7c478bd9Sstevel@tonic-gate pa_print(pr_context_t *context, uval_t *uval, int flag)
2724*7c478bd9Sstevel@tonic-gate {
2725*7c478bd9Sstevel@tonic-gate 	int	returnstat = 0;
2726*7c478bd9Sstevel@tonic-gate 	int	last;
2727*7c478bd9Sstevel@tonic-gate 
2728*7c478bd9Sstevel@tonic-gate 	switch (uval->uvaltype) {
2729*7c478bd9Sstevel@tonic-gate 	case PRA_INT32:
2730*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%d", uval->int32_val);
2731*7c478bd9Sstevel@tonic-gate 		break;
2732*7c478bd9Sstevel@tonic-gate 	case PRA_UINT32:
2733*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%u", uval->uint32_val);
2734*7c478bd9Sstevel@tonic-gate 		break;
2735*7c478bd9Sstevel@tonic-gate 	case PRA_INT64:
2736*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%"PRId64, uval->int64_val);
2737*7c478bd9Sstevel@tonic-gate 		break;
2738*7c478bd9Sstevel@tonic-gate 	case PRA_UINT64:
2739*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%"PRIu64, uval->uint64_val);
2740*7c478bd9Sstevel@tonic-gate 		break;
2741*7c478bd9Sstevel@tonic-gate 	case PRA_SHORT:
2742*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%hd", uval->short_val);
2743*7c478bd9Sstevel@tonic-gate 		break;
2744*7c478bd9Sstevel@tonic-gate 	case PRA_USHORT:
2745*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%hu", uval->ushort_val);
2746*7c478bd9Sstevel@tonic-gate 		break;
2747*7c478bd9Sstevel@tonic-gate 	case PRA_CHAR:
2748*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%c", uval->char_val);
2749*7c478bd9Sstevel@tonic-gate 		break;
2750*7c478bd9Sstevel@tonic-gate 	case PRA_BYTE:
2751*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%d", uval->char_val);
2752*7c478bd9Sstevel@tonic-gate 		break;
2753*7c478bd9Sstevel@tonic-gate 	case PRA_STRING:
2754*7c478bd9Sstevel@tonic-gate 		returnstat = pa_printstr(context, uval->string_val);
2755*7c478bd9Sstevel@tonic-gate 		break;
2756*7c478bd9Sstevel@tonic-gate 	case PRA_HEX32:
2757*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "0x%x", uval->int32_val);
2758*7c478bd9Sstevel@tonic-gate 		break;
2759*7c478bd9Sstevel@tonic-gate 	case PRA_HEX64:
2760*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "0x%"PRIx64, uval->int64_val);
2761*7c478bd9Sstevel@tonic-gate 		break;
2762*7c478bd9Sstevel@tonic-gate 	case PRA_SHEX:
2763*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "0x%hx", uval->short_val);
2764*7c478bd9Sstevel@tonic-gate 		break;
2765*7c478bd9Sstevel@tonic-gate 	case PRA_OCT:
2766*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%ho", uval->ushort_val);
2767*7c478bd9Sstevel@tonic-gate 		break;
2768*7c478bd9Sstevel@tonic-gate 	case PRA_LOCT:
2769*7c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%o", (int)uval->uint32_val);
2770*7c478bd9Sstevel@tonic-gate 		break;
2771*7c478bd9Sstevel@tonic-gate 	default:
2772*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("praudit: Unknown type.\n"));
2773*7c478bd9Sstevel@tonic-gate 		returnstat = -1;
2774*7c478bd9Sstevel@tonic-gate 		break;
2775*7c478bd9Sstevel@tonic-gate 	}
2776*7c478bd9Sstevel@tonic-gate 	if (returnstat < 0)
2777*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2778*7c478bd9Sstevel@tonic-gate 
2779*7c478bd9Sstevel@tonic-gate 	last = (context->audit_adr->adr_now ==
2780*7c478bd9Sstevel@tonic-gate 	    (context->audit_rec_start + context->audit_rec_len));
2781*7c478bd9Sstevel@tonic-gate 
2782*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM)) {
2783*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_ONELINE)) {
2784*7c478bd9Sstevel@tonic-gate 			if ((flag == 1) || last)
2785*7c478bd9Sstevel@tonic-gate 				returnstat = pr_putchar(context, '\n');
2786*7c478bd9Sstevel@tonic-gate 			else
2787*7c478bd9Sstevel@tonic-gate 				returnstat = pr_printf(context, "%s",
2788*7c478bd9Sstevel@tonic-gate 				    context->SEPARATOR);
2789*7c478bd9Sstevel@tonic-gate 		} else {
2790*7c478bd9Sstevel@tonic-gate 			if (!last)
2791*7c478bd9Sstevel@tonic-gate 				returnstat = pr_printf(context, "%s",
2792*7c478bd9Sstevel@tonic-gate 				    context->SEPARATOR);
2793*7c478bd9Sstevel@tonic-gate 			else
2794*7c478bd9Sstevel@tonic-gate 				returnstat = pr_putchar(context, '\n');
2795*7c478bd9Sstevel@tonic-gate 		}
2796*7c478bd9Sstevel@tonic-gate 	}
2797*7c478bd9Sstevel@tonic-gate 	if ((returnstat == 0) && (context->data_mode == FILEMODE))
2798*7c478bd9Sstevel@tonic-gate 		(void) fflush(stdout);
2799*7c478bd9Sstevel@tonic-gate 
2800*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2801*7c478bd9Sstevel@tonic-gate }
2802*7c478bd9Sstevel@tonic-gate 
2803*7c478bd9Sstevel@tonic-gate /*
2804*7c478bd9Sstevel@tonic-gate  * Convert binary data to ASCII for printing.
2805*7c478bd9Sstevel@tonic-gate  */
2806*7c478bd9Sstevel@tonic-gate void
2807*7c478bd9Sstevel@tonic-gate convertascii(char *p, char *c, int size)
2808*7c478bd9Sstevel@tonic-gate {
2809*7c478bd9Sstevel@tonic-gate 	register int	i;
2810*7c478bd9Sstevel@tonic-gate 
2811*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
2812*7c478bd9Sstevel@tonic-gate 		*(c + i) = (char)toascii(*(c + i));
2813*7c478bd9Sstevel@tonic-gate 		if ((int)iscntrl(*(c + i))) {
2814*7c478bd9Sstevel@tonic-gate 			*p++ = '^';
2815*7c478bd9Sstevel@tonic-gate 			*p++ = (char)(*(c + i) + 0x40);
2816*7c478bd9Sstevel@tonic-gate 		} else
2817*7c478bd9Sstevel@tonic-gate 			*p++ = *(c + i);
2818*7c478bd9Sstevel@tonic-gate 	}
2819*7c478bd9Sstevel@tonic-gate 
2820*7c478bd9Sstevel@tonic-gate 	*p = '\0';
2821*7c478bd9Sstevel@tonic-gate 
2822*7c478bd9Sstevel@tonic-gate }
2823*7c478bd9Sstevel@tonic-gate 
2824*7c478bd9Sstevel@tonic-gate 
2825*7c478bd9Sstevel@tonic-gate /*
2826*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2827*7c478bd9Sstevel@tonic-gate  * pa_xgeneric: Process Xobject token and display contents
2828*7c478bd9Sstevel@tonic-gate  *		      This routine will handle many of the attribute
2829*7c478bd9Sstevel@tonic-gate  *		      types introduced in TS 2.x, such as:
2830*7c478bd9Sstevel@tonic-gate  *
2831*7c478bd9Sstevel@tonic-gate  *		      AUT_XCOLORMAP, AUT_XCURSOR, AUT_XFONT,
2832*7c478bd9Sstevel@tonic-gate  *		      AUT_XGC, AUT_XPIXMAP, AUT_XWINDOW
2833*7c478bd9Sstevel@tonic-gate  *
2834*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the token id has been retrieved
2835*7c478bd9Sstevel@tonic-gate  *
2836*7c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
2837*7c478bd9Sstevel@tonic-gate  *			:  0 - successful
2838*7c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the xatom token id has been retrieved
2839*7c478bd9Sstevel@tonic-gate  *
2840*7c478bd9Sstevel@tonic-gate  * Format of xobj
2841*7c478bd9Sstevel@tonic-gate  *	text token id		adr_char
2842*7c478bd9Sstevel@tonic-gate  * 	XID 			adr_u_int32
2843*7c478bd9Sstevel@tonic-gate  * 	creator uid		adr_pw_uid
2844*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2845*7c478bd9Sstevel@tonic-gate  */
2846*7c478bd9Sstevel@tonic-gate int
2847*7c478bd9Sstevel@tonic-gate pa_xgeneric(pr_context_t *context)
2848*7c478bd9Sstevel@tonic-gate {
2849*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2850*7c478bd9Sstevel@tonic-gate 
2851*7c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_XID, 0, 0);
2852*7c478bd9Sstevel@tonic-gate 	return (process_tag(context, TAG_XCUID, returnstat, 1));
2853*7c478bd9Sstevel@tonic-gate }
2854*7c478bd9Sstevel@tonic-gate 
2855*7c478bd9Sstevel@tonic-gate 
2856*7c478bd9Sstevel@tonic-gate /*
2857*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------------------
2858*7c478bd9Sstevel@tonic-gate  * pa_liaison : Issues pr_adr_char to retrieve the next ADR item from the
2859*7c478bd9Sstevel@tonic-gate  *			input stream pointed to by audit_adr, and prints it
2860*7c478bd9Sstevel@tonic-gate  *			if status >= 0 either in ASCII or raw form
2861*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2862*7c478bd9Sstevel@tonic-gate  *		: 0 - successful
2863*7c478bd9Sstevel@tonic-gate  *		: 1 - warning, unknown label type
2864*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2865*7c478bd9Sstevel@tonic-gate  */
2866*7c478bd9Sstevel@tonic-gate int
2867*7c478bd9Sstevel@tonic-gate pa_liaison(pr_context_t *context, int status, int flag)
2868*7c478bd9Sstevel@tonic-gate {
2869*7c478bd9Sstevel@tonic-gate 	int	returnstat;
2870*7c478bd9Sstevel@tonic-gate 	int32_t	li;
2871*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2872*7c478bd9Sstevel@tonic-gate 
2873*7c478bd9Sstevel@tonic-gate 	if (status >= 0) {
2874*7c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_int32(context, &li, 1)) != 0) {
2875*7c478bd9Sstevel@tonic-gate 			return (returnstat);
2876*7c478bd9Sstevel@tonic-gate 		}
2877*7c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
2878*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
2879*7c478bd9Sstevel@tonic-gate 			uval.uint32_val = li;
2880*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
2881*7c478bd9Sstevel@tonic-gate 		}
2882*7c478bd9Sstevel@tonic-gate 		/* print in hexadecimal form */
2883*7c478bd9Sstevel@tonic-gate 		if ((context->format & PRF_RAWM) || (returnstat == 1)) {
2884*7c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_HEX32;
2885*7c478bd9Sstevel@tonic-gate 			uval.uint32_val = li;
2886*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
2887*7c478bd9Sstevel@tonic-gate 		}
2888*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2889*7c478bd9Sstevel@tonic-gate 	} else
2890*7c478bd9Sstevel@tonic-gate 		return (status);
2891*7c478bd9Sstevel@tonic-gate }
2892*7c478bd9Sstevel@tonic-gate 
2893*7c478bd9Sstevel@tonic-gate /*
2894*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------------------
2895*7c478bd9Sstevel@tonic-gate  * pa_xid : Issues pr_adr_int32 to retrieve the XID from the input
2896*7c478bd9Sstevel@tonic-gate  *	      stream pointed to by audit_adr, and prints it if
2897*7c478bd9Sstevel@tonic-gate  *	      status >= 0 either in ASCII or raw form
2898*7c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2899*7c478bd9Sstevel@tonic-gate  *		:  0 - successful
2900*7c478bd9Sstevel@tonic-gate  *		:  1 - warning, unknown label type
2901*7c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------------------
2902*7c478bd9Sstevel@tonic-gate  */
2903*7c478bd9Sstevel@tonic-gate 
2904*7c478bd9Sstevel@tonic-gate int
2905*7c478bd9Sstevel@tonic-gate pa_xid(pr_context_t *context, int status, int flag)
2906*7c478bd9Sstevel@tonic-gate {
2907*7c478bd9Sstevel@tonic-gate 	int returnstat;
2908*7c478bd9Sstevel@tonic-gate 	int32_t xid;
2909*7c478bd9Sstevel@tonic-gate 	uval_t	uval;
2910*7c478bd9Sstevel@tonic-gate 
2911*7c478bd9Sstevel@tonic-gate 	if (status < 0)
2912*7c478bd9Sstevel@tonic-gate 		return (status);
2913*7c478bd9Sstevel@tonic-gate 
2914*7c478bd9Sstevel@tonic-gate 	/* get XID from stream */
2915*7c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int32(context, (int32_t *)&xid, 1)) != 0)
2916*7c478bd9Sstevel@tonic-gate 		return (returnstat);
2917*7c478bd9Sstevel@tonic-gate 
2918*7c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
2919*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
2920*7c478bd9Sstevel@tonic-gate 		uval.string_val = hexconvert((char *)&xid, sizeof (xid),
2921*7c478bd9Sstevel@tonic-gate 		    sizeof (xid));
2922*7c478bd9Sstevel@tonic-gate 		if (uval.string_val) {
2923*7c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
2924*7c478bd9Sstevel@tonic-gate 			free(uval.string_val);
2925*7c478bd9Sstevel@tonic-gate 		}
2926*7c478bd9Sstevel@tonic-gate 	} else {
2927*7c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_INT32;
2928*7c478bd9Sstevel@tonic-gate 		uval.int32_val = xid;
2929*7c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
2930*7c478bd9Sstevel@tonic-gate 	}
2931*7c478bd9Sstevel@tonic-gate 
2932*7c478bd9Sstevel@tonic-gate 	return (returnstat);
2933*7c478bd9Sstevel@tonic-gate }
2934