xref: /titanic_53/usr/src/cmd/praudit/format.c (revision 8f9294f315395bcb89119429b2e5496111ce4976)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
581490fd2Sgww  * Common Development and Distribution License (the "License").
681490fd2Sgww  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
228dc347dbStz204579  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #define	_REENTRANT
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <ctype.h>
317c478bd9Sstevel@tonic-gate #include <errno.h>
327c478bd9Sstevel@tonic-gate #include <grp.h>
337c478bd9Sstevel@tonic-gate #include <libintl.h>
347c478bd9Sstevel@tonic-gate #include <netdb.h>
357c478bd9Sstevel@tonic-gate #include <time.h>
367c478bd9Sstevel@tonic-gate #include <pwd.h>
377c478bd9Sstevel@tonic-gate #include <stdio.h>
387c478bd9Sstevel@tonic-gate #include <stdlib.h>
397c478bd9Sstevel@tonic-gate #include <string.h>
407c478bd9Sstevel@tonic-gate #include <wchar.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
457c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
467c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
477c478bd9Sstevel@tonic-gate #include <security/pam_appl.h>
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
507c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
517c478bd9Sstevel@tonic-gate #include <sys/types.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #include "praudit.h"
547c478bd9Sstevel@tonic-gate #include "toktable.h"
557c478bd9Sstevel@tonic-gate #include "adt_xlate.h"
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate static void	convertascii(char *p, char *c, int size);
587c478bd9Sstevel@tonic-gate static int	convertbinary(char *p, char *c, int size);
597c478bd9Sstevel@tonic-gate static void	eventmodifier2string(ushort_t emodifier, char *modstring,
607c478bd9Sstevel@tonic-gate     size_t modlen);
617c478bd9Sstevel@tonic-gate static int	do_mtime32(pr_context_t *context, int status, int flag,
627c478bd9Sstevel@tonic-gate     uint32_t scale);
637c478bd9Sstevel@tonic-gate static int	do_mtime64(pr_context_t *context, int status, int flag,
647c478bd9Sstevel@tonic-gate     uint64_t scale);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * ------------------------------------------------------
687c478bd9Sstevel@tonic-gate  * field widths for arbitrary data token type
697c478bd9Sstevel@tonic-gate  * ------------------------------------------------------
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate static struct fw {
727c478bd9Sstevel@tonic-gate 	char	basic_unit;
737c478bd9Sstevel@tonic-gate 	struct {
747c478bd9Sstevel@tonic-gate 		char	print_base;
757c478bd9Sstevel@tonic-gate 		int	field_width;
767c478bd9Sstevel@tonic-gate 	} pwidth[5];
777c478bd9Sstevel@tonic-gate } fwidth[] = {
787c478bd9Sstevel@tonic-gate 	/* character data type, 8 bits */
797c478bd9Sstevel@tonic-gate 		AUR_CHAR,	AUP_BINARY,	12,
807c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	 6,
817c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	 6,
827c478bd9Sstevel@tonic-gate 				AUP_HEX,	 6,
838dc347dbStz204579 				AUP_STRING,	 1,
847c478bd9Sstevel@tonic-gate 		AUR_BYTE,	AUP_BINARY,	12,
857c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	 6,
867c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	 6,
877c478bd9Sstevel@tonic-gate 				AUP_HEX,	 6,
888dc347dbStz204579 				AUP_STRING,	 1,
897c478bd9Sstevel@tonic-gate 		AUR_SHORT,	AUP_BINARY,	20,
907c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	10,
917c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	10,
927c478bd9Sstevel@tonic-gate 				AUP_HEX,	 8,
937c478bd9Sstevel@tonic-gate 				AUP_STRING,	 6,
947c478bd9Sstevel@tonic-gate 		AUR_INT32,	AUP_BINARY,	36,
957c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	18,
967c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	18,
977c478bd9Sstevel@tonic-gate 				AUP_HEX,	12,
987c478bd9Sstevel@tonic-gate 				AUP_STRING,	10,
997c478bd9Sstevel@tonic-gate 		AUR_INT64,	AUP_BINARY,	68,
1007c478bd9Sstevel@tonic-gate 				AUP_OCTAL,	34,
1017c478bd9Sstevel@tonic-gate 				AUP_DECIMAL,	34,
1027c478bd9Sstevel@tonic-gate 				AUP_HEX,	20,
1037c478bd9Sstevel@tonic-gate 				AUP_STRING,	20};
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate static int	numwidthentries = sizeof (fwidth)
1077c478bd9Sstevel@tonic-gate 			/ sizeof (struct fw);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1127c478bd9Sstevel@tonic-gate  * do_newline:
1137c478bd9Sstevel@tonic-gate  *		  Print a newline, if needed according to various formatting
1147c478bd9Sstevel@tonic-gate  *		  rules.
1157c478bd9Sstevel@tonic-gate  * return codes :   0 - success
1167c478bd9Sstevel@tonic-gate  *		:  -1 - error
1177c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate int
1207c478bd9Sstevel@tonic-gate do_newline(pr_context_t *context, int flag)
1217c478bd9Sstevel@tonic-gate {
1227c478bd9Sstevel@tonic-gate 	int	retstat = 0;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_ONELINE) && (flag == 1))
1257c478bd9Sstevel@tonic-gate 		retstat = pr_putchar(context, '\n');
1267c478bd9Sstevel@tonic-gate 	else if (!(context->format & PRF_XMLM))
1277c478bd9Sstevel@tonic-gate 		retstat = pr_printf(context, "%s", context->SEPARATOR);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	return (retstat);
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate int
1337c478bd9Sstevel@tonic-gate open_tag(pr_context_t *context, int tagnum)
1347c478bd9Sstevel@tonic-gate {
1357c478bd9Sstevel@tonic-gate 	int		err = 0;
1367c478bd9Sstevel@tonic-gate 	token_desc_t	*tag;
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	/* no-op if not doing XML format */
1397c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM))
1407c478bd9Sstevel@tonic-gate 		return (0);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	tag = &tokentable[tagnum];
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	/*
1457c478bd9Sstevel@tonic-gate 	 * First if needed do an implicit finish of a pending open for an
1467c478bd9Sstevel@tonic-gate 	 * extended tag.  I.e., for the extended tag xxx:
1477c478bd9Sstevel@tonic-gate 	 *	<xxx a=".." b=".."> ...  </xxx>
1487c478bd9Sstevel@tonic-gate 	 * -- insert a close bracket after the last attribute
1497c478bd9Sstevel@tonic-gate 	 * (in other words, when the 1st non-attribute is opened while
1507c478bd9Sstevel@tonic-gate 	 * this is pending). Note that only one tag could be pending at
1517c478bd9Sstevel@tonic-gate 	 * a given time -- it couldn't be nested.
1527c478bd9Sstevel@tonic-gate 	 */
1537c478bd9Sstevel@tonic-gate 	if (context->pending_flag && (tag->t_type != T_ATTRIBUTE)) {
1547c478bd9Sstevel@tonic-gate 		/* complete pending extended open */
1557c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, '>');
1567c478bd9Sstevel@tonic-gate 		if (err != 0)
1577c478bd9Sstevel@tonic-gate 			return (err);
1587c478bd9Sstevel@tonic-gate 		context->pending_flag = 0;
1597c478bd9Sstevel@tonic-gate 	}
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	if (is_header_token(tagnum) || is_file_token(tagnum)) {
1627c478bd9Sstevel@tonic-gate 		/* File token or new record on new line */
1637c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, '\n');
1647c478bd9Sstevel@tonic-gate 	} else if (is_token(tagnum)) {
1657c478bd9Sstevel@tonic-gate 		/* Each token on new line if possible */
1667c478bd9Sstevel@tonic-gate 		err = do_newline(context, 1);
1677c478bd9Sstevel@tonic-gate 	}
1687c478bd9Sstevel@tonic-gate 	if (err != 0)
1697c478bd9Sstevel@tonic-gate 		return (err);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	switch (tag->t_type) {
1727c478bd9Sstevel@tonic-gate 	case T_ATTRIBUTE:
1737c478bd9Sstevel@tonic-gate 		err = pr_printf(context, " %s=\"", tag->t_tagname);
1747c478bd9Sstevel@tonic-gate 		break;
1757c478bd9Sstevel@tonic-gate 	case T_ELEMENT:
1767c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "<%s>", tag->t_tagname);
1777c478bd9Sstevel@tonic-gate 		break;
1787c478bd9Sstevel@tonic-gate 	case T_ENCLOSED:
1797c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "<%s", tag->t_tagname);
1807c478bd9Sstevel@tonic-gate 		break;
1817c478bd9Sstevel@tonic-gate 	case T_EXTENDED:
1827c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "<%s", tag->t_tagname);
1837c478bd9Sstevel@tonic-gate 		if (err == 0)
1847c478bd9Sstevel@tonic-gate 			context->pending_flag = tagnum;
1857c478bd9Sstevel@tonic-gate 		break;
1867c478bd9Sstevel@tonic-gate 	default:
1877c478bd9Sstevel@tonic-gate 		break;
1887c478bd9Sstevel@tonic-gate 	}
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	if (is_header_token(tagnum) && (err == 0))
1917c478bd9Sstevel@tonic-gate 		context->current_rec = tagnum;	/* set start of new record */
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	return (err);
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate  * Do an implicit close of a record when needed.
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate int
2007c478bd9Sstevel@tonic-gate check_close_rec(pr_context_t *context, int tagnum)
2017c478bd9Sstevel@tonic-gate {
2027c478bd9Sstevel@tonic-gate 	int	err = 0;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	/* no-op if not doing XML format */
2057c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM))
2067c478bd9Sstevel@tonic-gate 		return (0);
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	/*
2097c478bd9Sstevel@tonic-gate 	 * If we're opening a header or the file token (i.e., starting a new
2107c478bd9Sstevel@tonic-gate 	 * record), if there's a current record in progress do an implicit
2117c478bd9Sstevel@tonic-gate 	 * close of it.
2127c478bd9Sstevel@tonic-gate 	 */
2137c478bd9Sstevel@tonic-gate 	if ((is_header_token(tagnum) || is_file_token(tagnum)) &&
2147c478bd9Sstevel@tonic-gate 	    context->current_rec) {
2157c478bd9Sstevel@tonic-gate 		err = do_newline(context, 1);
2167c478bd9Sstevel@tonic-gate 		if (err == 0)
2177c478bd9Sstevel@tonic-gate 			err = close_tag(context, context->current_rec);
2187c478bd9Sstevel@tonic-gate 	}
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	return (err);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate /*
2247c478bd9Sstevel@tonic-gate  * explicit finish of a pending open for an extended tag.
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate int
2277c478bd9Sstevel@tonic-gate finish_open_tag(pr_context_t *context)
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate 	int	err = 0;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	/* no-op if not doing XML format */
2327c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM))
2337c478bd9Sstevel@tonic-gate 		return (0);
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	if (context->pending_flag) {
2367c478bd9Sstevel@tonic-gate 		/* complete pending extended open */
2377c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, '>');
2387c478bd9Sstevel@tonic-gate 		if (err == 0)
2397c478bd9Sstevel@tonic-gate 			context->pending_flag = 0;
2407c478bd9Sstevel@tonic-gate 	}
2417c478bd9Sstevel@tonic-gate 	return (err);
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate int
2457c478bd9Sstevel@tonic-gate close_tag(pr_context_t *context, int tagnum)
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate 	int		err = 0;
2487c478bd9Sstevel@tonic-gate 	token_desc_t	*tag;
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	/* no-op if not doing XML format */
2517c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM))
2527c478bd9Sstevel@tonic-gate 		return (0);
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	tag = &tokentable[tagnum];
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	switch (tag->t_type) {
2577c478bd9Sstevel@tonic-gate 	case T_ATTRIBUTE:
2587c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, '\"');
2597c478bd9Sstevel@tonic-gate 		break;
2607c478bd9Sstevel@tonic-gate 	case T_ELEMENT:
2617c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "</%s>", tag->t_tagname);
2627c478bd9Sstevel@tonic-gate 		break;
2637c478bd9Sstevel@tonic-gate 	case T_ENCLOSED:
2647c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "/>");
2657c478bd9Sstevel@tonic-gate 		break;
2667c478bd9Sstevel@tonic-gate 	case T_EXTENDED:
2677c478bd9Sstevel@tonic-gate 		err = pr_printf(context, "</%s>", tag->t_tagname);
2687c478bd9Sstevel@tonic-gate 		break;
2697c478bd9Sstevel@tonic-gate 	default:
2707c478bd9Sstevel@tonic-gate 		break;
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	if (is_header_token(tagnum) && (err == 0))
2747c478bd9Sstevel@tonic-gate 		context->current_rec = 0;	/* closing rec; none current */
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 	return (err);
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2817c478bd9Sstevel@tonic-gate  * process_tag:
2827c478bd9Sstevel@tonic-gate  *		  Calls the routine corresponding to the tag
2837c478bd9Sstevel@tonic-gate  *		  Note that to use this mechanism, all such routines must
2847c478bd9Sstevel@tonic-gate  *		  take 2 ints for their parameters; the first of these is
2857c478bd9Sstevel@tonic-gate  *		  the current status.
2867c478bd9Sstevel@tonic-gate  *
2877c478bd9Sstevel@tonic-gate  *		  flag = 1 for newline / delimiter, else 0
2887c478bd9Sstevel@tonic-gate  * return codes : -1 - error
2897c478bd9Sstevel@tonic-gate  *		:  0 - successful
2907c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
2917c478bd9Sstevel@tonic-gate  */
2927c478bd9Sstevel@tonic-gate int
2937c478bd9Sstevel@tonic-gate process_tag(pr_context_t *context, int tagnum, int status, int flag)
2947c478bd9Sstevel@tonic-gate {
2957c478bd9Sstevel@tonic-gate 	int retstat;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	retstat = status;
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	if (retstat)
3007c478bd9Sstevel@tonic-gate 		return (retstat);
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	if ((tagnum > 0) && (tagnum <= MAXTAG) &&
3037c478bd9Sstevel@tonic-gate 	    (tokentable[tagnum].func != NOFUNC)) {
3047c478bd9Sstevel@tonic-gate 		retstat = open_tag(context, tagnum);
3057c478bd9Sstevel@tonic-gate 		if (!retstat)
3067c478bd9Sstevel@tonic-gate 			retstat = (*tokentable[tagnum].func)(context, status,
3077c478bd9Sstevel@tonic-gate 			    flag);
3087c478bd9Sstevel@tonic-gate 		if (!retstat)
3097c478bd9Sstevel@tonic-gate 			retstat = close_tag(context, tagnum);
3107c478bd9Sstevel@tonic-gate 		return (retstat);
3117c478bd9Sstevel@tonic-gate 	}
3127c478bd9Sstevel@tonic-gate 	/* here if token id is not in table */
3137c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("praudit: No code associated with "
3147c478bd9Sstevel@tonic-gate 	    "tag id %d\n"), tagnum);
3157c478bd9Sstevel@tonic-gate 	return (0);
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate void
3197c478bd9Sstevel@tonic-gate get_Hname(uint32_t addr, char *buf, size_t buflen)
3207c478bd9Sstevel@tonic-gate {
3217c478bd9Sstevel@tonic-gate 	extern char	*inet_ntoa(const struct in_addr);
3227c478bd9Sstevel@tonic-gate 	struct hostent *phe;
3237c478bd9Sstevel@tonic-gate 	struct in_addr ia;
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	phe = gethostbyaddr((const char *)&addr, 4, AF_INET);
3267c478bd9Sstevel@tonic-gate 	if (phe == (struct hostent *)0) {
3277c478bd9Sstevel@tonic-gate 		ia.s_addr = addr;
3287c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, buflen, "%s", inet_ntoa(ia));
3297c478bd9Sstevel@tonic-gate 		return;
3307c478bd9Sstevel@tonic-gate 	}
3317c478bd9Sstevel@tonic-gate 	ia.s_addr = addr;
3327c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, buflen, "%s", phe->h_name);
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate void
3367c478bd9Sstevel@tonic-gate get_Hname_ex(uint32_t *addr, char *buf, size_t buflen)
3377c478bd9Sstevel@tonic-gate {
3387c478bd9Sstevel@tonic-gate 	struct hostent *phe;
3397c478bd9Sstevel@tonic-gate 	int err;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	phe = getipnodebyaddr((const void *)addr, 16, AF_INET6, &err);
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	if (phe == (struct hostent *)0) {
3447c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *)addr, buf, buflen);
3457c478bd9Sstevel@tonic-gate 	} else
3467c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, buflen, "%s", phe->h_name);
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	if (phe)
3497c478bd9Sstevel@tonic-gate 		freehostent(phe);
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate int
3537c478bd9Sstevel@tonic-gate pa_hostname(pr_context_t *context, int status, int flag)
3547c478bd9Sstevel@tonic-gate {
3557c478bd9Sstevel@tonic-gate 	int	returnstat;
3567c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr;
3577c478bd9Sstevel@tonic-gate 	struct in_addr ia;
3587c478bd9Sstevel@tonic-gate 	uval_t uval;
3597c478bd9Sstevel@tonic-gate 	char	buf[256];
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 	if (status <  0)
3627c478bd9Sstevel@tonic-gate 		return (status);
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0)
3657c478bd9Sstevel@tonic-gate 		return (returnstat);
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
3707c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
3717c478bd9Sstevel@tonic-gate 		get_Hname(ip_addr, buf, sizeof (buf));
3727c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
3737c478bd9Sstevel@tonic-gate 	} else {
3747c478bd9Sstevel@tonic-gate 		ia.s_addr = ip_addr;
3757c478bd9Sstevel@tonic-gate 		if ((uval.string_val = inet_ntoa(ia)) == NULL)
3767c478bd9Sstevel@tonic-gate 			return (-1);
3777c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate 	return (returnstat);
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate int
3837c478bd9Sstevel@tonic-gate pa_hostname_ex(pr_context_t *context, int status, int flag)
3847c478bd9Sstevel@tonic-gate {
3857c478bd9Sstevel@tonic-gate 	int	returnstat;
3867c478bd9Sstevel@tonic-gate 	uint32_t	ip_type;
3877c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[4];
3887c478bd9Sstevel@tonic-gate 	struct in_addr ia;
3897c478bd9Sstevel@tonic-gate 	char buf[256];
3907c478bd9Sstevel@tonic-gate 	uval_t uval;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	if (status <  0)
3937c478bd9Sstevel@tonic-gate 		return (status);
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	/* get ip type */
3967c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int32(context, (int32_t *)&ip_type, 1)) != 0)
3977c478bd9Sstevel@tonic-gate 		return (returnstat);
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	/* only IPv4 and IPv6 addresses are legal */
4007c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
4017c478bd9Sstevel@tonic-gate 		return (-1);
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 	/* get ip address */
4047c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
4057c478bd9Sstevel@tonic-gate 			return (returnstat);
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_HOSTID)) != 0)
4087c478bd9Sstevel@tonic-gate 		return (returnstat);
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
4117c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {		/* ipv4 address */
4127c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
4137c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
4147c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], buf, sizeof (buf));
4157c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
4167c478bd9Sstevel@tonic-gate 		} else {
4177c478bd9Sstevel@tonic-gate 			ia.s_addr = ip_addr[0];
4187c478bd9Sstevel@tonic-gate 			if ((uval.string_val = inet_ntoa(ia)) == NULL)
4197c478bd9Sstevel@tonic-gate 				return (-1);
4207c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
4217c478bd9Sstevel@tonic-gate 		}
4227c478bd9Sstevel@tonic-gate 	} else if (ip_type == AU_IPv6) {	/* IPv6 addresss (128 bits) */
4237c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
4247c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
4257c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, buf, sizeof (buf));
4267c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
4277c478bd9Sstevel@tonic-gate 		} else {
4287c478bd9Sstevel@tonic-gate 			uval.string_val = (char *)buf;
4297c478bd9Sstevel@tonic-gate 			(void) inet_ntop(AF_INET6, (void *)ip_addr, buf,
4307c478bd9Sstevel@tonic-gate 			    sizeof (buf));
4317c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
4327c478bd9Sstevel@tonic-gate 		}
4337c478bd9Sstevel@tonic-gate 	}
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 	if (returnstat != 0)
4367c478bd9Sstevel@tonic-gate 		return (returnstat);
4377c478bd9Sstevel@tonic-gate 	return (close_tag(context, TAG_HOSTID));
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate int
4417c478bd9Sstevel@tonic-gate pa_hostname_so(pr_context_t *context, int status, int flag)
4427c478bd9Sstevel@tonic-gate {
4437c478bd9Sstevel@tonic-gate 	int		returnstat;
4447c478bd9Sstevel@tonic-gate 	short		ip_type;
4457c478bd9Sstevel@tonic-gate 	ushort_t	ip_port;
4467c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[4];
4477c478bd9Sstevel@tonic-gate 	struct in_addr ia;
4487c478bd9Sstevel@tonic-gate 	char buf[256];
4497c478bd9Sstevel@tonic-gate 	uval_t uval;
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 	if (status <  0)
4527c478bd9Sstevel@tonic-gate 		return (status);
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 	/* get ip type */
4557c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_short(context, &ip_type, 1)) != 0)
4567c478bd9Sstevel@tonic-gate 		return (returnstat);
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	/* only IPv4 and IPv6 addresses are legal */
4597c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
4607c478bd9Sstevel@tonic-gate 		return (-1);
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	/* get local ip port */
4637c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_short(context, &ip_port, 1)) != 0)
4647c478bd9Sstevel@tonic-gate 		return (returnstat);
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_SOCKEXLPORT)) != 0)
4677c478bd9Sstevel@tonic-gate 		return (returnstat);
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
4707c478bd9Sstevel@tonic-gate 	uval.string_val = hexconvert((char *)&ip_port, sizeof (ip_port),
4717c478bd9Sstevel@tonic-gate 	    sizeof (ip_port));
4727c478bd9Sstevel@tonic-gate 	if (uval.string_val) {
4737c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, 0);
4747c478bd9Sstevel@tonic-gate 		free(uval.string_val);
4757c478bd9Sstevel@tonic-gate 	} else
4767c478bd9Sstevel@tonic-gate 		returnstat = -1;
4777c478bd9Sstevel@tonic-gate 	if (returnstat)
4787c478bd9Sstevel@tonic-gate 		return (returnstat);
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_SOCKEXLPORT)) != 0)
4817c478bd9Sstevel@tonic-gate 		return (returnstat);
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 	/* get local ip address */
4847c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
4857c478bd9Sstevel@tonic-gate 			return (returnstat);
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_SOCKEXLADDR)) != 0)
4887c478bd9Sstevel@tonic-gate 		return (returnstat);
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {		/* ipv4 address */
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
4937c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
4947c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], buf, sizeof (buf));
4957c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
4967c478bd9Sstevel@tonic-gate 		} else {
4977c478bd9Sstevel@tonic-gate 			ia.s_addr = ip_addr[0];
4987c478bd9Sstevel@tonic-gate 			if ((uval.string_val = inet_ntoa(ia)) == NULL)
4997c478bd9Sstevel@tonic-gate 				return (-1);
5007c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
5017c478bd9Sstevel@tonic-gate 		}
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	} else if (ip_type == AU_IPv6) {	/* IPv6 addresss (128 bits) */
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
5067c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
5077c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, buf, sizeof (buf));
5087c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
5097c478bd9Sstevel@tonic-gate 		} else {
5107c478bd9Sstevel@tonic-gate 			uval.string_val = (char *)buf;
5117c478bd9Sstevel@tonic-gate 			(void) inet_ntop(AF_INET6, (void *)ip_addr, buf,
5127c478bd9Sstevel@tonic-gate 			    sizeof (buf));
5137c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, 0);
5147c478bd9Sstevel@tonic-gate 		}
5157c478bd9Sstevel@tonic-gate 	} else
5167c478bd9Sstevel@tonic-gate 		returnstat = -1;
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 	if (returnstat)
5197c478bd9Sstevel@tonic-gate 		return (returnstat);
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_SOCKEXLADDR)) != 0)
5227c478bd9Sstevel@tonic-gate 		return (returnstat);
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 	/* get foreign ip port */
5257c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_short(context, &ip_port, 1)) != 0)
5267c478bd9Sstevel@tonic-gate 		return (returnstat);
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_SOCKEXFPORT)) != 0)
5297c478bd9Sstevel@tonic-gate 		return (returnstat);
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	uval.string_val = hexconvert((char *)&ip_port, sizeof (ip_port),
5327c478bd9Sstevel@tonic-gate 	    sizeof (ip_port));
5337c478bd9Sstevel@tonic-gate 	if (uval.string_val) {
5347c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, 0);
5357c478bd9Sstevel@tonic-gate 		free(uval.string_val);
5367c478bd9Sstevel@tonic-gate 	} else
5377c478bd9Sstevel@tonic-gate 		returnstat = -1;
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 	if (returnstat)
5407c478bd9Sstevel@tonic-gate 		return (returnstat);
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_SOCKEXFPORT)) != 0)
5437c478bd9Sstevel@tonic-gate 		return (returnstat);
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	/* get foreign ip address */
5467c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
5477c478bd9Sstevel@tonic-gate 			return (returnstat);
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_SOCKEXFADDR)) != 0)
5507c478bd9Sstevel@tonic-gate 		return (returnstat);
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {		/* ipv4 address */
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
5557c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
5567c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], buf, sizeof (buf));
5577c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
5587c478bd9Sstevel@tonic-gate 		} else {
5597c478bd9Sstevel@tonic-gate 			ia.s_addr = ip_addr[0];
5607c478bd9Sstevel@tonic-gate 			if ((uval.string_val = inet_ntoa(ia)) == NULL)
5617c478bd9Sstevel@tonic-gate 				return (-1);
5627c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
5637c478bd9Sstevel@tonic-gate 		}
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	} else if (ip_type == AU_IPv6) {	/* IPv6 addresss (128 bits) */
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
5687c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
5697c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, buf, sizeof (buf));
5707c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
5717c478bd9Sstevel@tonic-gate 		} else {
5727c478bd9Sstevel@tonic-gate 			uval.string_val = (char *)buf;
5737c478bd9Sstevel@tonic-gate 			(void) inet_ntop(AF_INET6, (void *)ip_addr, buf,
5747c478bd9Sstevel@tonic-gate 			    sizeof (buf));
5757c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
5767c478bd9Sstevel@tonic-gate 		}
5777c478bd9Sstevel@tonic-gate 	} else
5787c478bd9Sstevel@tonic-gate 		returnstat = -1;
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 	if (returnstat)
5817c478bd9Sstevel@tonic-gate 		return (returnstat);
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_SOCKEXFADDR)) != 0)
5847c478bd9Sstevel@tonic-gate 		return (returnstat);
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	return (returnstat);
5877c478bd9Sstevel@tonic-gate }
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate #define	NBITSMAJOR64	32	/* # of major device bits in 64-bit Solaris */
5917c478bd9Sstevel@tonic-gate #define	NBITSMINOR64	32	/* # of minor device bits in 64-bit Solaris */
5927c478bd9Sstevel@tonic-gate #define	MAXMAJ64	0xfffffffful	/* max major value */
5937c478bd9Sstevel@tonic-gate #define	MAXMIN64	0xfffffffful	/* max minor value */
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate #define	NBITSMAJOR32	14	/* # of SVR4 major device bits */
5967c478bd9Sstevel@tonic-gate #define	NBITSMINOR32	18	/* # of SVR4 minor device bits */
5977c478bd9Sstevel@tonic-gate #define	NMAXMAJ32	0x3fff	/* SVR4 max major value */
5987c478bd9Sstevel@tonic-gate #define	NMAXMIN32	0x3ffff	/* MAX minor for 3b2 software drivers. */
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate static int32_t
6027c478bd9Sstevel@tonic-gate minor_64(uint64_t dev)
6037c478bd9Sstevel@tonic-gate {
6047c478bd9Sstevel@tonic-gate 	if (dev == NODEV) {
6057c478bd9Sstevel@tonic-gate 		errno = EINVAL;
6067c478bd9Sstevel@tonic-gate 		return (NODEV);
6077c478bd9Sstevel@tonic-gate 	}
6087c478bd9Sstevel@tonic-gate 	return (int32_t)(dev & MAXMIN64);
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate static int32_t
6127c478bd9Sstevel@tonic-gate major_64(uint64_t dev)
6137c478bd9Sstevel@tonic-gate {
6147c478bd9Sstevel@tonic-gate 	uint32_t maj;
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 	maj = (uint32_t)(dev >> NBITSMINOR64);
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 	if (dev == NODEV || maj > MAXMAJ64) {
6197c478bd9Sstevel@tonic-gate 		errno = EINVAL;
6207c478bd9Sstevel@tonic-gate 		return (NODEV);
6217c478bd9Sstevel@tonic-gate 	}
6227c478bd9Sstevel@tonic-gate 	return (int32_t)(maj);
6237c478bd9Sstevel@tonic-gate }
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate static int32_t
6267c478bd9Sstevel@tonic-gate minor_32(uint32_t dev)
6277c478bd9Sstevel@tonic-gate {
6287c478bd9Sstevel@tonic-gate 	if (dev == NODEV) {
6297c478bd9Sstevel@tonic-gate 		errno = EINVAL;
6307c478bd9Sstevel@tonic-gate 		return (NODEV);
6317c478bd9Sstevel@tonic-gate 	}
6327c478bd9Sstevel@tonic-gate 	return (int32_t)(dev & MAXMIN32);
6337c478bd9Sstevel@tonic-gate }
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate static int32_t
6367c478bd9Sstevel@tonic-gate major_32(uint32_t dev)
6377c478bd9Sstevel@tonic-gate {
6387c478bd9Sstevel@tonic-gate 	uint32_t maj;
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 	maj = (uint32_t)(dev >> NBITSMINOR32);
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate 	if (dev == NODEV || maj > MAXMAJ32) {
6437c478bd9Sstevel@tonic-gate 		errno = EINVAL;
6447c478bd9Sstevel@tonic-gate 		return (NODEV);
6457c478bd9Sstevel@tonic-gate 	}
6467c478bd9Sstevel@tonic-gate 	return (int32_t)(maj);
6477c478bd9Sstevel@tonic-gate }
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate /*
6517c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
6527c478bd9Sstevel@tonic-gate  * pa_tid() 	: Process terminal id and display contents
6537c478bd9Sstevel@tonic-gate  * return codes	: -1 - error
6547c478bd9Sstevel@tonic-gate  *		:  0 - successful
6557c478bd9Sstevel@tonic-gate  *
6567c478bd9Sstevel@tonic-gate  *	terminal id port		adr_int32
6577c478bd9Sstevel@tonic-gate  *	terminal id machine		adr_int32
6587c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
6597c478bd9Sstevel@tonic-gate  */
6607c478bd9Sstevel@tonic-gate int
6617c478bd9Sstevel@tonic-gate pa_tid32(pr_context_t *context, int status, int flag)
6627c478bd9Sstevel@tonic-gate {
6637c478bd9Sstevel@tonic-gate 	int	returnstat;
6647c478bd9Sstevel@tonic-gate 	int32_t dev_maj_min;
6657c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr;
6667c478bd9Sstevel@tonic-gate 	struct in_addr ia;
6677c478bd9Sstevel@tonic-gate 	char	*ipstring;
6687c478bd9Sstevel@tonic-gate 	char	buf[256];
6697c478bd9Sstevel@tonic-gate 	uval_t	uval;
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate 	if (status <  0)
6727c478bd9Sstevel@tonic-gate 		return (status);
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int32(context, &dev_maj_min, 1)) != 0)
6757c478bd9Sstevel@tonic-gate 		return (returnstat);
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0)
6787c478bd9Sstevel@tonic-gate 		return (returnstat);
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
6817c478bd9Sstevel@tonic-gate 	uval.string_val = buf;
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
6847c478bd9Sstevel@tonic-gate 		char	hostname[256];
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 		get_Hname(ip_addr, hostname, sizeof (hostname));
6877c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
6887c478bd9Sstevel@tonic-gate 		    major_32(dev_maj_min),
6897c478bd9Sstevel@tonic-gate 		    minor_32(dev_maj_min),
6907c478bd9Sstevel@tonic-gate 		    hostname);
6917c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
6927c478bd9Sstevel@tonic-gate 	}
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate 	ia.s_addr = ip_addr;
6957c478bd9Sstevel@tonic-gate 	if ((ipstring = inet_ntoa(ia)) == NULL)
6967c478bd9Sstevel@tonic-gate 		return (-1);
6977c478bd9Sstevel@tonic-gate 
698*8f9294f3Sgww 	(void) snprintf(buf, sizeof (buf), "%d %d %s", major_32(dev_maj_min),
6997c478bd9Sstevel@tonic-gate 	    minor_32(dev_maj_min),
7007c478bd9Sstevel@tonic-gate 	    ipstring);
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate 	return (pa_print(context, &uval, flag));
7037c478bd9Sstevel@tonic-gate }
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate int
7067c478bd9Sstevel@tonic-gate pa_tid32_ex(pr_context_t *context, int status, int flag)
7077c478bd9Sstevel@tonic-gate {
7087c478bd9Sstevel@tonic-gate 	int		returnstat;
7097c478bd9Sstevel@tonic-gate 	int32_t		dev_maj_min;
7107c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[16];
7117c478bd9Sstevel@tonic-gate 	uint32_t	ip_type;
7127c478bd9Sstevel@tonic-gate 	struct in_addr	ia;
7137c478bd9Sstevel@tonic-gate 	char		*ipstring;
7147c478bd9Sstevel@tonic-gate 	char		hostname[256];
7157c478bd9Sstevel@tonic-gate 	char		buf[256];
7167c478bd9Sstevel@tonic-gate 	char		tbuf[256];
7177c478bd9Sstevel@tonic-gate 	uval_t		uval;
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate 	if (status <  0)
7207c478bd9Sstevel@tonic-gate 		return (status);
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 	/* get port info */
7237c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int32(context, &dev_maj_min, 1)) != 0)
7247c478bd9Sstevel@tonic-gate 		return (returnstat);
7257c478bd9Sstevel@tonic-gate 
7267c478bd9Sstevel@tonic-gate 	/* get address type */
7277c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
7287c478bd9Sstevel@tonic-gate 		return (returnstat);
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate 	/* legal address types are either AU_IPv4 or AU_IPv6 only */
7317c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
7327c478bd9Sstevel@tonic-gate 		return (-1);
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 	/* get address (4/16) */
7357c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
7367c478bd9Sstevel@tonic-gate 		return (returnstat);
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
7397c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {
7407c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
7437c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], hostname, sizeof (hostname));
7447c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%d %d %s",
745*8f9294f3Sgww 			    major_32(dev_maj_min), minor_32(dev_maj_min),
7467c478bd9Sstevel@tonic-gate 			    hostname);
7477c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
7487c478bd9Sstevel@tonic-gate 		}
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 		ia.s_addr = ip_addr[0];
7517c478bd9Sstevel@tonic-gate 		if ((ipstring = inet_ntoa(ia)) == NULL)
7527c478bd9Sstevel@tonic-gate 			return (-1);
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
755*8f9294f3Sgww 		    major_32(dev_maj_min), minor_32(dev_maj_min), ipstring);
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
7587c478bd9Sstevel@tonic-gate 	} else {
7597c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
7627c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, hostname, sizeof (hostname));
7637c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%d %d %s",
764*8f9294f3Sgww 			    major_32(dev_maj_min), minor_32(dev_maj_min),
7657c478bd9Sstevel@tonic-gate 			    hostname);
7667c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
7677c478bd9Sstevel@tonic-gate 		}
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf,
7707c478bd9Sstevel@tonic-gate 		    sizeof (tbuf));
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
773*8f9294f3Sgww 		    major_32(dev_maj_min), minor_32(dev_maj_min), tbuf);
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
7767c478bd9Sstevel@tonic-gate 	}
7777c478bd9Sstevel@tonic-gate }
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate int
7807c478bd9Sstevel@tonic-gate pa_ip_addr(pr_context_t *context, int status, int flag)
7817c478bd9Sstevel@tonic-gate {
7827c478bd9Sstevel@tonic-gate 	int		returnstat;
7837c478bd9Sstevel@tonic-gate 	uval_t		uval;
7847c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[4];
7857c478bd9Sstevel@tonic-gate 	uint32_t	ip_type;
7867c478bd9Sstevel@tonic-gate 	struct in_addr	ia;
7877c478bd9Sstevel@tonic-gate 	char		*ipstring;
7887c478bd9Sstevel@tonic-gate 	char		hostname[256];
7897c478bd9Sstevel@tonic-gate 	char		buf[256];
7907c478bd9Sstevel@tonic-gate 	char		tbuf[256];
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 	if (status <  0)
7937c478bd9Sstevel@tonic-gate 		return (status);
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate 	/* get address type */
7967c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
7977c478bd9Sstevel@tonic-gate 		return (returnstat);
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate 	/* legal address type is AU_IPv4 or AU_IPv6 */
8007c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
8017c478bd9Sstevel@tonic-gate 		return (-1);
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate 	/* get address (4/16) */
8047c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
8057c478bd9Sstevel@tonic-gate 		return (returnstat);
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
8087c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {
8097c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
8127c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], hostname, sizeof (hostname));
813*8f9294f3Sgww 			(void) snprintf(buf, sizeof (buf), "%s", hostname);
8147c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
8157c478bd9Sstevel@tonic-gate 		}
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 		ia.s_addr = ip_addr[0];
8187c478bd9Sstevel@tonic-gate 		if ((ipstring = inet_ntoa(ia)) == NULL)
8197c478bd9Sstevel@tonic-gate 			return (-1);
8207c478bd9Sstevel@tonic-gate 
821*8f9294f3Sgww 		(void) snprintf(buf, sizeof (buf), "%s", ipstring);
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
8247c478bd9Sstevel@tonic-gate 	} else {
8257c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
8267c478bd9Sstevel@tonic-gate 
8277c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
8287c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, hostname, sizeof (hostname));
8297c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%s",
8307c478bd9Sstevel@tonic-gate 			    hostname);
8317c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
8327c478bd9Sstevel@tonic-gate 		}
8337c478bd9Sstevel@tonic-gate 
8347c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf,
8357c478bd9Sstevel@tonic-gate 		    sizeof (tbuf));
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%s", tbuf);
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
8407c478bd9Sstevel@tonic-gate 	}
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate }
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate int
8457c478bd9Sstevel@tonic-gate pa_tid64(pr_context_t *context, int status, int flag)
8467c478bd9Sstevel@tonic-gate {
8477c478bd9Sstevel@tonic-gate 	int	returnstat;
8487c478bd9Sstevel@tonic-gate 	int64_t dev_maj_min;
8497c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr;
8507c478bd9Sstevel@tonic-gate 	struct in_addr ia;
8517c478bd9Sstevel@tonic-gate 	char	*ipstring;
8527c478bd9Sstevel@tonic-gate 	char	buf[256];
8537c478bd9Sstevel@tonic-gate 	uval_t	uval;
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 	if (status <  0)
8567c478bd9Sstevel@tonic-gate 		return (status);
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0)
8597c478bd9Sstevel@tonic-gate 		return (returnstat);
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0)
8627c478bd9Sstevel@tonic-gate 		return (returnstat);
8637c478bd9Sstevel@tonic-gate 
8647c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
8657c478bd9Sstevel@tonic-gate 	uval.string_val = buf;
8667c478bd9Sstevel@tonic-gate 
8677c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
8687c478bd9Sstevel@tonic-gate 		char	hostname[256];
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 		get_Hname(ip_addr, hostname, sizeof (hostname));
8717c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
872*8f9294f3Sgww 		    major_64(dev_maj_min), minor_64(dev_maj_min), hostname);
8737c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
8747c478bd9Sstevel@tonic-gate 	}
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 	ia.s_addr = ip_addr;
8777c478bd9Sstevel@tonic-gate 	if ((ipstring = inet_ntoa(ia)) == NULL)
8787c478bd9Sstevel@tonic-gate 		return (-1);
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf), "%d %d %s",
881*8f9294f3Sgww 	    major_64(dev_maj_min), minor_64(dev_maj_min), ipstring);
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate 	return (pa_print(context, &uval, flag));
8847c478bd9Sstevel@tonic-gate }
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate int
8877c478bd9Sstevel@tonic-gate pa_tid64_ex(pr_context_t *context, int status, int flag)
8887c478bd9Sstevel@tonic-gate {
8897c478bd9Sstevel@tonic-gate 	int		returnstat;
8907c478bd9Sstevel@tonic-gate 	int64_t		dev_maj_min;
8917c478bd9Sstevel@tonic-gate 	uint32_t	ip_addr[4];
8927c478bd9Sstevel@tonic-gate 	uint32_t	ip_type;
8937c478bd9Sstevel@tonic-gate 	struct in_addr	ia;
8947c478bd9Sstevel@tonic-gate 	char		*ipstring;
8957c478bd9Sstevel@tonic-gate 	char		hostname[256];
8967c478bd9Sstevel@tonic-gate 	char		buf[256];
8977c478bd9Sstevel@tonic-gate 	char		tbuf[256];
8987c478bd9Sstevel@tonic-gate 	uval_t		uval;
8997c478bd9Sstevel@tonic-gate 
9007c478bd9Sstevel@tonic-gate 	if (status <  0)
9017c478bd9Sstevel@tonic-gate 		return (status);
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate 	/* get port info */
9047c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0)
9057c478bd9Sstevel@tonic-gate 		return (returnstat);
9067c478bd9Sstevel@tonic-gate 
9077c478bd9Sstevel@tonic-gate 	/* get address type */
9087c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
9097c478bd9Sstevel@tonic-gate 		return (returnstat);
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate 	/* legal address types are either AU_IPv4 or AU_IPv6 only */
9127c478bd9Sstevel@tonic-gate 	if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
9137c478bd9Sstevel@tonic-gate 		return (-1);
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@tonic-gate 	/* get address (4/16) */
9167c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, (char *)&ip_addr, ip_type)) != 0)
9177c478bd9Sstevel@tonic-gate 		return (returnstat);
9187c478bd9Sstevel@tonic-gate 
9197c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
9207c478bd9Sstevel@tonic-gate 	if (ip_type == AU_IPv4) {
9217c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
9247c478bd9Sstevel@tonic-gate 			get_Hname(ip_addr[0], hostname, sizeof (hostname));
9257c478bd9Sstevel@tonic-gate 			uval.string_val = buf;
9267c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%d %d %s",
927*8f9294f3Sgww 			    major_64(dev_maj_min), minor_64(dev_maj_min),
9287c478bd9Sstevel@tonic-gate 			    hostname);
9297c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
9307c478bd9Sstevel@tonic-gate 		}
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 		ia.s_addr = ip_addr[0];
9337c478bd9Sstevel@tonic-gate 		if ((ipstring = inet_ntoa(ia)) == NULL)
9347c478bd9Sstevel@tonic-gate 			return (-1);
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
937*8f9294f3Sgww 		    major_64(dev_maj_min), minor_64(dev_maj_min), ipstring);
9387c478bd9Sstevel@tonic-gate 
9397c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
9407c478bd9Sstevel@tonic-gate 	} else {
9417c478bd9Sstevel@tonic-gate 		uval.string_val = buf;
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
9447c478bd9Sstevel@tonic-gate 			get_Hname_ex(ip_addr, hostname, sizeof (hostname));
9457c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, sizeof (buf), "%d %d %s",
946*8f9294f3Sgww 			    major_64(dev_maj_min), minor_64(dev_maj_min),
9477c478bd9Sstevel@tonic-gate 			    hostname);
9487c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
9497c478bd9Sstevel@tonic-gate 		}
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate 		(void) inet_ntop(AF_INET6, (void *)ip_addr, tbuf,
9527c478bd9Sstevel@tonic-gate 		    sizeof (tbuf));
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, sizeof (buf), "%d %d %s",
955*8f9294f3Sgww 		    major_64(dev_maj_min), minor_64(dev_maj_min), tbuf);
9567c478bd9Sstevel@tonic-gate 
9577c478bd9Sstevel@tonic-gate 		return (pa_print(context, &uval, flag));
9587c478bd9Sstevel@tonic-gate 	}
9597c478bd9Sstevel@tonic-gate }
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate /*
9637c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------
9647c478bd9Sstevel@tonic-gate  * findfieldwidth:
9657c478bd9Sstevel@tonic-gate  * Returns the field width based on the basic unit and print mode.
9667c478bd9Sstevel@tonic-gate  * This routine is called to determine the field width for the
9677c478bd9Sstevel@tonic-gate  * data items in the arbitrary data token where the tokens are
9687c478bd9Sstevel@tonic-gate  * to be printed in more than one line.  The field width can be
9697c478bd9Sstevel@tonic-gate  * found in the fwidth structure.
9707c478bd9Sstevel@tonic-gate  *
9717c478bd9Sstevel@tonic-gate  * Input parameters:
9727c478bd9Sstevel@tonic-gate  * basicunit	Can be one of AUR_CHAR, AUR_BYTE, AUR_SHORT,
9737c478bd9Sstevel@tonic-gate  *		AUR_INT32, or AUR_INT64
9747c478bd9Sstevel@tonic-gate  * howtoprint	Print mode. Can be one of AUP_BINARY, AUP_OCTAL,
9757c478bd9Sstevel@tonic-gate  *		AUP_DECIMAL, or AUP_HEX.
9767c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------
9777c478bd9Sstevel@tonic-gate  */
9787c478bd9Sstevel@tonic-gate int
9797c478bd9Sstevel@tonic-gate findfieldwidth(char basicunit, char howtoprint)
9807c478bd9Sstevel@tonic-gate {
9817c478bd9Sstevel@tonic-gate 	int	i, j;
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 	for (i = 0; i < numwidthentries; i++) {
9847c478bd9Sstevel@tonic-gate 		if (fwidth[i].basic_unit == basicunit) {
9857c478bd9Sstevel@tonic-gate 			for (j = 0; j <= 4; j++) {
9867c478bd9Sstevel@tonic-gate 				if (fwidth[i].pwidth[j].print_base ==
987*8f9294f3Sgww 				    howtoprint) {
988*8f9294f3Sgww 					return (
989*8f9294f3Sgww 					    fwidth[i].pwidth[j].field_width);
990*8f9294f3Sgww 				}
9917c478bd9Sstevel@tonic-gate 			}
9927c478bd9Sstevel@tonic-gate 			/*
9937c478bd9Sstevel@tonic-gate 			 * if we got here, then we didn't get what we were after
9947c478bd9Sstevel@tonic-gate 			 */
9957c478bd9Sstevel@tonic-gate 			return (0);
9967c478bd9Sstevel@tonic-gate 		}
9977c478bd9Sstevel@tonic-gate 	}
9987c478bd9Sstevel@tonic-gate 	/* if we got here, we didn't get what we wanted either */
9997c478bd9Sstevel@tonic-gate 	return (0);
10007c478bd9Sstevel@tonic-gate }
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate /*
10047c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
10057c478bd9Sstevel@tonic-gate  * pa_cmd: Retrieves the cmd item from the input stream.
10067c478bd9Sstevel@tonic-gate  * return codes : -1 - error
10077c478bd9Sstevel@tonic-gate  *		:  0 - successful
10087c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
10097c478bd9Sstevel@tonic-gate  */
10107c478bd9Sstevel@tonic-gate int
10117c478bd9Sstevel@tonic-gate pa_cmd(pr_context_t *context, int status, int flag)
10127c478bd9Sstevel@tonic-gate {
10137c478bd9Sstevel@tonic-gate 	char	*cmd;  /* cmd */
10147c478bd9Sstevel@tonic-gate 	short	length;
10157c478bd9Sstevel@tonic-gate 	int	returnstat;
10167c478bd9Sstevel@tonic-gate 	uval_t	uval;
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate 	/*
10197c478bd9Sstevel@tonic-gate 	 * We need to know how much space to allocate for our string, so
10207c478bd9Sstevel@tonic-gate 	 * read the length first, then call pr_adr_char to read those bytes.
10217c478bd9Sstevel@tonic-gate 	 */
10227c478bd9Sstevel@tonic-gate 	if (status >= 0) {
10237c478bd9Sstevel@tonic-gate 		if (pr_adr_short(context, &length, 1) == 0) {
10247c478bd9Sstevel@tonic-gate 			if ((cmd = (char *)malloc(length + 1)) == NULL)
10257c478bd9Sstevel@tonic-gate 				return (-1);
10267c478bd9Sstevel@tonic-gate 			if (pr_adr_char(context, cmd, length) == 0) {
10277c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_STRING;
10287c478bd9Sstevel@tonic-gate 				uval.string_val = cmd;
10297c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
10307c478bd9Sstevel@tonic-gate 			} else {
10317c478bd9Sstevel@tonic-gate 				returnstat = -1;
10327c478bd9Sstevel@tonic-gate 			}
10337c478bd9Sstevel@tonic-gate 			free(cmd);
10347c478bd9Sstevel@tonic-gate 			return (returnstat);
10357c478bd9Sstevel@tonic-gate 		} else
10367c478bd9Sstevel@tonic-gate 			return (-1);
10377c478bd9Sstevel@tonic-gate 	} else
10387c478bd9Sstevel@tonic-gate 		return (status);
10397c478bd9Sstevel@tonic-gate }
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate 
10437c478bd9Sstevel@tonic-gate /*
10447c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
10457c478bd9Sstevel@tonic-gate  * pa_adr_byte	: Issues pr_adr_char to retrieve the next ADR item from
10467c478bd9Sstevel@tonic-gate  *		  the input stream pointed to by audit_adr, and prints it
10477c478bd9Sstevel@tonic-gate  *		  as an integer if status >= 0
10487c478bd9Sstevel@tonic-gate  * return codes : -1 - error
10497c478bd9Sstevel@tonic-gate  *		:  0 - successful
10507c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
10517c478bd9Sstevel@tonic-gate  */
10527c478bd9Sstevel@tonic-gate int
10537c478bd9Sstevel@tonic-gate pa_adr_byte(pr_context_t *context, int status, int flag)
10547c478bd9Sstevel@tonic-gate {
10557c478bd9Sstevel@tonic-gate 	char	c;
10567c478bd9Sstevel@tonic-gate 	uval_t	uval;
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate 	if (status >= 0) {
10597c478bd9Sstevel@tonic-gate 		if (pr_adr_char(context, &c, 1) == 0) {
10607c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_BYTE;
10617c478bd9Sstevel@tonic-gate 			uval.char_val = c;
10627c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
10637c478bd9Sstevel@tonic-gate 		} else
10647c478bd9Sstevel@tonic-gate 			return (-1);
10657c478bd9Sstevel@tonic-gate 	} else
10667c478bd9Sstevel@tonic-gate 		return (status);
10677c478bd9Sstevel@tonic-gate }
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate /*
10707c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
10717c478bd9Sstevel@tonic-gate  * pa_adr_charhex: Issues pr_adr_char to retrieve the next ADR item from
10727c478bd9Sstevel@tonic-gate  *			the input stream pointed to by audit_adr, and prints it
10737c478bd9Sstevel@tonic-gate  *			in hexadecimal if status >= 0
10747c478bd9Sstevel@tonic-gate  * return codes  : -1 - error
10757c478bd9Sstevel@tonic-gate  *		 :  0 - successful
10767c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
10777c478bd9Sstevel@tonic-gate  */
10787c478bd9Sstevel@tonic-gate int
10797c478bd9Sstevel@tonic-gate pa_adr_charhex(pr_context_t *context, int status, int flag)
10807c478bd9Sstevel@tonic-gate {
10817c478bd9Sstevel@tonic-gate 	char	p[2];
10827c478bd9Sstevel@tonic-gate 	int	returnstat;
10837c478bd9Sstevel@tonic-gate 	uval_t	uval;
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate 	if (status >= 0) {
10867c478bd9Sstevel@tonic-gate 		p[0] = p[1] = 0;
10877c478bd9Sstevel@tonic-gate 
10887c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_char(context, p, 1)) == 0) {
10897c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
10907c478bd9Sstevel@tonic-gate 			uval.string_val = hexconvert(p, sizeof (char),
10917c478bd9Sstevel@tonic-gate 			    sizeof (char));
10927c478bd9Sstevel@tonic-gate 			if (uval.string_val) {
10937c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
10947c478bd9Sstevel@tonic-gate 				free(uval.string_val);
10957c478bd9Sstevel@tonic-gate 			}
10967c478bd9Sstevel@tonic-gate 		}
10977c478bd9Sstevel@tonic-gate 		return (returnstat);
10987c478bd9Sstevel@tonic-gate 	} else
10997c478bd9Sstevel@tonic-gate 		return (status);
11007c478bd9Sstevel@tonic-gate }
11017c478bd9Sstevel@tonic-gate 
11027c478bd9Sstevel@tonic-gate /*
11037c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
11047c478bd9Sstevel@tonic-gate  * pa_adr_int32	: Issues pr_adr_int32 to retrieve the next ADR item from the
11057c478bd9Sstevel@tonic-gate  *		  input stream pointed to by audit_adr, and prints it
11067c478bd9Sstevel@tonic-gate  *		  if status >= 0
11077c478bd9Sstevel@tonic-gate  * return codes : -1 - error
11087c478bd9Sstevel@tonic-gate  *		:  0 - successful
11097c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
11107c478bd9Sstevel@tonic-gate  */
11117c478bd9Sstevel@tonic-gate int
11127c478bd9Sstevel@tonic-gate pa_adr_int32(pr_context_t *context, int status, int flag)
11137c478bd9Sstevel@tonic-gate {
11147c478bd9Sstevel@tonic-gate 	int32_t	c;
11157c478bd9Sstevel@tonic-gate 	uval_t	uval;
11167c478bd9Sstevel@tonic-gate 
11177c478bd9Sstevel@tonic-gate 	if (status >= 0) {
11187c478bd9Sstevel@tonic-gate 		if (pr_adr_int32(context, &c, 1) == 0) {
11197c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_INT32;
11207c478bd9Sstevel@tonic-gate 			uval.int32_val = c;
11217c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
11227c478bd9Sstevel@tonic-gate 		} else
11237c478bd9Sstevel@tonic-gate 			return (-1);
11247c478bd9Sstevel@tonic-gate 	} else
11257c478bd9Sstevel@tonic-gate 		return (status);
11267c478bd9Sstevel@tonic-gate }
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate 
11297c478bd9Sstevel@tonic-gate 
11307c478bd9Sstevel@tonic-gate 
11317c478bd9Sstevel@tonic-gate /*
11327c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
11337c478bd9Sstevel@tonic-gate  * pa_adr_int64	: Issues pr_adr_int64 to retrieve the next ADR item from the
11347c478bd9Sstevel@tonic-gate  *		  input stream pointed to by audit_adr, and prints it
11357c478bd9Sstevel@tonic-gate  *		  if status >= 0
11367c478bd9Sstevel@tonic-gate  * return codes : -1 - error
11377c478bd9Sstevel@tonic-gate  *		:  0 - successful
11387c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
11397c478bd9Sstevel@tonic-gate  */
11407c478bd9Sstevel@tonic-gate int
11417c478bd9Sstevel@tonic-gate pa_adr_int64(pr_context_t *context, int status, int flag)
11427c478bd9Sstevel@tonic-gate {
11437c478bd9Sstevel@tonic-gate 	int64_t	c;
11447c478bd9Sstevel@tonic-gate 	uval_t	uval;
11457c478bd9Sstevel@tonic-gate 
11467c478bd9Sstevel@tonic-gate 	if (status >= 0) {
11477c478bd9Sstevel@tonic-gate 		if (pr_adr_int64(context, &c, 1) == 0) {
11487c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_INT64;
11497c478bd9Sstevel@tonic-gate 			uval.int64_val = c;
11507c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
11517c478bd9Sstevel@tonic-gate 		} else
11527c478bd9Sstevel@tonic-gate 			return (-1);
11537c478bd9Sstevel@tonic-gate 	} else
11547c478bd9Sstevel@tonic-gate 		return (status);
11557c478bd9Sstevel@tonic-gate }
11567c478bd9Sstevel@tonic-gate 
11577c478bd9Sstevel@tonic-gate /*
11587c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
11597c478bd9Sstevel@tonic-gate  * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the
11607c478bd9Sstevel@tonic-gate  *			input stream pointed to by audit_adr, and prints it
11617c478bd9Sstevel@tonic-gate  *			in hexadecimal if status >= 0
11627c478bd9Sstevel@tonic-gate  * return codes  : -1 - error
11637c478bd9Sstevel@tonic-gate  *		:  0 - successful
11647c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
11657c478bd9Sstevel@tonic-gate  */
11667c478bd9Sstevel@tonic-gate int
11677c478bd9Sstevel@tonic-gate pa_adr_int32hex(pr_context_t *context, int status, int flag)
11687c478bd9Sstevel@tonic-gate {
11697c478bd9Sstevel@tonic-gate 	int32_t	l;
11707c478bd9Sstevel@tonic-gate 	int	returnstat;
11717c478bd9Sstevel@tonic-gate 	uval_t	uval;
11727c478bd9Sstevel@tonic-gate 
11737c478bd9Sstevel@tonic-gate 	if (status >= 0) {
11747c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_int32(context, &l, 1)) == 0) {
11757c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_HEX32;
11767c478bd9Sstevel@tonic-gate 			uval.int32_val = l;
11777c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
11787c478bd9Sstevel@tonic-gate 		}
11797c478bd9Sstevel@tonic-gate 		return (returnstat);
11807c478bd9Sstevel@tonic-gate 	} else
11817c478bd9Sstevel@tonic-gate 		return (status);
11827c478bd9Sstevel@tonic-gate }
11837c478bd9Sstevel@tonic-gate 
11847c478bd9Sstevel@tonic-gate /*
11857c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
11867c478bd9Sstevel@tonic-gate  * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the
11877c478bd9Sstevel@tonic-gate  *			input stream pointed to by audit_adr, and prints it
11887c478bd9Sstevel@tonic-gate  *			in hexadecimal if status >= 0
11897c478bd9Sstevel@tonic-gate  * return codes  : -1 - error
11907c478bd9Sstevel@tonic-gate  *		:  0 - successful
11917c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
11927c478bd9Sstevel@tonic-gate  */
11937c478bd9Sstevel@tonic-gate int
11947c478bd9Sstevel@tonic-gate pa_adr_int64hex(pr_context_t *context, int status, int flag)
11957c478bd9Sstevel@tonic-gate {
11967c478bd9Sstevel@tonic-gate 	int64_t	l;
11977c478bd9Sstevel@tonic-gate 	int	returnstat;
11987c478bd9Sstevel@tonic-gate 	uval_t	uval;
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate 	if (status >= 0) {
12017c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_int64(context, &l, 1)) == 0) {
12027c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_HEX64;
12037c478bd9Sstevel@tonic-gate 			uval.int64_val = l;
12047c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
12057c478bd9Sstevel@tonic-gate 		}
12067c478bd9Sstevel@tonic-gate 		return (returnstat);
12077c478bd9Sstevel@tonic-gate 	} else
12087c478bd9Sstevel@tonic-gate 		return (status);
12097c478bd9Sstevel@tonic-gate }
12107c478bd9Sstevel@tonic-gate 
12117c478bd9Sstevel@tonic-gate 
12127c478bd9Sstevel@tonic-gate /*
12137c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
12147c478bd9Sstevel@tonic-gate  * bu2string: Maps a print basic unit type to a string.
12157c478bd9Sstevel@tonic-gate  * returns  : The string mapping or "unknown basic unit type".
12167c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
12177c478bd9Sstevel@tonic-gate  */
12187c478bd9Sstevel@tonic-gate char *
12197c478bd9Sstevel@tonic-gate bu2string(char basic_unit)
12207c478bd9Sstevel@tonic-gate {
12217c478bd9Sstevel@tonic-gate 	register int	i;
12227c478bd9Sstevel@tonic-gate 
12237c478bd9Sstevel@tonic-gate 	struct bu_map_ent {
12247c478bd9Sstevel@tonic-gate 		char	basic_unit;
12257c478bd9Sstevel@tonic-gate 		char	*string;
12267c478bd9Sstevel@tonic-gate 	};
12277c478bd9Sstevel@tonic-gate 
12287c478bd9Sstevel@tonic-gate 	/*
12297c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
12307c478bd9Sstevel@tonic-gate 	 * These names are data units when displaying the arbitrary data
12317c478bd9Sstevel@tonic-gate 	 * token.
12327c478bd9Sstevel@tonic-gate 	 */
12337c478bd9Sstevel@tonic-gate 
12347c478bd9Sstevel@tonic-gate 	static struct bu_map_ent bu_map[] = {
12357c478bd9Sstevel@tonic-gate 				{ AUR_BYTE, "byte" },
12367c478bd9Sstevel@tonic-gate 				{ AUR_CHAR, "char" },
12377c478bd9Sstevel@tonic-gate 				{ AUR_SHORT, "short" },
12387c478bd9Sstevel@tonic-gate 				{ AUR_INT32, "int32" },
12397c478bd9Sstevel@tonic-gate 				{ AUR_INT64, "int64" } 	};
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate 	for (i = 0; i < sizeof (bu_map) / sizeof (struct bu_map_ent); i++)
12427c478bd9Sstevel@tonic-gate 		if (basic_unit == bu_map[i].basic_unit)
12437c478bd9Sstevel@tonic-gate 			return (gettext(bu_map[i].string));
12447c478bd9Sstevel@tonic-gate 
12457c478bd9Sstevel@tonic-gate 	return (gettext("unknown basic unit type"));
12467c478bd9Sstevel@tonic-gate }
12477c478bd9Sstevel@tonic-gate 
12487c478bd9Sstevel@tonic-gate 
12497c478bd9Sstevel@tonic-gate /*
12507c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
12517c478bd9Sstevel@tonic-gate  * eventmodifier2string: Maps event modifier flags to a readable string.
12527c478bd9Sstevel@tonic-gate  * returns: The string mapping or "none".
12537c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
12547c478bd9Sstevel@tonic-gate  */
12557c478bd9Sstevel@tonic-gate static void
12567c478bd9Sstevel@tonic-gate eventmodifier2string(ushort_t emodifier, char *modstring, size_t modlen)
12577c478bd9Sstevel@tonic-gate {
12587c478bd9Sstevel@tonic-gate 	register int	i, j;
12597c478bd9Sstevel@tonic-gate 
12607c478bd9Sstevel@tonic-gate 	struct em_map_ent {
12617c478bd9Sstevel@tonic-gate 		int	mask;
12627c478bd9Sstevel@tonic-gate 		char	*string;
12637c478bd9Sstevel@tonic-gate 	};
12647c478bd9Sstevel@tonic-gate 
12657c478bd9Sstevel@tonic-gate 	/*
12667c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
12677c478bd9Sstevel@tonic-gate 	 * These abbreviations represent the event modifier field of the
12687c478bd9Sstevel@tonic-gate 	 * header token.  To gain a better understanding of each modifier,
1269*8f9294f3Sgww 	 * read
1270*8f9294f3Sgww 	 * System Administration Guide: Security Services >> Solaris Auditing
1271*8f9294f3Sgww 	 * at http://docs.sun.com.
12727c478bd9Sstevel@tonic-gate 	 */
12737c478bd9Sstevel@tonic-gate 
12747c478bd9Sstevel@tonic-gate 	static struct em_map_ent em_map[] = {
12757c478bd9Sstevel@tonic-gate 		{ (int)PAD_READ,	"rd" },	/* data read from object */
12767c478bd9Sstevel@tonic-gate 		{ (int)PAD_WRITE,	"wr" },	/* data written to object */
12777c478bd9Sstevel@tonic-gate 		{ (int)PAD_SPRIVUSE,	"sp" },	/* successfully used priv */
12787c478bd9Sstevel@tonic-gate 		{ (int)PAD_FPRIVUSE,	"fp" },	/* failed use of priv */
12797c478bd9Sstevel@tonic-gate 		{ (int)PAD_NONATTR,	"na" },	/* non-attributable event */
12807c478bd9Sstevel@tonic-gate 		{ (int)PAD_FAILURE,	"fe" }	/* fail audit event */
12817c478bd9Sstevel@tonic-gate 	};
12827c478bd9Sstevel@tonic-gate 
12837c478bd9Sstevel@tonic-gate 	modstring[0] = '\0';
12847c478bd9Sstevel@tonic-gate 
12857c478bd9Sstevel@tonic-gate 	for (i = 0, j = 0; i < sizeof (em_map) / sizeof (struct em_map_ent);
12867c478bd9Sstevel@tonic-gate 	    i++) {
12877c478bd9Sstevel@tonic-gate 		if ((int)emodifier & em_map[i].mask) {
12887c478bd9Sstevel@tonic-gate 			if (j++)
12897c478bd9Sstevel@tonic-gate 				(void) strlcat(modstring, ":", modlen);
12907c478bd9Sstevel@tonic-gate 			(void) strlcat(modstring, em_map[i].string, modlen);
12917c478bd9Sstevel@tonic-gate 		}
12927c478bd9Sstevel@tonic-gate 	}
12937c478bd9Sstevel@tonic-gate }
12947c478bd9Sstevel@tonic-gate 
12957c478bd9Sstevel@tonic-gate 
12967c478bd9Sstevel@tonic-gate /*
12977c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------
12987c478bd9Sstevel@tonic-gate  * convert_char_to_string:
12997c478bd9Sstevel@tonic-gate  *   Converts a byte to string depending on the print mode
13007c478bd9Sstevel@tonic-gate  * input	: printmode, which may be one of AUP_BINARY,
13017c478bd9Sstevel@tonic-gate  *		  AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
13027c478bd9Sstevel@tonic-gate  *		  c, which is the byte to convert
13037c478bd9Sstevel@tonic-gate  * output	: p, which is a pointer to the location where
13047c478bd9Sstevel@tonic-gate  *		  the resulting string is to be stored
13057c478bd9Sstevel@tonic-gate  *  ----------------------------------------------------------
13067c478bd9Sstevel@tonic-gate  */
13077c478bd9Sstevel@tonic-gate 
13087c478bd9Sstevel@tonic-gate int
13097c478bd9Sstevel@tonic-gate convert_char_to_string(char printmode, char c, char *p)
13107c478bd9Sstevel@tonic-gate {
13117c478bd9Sstevel@tonic-gate 	union {
13127c478bd9Sstevel@tonic-gate 		char	c1[4];
13137c478bd9Sstevel@tonic-gate 		int	c2;
13147c478bd9Sstevel@tonic-gate 	} dat;
13157c478bd9Sstevel@tonic-gate 
13167c478bd9Sstevel@tonic-gate 	dat.c2 = 0;
13177c478bd9Sstevel@tonic-gate 	dat.c1[3] = c;
13187c478bd9Sstevel@tonic-gate 
13197c478bd9Sstevel@tonic-gate 	if (printmode == AUP_BINARY)
13207c478bd9Sstevel@tonic-gate 		(void) convertbinary(p, &c, sizeof (char));
13217c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_OCTAL)
13227c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%o", (int)dat.c2);
13237c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_DECIMAL)
13247c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%d", c);
13257c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_HEX)
13267c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "0x%x", (int)dat.c2);
13277c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_STRING)
13287c478bd9Sstevel@tonic-gate 		convertascii(p, &c, sizeof (char));
13297c478bd9Sstevel@tonic-gate 	return (0);
13307c478bd9Sstevel@tonic-gate }
13317c478bd9Sstevel@tonic-gate 
13327c478bd9Sstevel@tonic-gate /*
13337c478bd9Sstevel@tonic-gate  * --------------------------------------------------------------
13347c478bd9Sstevel@tonic-gate  * convert_short_to_string:
13357c478bd9Sstevel@tonic-gate  * Converts a short integer to string depending on the print mode
13367c478bd9Sstevel@tonic-gate  * input	: printmode, which may be one of AUP_BINARY,
13377c478bd9Sstevel@tonic-gate  *		AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
13387c478bd9Sstevel@tonic-gate  *		c, which is the short integer to convert
13397c478bd9Sstevel@tonic-gate  * output	: p, which is a pointer to the location where
13407c478bd9Sstevel@tonic-gate  *		the resulting string is to be stored
13417c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------------
13427c478bd9Sstevel@tonic-gate  */
13437c478bd9Sstevel@tonic-gate int
13447c478bd9Sstevel@tonic-gate convert_short_to_string(char printmode, short c, char *p)
13457c478bd9Sstevel@tonic-gate {
13467c478bd9Sstevel@tonic-gate 	union {
13477c478bd9Sstevel@tonic-gate 		short	c1[2];
13487c478bd9Sstevel@tonic-gate 		int	c2;
13497c478bd9Sstevel@tonic-gate 	} dat;
13507c478bd9Sstevel@tonic-gate 
13517c478bd9Sstevel@tonic-gate 	dat.c2 = 0;
13527c478bd9Sstevel@tonic-gate 	dat.c1[1] = c;
13537c478bd9Sstevel@tonic-gate 
13547c478bd9Sstevel@tonic-gate 	if (printmode == AUP_BINARY)
13557c478bd9Sstevel@tonic-gate 		(void) convertbinary(p, (char *)&c, sizeof (short));
13567c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_OCTAL)
13577c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%o", (int)dat.c2);
13587c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_DECIMAL)
13597c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%hd", c);
13607c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_HEX)
13617c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "0x%x", (int)dat.c2);
13627c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_STRING)
13637c478bd9Sstevel@tonic-gate 		convertascii(p, (char *)&c, sizeof (short));
13647c478bd9Sstevel@tonic-gate 	return (0);
13657c478bd9Sstevel@tonic-gate }
13667c478bd9Sstevel@tonic-gate 
13677c478bd9Sstevel@tonic-gate /*
13687c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------
13697c478bd9Sstevel@tonic-gate  * convert_int32_to_string:
13707c478bd9Sstevel@tonic-gate  * Converts a integer to string depending on the print mode
13717c478bd9Sstevel@tonic-gate  * input	: printmode, which may be one of AUP_BINARY,
13727c478bd9Sstevel@tonic-gate  *		AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
13737c478bd9Sstevel@tonic-gate  *		c, which is the integer to convert
13747c478bd9Sstevel@tonic-gate  * output	: p, which is a pointer to the location where
13757c478bd9Sstevel@tonic-gate  *		the resulting string is to be stored
13767c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------
13777c478bd9Sstevel@tonic-gate  */
13787c478bd9Sstevel@tonic-gate int
13797c478bd9Sstevel@tonic-gate convert_int32_to_string(char printmode, int32_t c, char *p)
13807c478bd9Sstevel@tonic-gate {
13817c478bd9Sstevel@tonic-gate 	if (printmode == AUP_BINARY)
13827c478bd9Sstevel@tonic-gate 		(void) convertbinary(p, (char *)&c, sizeof (int32_t));
13837c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_OCTAL)
13847c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%o", c);
13857c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_DECIMAL)
13867c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%d", c);
13877c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_HEX)
13887c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "0x%x", c);
13897c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_STRING)
13907c478bd9Sstevel@tonic-gate 		convertascii(p, (char *)&c, sizeof (int));
13917c478bd9Sstevel@tonic-gate 	return (0);
13927c478bd9Sstevel@tonic-gate }
13937c478bd9Sstevel@tonic-gate 
13947c478bd9Sstevel@tonic-gate /*
13957c478bd9Sstevel@tonic-gate  * ---------------------------------------------------------
13967c478bd9Sstevel@tonic-gate  * convert_int64_to_string:
13977c478bd9Sstevel@tonic-gate  * Converts a integer to string depending on the print mode
13987c478bd9Sstevel@tonic-gate  * input	: printmode, which may be one of AUP_BINARY,
13997c478bd9Sstevel@tonic-gate  *		AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
14007c478bd9Sstevel@tonic-gate  *		c, which is the integer to convert
14017c478bd9Sstevel@tonic-gate  * output	: p, which is a pointer to the location where
14027c478bd9Sstevel@tonic-gate  *		the resulting string is to be stored
14037c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------
14047c478bd9Sstevel@tonic-gate  */
14057c478bd9Sstevel@tonic-gate int
14067c478bd9Sstevel@tonic-gate convert_int64_to_string(char printmode, int64_t c, char *p)
14077c478bd9Sstevel@tonic-gate {
14087c478bd9Sstevel@tonic-gate 	if (printmode == AUP_BINARY)
14097c478bd9Sstevel@tonic-gate 		(void) convertbinary(p, (char *)&c, sizeof (int64_t));
14107c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_OCTAL)
14117c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%"PRIo64, c);
14127c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_DECIMAL)
14137c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%"PRId64, c);
14147c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_HEX)
14157c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "0x%"PRIx64, c);
14167c478bd9Sstevel@tonic-gate 	else if (printmode == AUP_STRING)
14177c478bd9Sstevel@tonic-gate 		convertascii(p, (char *)&c, sizeof (int64_t));
14187c478bd9Sstevel@tonic-gate 	return (0);
14197c478bd9Sstevel@tonic-gate }
14207c478bd9Sstevel@tonic-gate 
14217c478bd9Sstevel@tonic-gate 
14227c478bd9Sstevel@tonic-gate /*
14237c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------
14247c478bd9Sstevel@tonic-gate  * convertbinary:
14257c478bd9Sstevel@tonic-gate  * Converts a unit c of 'size' bytes long into a binary string
14267c478bd9Sstevel@tonic-gate  * and returns it into the position pointed to by p
14277c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------
14287c478bd9Sstevel@tonic-gate  */
14297c478bd9Sstevel@tonic-gate int
14307c478bd9Sstevel@tonic-gate convertbinary(char *p, char *c, int size)
14317c478bd9Sstevel@tonic-gate {
14327c478bd9Sstevel@tonic-gate 	char	*s, *t, *ss;
14337c478bd9Sstevel@tonic-gate 	int	i, j;
14347c478bd9Sstevel@tonic-gate 
14357c478bd9Sstevel@tonic-gate 	if ((s = (char *)malloc(8 * size + 1)) == NULL)
14367c478bd9Sstevel@tonic-gate 		return (0);
14377c478bd9Sstevel@tonic-gate 
14387c478bd9Sstevel@tonic-gate 	ss = s;
14397c478bd9Sstevel@tonic-gate 
14407c478bd9Sstevel@tonic-gate 	/* first convert to binary */
14417c478bd9Sstevel@tonic-gate 	t = s;
14427c478bd9Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
14437c478bd9Sstevel@tonic-gate 		for (j = 0; j < 8; j++)
14447c478bd9Sstevel@tonic-gate 			(void) sprintf(t++, "%d", ((*c >> (7 - j)) & (0x01)));
14457c478bd9Sstevel@tonic-gate 		c++;
14467c478bd9Sstevel@tonic-gate 	}
14477c478bd9Sstevel@tonic-gate 	*t = '\0';
14487c478bd9Sstevel@tonic-gate 
14497c478bd9Sstevel@tonic-gate 	/* now string leading zero's if any */
14507c478bd9Sstevel@tonic-gate 	j = strlen(s) - 1;
14517c478bd9Sstevel@tonic-gate 	for (i = 0; i < j; i++) {
14527c478bd9Sstevel@tonic-gate 		if (*s != '0')
14537c478bd9Sstevel@tonic-gate 			break;
14547c478bd9Sstevel@tonic-gate 			else
14557c478bd9Sstevel@tonic-gate 			s++;
14567c478bd9Sstevel@tonic-gate 	}
14577c478bd9Sstevel@tonic-gate 
14587c478bd9Sstevel@tonic-gate 	/* now copy the contents of s to p */
14597c478bd9Sstevel@tonic-gate 	t = p;
14607c478bd9Sstevel@tonic-gate 	for (i = 0; i < (8 * size + 1); i++) {
14617c478bd9Sstevel@tonic-gate 		if (*s == '\0') {
14627c478bd9Sstevel@tonic-gate 			*t = '\0';
14637c478bd9Sstevel@tonic-gate 			break;
14647c478bd9Sstevel@tonic-gate 		}
14657c478bd9Sstevel@tonic-gate 		*t++ = *s++;
14667c478bd9Sstevel@tonic-gate 	}
14677c478bd9Sstevel@tonic-gate 	free(ss);
14687c478bd9Sstevel@tonic-gate 
14697c478bd9Sstevel@tonic-gate 	return (1);
14707c478bd9Sstevel@tonic-gate }
14717c478bd9Sstevel@tonic-gate 
14727c478bd9Sstevel@tonic-gate 
14737c478bd9Sstevel@tonic-gate static char hex[] = "0123456789abcdef";
14747c478bd9Sstevel@tonic-gate /*
14757c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
14767c478bd9Sstevel@tonic-gate  * hexconvert	: Converts a string of (size) bytes to hexadecimal, and
14777c478bd9Sstevel@tonic-gate  *		returns the hexadecimal string.
14787c478bd9Sstevel@tonic-gate  * returns	: - NULL if memory cannot be allocated for the string, or
14797c478bd9Sstevel@tonic-gate  *		- pointer to the hexadecimal string if successful
14807c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
14817c478bd9Sstevel@tonic-gate  */
14827c478bd9Sstevel@tonic-gate char *
14837c478bd9Sstevel@tonic-gate hexconvert(char *c, int size, int chunk)
14847c478bd9Sstevel@tonic-gate {
14857c478bd9Sstevel@tonic-gate 	register char	*s, *t;
14867c478bd9Sstevel@tonic-gate 	register int	i, j, k;
14877c478bd9Sstevel@tonic-gate 	int	numchunks;
14887c478bd9Sstevel@tonic-gate 	int	leftovers;
14897c478bd9Sstevel@tonic-gate 
14907c478bd9Sstevel@tonic-gate 	if (size <= 0)
14917c478bd9Sstevel@tonic-gate 		return (NULL);
14927c478bd9Sstevel@tonic-gate 
14937c478bd9Sstevel@tonic-gate 	if ((s = (char *)malloc((size * 5) + 1)) == NULL)
14947c478bd9Sstevel@tonic-gate 		return (NULL);
14957c478bd9Sstevel@tonic-gate 
14967c478bd9Sstevel@tonic-gate 	if (chunk > size || chunk <= 0)
14977c478bd9Sstevel@tonic-gate 		chunk = size;
14987c478bd9Sstevel@tonic-gate 
14997c478bd9Sstevel@tonic-gate 	numchunks = size / chunk;
15007c478bd9Sstevel@tonic-gate 	leftovers = size % chunk;
15017c478bd9Sstevel@tonic-gate 
15027c478bd9Sstevel@tonic-gate 	t = s;
15037c478bd9Sstevel@tonic-gate 	for (i = j = 0; i < numchunks; i++) {
15047c478bd9Sstevel@tonic-gate 		if (j++) {
15057c478bd9Sstevel@tonic-gate 			*t++ = ' ';
15067c478bd9Sstevel@tonic-gate 		}
15077c478bd9Sstevel@tonic-gate 		*t++ = '0';
15087c478bd9Sstevel@tonic-gate 		*t++ = 'x';
15097c478bd9Sstevel@tonic-gate 		for (k = 0; k < chunk; k++) {
15107c478bd9Sstevel@tonic-gate 			*t++ = hex[(uint_t)((uchar_t)*c >> 4)];
15117c478bd9Sstevel@tonic-gate 			*t++ = hex[(uint_t)((uchar_t)*c & 0xF)];
15127c478bd9Sstevel@tonic-gate 			c++;
15137c478bd9Sstevel@tonic-gate 		}
15147c478bd9Sstevel@tonic-gate 	}
15157c478bd9Sstevel@tonic-gate 
15167c478bd9Sstevel@tonic-gate 	if (leftovers) {
15177c478bd9Sstevel@tonic-gate 		*t++ = ' ';
15187c478bd9Sstevel@tonic-gate 		*t++ = '0';
15197c478bd9Sstevel@tonic-gate 		*t++ = 'x';
15207c478bd9Sstevel@tonic-gate 		for (i = 0; i < leftovers; i++) {
15217c478bd9Sstevel@tonic-gate 			*t++ = hex[(uint_t)((uchar_t)*c >> 4)];
15227c478bd9Sstevel@tonic-gate 			*t++ = hex[(uint_t)((uchar_t)*c & 0xF)];
15237c478bd9Sstevel@tonic-gate 			c++;
15247c478bd9Sstevel@tonic-gate 		}
15257c478bd9Sstevel@tonic-gate 	}
15267c478bd9Sstevel@tonic-gate 
15277c478bd9Sstevel@tonic-gate 	*t = '\0';
15287c478bd9Sstevel@tonic-gate 	return (s);
15297c478bd9Sstevel@tonic-gate }
15307c478bd9Sstevel@tonic-gate 
15317c478bd9Sstevel@tonic-gate 
15327c478bd9Sstevel@tonic-gate /*
15337c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
15347c478bd9Sstevel@tonic-gate  * htp2string: Maps a print suggestion to a string.
15357c478bd9Sstevel@tonic-gate  * returns   : The string mapping or "unknown print suggestion".
15367c478bd9Sstevel@tonic-gate  * -------------------------------------------------------------------
15377c478bd9Sstevel@tonic-gate  */
15387c478bd9Sstevel@tonic-gate char *
15397c478bd9Sstevel@tonic-gate htp2string(char print_sugg)
15407c478bd9Sstevel@tonic-gate {
15417c478bd9Sstevel@tonic-gate 	register int	i;
15427c478bd9Sstevel@tonic-gate 
15437c478bd9Sstevel@tonic-gate 	struct htp_map_ent {
15447c478bd9Sstevel@tonic-gate 		char	print_sugg;
15457c478bd9Sstevel@tonic-gate 		char	*print_string;
15467c478bd9Sstevel@tonic-gate 	};
15477c478bd9Sstevel@tonic-gate 
15487c478bd9Sstevel@tonic-gate 	/*
15497c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
15507c478bd9Sstevel@tonic-gate 	 * These names are data types when displaying the arbitrary data
15517c478bd9Sstevel@tonic-gate 	 * token.
15527c478bd9Sstevel@tonic-gate 	 */
15537c478bd9Sstevel@tonic-gate 
15547c478bd9Sstevel@tonic-gate 	static struct htp_map_ent htp_map[] = {
15557c478bd9Sstevel@tonic-gate 				{ AUP_BINARY, "binary" },
15567c478bd9Sstevel@tonic-gate 				{ AUP_OCTAL, "octal" },
15577c478bd9Sstevel@tonic-gate 				{ AUP_DECIMAL, "decimal" },
15587c478bd9Sstevel@tonic-gate 				{ AUP_HEX, "hexadecimal" },
15597c478bd9Sstevel@tonic-gate 				{ AUP_STRING, "string" } 	};
15607c478bd9Sstevel@tonic-gate 
15617c478bd9Sstevel@tonic-gate 	for (i = 0; i < sizeof (htp_map) / sizeof (struct htp_map_ent); i++)
15627c478bd9Sstevel@tonic-gate 		if (print_sugg == htp_map[i].print_sugg)
15637c478bd9Sstevel@tonic-gate 			return (gettext(htp_map[i].print_string));
15647c478bd9Sstevel@tonic-gate 
15657c478bd9Sstevel@tonic-gate 	return (gettext("unknown print suggestion"));
15667c478bd9Sstevel@tonic-gate }
15677c478bd9Sstevel@tonic-gate 
15687c478bd9Sstevel@tonic-gate /*
15697c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------------
15707c478bd9Sstevel@tonic-gate  * pa_adr_short: Issues pr_adr_short to retrieve the next ADR item from the
15717c478bd9Sstevel@tonic-gate  *		input stream pointed to by audit_adr, and prints it
15727c478bd9Sstevel@tonic-gate  *		if status >= 0
15737c478bd9Sstevel@tonic-gate  * return codes: -1 - error
15747c478bd9Sstevel@tonic-gate  *		:  0 - successful
15757c478bd9Sstevel@tonic-gate  * ----------------------------------------------------------------------
15767c478bd9Sstevel@tonic-gate  */
15777c478bd9Sstevel@tonic-gate int
15787c478bd9Sstevel@tonic-gate pa_adr_short(pr_context_t *context, int status, int flag)
15797c478bd9Sstevel@tonic-gate {
15807c478bd9Sstevel@tonic-gate 	short	c;
15817c478bd9Sstevel@tonic-gate 	uval_t	uval;
15827c478bd9Sstevel@tonic-gate 
15837c478bd9Sstevel@tonic-gate 	if (status >= 0) {
15847c478bd9Sstevel@tonic-gate 		if (pr_adr_short(context, &c, 1) == 0) {
15857c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_SHORT;
15867c478bd9Sstevel@tonic-gate 			uval.short_val = c;
15877c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
15887c478bd9Sstevel@tonic-gate 		} else
15897c478bd9Sstevel@tonic-gate 			return (-1);
15907c478bd9Sstevel@tonic-gate 	} else
15917c478bd9Sstevel@tonic-gate 		return (status);
15927c478bd9Sstevel@tonic-gate }
15937c478bd9Sstevel@tonic-gate 
15947c478bd9Sstevel@tonic-gate /*
15957c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
15967c478bd9Sstevel@tonic-gate  * pa_adr_shorthex: Issues pr_adr_short to retrieve the next ADR item from the
15977c478bd9Sstevel@tonic-gate  *			input stream pointed to by audit_adr, and prints it
15987c478bd9Sstevel@tonic-gate  *			in hexadecimal if status >= 0
15997c478bd9Sstevel@tonic-gate  * return codes  : -1 - error
16007c478bd9Sstevel@tonic-gate  *		:  0 - successful
16017c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
16027c478bd9Sstevel@tonic-gate  */
16037c478bd9Sstevel@tonic-gate int
16047c478bd9Sstevel@tonic-gate pa_adr_shorthex(pr_context_t *context, int status, int flag)
16057c478bd9Sstevel@tonic-gate {
16067c478bd9Sstevel@tonic-gate 	short	s;
16077c478bd9Sstevel@tonic-gate 	int	returnstat;
16087c478bd9Sstevel@tonic-gate 	uval_t	uval;
16097c478bd9Sstevel@tonic-gate 
16107c478bd9Sstevel@tonic-gate 	if (status >= 0) {
16117c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_short(context, &s, 1)) == 0) {
16127c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
16137c478bd9Sstevel@tonic-gate 			uval.string_val = hexconvert((char *)&s, sizeof (s),
16147c478bd9Sstevel@tonic-gate 			    sizeof (s));
16157c478bd9Sstevel@tonic-gate 			if (uval.string_val) {
16167c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
16177c478bd9Sstevel@tonic-gate 				free(uval.string_val);
16187c478bd9Sstevel@tonic-gate 			}
16197c478bd9Sstevel@tonic-gate 		}
16207c478bd9Sstevel@tonic-gate 		return (returnstat);
16217c478bd9Sstevel@tonic-gate 	} else
16227c478bd9Sstevel@tonic-gate 		return (status);
16237c478bd9Sstevel@tonic-gate }
16247c478bd9Sstevel@tonic-gate 
16257c478bd9Sstevel@tonic-gate 
16267c478bd9Sstevel@tonic-gate /*
16277c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
16287c478bd9Sstevel@tonic-gate  * pa_adr_string: Retrieves a string from the input stream and prints it
16297c478bd9Sstevel@tonic-gate  *		  if status >= 0
16307c478bd9Sstevel@tonic-gate  * return codes : -1 - error
16317c478bd9Sstevel@tonic-gate  *		:  0 - successful
16327c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
16337c478bd9Sstevel@tonic-gate  */
16347c478bd9Sstevel@tonic-gate int
16357c478bd9Sstevel@tonic-gate pa_adr_string(pr_context_t *context, int status, int flag)
16367c478bd9Sstevel@tonic-gate {
16377c478bd9Sstevel@tonic-gate 	char	*c;
16387c478bd9Sstevel@tonic-gate 	char	*p;
16397c478bd9Sstevel@tonic-gate 	short	length;
16407c478bd9Sstevel@tonic-gate 	int	returnstat;
16417c478bd9Sstevel@tonic-gate 	uval_t	uval;
16427c478bd9Sstevel@tonic-gate 
16437c478bd9Sstevel@tonic-gate 	/*
16447c478bd9Sstevel@tonic-gate 	 * We need to know how much space to allocate for our string, so
16457c478bd9Sstevel@tonic-gate 	 * read the length first, then call pr_adr_char to read those bytes.
16467c478bd9Sstevel@tonic-gate 	 */
16477c478bd9Sstevel@tonic-gate 	if (status < 0)
16487c478bd9Sstevel@tonic-gate 		return (status);
16497c478bd9Sstevel@tonic-gate 
16507c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_short(context, &length, 1)) != 0)
16517c478bd9Sstevel@tonic-gate 		return (returnstat);
16527c478bd9Sstevel@tonic-gate 	if ((c = (char *)malloc(length + 1)) == NULL)
16537c478bd9Sstevel@tonic-gate 		return (-1);
16547c478bd9Sstevel@tonic-gate 	if ((p = (char *)malloc((length * 2) + 1)) == NULL) {
16557c478bd9Sstevel@tonic-gate 		free(c);
16567c478bd9Sstevel@tonic-gate 		return (-1);
16577c478bd9Sstevel@tonic-gate 	}
16587c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, c, length)) != 0) {
16597c478bd9Sstevel@tonic-gate 		free(c);
16607c478bd9Sstevel@tonic-gate 		free(p);
16617c478bd9Sstevel@tonic-gate 		return (returnstat);
16627c478bd9Sstevel@tonic-gate 	}
16637c478bd9Sstevel@tonic-gate 	convertascii(p, c, length - 1);
16647c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
16657c478bd9Sstevel@tonic-gate 	uval.string_val = p;
16667c478bd9Sstevel@tonic-gate 	returnstat = pa_print(context, &uval, flag);
16677c478bd9Sstevel@tonic-gate 	free(c);
16687c478bd9Sstevel@tonic-gate 	free(p);
16697c478bd9Sstevel@tonic-gate 	return (returnstat);
16707c478bd9Sstevel@tonic-gate }
16717c478bd9Sstevel@tonic-gate 
16727c478bd9Sstevel@tonic-gate /*
16737c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
16747c478bd9Sstevel@tonic-gate  * pa_file_string: Retrieves a file string from the input stream and prints it
16757c478bd9Sstevel@tonic-gate  *		  if status >= 0
16767c478bd9Sstevel@tonic-gate  * return codes : -1 - error
16777c478bd9Sstevel@tonic-gate  *		:  0 - successful
16787c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
16797c478bd9Sstevel@tonic-gate  */
16807c478bd9Sstevel@tonic-gate int
16817c478bd9Sstevel@tonic-gate pa_file_string(pr_context_t *context, int status, int flag)
16827c478bd9Sstevel@tonic-gate {
16837c478bd9Sstevel@tonic-gate 	char	*c;
16847c478bd9Sstevel@tonic-gate 	char	*p;
16857c478bd9Sstevel@tonic-gate 	short	length;
16867c478bd9Sstevel@tonic-gate 	int	returnstat;
16877c478bd9Sstevel@tonic-gate 	uval_t	uval;
16887c478bd9Sstevel@tonic-gate 
16897c478bd9Sstevel@tonic-gate 	/*
16907c478bd9Sstevel@tonic-gate 	 * We need to know how much space to allocate for our string, so
16917c478bd9Sstevel@tonic-gate 	 * read the length first, then call pr_adr_char to read those bytes.
16927c478bd9Sstevel@tonic-gate 	 */
16937c478bd9Sstevel@tonic-gate 	if (status < 0)
16947c478bd9Sstevel@tonic-gate 		return (status);
16957c478bd9Sstevel@tonic-gate 
16967c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_short(context, &length, 1)) != 0)
16977c478bd9Sstevel@tonic-gate 		return (returnstat);
16987c478bd9Sstevel@tonic-gate 	if ((c = (char *)malloc(length + 1)) == NULL)
16997c478bd9Sstevel@tonic-gate 		return (-1);
17007c478bd9Sstevel@tonic-gate 	if ((p = (char *)malloc((length * 2) + 1)) == NULL) {
17017c478bd9Sstevel@tonic-gate 		free(c);
17027c478bd9Sstevel@tonic-gate 		return (-1);
17037c478bd9Sstevel@tonic-gate 	}
17047c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_char(context, c, length)) != 0) {
17057c478bd9Sstevel@tonic-gate 		free(c);
17067c478bd9Sstevel@tonic-gate 		free(p);
17077c478bd9Sstevel@tonic-gate 		return (returnstat);
17087c478bd9Sstevel@tonic-gate 	}
17097c478bd9Sstevel@tonic-gate 
17107c478bd9Sstevel@tonic-gate 	if (is_file_token(context->tokenid))
17117c478bd9Sstevel@tonic-gate 		context->audit_rec_len += length;
17127c478bd9Sstevel@tonic-gate 
17137c478bd9Sstevel@tonic-gate 	convertascii(p, c, length - 1);
17147c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_STRING;
17157c478bd9Sstevel@tonic-gate 	uval.string_val = p;
17167c478bd9Sstevel@tonic-gate 
17177c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
17187c478bd9Sstevel@tonic-gate 		returnstat = finish_open_tag(context);
17197c478bd9Sstevel@tonic-gate 
17207c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
17217c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
17227c478bd9Sstevel@tonic-gate 
17237c478bd9Sstevel@tonic-gate 	free(c);
17247c478bd9Sstevel@tonic-gate 	free(p);
17257c478bd9Sstevel@tonic-gate 	return (returnstat);
17267c478bd9Sstevel@tonic-gate }
17277c478bd9Sstevel@tonic-gate 
17287c478bd9Sstevel@tonic-gate static int
17297c478bd9Sstevel@tonic-gate pa_putstr_xml(pr_context_t *context, int printable, char *str, size_t len)
17307c478bd9Sstevel@tonic-gate {
17317c478bd9Sstevel@tonic-gate 	int	err;
17327c478bd9Sstevel@tonic-gate 
17337c478bd9Sstevel@tonic-gate 	if (!printable) {
17347c478bd9Sstevel@tonic-gate 		/*
17357c478bd9Sstevel@tonic-gate 		 * Unprintable chars should always be converted to the
17367c478bd9Sstevel@tonic-gate 		 * visible form. If there are unprintable characters which
17377c478bd9Sstevel@tonic-gate 		 * require special treatment in xml, those should be
17387c478bd9Sstevel@tonic-gate 		 * handled here.
17397c478bd9Sstevel@tonic-gate 		 */
17407c478bd9Sstevel@tonic-gate 		do {
17417c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "\\%03o",
17427c478bd9Sstevel@tonic-gate 			    (unsigned char)*str++);
17437c478bd9Sstevel@tonic-gate 		} while (err == 0 && --len != 0);
17447c478bd9Sstevel@tonic-gate 		return (err);
17457c478bd9Sstevel@tonic-gate 	}
17467c478bd9Sstevel@tonic-gate 	/* printable characters */
17477c478bd9Sstevel@tonic-gate 	if (len == 1) {
17487c478bd9Sstevel@tonic-gate 		/*
17497c478bd9Sstevel@tonic-gate 		 * check for the special chars only when char size was 1
17507c478bd9Sstevel@tonic-gate 		 * ie, ignore special chars appear in the middle of multibyte
17517c478bd9Sstevel@tonic-gate 		 * sequence.
17527c478bd9Sstevel@tonic-gate 		 */
17537c478bd9Sstevel@tonic-gate 
17547c478bd9Sstevel@tonic-gate 		/* Escape for XML */
17557c478bd9Sstevel@tonic-gate 		switch (*str) {
17567c478bd9Sstevel@tonic-gate 		case '&':
17577c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&amp;");
17587c478bd9Sstevel@tonic-gate 			break;
17597c478bd9Sstevel@tonic-gate 
17607c478bd9Sstevel@tonic-gate 		case '<':
17617c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&lt;");
17627c478bd9Sstevel@tonic-gate 			break;
17637c478bd9Sstevel@tonic-gate 
17647c478bd9Sstevel@tonic-gate 		case '>':
17657c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&gt;");
17667c478bd9Sstevel@tonic-gate 			break;
17677c478bd9Sstevel@tonic-gate 
17687c478bd9Sstevel@tonic-gate 		case '\"':
17697c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&quot;");
17707c478bd9Sstevel@tonic-gate 			break;
17717c478bd9Sstevel@tonic-gate 
17727c478bd9Sstevel@tonic-gate 		case '\'':
17737c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "%s", "&apos;");
17747c478bd9Sstevel@tonic-gate 			break;
17757c478bd9Sstevel@tonic-gate 
17767c478bd9Sstevel@tonic-gate 		default:
17777c478bd9Sstevel@tonic-gate 			err = pr_putchar(context, *str);
17787c478bd9Sstevel@tonic-gate 			break;
17797c478bd9Sstevel@tonic-gate 		}
17807c478bd9Sstevel@tonic-gate 		return (err);
17817c478bd9Sstevel@tonic-gate 	}
17827c478bd9Sstevel@tonic-gate 	do {
17837c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, *str++);
17847c478bd9Sstevel@tonic-gate 	} while (err == 0 && --len != 0);
17857c478bd9Sstevel@tonic-gate 	return (err);
17867c478bd9Sstevel@tonic-gate }
17877c478bd9Sstevel@tonic-gate 
17887c478bd9Sstevel@tonic-gate static int
17897c478bd9Sstevel@tonic-gate pa_putstr(pr_context_t *context, int printable, char *str, size_t len)
17907c478bd9Sstevel@tonic-gate {
17917c478bd9Sstevel@tonic-gate 	int	err;
17927c478bd9Sstevel@tonic-gate 
17937c478bd9Sstevel@tonic-gate 	if (context->format & PRF_XMLM)
17947c478bd9Sstevel@tonic-gate 		return (pa_putstr_xml(context, printable, str, len));
17957c478bd9Sstevel@tonic-gate 
17967c478bd9Sstevel@tonic-gate 	if (!printable) {
17977c478bd9Sstevel@tonic-gate 		do {
17987c478bd9Sstevel@tonic-gate 			err = pr_printf(context, "\\%03o",
17997c478bd9Sstevel@tonic-gate 			    (unsigned char)*str++);
18007c478bd9Sstevel@tonic-gate 		} while (err == 0 && --len != 0);
18017c478bd9Sstevel@tonic-gate 		return (err);
18027c478bd9Sstevel@tonic-gate 	}
18037c478bd9Sstevel@tonic-gate 	do {
18047c478bd9Sstevel@tonic-gate 		err = pr_putchar(context, *str++);
18057c478bd9Sstevel@tonic-gate 	} while (err == 0 && --len != 0);
18067c478bd9Sstevel@tonic-gate 	return (err);
18077c478bd9Sstevel@tonic-gate }
18087c478bd9Sstevel@tonic-gate 
18097c478bd9Sstevel@tonic-gate int
18107c478bd9Sstevel@tonic-gate pa_string(pr_context_t *context, int status, int flag)
18117c478bd9Sstevel@tonic-gate {
18127c478bd9Sstevel@tonic-gate 	int	rstat, wstat;
18137c478bd9Sstevel@tonic-gate 	int	i, printable, eos;
18147c478bd9Sstevel@tonic-gate 	int	mlen, rlen;
18157c478bd9Sstevel@tonic-gate 	int	mbmax = MB_CUR_MAX;
18167c478bd9Sstevel@tonic-gate 	wchar_t	wc;
18177c478bd9Sstevel@tonic-gate 	char	mbuf[MB_LEN_MAX + 1];
18187c478bd9Sstevel@tonic-gate 	char	c;
18197c478bd9Sstevel@tonic-gate 
18207c478bd9Sstevel@tonic-gate 	if (status < 0)
18217c478bd9Sstevel@tonic-gate 		return (status);
18227c478bd9Sstevel@tonic-gate 
18237c478bd9Sstevel@tonic-gate 	rstat = wstat = 0;
18247c478bd9Sstevel@tonic-gate 
18257c478bd9Sstevel@tonic-gate 	if (mbmax == 1) {
18267c478bd9Sstevel@tonic-gate 		while (wstat == 0) {
18277c478bd9Sstevel@tonic-gate 			if ((rstat = pr_adr_char(context, &c, 1)) < 0)
18287c478bd9Sstevel@tonic-gate 				break;
18297c478bd9Sstevel@tonic-gate 			if (c == '\0')
18307c478bd9Sstevel@tonic-gate 				break;
18317c478bd9Sstevel@tonic-gate 			printable = isprint((unsigned char)c);
18327c478bd9Sstevel@tonic-gate 			wstat = pa_putstr(context, printable, &c, 1);
18337c478bd9Sstevel@tonic-gate 		}
18347c478bd9Sstevel@tonic-gate 		goto done;
18357c478bd9Sstevel@tonic-gate 	}
18367c478bd9Sstevel@tonic-gate 
18377c478bd9Sstevel@tonic-gate 	mlen = eos = 0;
18387c478bd9Sstevel@tonic-gate 	while (wstat == 0) {
18397c478bd9Sstevel@tonic-gate 		rlen = 0;
18407c478bd9Sstevel@tonic-gate 		do {
18417c478bd9Sstevel@tonic-gate 			if (!eos) {
18427c478bd9Sstevel@tonic-gate 				rstat = pr_adr_char(context, &c, 1);
18437c478bd9Sstevel@tonic-gate 				if (rstat != 0 || c == '\0')
18447c478bd9Sstevel@tonic-gate 					eos = 1;
18457c478bd9Sstevel@tonic-gate 				else
18467c478bd9Sstevel@tonic-gate 					mbuf[mlen++] = c;
18477c478bd9Sstevel@tonic-gate 			}
18487c478bd9Sstevel@tonic-gate 			rlen = mbtowc(&wc, mbuf, mlen);
18497c478bd9Sstevel@tonic-gate 		} while (!eos && mlen < mbmax && rlen <= 0);
18507c478bd9Sstevel@tonic-gate 
18517c478bd9Sstevel@tonic-gate 		if (mlen == 0)
18527c478bd9Sstevel@tonic-gate 			break;	/* end of string */
18537c478bd9Sstevel@tonic-gate 
18547c478bd9Sstevel@tonic-gate 		if (rlen <= 0) { /* no good sequence */
18557c478bd9Sstevel@tonic-gate 			rlen = 1;
18567c478bd9Sstevel@tonic-gate 			printable = 0;
18577c478bd9Sstevel@tonic-gate 		} else {
18587c478bd9Sstevel@tonic-gate 			printable = iswprint(wc);
18597c478bd9Sstevel@tonic-gate 		}
18607c478bd9Sstevel@tonic-gate 		wstat = pa_putstr(context, printable, mbuf, rlen);
18617c478bd9Sstevel@tonic-gate 		mlen -= rlen;
18627c478bd9Sstevel@tonic-gate 		if (mlen > 0) {
18637c478bd9Sstevel@tonic-gate 			for (i = 0; i < mlen; i++)
18647c478bd9Sstevel@tonic-gate 				mbuf[i] = mbuf[rlen + i];
18657c478bd9Sstevel@tonic-gate 		}
18667c478bd9Sstevel@tonic-gate 	}
18677c478bd9Sstevel@tonic-gate 
18687c478bd9Sstevel@tonic-gate done:
18697c478bd9Sstevel@tonic-gate 	if (wstat == 0)
18707c478bd9Sstevel@tonic-gate 		wstat = do_newline(context, flag);
18717c478bd9Sstevel@tonic-gate 
18727c478bd9Sstevel@tonic-gate 	if (wstat == 0 && context->data_mode == FILEMODE)
18737c478bd9Sstevel@tonic-gate 		(void) fflush(stdout);
18747c478bd9Sstevel@tonic-gate 
18757c478bd9Sstevel@tonic-gate 	return ((rstat != 0 || wstat != 0) ? -1 : 0);
18767c478bd9Sstevel@tonic-gate }
18777c478bd9Sstevel@tonic-gate 
18787c478bd9Sstevel@tonic-gate /*
18797c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
18807c478bd9Sstevel@tonic-gate  * pa_adr_u_int32: Issues pr_adr_u_int32 to retrieve the next ADR item from
18817c478bd9Sstevel@tonic-gate  *		  the input stream pointed to by audit_adr, and prints it
18827c478bd9Sstevel@tonic-gate  *		  if status = 0
18837c478bd9Sstevel@tonic-gate  * return codes : -1 - error
18847c478bd9Sstevel@tonic-gate  *		:  0 - successful
18857c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
18867c478bd9Sstevel@tonic-gate  */
18877c478bd9Sstevel@tonic-gate 
18887c478bd9Sstevel@tonic-gate 
18897c478bd9Sstevel@tonic-gate int
18907c478bd9Sstevel@tonic-gate pa_adr_u_int32(pr_context_t *context, int status, int flag)
18917c478bd9Sstevel@tonic-gate {
18927c478bd9Sstevel@tonic-gate 	uint32_t c;
18937c478bd9Sstevel@tonic-gate 	uval_t	uval;
18947c478bd9Sstevel@tonic-gate 
18957c478bd9Sstevel@tonic-gate 	if (status >= 0) {
18967c478bd9Sstevel@tonic-gate 		if (pr_adr_u_int32(context, &c, 1) == 0) {
18977c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
18987c478bd9Sstevel@tonic-gate 			uval.uint32_val = c;
18997c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
19007c478bd9Sstevel@tonic-gate 		} else
19017c478bd9Sstevel@tonic-gate 			return (-1);
19027c478bd9Sstevel@tonic-gate 	} else
19037c478bd9Sstevel@tonic-gate 		return (status);
19047c478bd9Sstevel@tonic-gate }
19057c478bd9Sstevel@tonic-gate 
19067c478bd9Sstevel@tonic-gate 
19077c478bd9Sstevel@tonic-gate 
19087c478bd9Sstevel@tonic-gate /*
19097c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
19107c478bd9Sstevel@tonic-gate  * pa_adr_u_int64: Issues pr_adr_u_int64 to retrieve the next ADR item from the
19117c478bd9Sstevel@tonic-gate  *		  input stream pointed to by audit_adr, and prints it
19127c478bd9Sstevel@tonic-gate  *		  if status = 0
19137c478bd9Sstevel@tonic-gate  * return codes : -1 - error
19147c478bd9Sstevel@tonic-gate  *		:  0 - successful
19157c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
19167c478bd9Sstevel@tonic-gate  */
19177c478bd9Sstevel@tonic-gate int
19187c478bd9Sstevel@tonic-gate pa_adr_u_int64(pr_context_t *context, int status, int flag)
19197c478bd9Sstevel@tonic-gate {
19207c478bd9Sstevel@tonic-gate 	uint64_t c;
19217c478bd9Sstevel@tonic-gate 	uval_t	uval;
19227c478bd9Sstevel@tonic-gate 
19237c478bd9Sstevel@tonic-gate 	if (status >= 0) {
19247c478bd9Sstevel@tonic-gate 		if (pr_adr_u_int64(context, &c, 1) == 0) {
19257c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT64;
19267c478bd9Sstevel@tonic-gate 			uval.uint64_val = c;
19277c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
19287c478bd9Sstevel@tonic-gate 		} else
19297c478bd9Sstevel@tonic-gate 			return (-1);
19307c478bd9Sstevel@tonic-gate 	} else
19317c478bd9Sstevel@tonic-gate 		return (status);
19327c478bd9Sstevel@tonic-gate }
19337c478bd9Sstevel@tonic-gate 
19347c478bd9Sstevel@tonic-gate 
19357c478bd9Sstevel@tonic-gate /*
19367c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
19377c478bd9Sstevel@tonic-gate  * pa_adr_u_short: Issues pr_adr_u_short to retrieve the next ADR item from
19387c478bd9Sstevel@tonic-gate  *			the input stream pointed to by audit_adr, and prints it
19397c478bd9Sstevel@tonic-gate  *			if status = 0
19407c478bd9Sstevel@tonic-gate  * return codes : -1 - error
19417c478bd9Sstevel@tonic-gate  *		:  0 - successful
19427c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
19437c478bd9Sstevel@tonic-gate  */
19447c478bd9Sstevel@tonic-gate int
19457c478bd9Sstevel@tonic-gate pa_adr_u_short(pr_context_t *context, int status, int flag)
19467c478bd9Sstevel@tonic-gate {
19477c478bd9Sstevel@tonic-gate 	ushort_t c;
19487c478bd9Sstevel@tonic-gate 	uval_t	uval;
19497c478bd9Sstevel@tonic-gate 
19507c478bd9Sstevel@tonic-gate 	if (status >= 0) {
19517c478bd9Sstevel@tonic-gate 		if (pr_adr_u_short(context, &c, 1) == 0) {
19527c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_USHORT;
19537c478bd9Sstevel@tonic-gate 			uval.ushort_val = c;
19547c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
19557c478bd9Sstevel@tonic-gate 		} else
19567c478bd9Sstevel@tonic-gate 			return (-1);
19577c478bd9Sstevel@tonic-gate 	} else
19587c478bd9Sstevel@tonic-gate 		return (status);
19597c478bd9Sstevel@tonic-gate }
19607c478bd9Sstevel@tonic-gate 
19617c478bd9Sstevel@tonic-gate /*
19627c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
19637c478bd9Sstevel@tonic-gate  * pa_reclen: Issues pr_adr_u_long to retrieve the length of the record
19647c478bd9Sstevel@tonic-gate  *		  from the input stream pointed to by audit_adr,
19657c478bd9Sstevel@tonic-gate  *		  and prints it (unless format is XML) if status = 0
19667c478bd9Sstevel@tonic-gate  * return codes : -1 - error
19677c478bd9Sstevel@tonic-gate  *		:  0 - successful
19687c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
19697c478bd9Sstevel@tonic-gate  */
19707c478bd9Sstevel@tonic-gate int
19717c478bd9Sstevel@tonic-gate pa_reclen(pr_context_t *context, int status)
19727c478bd9Sstevel@tonic-gate {
19737c478bd9Sstevel@tonic-gate 	uint32_t c;
19747c478bd9Sstevel@tonic-gate 	uval_t	uval;
19757c478bd9Sstevel@tonic-gate 
19767c478bd9Sstevel@tonic-gate 	if (status >= 0) {
19777c478bd9Sstevel@tonic-gate 		if ((int)pr_adr_u_int32(context, &c, 1) == 0) {
19787c478bd9Sstevel@tonic-gate 			context->audit_rec_len = c;
19797c478bd9Sstevel@tonic-gate 
19807c478bd9Sstevel@tonic-gate 			/* Don't print this for XML format */
19817c478bd9Sstevel@tonic-gate 			if (context->format & PRF_XMLM) {
19827c478bd9Sstevel@tonic-gate 				return (0);
19837c478bd9Sstevel@tonic-gate 			} else {
19847c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_UINT32;
19857c478bd9Sstevel@tonic-gate 				uval.uint32_val = c;
19867c478bd9Sstevel@tonic-gate 				return (pa_print(context, &uval, 0));
19877c478bd9Sstevel@tonic-gate 			}
19887c478bd9Sstevel@tonic-gate 		} else
19897c478bd9Sstevel@tonic-gate 			return (-1);
19907c478bd9Sstevel@tonic-gate 	} else
19917c478bd9Sstevel@tonic-gate 		return (status);
19927c478bd9Sstevel@tonic-gate }
19937c478bd9Sstevel@tonic-gate 
19947c478bd9Sstevel@tonic-gate /*
19957c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
19967c478bd9Sstevel@tonic-gate  * pa_mode	: Issues pr_adr_u_short to retrieve the next ADR item from
19977c478bd9Sstevel@tonic-gate  *		the input stream pointed to by audit_adr, and prints it
19987c478bd9Sstevel@tonic-gate  *		in octal if status = 0
19997c478bd9Sstevel@tonic-gate  * return codes : -1 - error
20007c478bd9Sstevel@tonic-gate  *		:  0 - successful
20017c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
20027c478bd9Sstevel@tonic-gate  */
20037c478bd9Sstevel@tonic-gate int
20047c478bd9Sstevel@tonic-gate pa_mode(pr_context_t *context, int status, int flag)
20057c478bd9Sstevel@tonic-gate {
20067c478bd9Sstevel@tonic-gate 	uint32_t c;
20077c478bd9Sstevel@tonic-gate 	uval_t	uval;
20087c478bd9Sstevel@tonic-gate 
20097c478bd9Sstevel@tonic-gate 	if (status >= 0) {
20107c478bd9Sstevel@tonic-gate 		if (pr_adr_u_int32(context, &c, 1) == 0) {
20117c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_LOCT;
20127c478bd9Sstevel@tonic-gate 			uval.uint32_val = c;
20137c478bd9Sstevel@tonic-gate 			return (pa_print(context, &uval, flag));
20147c478bd9Sstevel@tonic-gate 		} else
20157c478bd9Sstevel@tonic-gate 			return (-1);
20167c478bd9Sstevel@tonic-gate 	} else
20177c478bd9Sstevel@tonic-gate 		return (status);
20187c478bd9Sstevel@tonic-gate }
20197c478bd9Sstevel@tonic-gate 
20207c478bd9Sstevel@tonic-gate 
20217c478bd9Sstevel@tonic-gate /*
20227c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
20237c478bd9Sstevel@tonic-gate  * pa_pw_uid()	: Issues pr_adr_u_int32 to reads uid from input stream
20247c478bd9Sstevel@tonic-gate  *		pointed to by audit_adr, and displays it in either
20257c478bd9Sstevel@tonic-gate  *		raw form or its ASCII representation, if status >= 0.
20267c478bd9Sstevel@tonic-gate  * return codes : -1 - error
20277c478bd9Sstevel@tonic-gate  * 		:  1 - warning, passwd entry not found
20287c478bd9Sstevel@tonic-gate  *		:  0 - successful
20297c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
20307c478bd9Sstevel@tonic-gate  */
20317c478bd9Sstevel@tonic-gate int
20327c478bd9Sstevel@tonic-gate pa_pw_uid(pr_context_t *context, int status, int flag)
20337c478bd9Sstevel@tonic-gate {
20347c478bd9Sstevel@tonic-gate 	int	returnstat;
20357c478bd9Sstevel@tonic-gate 	struct passwd *pw;
20367c478bd9Sstevel@tonic-gate 	uint32_t uid;
20377c478bd9Sstevel@tonic-gate 	uval_t	uval;
20387c478bd9Sstevel@tonic-gate 
20397c478bd9Sstevel@tonic-gate 	if (status < 0)
20407c478bd9Sstevel@tonic-gate 		return (status);
20417c478bd9Sstevel@tonic-gate 
20427c478bd9Sstevel@tonic-gate 	if (pr_adr_u_int32(context, &uid, 1) != 0)
20437c478bd9Sstevel@tonic-gate 		/* cannot retrieve uid */
20447c478bd9Sstevel@tonic-gate 		return (-1);
20457c478bd9Sstevel@tonic-gate 
20467c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
20477c478bd9Sstevel@tonic-gate 		/* get password file entry */
20487c478bd9Sstevel@tonic-gate 		if ((pw = getpwuid(uid)) == NULL) {
20497c478bd9Sstevel@tonic-gate 			returnstat = 1;
20507c478bd9Sstevel@tonic-gate 		} else {
20517c478bd9Sstevel@tonic-gate 			/* print in ASCII form */
20527c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
20537c478bd9Sstevel@tonic-gate 			uval.string_val = pw->pw_name;
20547c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
20557c478bd9Sstevel@tonic-gate 		}
20567c478bd9Sstevel@tonic-gate 	}
20577c478bd9Sstevel@tonic-gate 	/* print in integer form */
20587c478bd9Sstevel@tonic-gate 	if ((context->format & PRF_RAWM) || (returnstat == 1)) {
20597c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_INT32;
20607c478bd9Sstevel@tonic-gate 		uval.int32_val = uid;
20617c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
20627c478bd9Sstevel@tonic-gate 	}
20637c478bd9Sstevel@tonic-gate 	return (returnstat);
20647c478bd9Sstevel@tonic-gate }
20657c478bd9Sstevel@tonic-gate 
20667c478bd9Sstevel@tonic-gate 
20677c478bd9Sstevel@tonic-gate /*
20687c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
20697c478bd9Sstevel@tonic-gate  * pa_gr_uid()	: Issues pr_adr_u_int32 to reads group uid from input stream
20707c478bd9Sstevel@tonic-gate  *			pointed to by audit_adr, and displays it in either
20717c478bd9Sstevel@tonic-gate  *			raw form or its ASCII representation, if status >= 0.
20727c478bd9Sstevel@tonic-gate  * return codes : -1 - error
20737c478bd9Sstevel@tonic-gate  * 		:  1 - warning, passwd entry not found
20747c478bd9Sstevel@tonic-gate  *		:  0 - successful
20757c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
20767c478bd9Sstevel@tonic-gate  */
20777c478bd9Sstevel@tonic-gate int
20787c478bd9Sstevel@tonic-gate pa_gr_uid(pr_context_t *context, int status, int flag)
20797c478bd9Sstevel@tonic-gate {
20807c478bd9Sstevel@tonic-gate 	int	returnstat;
20817c478bd9Sstevel@tonic-gate 	struct group *gr;
20827c478bd9Sstevel@tonic-gate 	uint32_t gid;
20837c478bd9Sstevel@tonic-gate 	uval_t	uval;
20847c478bd9Sstevel@tonic-gate 
20857c478bd9Sstevel@tonic-gate 	if (status < 0)
20867c478bd9Sstevel@tonic-gate 		return (status);
20877c478bd9Sstevel@tonic-gate 
20887c478bd9Sstevel@tonic-gate 	if (pr_adr_u_int32(context, &gid, 1) != 0)
20897c478bd9Sstevel@tonic-gate 		/* cannot retrieve gid */
20907c478bd9Sstevel@tonic-gate 		return (-1);
20917c478bd9Sstevel@tonic-gate 
20927c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
20937c478bd9Sstevel@tonic-gate 		/* get group file entry */
20947c478bd9Sstevel@tonic-gate 		if ((gr = getgrgid(gid)) == NULL) {
20957c478bd9Sstevel@tonic-gate 			returnstat = 1;
20967c478bd9Sstevel@tonic-gate 		} else {
20977c478bd9Sstevel@tonic-gate 			/* print in ASCII form */
20987c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
20997c478bd9Sstevel@tonic-gate 			uval.string_val = gr->gr_name;
21007c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
21017c478bd9Sstevel@tonic-gate 		}
21027c478bd9Sstevel@tonic-gate 	}
21037c478bd9Sstevel@tonic-gate 	/* print in integer form */
21047c478bd9Sstevel@tonic-gate 	if ((context->format & PRF_RAWM) || (returnstat == 1)) {
21057c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_INT32;
21067c478bd9Sstevel@tonic-gate 		uval.int32_val = gid;
21077c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
21087c478bd9Sstevel@tonic-gate 	}
21097c478bd9Sstevel@tonic-gate 	return (returnstat);
21107c478bd9Sstevel@tonic-gate }
21117c478bd9Sstevel@tonic-gate 
21127c478bd9Sstevel@tonic-gate 
21137c478bd9Sstevel@tonic-gate /*
21147c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
21157c478bd9Sstevel@tonic-gate  * pa_pw_uid_gr_gid()	: Issues pr_adr_u_int32 to reads uid or group uid
21167c478bd9Sstevel@tonic-gate  *			from input stream
21177c478bd9Sstevel@tonic-gate  *			pointed to by audit_adr, and displays it in either
21187c478bd9Sstevel@tonic-gate  *			raw form or its ASCII representation, if status >= 0.
21197c478bd9Sstevel@tonic-gate  * return codes : -1 - error
21207c478bd9Sstevel@tonic-gate  * 		:  1 - warning, passwd entry not found
21217c478bd9Sstevel@tonic-gate  *		:  0 - successful
21227c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
21237c478bd9Sstevel@tonic-gate  */
21247c478bd9Sstevel@tonic-gate int
21257c478bd9Sstevel@tonic-gate pa_pw_uid_gr_gid(pr_context_t *context, int status, int flag)
21267c478bd9Sstevel@tonic-gate {
21277c478bd9Sstevel@tonic-gate 	int	returnstat;
21287c478bd9Sstevel@tonic-gate 	uint32_t	value;
21297c478bd9Sstevel@tonic-gate 	uval_t		uval;
21307c478bd9Sstevel@tonic-gate 
21317c478bd9Sstevel@tonic-gate 	if (status < 0)
21327c478bd9Sstevel@tonic-gate 		return (status);
21337c478bd9Sstevel@tonic-gate 
21347c478bd9Sstevel@tonic-gate 	/* get value of a_type */
21357c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &value, 1)) != 0)
21367c478bd9Sstevel@tonic-gate 		return (returnstat);
21377c478bd9Sstevel@tonic-gate 
21387c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ACLTYPE)) != 0)
21397c478bd9Sstevel@tonic-gate 		return (returnstat);
21407c478bd9Sstevel@tonic-gate 
21417c478bd9Sstevel@tonic-gate 	uval.uvaltype = PRA_UINT32;
21427c478bd9Sstevel@tonic-gate 	uval.uint32_val = value;
21437c478bd9Sstevel@tonic-gate 	if ((returnstat = pa_print(context, &uval, flag)) != 0)
21447c478bd9Sstevel@tonic-gate 		return (returnstat);
21457c478bd9Sstevel@tonic-gate 
21467c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_ACLTYPE)) != 0)
21477c478bd9Sstevel@tonic-gate 		return (returnstat);
21487c478bd9Sstevel@tonic-gate 
21497c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ACLVAL)) != 0)
21507c478bd9Sstevel@tonic-gate 		return (returnstat);
21517c478bd9Sstevel@tonic-gate 	/*
21527c478bd9Sstevel@tonic-gate 	 * TRANSLATION_NOTE
21537c478bd9Sstevel@tonic-gate 	 * The "mask" and "other" strings refer to the class mask
21547c478bd9Sstevel@tonic-gate 	 * and other (or world) entries in an ACL.
21557c478bd9Sstevel@tonic-gate 	 * The "unrecognized" string refers to an unrecognized ACL
21567c478bd9Sstevel@tonic-gate 	 * entry.
21577c478bd9Sstevel@tonic-gate 	 */
21587c478bd9Sstevel@tonic-gate 	switch (value) {
21597c478bd9Sstevel@tonic-gate 		case USER_OBJ:
21607c478bd9Sstevel@tonic-gate 		case USER:
21617c478bd9Sstevel@tonic-gate 			returnstat = pa_pw_uid(context, returnstat, flag);
21627c478bd9Sstevel@tonic-gate 			break;
21637c478bd9Sstevel@tonic-gate 		case GROUP_OBJ:
21647c478bd9Sstevel@tonic-gate 		case GROUP:
21657c478bd9Sstevel@tonic-gate 			returnstat = pa_gr_uid(context, returnstat, flag);
21667c478bd9Sstevel@tonic-gate 			break;
21677c478bd9Sstevel@tonic-gate 		case CLASS_OBJ:
21687c478bd9Sstevel@tonic-gate 			returnstat = pr_adr_u_int32(context, &value, 1);
21697c478bd9Sstevel@tonic-gate 			if (returnstat != 0)
21707c478bd9Sstevel@tonic-gate 				return (returnstat);
21717c478bd9Sstevel@tonic-gate 
21727c478bd9Sstevel@tonic-gate 			if (!(context->format & PRF_RAWM)) {
21737c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_STRING;
21747c478bd9Sstevel@tonic-gate 				uval.string_val = gettext("mask");
21757c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
21767c478bd9Sstevel@tonic-gate 			} else {
21777c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_UINT32;
21787c478bd9Sstevel@tonic-gate 				uval.uint32_val = value;
2179*8f9294f3Sgww 				if ((returnstat =
2180*8f9294f3Sgww 				    pa_print(context, &uval, flag)) != 0) {
21817c478bd9Sstevel@tonic-gate 					return (returnstat);
21827c478bd9Sstevel@tonic-gate 				}
2183*8f9294f3Sgww 			}
21847c478bd9Sstevel@tonic-gate 			break;
21857c478bd9Sstevel@tonic-gate 		case OTHER_OBJ:
21867c478bd9Sstevel@tonic-gate 			returnstat = pr_adr_u_int32(context, &value, 1);
21877c478bd9Sstevel@tonic-gate 			if (returnstat != 0)
21887c478bd9Sstevel@tonic-gate 				return (returnstat);
21897c478bd9Sstevel@tonic-gate 
21907c478bd9Sstevel@tonic-gate 			if (!(context->format & PRF_RAWM)) {
21917c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_STRING;
21927c478bd9Sstevel@tonic-gate 				uval.string_val = gettext("other");
21937c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
21947c478bd9Sstevel@tonic-gate 			} else {
21957c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_UINT32;
21967c478bd9Sstevel@tonic-gate 				uval.uint32_val = value;
2197*8f9294f3Sgww 				if ((returnstat =
2198*8f9294f3Sgww 				    pa_print(context, &uval, flag)) != 0) {
21997c478bd9Sstevel@tonic-gate 					return (returnstat);
22007c478bd9Sstevel@tonic-gate 				}
2201*8f9294f3Sgww 			}
22027c478bd9Sstevel@tonic-gate 			break;
22037c478bd9Sstevel@tonic-gate 		default:
22047c478bd9Sstevel@tonic-gate 			returnstat = pr_adr_u_int32(context, &value, 1);
22057c478bd9Sstevel@tonic-gate 			if (returnstat != 0)
22067c478bd9Sstevel@tonic-gate 				return (returnstat);
22077c478bd9Sstevel@tonic-gate 
22087c478bd9Sstevel@tonic-gate 			if (!(context->format & PRF_RAWM)) {
22097c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_STRING;
22107c478bd9Sstevel@tonic-gate 				uval.string_val = gettext("unrecognized");
22117c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
22127c478bd9Sstevel@tonic-gate 			} else {
22137c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_UINT32;
22147c478bd9Sstevel@tonic-gate 				uval.uint32_val = value;
2215*8f9294f3Sgww 				if ((returnstat =
2216*8f9294f3Sgww 				    pa_print(context, &uval, flag)) != 0) {
22177c478bd9Sstevel@tonic-gate 					return (returnstat);
22187c478bd9Sstevel@tonic-gate 				}
22197c478bd9Sstevel@tonic-gate 			}
2220*8f9294f3Sgww 	}
22217c478bd9Sstevel@tonic-gate 
22227c478bd9Sstevel@tonic-gate 	if ((returnstat = close_tag(context, TAG_ACLVAL)) != 0)
22237c478bd9Sstevel@tonic-gate 		return (returnstat);
22247c478bd9Sstevel@tonic-gate 
22257c478bd9Sstevel@tonic-gate 	return (returnstat);
22267c478bd9Sstevel@tonic-gate }
22277c478bd9Sstevel@tonic-gate 
22287c478bd9Sstevel@tonic-gate 
22297c478bd9Sstevel@tonic-gate /*
22307c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
22317c478bd9Sstevel@tonic-gate  * pa_event_modifier(): Issues pr_adr_u_short to retrieve the next ADR item from
22327c478bd9Sstevel@tonic-gate  *		  the input stream pointed to by audit_adr.  This is the
22337c478bd9Sstevel@tonic-gate  *		  event type, and is displayed in hex;
22347c478bd9Sstevel@tonic-gate  * return codes : -1 - error
22357c478bd9Sstevel@tonic-gate  *		:  0 - successful
22367c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
22377c478bd9Sstevel@tonic-gate  */
22387c478bd9Sstevel@tonic-gate int
22397c478bd9Sstevel@tonic-gate pa_event_modifier(pr_context_t *context, int status,  int flag)
22407c478bd9Sstevel@tonic-gate {
22417c478bd9Sstevel@tonic-gate 	int	returnstat;
22427c478bd9Sstevel@tonic-gate 	ushort_t emodifier;
22437c478bd9Sstevel@tonic-gate 	uval_t	uval;
22447c478bd9Sstevel@tonic-gate 	char	modstring[64];
22457c478bd9Sstevel@tonic-gate 
22467c478bd9Sstevel@tonic-gate 	if (status < 0)
22477c478bd9Sstevel@tonic-gate 		return (status);
22487c478bd9Sstevel@tonic-gate 
22497c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_short(context, &emodifier, 1)) != 0)
22507c478bd9Sstevel@tonic-gate 		return (returnstat);
22517c478bd9Sstevel@tonic-gate 
22527c478bd9Sstevel@tonic-gate 	/* For XML, only print when modifier is non-zero */
22537c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM) || (emodifier != 0)) {
22547c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
22557c478bd9Sstevel@tonic-gate 
22567c478bd9Sstevel@tonic-gate 		returnstat = open_tag(context, TAG_EVMOD);
22577c478bd9Sstevel@tonic-gate 
22587c478bd9Sstevel@tonic-gate 		if (returnstat >= 0) {
22597c478bd9Sstevel@tonic-gate 			if (!(context->format & PRF_RAWM)) {
22607c478bd9Sstevel@tonic-gate 				eventmodifier2string(emodifier, modstring,
22617c478bd9Sstevel@tonic-gate 				    sizeof (modstring));
22627c478bd9Sstevel@tonic-gate 				uval.string_val = modstring;
22637c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
22647c478bd9Sstevel@tonic-gate 			} else {
22657c478bd9Sstevel@tonic-gate 				uval.string_val = hexconvert((char *)&emodifier,
22667c478bd9Sstevel@tonic-gate 				    sizeof (emodifier), sizeof (emodifier));
22677c478bd9Sstevel@tonic-gate 				if (uval.string_val) {
22687c478bd9Sstevel@tonic-gate 					returnstat = pa_print(context, &uval,
22697c478bd9Sstevel@tonic-gate 					    flag);
22707c478bd9Sstevel@tonic-gate 					free(uval.string_val);
22717c478bd9Sstevel@tonic-gate 				}
22727c478bd9Sstevel@tonic-gate 			}
22737c478bd9Sstevel@tonic-gate 		}
22747c478bd9Sstevel@tonic-gate 		if (returnstat >= 0)
22757c478bd9Sstevel@tonic-gate 			returnstat = close_tag(context, TAG_EVMOD);
22767c478bd9Sstevel@tonic-gate 	}
22777c478bd9Sstevel@tonic-gate 
22787c478bd9Sstevel@tonic-gate 	return (returnstat);
22797c478bd9Sstevel@tonic-gate }
22807c478bd9Sstevel@tonic-gate 
22817c478bd9Sstevel@tonic-gate 
22827c478bd9Sstevel@tonic-gate /*
22837c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
22847c478bd9Sstevel@tonic-gate  * pa_event_type(): Issues pr_adr_u_short to retrieve the next ADR item from
22857c478bd9Sstevel@tonic-gate  *		  the input stream pointed to by audit_adr.  This is the
22867c478bd9Sstevel@tonic-gate  *		  event type, and is displayed in either raw or
22877c478bd9Sstevel@tonic-gate  *		  ASCII form as appropriate
22887c478bd9Sstevel@tonic-gate  * return codes : -1 - error
22897c478bd9Sstevel@tonic-gate  *		:  0 - successful
22907c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
22917c478bd9Sstevel@tonic-gate  */
22927c478bd9Sstevel@tonic-gate int
22937c478bd9Sstevel@tonic-gate pa_event_type(pr_context_t *context, int status,  int flag)
22947c478bd9Sstevel@tonic-gate {
22957c478bd9Sstevel@tonic-gate 	ushort_t etype;
22967c478bd9Sstevel@tonic-gate 	int	returnstat;
22977c478bd9Sstevel@tonic-gate 	au_event_ent_t *p_event = NULL;
22987c478bd9Sstevel@tonic-gate 	uval_t	uval;
22997c478bd9Sstevel@tonic-gate 
23007c478bd9Sstevel@tonic-gate 	if (status >= 0) {
23017c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_u_short(context, &etype, 1)) == 0) {
23027c478bd9Sstevel@tonic-gate 			if (!(context->format & PRF_RAWM)) {
23037c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_STRING;
23047c478bd9Sstevel@tonic-gate 				if (context->format & PRF_NOCACHE) {
23057c478bd9Sstevel@tonic-gate 					p_event = getauevnum(etype);
23067c478bd9Sstevel@tonic-gate 				} else {
23077c478bd9Sstevel@tonic-gate 					(void) cacheauevent(&p_event, etype);
23087c478bd9Sstevel@tonic-gate 				}
23097c478bd9Sstevel@tonic-gate 				if (p_event != NULL) {
23107c478bd9Sstevel@tonic-gate 					if (context->format & PRF_SHORTM)
23117c478bd9Sstevel@tonic-gate 						uval.string_val =
23127c478bd9Sstevel@tonic-gate 						    p_event->ae_name;
23137c478bd9Sstevel@tonic-gate 					else
23147c478bd9Sstevel@tonic-gate 						uval.string_val =
23157c478bd9Sstevel@tonic-gate 						    p_event->ae_desc;
23167c478bd9Sstevel@tonic-gate 				} else {
23177c478bd9Sstevel@tonic-gate 					uval.string_val =
23187c478bd9Sstevel@tonic-gate 					    gettext("invalid event number");
23197c478bd9Sstevel@tonic-gate 				}
23207c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
23217c478bd9Sstevel@tonic-gate 			} else {
23227c478bd9Sstevel@tonic-gate 				uval.uvaltype = PRA_USHORT;
23237c478bd9Sstevel@tonic-gate 				uval.ushort_val = etype;
23247c478bd9Sstevel@tonic-gate 				returnstat = pa_print(context, &uval, flag);
23257c478bd9Sstevel@tonic-gate 			}
23267c478bd9Sstevel@tonic-gate 		}
23277c478bd9Sstevel@tonic-gate 		return (returnstat);
23287c478bd9Sstevel@tonic-gate 	} else
23297c478bd9Sstevel@tonic-gate 		return (status);
23307c478bd9Sstevel@tonic-gate 
23317c478bd9Sstevel@tonic-gate }
23327c478bd9Sstevel@tonic-gate 
23337c478bd9Sstevel@tonic-gate 
23347c478bd9Sstevel@tonic-gate /*
23357c478bd9Sstevel@tonic-gate  * Print time from struct timeval to millisecond resolution.
23367c478bd9Sstevel@tonic-gate  *
23377c478bd9Sstevel@tonic-gate  *	typedef long	time_t;		time of day in seconds
23387c478bd9Sstevel@tonic-gate  *	typedef	long	useconds_t;	signed # of microseconds
23397c478bd9Sstevel@tonic-gate  *
23407c478bd9Sstevel@tonic-gate  * struct timeval {
23417c478bd9Sstevel@tonic-gate  *	time_t		tv_sec;		seconds
23427c478bd9Sstevel@tonic-gate  *	suseconds_t	tv_usec;	and microseconds
23437c478bd9Sstevel@tonic-gate  * };
23447c478bd9Sstevel@tonic-gate  */
23457c478bd9Sstevel@tonic-gate 
23467c478bd9Sstevel@tonic-gate int
23477c478bd9Sstevel@tonic-gate pa_utime32(pr_context_t *context, int status, int flag)
23487c478bd9Sstevel@tonic-gate {
23497c478bd9Sstevel@tonic-gate 	uint32_t scale = 1000;		/* usec to msec */
23507c478bd9Sstevel@tonic-gate 
23517c478bd9Sstevel@tonic-gate 	return (do_mtime32(context, status, flag, scale));
23527c478bd9Sstevel@tonic-gate }
23537c478bd9Sstevel@tonic-gate 
23547c478bd9Sstevel@tonic-gate /*
23557c478bd9Sstevel@tonic-gate  * Print time from timestruc_t to millisecond resolution.
23567c478bd9Sstevel@tonic-gate  *
23577c478bd9Sstevel@tonic-gate  *	typedef struct timespec timestruct_t;
23587c478bd9Sstevel@tonic-gate  * struct timespec{
23597c478bd9Sstevel@tonic-gate  *	time_t	tv_sec;		seconds
23607c478bd9Sstevel@tonic-gate  *	long	tv_nsec;	and nanoseconds
23617c478bd9Sstevel@tonic-gate  * };
23627c478bd9Sstevel@tonic-gate  */
23637c478bd9Sstevel@tonic-gate int
23647c478bd9Sstevel@tonic-gate pa_ntime32(pr_context_t *context, int status, int flag)
23657c478bd9Sstevel@tonic-gate {
23667c478bd9Sstevel@tonic-gate 	uint32_t scale = 1000000;	/* nsec to msec */
23677c478bd9Sstevel@tonic-gate 
23687c478bd9Sstevel@tonic-gate 	return (do_mtime32(context, status, flag, scale));
23697c478bd9Sstevel@tonic-gate }
23707c478bd9Sstevel@tonic-gate 
23717c478bd9Sstevel@tonic-gate /*
23727c478bd9Sstevel@tonic-gate  * Format the timezone +/- HH:MM and terminate the string
23737c478bd9Sstevel@tonic-gate  * Note tm and tv_sec are the same time.
23747c478bd9Sstevel@tonic-gate  * Too bad strftime won't produce an ISO 8601 time zone numeric
23757c478bd9Sstevel@tonic-gate  */
23767c478bd9Sstevel@tonic-gate 
23777c478bd9Sstevel@tonic-gate #define	MINS	(24L * 60)
23787c478bd9Sstevel@tonic-gate static void
23797c478bd9Sstevel@tonic-gate tzone(struct tm *tm, time_t *tv_sec, char *p)
23807c478bd9Sstevel@tonic-gate {
23817c478bd9Sstevel@tonic-gate 	struct tm *gmt;
23827c478bd9Sstevel@tonic-gate 	int min_off;
23837c478bd9Sstevel@tonic-gate 
23847c478bd9Sstevel@tonic-gate 	gmt = gmtime(tv_sec);
23857c478bd9Sstevel@tonic-gate 
23867c478bd9Sstevel@tonic-gate 	min_off = ((tm->tm_hour - gmt->tm_hour) * 60) +
23877c478bd9Sstevel@tonic-gate 	    (tm->tm_min - gmt->tm_min);
23887c478bd9Sstevel@tonic-gate 
23897c478bd9Sstevel@tonic-gate 	if (tm->tm_year < gmt->tm_year)		/* cross new year */
23907c478bd9Sstevel@tonic-gate 		min_off -= MINS;
23917c478bd9Sstevel@tonic-gate 	else if (tm->tm_year > gmt->tm_year)
23927c478bd9Sstevel@tonic-gate 		min_off += MINS;
23937c478bd9Sstevel@tonic-gate 	else if (tm->tm_yday < gmt->tm_yday)	/* cross dateline */
23947c478bd9Sstevel@tonic-gate 		min_off -= MINS;
23957c478bd9Sstevel@tonic-gate 	else if (tm->tm_yday > gmt->tm_yday)
23967c478bd9Sstevel@tonic-gate 		min_off += MINS;
23977c478bd9Sstevel@tonic-gate 
23987c478bd9Sstevel@tonic-gate 	if (min_off < 0) {
23997c478bd9Sstevel@tonic-gate 		min_off = -min_off;
24007c478bd9Sstevel@tonic-gate 		*p++ = '-';
24017c478bd9Sstevel@tonic-gate 	} else {
24027c478bd9Sstevel@tonic-gate 		*p++ = '+';
24037c478bd9Sstevel@tonic-gate 	}
24047c478bd9Sstevel@tonic-gate 
24057c478bd9Sstevel@tonic-gate 	*p++ = min_off / 600 + '0';		/* 10s of hours */
24067c478bd9Sstevel@tonic-gate 	min_off = min_off - min_off / 600 * 600;
24077c478bd9Sstevel@tonic-gate 	*p++ = min_off / 60 % 10 + '0';		/* hours */
24087c478bd9Sstevel@tonic-gate 	min_off = min_off - min_off / 60 * 60;
24097c478bd9Sstevel@tonic-gate 	*p++ = ':';
24107c478bd9Sstevel@tonic-gate 	*p++ = min_off / 10 + '0';		/* 10s of minutes */
24117c478bd9Sstevel@tonic-gate 	*p++ = min_off % 10 + '0';		/* minutes */
24127c478bd9Sstevel@tonic-gate 	*p = '\0';
24137c478bd9Sstevel@tonic-gate }
24147c478bd9Sstevel@tonic-gate 
24157c478bd9Sstevel@tonic-gate /*
24167c478bd9Sstevel@tonic-gate  * Format the milliseconds in place in the string.
24177c478bd9Sstevel@tonic-gate  * Borrowed from strftime.c:itoa()
24187c478bd9Sstevel@tonic-gate  */
24197c478bd9Sstevel@tonic-gate static void
24207c478bd9Sstevel@tonic-gate msec32(uint32_t msec, char *p)
24217c478bd9Sstevel@tonic-gate {
24227c478bd9Sstevel@tonic-gate 	*p++ = msec / 100 + '0';
24237c478bd9Sstevel@tonic-gate 	msec  = msec - msec / 100 * 100;
24247c478bd9Sstevel@tonic-gate 	*p++ = msec / 10 + '0';
24257c478bd9Sstevel@tonic-gate 	*p++ = msec % 10 +'0';
24267c478bd9Sstevel@tonic-gate }
24277c478bd9Sstevel@tonic-gate 
24287c478bd9Sstevel@tonic-gate /*
24297c478bd9Sstevel@tonic-gate  * Format time and print relative to scale factor from micro/nano seconds.
24307c478bd9Sstevel@tonic-gate  */
24317c478bd9Sstevel@tonic-gate static int
24327c478bd9Sstevel@tonic-gate do_mtime32(pr_context_t *context, int status, int flag, uint32_t scale)
24337c478bd9Sstevel@tonic-gate {
24347c478bd9Sstevel@tonic-gate 	uint32_t t32;
24357c478bd9Sstevel@tonic-gate 	time_t tv_sec;
24367c478bd9Sstevel@tonic-gate 	struct tm tm;
24377c478bd9Sstevel@tonic-gate 	char	time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")];
24387c478bd9Sstevel@tonic-gate 	int	returnstat;
24397c478bd9Sstevel@tonic-gate 	uval_t	uval;
24407c478bd9Sstevel@tonic-gate 
24417c478bd9Sstevel@tonic-gate 	if (status < 0)
24427c478bd9Sstevel@tonic-gate 		return (status);
24437c478bd9Sstevel@tonic-gate 
24447c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ISO)) != 0)
24457c478bd9Sstevel@tonic-gate 		return (returnstat);
24467c478bd9Sstevel@tonic-gate 
24477c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context,
24487c478bd9Sstevel@tonic-gate 	    (uint32_t *)&tv_sec, 1)) != 0)
24497c478bd9Sstevel@tonic-gate 		return (returnstat);
24507c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int32(context, &t32, 1)) == 0) {
24517c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
24527c478bd9Sstevel@tonic-gate 			(void) localtime_r(&tv_sec, &tm);
24537c478bd9Sstevel@tonic-gate 			(void) strftime(time_created,
24547c478bd9Sstevel@tonic-gate 			    sizeof ("YYYY-MM-DD HH:MM:SS.xxx "),
24557c478bd9Sstevel@tonic-gate 			    "%Y-%m-%d %H:%M:%S.xxx ", &tm);
24567c478bd9Sstevel@tonic-gate 			msec32(t32/scale,
24577c478bd9Sstevel@tonic-gate 			    &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]);
24587c478bd9Sstevel@tonic-gate 			tzone(&tm, &tv_sec,
24597c478bd9Sstevel@tonic-gate 			    &time_created[
24607c478bd9Sstevel@tonic-gate 			    sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]);
24617c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
24627c478bd9Sstevel@tonic-gate 			uval.string_val = time_created;
24637c478bd9Sstevel@tonic-gate 		} else {
24647c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
24657c478bd9Sstevel@tonic-gate 			uval.uint32_val = (uint32_t)tv_sec;
24667c478bd9Sstevel@tonic-gate 			(void) pa_print(context, &uval, 0);
24677c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
24687c478bd9Sstevel@tonic-gate 			uval.uint32_val = t32;
24697c478bd9Sstevel@tonic-gate 		}
24707c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
24717c478bd9Sstevel@tonic-gate 	}
24727c478bd9Sstevel@tonic-gate 
24737c478bd9Sstevel@tonic-gate 	if (returnstat == 0)
24747c478bd9Sstevel@tonic-gate 		return (close_tag(context, TAG_ISO));
24757c478bd9Sstevel@tonic-gate 	else
24767c478bd9Sstevel@tonic-gate 		return (returnstat);
24777c478bd9Sstevel@tonic-gate }
24787c478bd9Sstevel@tonic-gate 
24797c478bd9Sstevel@tonic-gate /*
24807c478bd9Sstevel@tonic-gate  * Print time from struct timeval to millisecond resolution.
24817c478bd9Sstevel@tonic-gate  *
24827c478bd9Sstevel@tonic-gate  *	typedef long	time_t;		time of day in seconds
24837c478bd9Sstevel@tonic-gate  *	typedef	long	useconds_t;	signed # of microseconds
24847c478bd9Sstevel@tonic-gate  *
24857c478bd9Sstevel@tonic-gate  * struct timeval {
24867c478bd9Sstevel@tonic-gate  *	time_t		tv_sec;		seconds
24877c478bd9Sstevel@tonic-gate  *	suseconds_t	tv_usec;	and microseconds
24887c478bd9Sstevel@tonic-gate  * };
24897c478bd9Sstevel@tonic-gate  */
24907c478bd9Sstevel@tonic-gate 
24917c478bd9Sstevel@tonic-gate int
24927c478bd9Sstevel@tonic-gate pa_utime64(pr_context_t *context, int status, int flag)
24937c478bd9Sstevel@tonic-gate {
24947c478bd9Sstevel@tonic-gate 	uint64_t scale = 1000;		/* usec to msec */
24957c478bd9Sstevel@tonic-gate 
24967c478bd9Sstevel@tonic-gate 	return (do_mtime64(context, status, flag, scale));
24977c478bd9Sstevel@tonic-gate }
24987c478bd9Sstevel@tonic-gate 
24997c478bd9Sstevel@tonic-gate /*
25007c478bd9Sstevel@tonic-gate  * Print time from timestruc_t to millisecond resolution.
25017c478bd9Sstevel@tonic-gate  *
25027c478bd9Sstevel@tonic-gate  *	typedef struct timespec timestruct_t;
25037c478bd9Sstevel@tonic-gate  * struct timespec{
25047c478bd9Sstevel@tonic-gate  *	time_t	tv_sec;		seconds
25057c478bd9Sstevel@tonic-gate  *	long	tv_nsec;	and nanoseconds
25067c478bd9Sstevel@tonic-gate  * };
25077c478bd9Sstevel@tonic-gate  */
25087c478bd9Sstevel@tonic-gate int
25097c478bd9Sstevel@tonic-gate pa_ntime64(pr_context_t *context, int status, int flag)
25107c478bd9Sstevel@tonic-gate {
25117c478bd9Sstevel@tonic-gate 	uint64_t scale = 1000000;	/* nsec to msec */
25127c478bd9Sstevel@tonic-gate 
25137c478bd9Sstevel@tonic-gate 	return (do_mtime64(context, status, flag, scale));
25147c478bd9Sstevel@tonic-gate }
25157c478bd9Sstevel@tonic-gate 
25167c478bd9Sstevel@tonic-gate /*
25177c478bd9Sstevel@tonic-gate  * Format the milliseconds in place in the string.
25187c478bd9Sstevel@tonic-gate  * Borrowed from strftime.c:itoa()
25197c478bd9Sstevel@tonic-gate  */
25207c478bd9Sstevel@tonic-gate static void
25217c478bd9Sstevel@tonic-gate msec64(uint64_t msec, char *p)
25227c478bd9Sstevel@tonic-gate {
25237c478bd9Sstevel@tonic-gate 	*p++ = msec / 100 + '0';
25247c478bd9Sstevel@tonic-gate 	msec = msec - msec / 100 * 100;
25257c478bd9Sstevel@tonic-gate 	*p++ = msec / 10 + '0';
25267c478bd9Sstevel@tonic-gate 	*p++ = msec % 10 +'0';
25277c478bd9Sstevel@tonic-gate }
25287c478bd9Sstevel@tonic-gate 
25297c478bd9Sstevel@tonic-gate /*
25307c478bd9Sstevel@tonic-gate  * Format time and print relative to scale factor from micro/nano seconds.
25317c478bd9Sstevel@tonic-gate  */
25327c478bd9Sstevel@tonic-gate static int
25337c478bd9Sstevel@tonic-gate do_mtime64(pr_context_t *context, int status, int flag, uint64_t scale)
25347c478bd9Sstevel@tonic-gate {
25357c478bd9Sstevel@tonic-gate 	uint64_t t64_sec;
25367c478bd9Sstevel@tonic-gate 	uint64_t t64_msec;
25377c478bd9Sstevel@tonic-gate 	time_t tv_sec;
25387c478bd9Sstevel@tonic-gate 	struct tm tm;
25397c478bd9Sstevel@tonic-gate 	char	time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")];
25407c478bd9Sstevel@tonic-gate 	int	returnstat;
25417c478bd9Sstevel@tonic-gate 	uval_t	uval;
25427c478bd9Sstevel@tonic-gate 
25437c478bd9Sstevel@tonic-gate 	if (status < 0)
25447c478bd9Sstevel@tonic-gate 		return (status);
25457c478bd9Sstevel@tonic-gate 
25467c478bd9Sstevel@tonic-gate 	if ((returnstat = open_tag(context, TAG_ISO)) != 0)
25477c478bd9Sstevel@tonic-gate 		return (returnstat);
25487c478bd9Sstevel@tonic-gate 
25497c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int64(context, &t64_sec, 1)) != 0)
25507c478bd9Sstevel@tonic-gate 		return (returnstat);
25517c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_u_int64(context, &t64_msec, 1)) == 0) {
25527c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
25537c478bd9Sstevel@tonic-gate #ifndef	_LP64
25547c478bd9Sstevel@tonic-gate 			/*
25557c478bd9Sstevel@tonic-gate 			 * N.B.
25567c478bd9Sstevel@tonic-gate 			 * This fails for years from 2038
25577c478bd9Sstevel@tonic-gate 			 * The Y2K+38 problem
25587c478bd9Sstevel@tonic-gate 			 */
25597c478bd9Sstevel@tonic-gate #endif	/* !_LP64 */
25607c478bd9Sstevel@tonic-gate 			tv_sec = (time_t)t64_sec;
25617c478bd9Sstevel@tonic-gate 			(void) localtime_r(&tv_sec, &tm);
25627c478bd9Sstevel@tonic-gate 			(void) strftime(time_created,
25637c478bd9Sstevel@tonic-gate 			    sizeof ("YYYY-MM-DD HH:MM:SS.xxx "),
25647c478bd9Sstevel@tonic-gate 			    "%Y-%m-%d %H:%M:%S.xxx ", &tm);
25657c478bd9Sstevel@tonic-gate 			msec64(t64_msec/scale,
25667c478bd9Sstevel@tonic-gate 			    &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]);
25677c478bd9Sstevel@tonic-gate 			tzone(&tm, &tv_sec,
25687c478bd9Sstevel@tonic-gate 			    &time_created[
25697c478bd9Sstevel@tonic-gate 			    sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]);
25707c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_STRING;
25717c478bd9Sstevel@tonic-gate 			uval.string_val = time_created;
25727c478bd9Sstevel@tonic-gate 		} else {
25737c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT64;
25747c478bd9Sstevel@tonic-gate 			uval.uint64_val = t64_sec;
25757c478bd9Sstevel@tonic-gate 			(void) pa_print(context, &uval, 0);
25767c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT64;
25777c478bd9Sstevel@tonic-gate 			uval.uint64_val = t64_msec;
25787c478bd9Sstevel@tonic-gate 		}
25797c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
25807c478bd9Sstevel@tonic-gate 	}
25817c478bd9Sstevel@tonic-gate 
25827c478bd9Sstevel@tonic-gate 	if (returnstat < 0)
25837c478bd9Sstevel@tonic-gate 		return (returnstat);
25847c478bd9Sstevel@tonic-gate 
25857c478bd9Sstevel@tonic-gate 	return (close_tag(context, TAG_ISO));
25867c478bd9Sstevel@tonic-gate }
25877c478bd9Sstevel@tonic-gate 
25887c478bd9Sstevel@tonic-gate /*
25897c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
25907c478bd9Sstevel@tonic-gate  * pa_error()   :  convert the return token error code.
25917c478bd9Sstevel@tonic-gate  *
25927c478bd9Sstevel@tonic-gate  * output	: buf string representing return token error code.
25937c478bd9Sstevel@tonic-gate  *
25947c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
25957c478bd9Sstevel@tonic-gate  */
25967c478bd9Sstevel@tonic-gate void
25977c478bd9Sstevel@tonic-gate pa_error(const uchar_t err, char *buf, size_t buflen)
25987c478bd9Sstevel@tonic-gate {
25997c478bd9Sstevel@tonic-gate 	if (err == 0) {
26007c478bd9Sstevel@tonic-gate 		(void) strlcpy(buf, gettext("success"), buflen);
26017c478bd9Sstevel@tonic-gate 	} else if ((char)err == -1) {
26027c478bd9Sstevel@tonic-gate 		(void) strlcpy(buf, gettext("failure"), buflen);
26037c478bd9Sstevel@tonic-gate 	} else {
26047c478bd9Sstevel@tonic-gate 		char *emsg = strerror(err);
26057c478bd9Sstevel@tonic-gate 
26067c478bd9Sstevel@tonic-gate 		if (emsg != NULL) {
26077c478bd9Sstevel@tonic-gate 			(void) strlcpy(buf, gettext("failure: "), buflen);
26087c478bd9Sstevel@tonic-gate 			(void) strlcat(buf, emsg, buflen);
26097c478bd9Sstevel@tonic-gate 		} else {
26107c478bd9Sstevel@tonic-gate 			(void) snprintf(buf, buflen, "%s%d",
26117c478bd9Sstevel@tonic-gate 			    gettext("failure: "), err);
26127c478bd9Sstevel@tonic-gate 		}
26137c478bd9Sstevel@tonic-gate 	}
26147c478bd9Sstevel@tonic-gate }
26157c478bd9Sstevel@tonic-gate 
26167c478bd9Sstevel@tonic-gate /*
26177c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
26187c478bd9Sstevel@tonic-gate  * pa_retval()   :  convert the return token return value code.
26197c478bd9Sstevel@tonic-gate  *
26207c478bd9Sstevel@tonic-gate  * output	: buf string representing return token error code.
26217c478bd9Sstevel@tonic-gate  *
26227c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
26237c478bd9Sstevel@tonic-gate  */
26247c478bd9Sstevel@tonic-gate void
26257c478bd9Sstevel@tonic-gate pa_retval(const int32_t retval, char *buf, size_t buflen)
26267c478bd9Sstevel@tonic-gate {
26277c478bd9Sstevel@tonic-gate 	struct msg_text	*msglist = &adt_msg_text[ADT_LIST_FAIL_VALUE];
26287c478bd9Sstevel@tonic-gate 
26297c478bd9Sstevel@tonic-gate 	if ((retval + msglist->ml_offset >= msglist->ml_min_index) &&
26307c478bd9Sstevel@tonic-gate 	    (retval + msglist->ml_offset <= msglist->ml_max_index)) {
26317c478bd9Sstevel@tonic-gate 
26327c478bd9Sstevel@tonic-gate 		(void) strlcpy(buf,
26337c478bd9Sstevel@tonic-gate 		    gettext(msglist->ml_msg_list[retval + msglist->ml_offset]),
26347c478bd9Sstevel@tonic-gate 		    buflen);
26357c478bd9Sstevel@tonic-gate 	} else if ((retval >= ADT_FAIL_PAM) &&
26367c478bd9Sstevel@tonic-gate 	    (retval < ADT_FAIL_PAM + PAM_TOTAL_ERRNUM))
26377c478bd9Sstevel@tonic-gate 		(void) strlcpy(buf, pam_strerror(NULL, retval - ADT_FAIL_PAM),
26387c478bd9Sstevel@tonic-gate 		    buflen);
26397c478bd9Sstevel@tonic-gate 	else
26407c478bd9Sstevel@tonic-gate 		(void) snprintf(buf, buflen, "%d", retval);
26417c478bd9Sstevel@tonic-gate }
26427c478bd9Sstevel@tonic-gate 
26437c478bd9Sstevel@tonic-gate 
26447c478bd9Sstevel@tonic-gate /*
26457c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
26467c478bd9Sstevel@tonic-gate  * pa_printstr()	:  print a given string, translating unprintables
26477c478bd9Sstevel@tonic-gate  *			:  as needed.
26487c478bd9Sstevel@tonic-gate  */
26497c478bd9Sstevel@tonic-gate static int
26507c478bd9Sstevel@tonic-gate pa_printstr(pr_context_t *context, char *str)
26517c478bd9Sstevel@tonic-gate {
26527c478bd9Sstevel@tonic-gate 	int	err = 0;
26537c478bd9Sstevel@tonic-gate 	int	len, printable;
26547c478bd9Sstevel@tonic-gate 	int	mbmax = MB_CUR_MAX;
26557c478bd9Sstevel@tonic-gate 	wchar_t	wc;
26567c478bd9Sstevel@tonic-gate 	char	c;
26577c478bd9Sstevel@tonic-gate 
26587c478bd9Sstevel@tonic-gate 	if (mbmax == 1) {
26597c478bd9Sstevel@tonic-gate 		/* fast path */
26607c478bd9Sstevel@tonic-gate 		while (err == 0 && *str != '\0') {
26617c478bd9Sstevel@tonic-gate 			c = *str++;
26627c478bd9Sstevel@tonic-gate 			printable = isprint((unsigned char)c);
26637c478bd9Sstevel@tonic-gate 			err = pa_putstr(context, printable, &c, 1);
26647c478bd9Sstevel@tonic-gate 		}
26657c478bd9Sstevel@tonic-gate 		return (err);
26667c478bd9Sstevel@tonic-gate 	}
26677c478bd9Sstevel@tonic-gate 	while (err == 0 && *str != '\0') {
26687c478bd9Sstevel@tonic-gate 		len = mbtowc(&wc, str, mbmax);
26697c478bd9Sstevel@tonic-gate 		if (len <= 0) {
26707c478bd9Sstevel@tonic-gate 			len = 1;
26717c478bd9Sstevel@tonic-gate 			printable = 0;
26727c478bd9Sstevel@tonic-gate 		} else {
26737c478bd9Sstevel@tonic-gate 			printable = iswprint(wc);
26747c478bd9Sstevel@tonic-gate 		}
26757c478bd9Sstevel@tonic-gate 		err = pa_putstr(context, printable, str, len);
26767c478bd9Sstevel@tonic-gate 		str += len;
26777c478bd9Sstevel@tonic-gate 	}
26787c478bd9Sstevel@tonic-gate 	return (err);
26797c478bd9Sstevel@tonic-gate }
26807c478bd9Sstevel@tonic-gate 
26817c478bd9Sstevel@tonic-gate /*
26827c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
26837c478bd9Sstevel@tonic-gate  * pa_print()	:  print as one str or formatted for easy reading.
26847c478bd9Sstevel@tonic-gate  * 		: flag - indicates whether to output a new line for
26857c478bd9Sstevel@tonic-gate  *		: multi-line output.
26867c478bd9Sstevel@tonic-gate  * 		:		= 0; no new line
26877c478bd9Sstevel@tonic-gate  *		:		= 1; new line if regular output
26887c478bd9Sstevel@tonic-gate  * output	: The audit record information is displayed in the
26897c478bd9Sstevel@tonic-gate  *		  type specified by uvaltype and value specified in
26907c478bd9Sstevel@tonic-gate  *		  uval.  The printing of the delimiter or newline is
26917c478bd9Sstevel@tonic-gate  *		  determined by PRF_ONELINE, and the flag value,
26927c478bd9Sstevel@tonic-gate  *		  as follows:
26937c478bd9Sstevel@tonic-gate  *			+--------+------+------+-----------------+
26947c478bd9Sstevel@tonic-gate  *			|ONELINE | flag | last | Action          |
26957c478bd9Sstevel@tonic-gate  *			+--------+------+------+-----------------+
26967c478bd9Sstevel@tonic-gate  *			|    Y   |   Y  |   T  | print new line  |
26977c478bd9Sstevel@tonic-gate  *			|    Y   |   Y  |   F  | print delimiter |
26987c478bd9Sstevel@tonic-gate  *			|    Y   |   N  |   T  | print new line  |
26997c478bd9Sstevel@tonic-gate  *			|    Y   |   N  |   F  | print delimiter |
27007c478bd9Sstevel@tonic-gate  *			|    N   |   Y  |   T  | print new line  |
27017c478bd9Sstevel@tonic-gate  *			|    N   |   Y  |   F  | print new line  |
27027c478bd9Sstevel@tonic-gate  *			|    N   |   N  |   T  | print new line  |
27037c478bd9Sstevel@tonic-gate  *			|    N   |   N  |   F  | print delimiter |
27047c478bd9Sstevel@tonic-gate  *			+--------+------+------+-----------------+
27057c478bd9Sstevel@tonic-gate  *
27067c478bd9Sstevel@tonic-gate  * return codes : -1 - error
27077c478bd9Sstevel@tonic-gate  *		0 - successful
27087c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
27097c478bd9Sstevel@tonic-gate  */
27107c478bd9Sstevel@tonic-gate int
27117c478bd9Sstevel@tonic-gate pa_print(pr_context_t *context, uval_t *uval, int flag)
27127c478bd9Sstevel@tonic-gate {
27137c478bd9Sstevel@tonic-gate 	int	returnstat = 0;
27147c478bd9Sstevel@tonic-gate 	int	last;
27157c478bd9Sstevel@tonic-gate 
27167c478bd9Sstevel@tonic-gate 	switch (uval->uvaltype) {
27177c478bd9Sstevel@tonic-gate 	case PRA_INT32:
27187c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%d", uval->int32_val);
27197c478bd9Sstevel@tonic-gate 		break;
27207c478bd9Sstevel@tonic-gate 	case PRA_UINT32:
27217c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%u", uval->uint32_val);
27227c478bd9Sstevel@tonic-gate 		break;
27237c478bd9Sstevel@tonic-gate 	case PRA_INT64:
27247c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%"PRId64, uval->int64_val);
27257c478bd9Sstevel@tonic-gate 		break;
27267c478bd9Sstevel@tonic-gate 	case PRA_UINT64:
27277c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%"PRIu64, uval->uint64_val);
27287c478bd9Sstevel@tonic-gate 		break;
27297c478bd9Sstevel@tonic-gate 	case PRA_SHORT:
27307c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%hd", uval->short_val);
27317c478bd9Sstevel@tonic-gate 		break;
27327c478bd9Sstevel@tonic-gate 	case PRA_USHORT:
27337c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%hu", uval->ushort_val);
27347c478bd9Sstevel@tonic-gate 		break;
27357c478bd9Sstevel@tonic-gate 	case PRA_CHAR:
27367c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%c", uval->char_val);
27377c478bd9Sstevel@tonic-gate 		break;
27387c478bd9Sstevel@tonic-gate 	case PRA_BYTE:
27397c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%d", uval->char_val);
27407c478bd9Sstevel@tonic-gate 		break;
27417c478bd9Sstevel@tonic-gate 	case PRA_STRING:
27427c478bd9Sstevel@tonic-gate 		returnstat = pa_printstr(context, uval->string_val);
27437c478bd9Sstevel@tonic-gate 		break;
27447c478bd9Sstevel@tonic-gate 	case PRA_HEX32:
27457c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "0x%x", uval->int32_val);
27467c478bd9Sstevel@tonic-gate 		break;
27477c478bd9Sstevel@tonic-gate 	case PRA_HEX64:
27487c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "0x%"PRIx64, uval->int64_val);
27497c478bd9Sstevel@tonic-gate 		break;
27507c478bd9Sstevel@tonic-gate 	case PRA_SHEX:
27517c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "0x%hx", uval->short_val);
27527c478bd9Sstevel@tonic-gate 		break;
27537c478bd9Sstevel@tonic-gate 	case PRA_OCT:
27547c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%ho", uval->ushort_val);
27557c478bd9Sstevel@tonic-gate 		break;
27567c478bd9Sstevel@tonic-gate 	case PRA_LOCT:
27577c478bd9Sstevel@tonic-gate 		returnstat = pr_printf(context, "%o", (int)uval->uint32_val);
27587c478bd9Sstevel@tonic-gate 		break;
27597c478bd9Sstevel@tonic-gate 	default:
27607c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("praudit: Unknown type.\n"));
27617c478bd9Sstevel@tonic-gate 		returnstat = -1;
27627c478bd9Sstevel@tonic-gate 		break;
27637c478bd9Sstevel@tonic-gate 	}
27647c478bd9Sstevel@tonic-gate 	if (returnstat < 0)
27657c478bd9Sstevel@tonic-gate 		return (returnstat);
27667c478bd9Sstevel@tonic-gate 
27677c478bd9Sstevel@tonic-gate 	last = (context->audit_adr->adr_now ==
27687c478bd9Sstevel@tonic-gate 	    (context->audit_rec_start + context->audit_rec_len));
27697c478bd9Sstevel@tonic-gate 
27707c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_XMLM)) {
27717c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_ONELINE)) {
27727c478bd9Sstevel@tonic-gate 			if ((flag == 1) || last)
27737c478bd9Sstevel@tonic-gate 				returnstat = pr_putchar(context, '\n');
27747c478bd9Sstevel@tonic-gate 			else
27757c478bd9Sstevel@tonic-gate 				returnstat = pr_printf(context, "%s",
27767c478bd9Sstevel@tonic-gate 				    context->SEPARATOR);
27777c478bd9Sstevel@tonic-gate 		} else {
27787c478bd9Sstevel@tonic-gate 			if (!last)
27797c478bd9Sstevel@tonic-gate 				returnstat = pr_printf(context, "%s",
27807c478bd9Sstevel@tonic-gate 				    context->SEPARATOR);
27817c478bd9Sstevel@tonic-gate 			else
27827c478bd9Sstevel@tonic-gate 				returnstat = pr_putchar(context, '\n');
27837c478bd9Sstevel@tonic-gate 		}
27847c478bd9Sstevel@tonic-gate 	}
27857c478bd9Sstevel@tonic-gate 	if ((returnstat == 0) && (context->data_mode == FILEMODE))
27867c478bd9Sstevel@tonic-gate 		(void) fflush(stdout);
27877c478bd9Sstevel@tonic-gate 
27887c478bd9Sstevel@tonic-gate 	return (returnstat);
27897c478bd9Sstevel@tonic-gate }
27907c478bd9Sstevel@tonic-gate 
27918dc347dbStz204579 static struct cntrl_mapping {
27928dc347dbStz204579 	char from;
27938dc347dbStz204579 	char to;
27948dc347dbStz204579 } cntrl_map[] = {
27958dc347dbStz204579 	'\0', '0',
27968dc347dbStz204579 	'\a', 'a',
27978dc347dbStz204579 	'\b', 'b',
27988dc347dbStz204579 	'\t', 't',
27998dc347dbStz204579 	'\f', 'f',
28008dc347dbStz204579 	'\n', 'n',
28018dc347dbStz204579 	'\r', 'r',
28028dc347dbStz204579 	'\v', 'v'
28038dc347dbStz204579 };
28048dc347dbStz204579 
28058dc347dbStz204579 static int cntrl_map_entries = sizeof (cntrl_map)
28068dc347dbStz204579 	/ sizeof (struct cntrl_mapping);
28078dc347dbStz204579 
28087c478bd9Sstevel@tonic-gate /*
28097c478bd9Sstevel@tonic-gate  * Convert binary data to ASCII for printing.
28107c478bd9Sstevel@tonic-gate  */
28117c478bd9Sstevel@tonic-gate void
28127c478bd9Sstevel@tonic-gate convertascii(char *p, char *c, int size)
28137c478bd9Sstevel@tonic-gate {
28147c478bd9Sstevel@tonic-gate 	register int	i;
28158dc347dbStz204579 	register int	j, match;
28167c478bd9Sstevel@tonic-gate 
28177c478bd9Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
28187c478bd9Sstevel@tonic-gate 		*(c + i) = (char)toascii(*(c + i));
28197c478bd9Sstevel@tonic-gate 		if ((int)iscntrl(*(c + i))) {
28208dc347dbStz204579 			for (j = match = 0; j < cntrl_map_entries; j++)
28218dc347dbStz204579 				if (cntrl_map[j].from == *(c + i)) {
28228dc347dbStz204579 					*p++ = '\\';
28238dc347dbStz204579 					*p++ = cntrl_map[j].to;
28248dc347dbStz204579 					match = 1;
28258dc347dbStz204579 				}
28268dc347dbStz204579 			if (!match) {
28277c478bd9Sstevel@tonic-gate 				*p++ = '^';
28287c478bd9Sstevel@tonic-gate 				*p++ = (char)(*(c + i) + 0x40);
28298dc347dbStz204579 			}
28307c478bd9Sstevel@tonic-gate 		} else
28317c478bd9Sstevel@tonic-gate 			*p++ = *(c + i);
28327c478bd9Sstevel@tonic-gate 	}
28337c478bd9Sstevel@tonic-gate 
28347c478bd9Sstevel@tonic-gate 	*p = '\0';
28357c478bd9Sstevel@tonic-gate 
28367c478bd9Sstevel@tonic-gate }
28377c478bd9Sstevel@tonic-gate 
28387c478bd9Sstevel@tonic-gate 
28397c478bd9Sstevel@tonic-gate /*
28407c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
28417c478bd9Sstevel@tonic-gate  * pa_xgeneric: Process Xobject token and display contents
28427c478bd9Sstevel@tonic-gate  *		      This routine will handle many of the attribute
28437c478bd9Sstevel@tonic-gate  *		      types introduced in TS 2.x, such as:
28447c478bd9Sstevel@tonic-gate  *
28457c478bd9Sstevel@tonic-gate  *		      AUT_XCOLORMAP, AUT_XCURSOR, AUT_XFONT,
28467c478bd9Sstevel@tonic-gate  *		      AUT_XGC, AUT_XPIXMAP, AUT_XWINDOW
28477c478bd9Sstevel@tonic-gate  *
28487c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the token id has been retrieved
28497c478bd9Sstevel@tonic-gate  *
28507c478bd9Sstevel@tonic-gate  * return codes		: -1 - error
28517c478bd9Sstevel@tonic-gate  *			:  0 - successful
28527c478bd9Sstevel@tonic-gate  * NOTE: At the time of call, the xatom token id has been retrieved
28537c478bd9Sstevel@tonic-gate  *
28547c478bd9Sstevel@tonic-gate  * Format of xobj
28557c478bd9Sstevel@tonic-gate  *	text token id		adr_char
28567c478bd9Sstevel@tonic-gate  * 	XID 			adr_u_int32
28577c478bd9Sstevel@tonic-gate  * 	creator uid		adr_pw_uid
28587c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
28597c478bd9Sstevel@tonic-gate  */
28607c478bd9Sstevel@tonic-gate int
28617c478bd9Sstevel@tonic-gate pa_xgeneric(pr_context_t *context)
28627c478bd9Sstevel@tonic-gate {
28637c478bd9Sstevel@tonic-gate 	int	returnstat;
28647c478bd9Sstevel@tonic-gate 
28657c478bd9Sstevel@tonic-gate 	returnstat = process_tag(context, TAG_XID, 0, 0);
28667c478bd9Sstevel@tonic-gate 	return (process_tag(context, TAG_XCUID, returnstat, 1));
28677c478bd9Sstevel@tonic-gate }
28687c478bd9Sstevel@tonic-gate 
28697c478bd9Sstevel@tonic-gate 
28707c478bd9Sstevel@tonic-gate /*
28717c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------------------
28727c478bd9Sstevel@tonic-gate  * pa_liaison : Issues pr_adr_char to retrieve the next ADR item from the
28737c478bd9Sstevel@tonic-gate  *			input stream pointed to by audit_adr, and prints it
28747c478bd9Sstevel@tonic-gate  *			if status >= 0 either in ASCII or raw form
28757c478bd9Sstevel@tonic-gate  * return codes : -1 - error
28767c478bd9Sstevel@tonic-gate  *		: 0 - successful
28777c478bd9Sstevel@tonic-gate  *		: 1 - warning, unknown label type
28787c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
28797c478bd9Sstevel@tonic-gate  */
28807c478bd9Sstevel@tonic-gate int
28817c478bd9Sstevel@tonic-gate pa_liaison(pr_context_t *context, int status, int flag)
28827c478bd9Sstevel@tonic-gate {
28837c478bd9Sstevel@tonic-gate 	int	returnstat;
28847c478bd9Sstevel@tonic-gate 	int32_t	li;
28857c478bd9Sstevel@tonic-gate 	uval_t	uval;
28867c478bd9Sstevel@tonic-gate 
28877c478bd9Sstevel@tonic-gate 	if (status >= 0) {
28887c478bd9Sstevel@tonic-gate 		if ((returnstat = pr_adr_int32(context, &li, 1)) != 0) {
28897c478bd9Sstevel@tonic-gate 			return (returnstat);
28907c478bd9Sstevel@tonic-gate 		}
28917c478bd9Sstevel@tonic-gate 		if (!(context->format & PRF_RAWM)) {
28927c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_UINT32;
28937c478bd9Sstevel@tonic-gate 			uval.uint32_val = li;
28947c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
28957c478bd9Sstevel@tonic-gate 		}
28967c478bd9Sstevel@tonic-gate 		/* print in hexadecimal form */
28977c478bd9Sstevel@tonic-gate 		if ((context->format & PRF_RAWM) || (returnstat == 1)) {
28987c478bd9Sstevel@tonic-gate 			uval.uvaltype = PRA_HEX32;
28997c478bd9Sstevel@tonic-gate 			uval.uint32_val = li;
29007c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
29017c478bd9Sstevel@tonic-gate 		}
29027c478bd9Sstevel@tonic-gate 		return (returnstat);
29037c478bd9Sstevel@tonic-gate 	} else
29047c478bd9Sstevel@tonic-gate 		return (status);
29057c478bd9Sstevel@tonic-gate }
29067c478bd9Sstevel@tonic-gate 
29077c478bd9Sstevel@tonic-gate /*
29087c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------------------
29097c478bd9Sstevel@tonic-gate  * pa_xid : Issues pr_adr_int32 to retrieve the XID from the input
29107c478bd9Sstevel@tonic-gate  *	      stream pointed to by audit_adr, and prints it if
29117c478bd9Sstevel@tonic-gate  *	      status >= 0 either in ASCII or raw form
29127c478bd9Sstevel@tonic-gate  * return codes : -1 - error
29137c478bd9Sstevel@tonic-gate  *		:  0 - successful
29147c478bd9Sstevel@tonic-gate  *		:  1 - warning, unknown label type
29157c478bd9Sstevel@tonic-gate  * ------------------------------------------------------------------------
29167c478bd9Sstevel@tonic-gate  */
29177c478bd9Sstevel@tonic-gate 
29187c478bd9Sstevel@tonic-gate int
29197c478bd9Sstevel@tonic-gate pa_xid(pr_context_t *context, int status, int flag)
29207c478bd9Sstevel@tonic-gate {
29217c478bd9Sstevel@tonic-gate 	int returnstat;
29227c478bd9Sstevel@tonic-gate 	int32_t xid;
29237c478bd9Sstevel@tonic-gate 	uval_t	uval;
29247c478bd9Sstevel@tonic-gate 
29257c478bd9Sstevel@tonic-gate 	if (status < 0)
29267c478bd9Sstevel@tonic-gate 		return (status);
29277c478bd9Sstevel@tonic-gate 
29287c478bd9Sstevel@tonic-gate 	/* get XID from stream */
29297c478bd9Sstevel@tonic-gate 	if ((returnstat = pr_adr_int32(context, (int32_t *)&xid, 1)) != 0)
29307c478bd9Sstevel@tonic-gate 		return (returnstat);
29317c478bd9Sstevel@tonic-gate 
29327c478bd9Sstevel@tonic-gate 	if (!(context->format & PRF_RAWM)) {
29337c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_STRING;
29347c478bd9Sstevel@tonic-gate 		uval.string_val = hexconvert((char *)&xid, sizeof (xid),
29357c478bd9Sstevel@tonic-gate 		    sizeof (xid));
29367c478bd9Sstevel@tonic-gate 		if (uval.string_val) {
29377c478bd9Sstevel@tonic-gate 			returnstat = pa_print(context, &uval, flag);
29387c478bd9Sstevel@tonic-gate 			free(uval.string_val);
29397c478bd9Sstevel@tonic-gate 		}
29407c478bd9Sstevel@tonic-gate 	} else {
29417c478bd9Sstevel@tonic-gate 		uval.uvaltype = PRA_INT32;
29427c478bd9Sstevel@tonic-gate 		uval.int32_val = xid;
29437c478bd9Sstevel@tonic-gate 		returnstat = pa_print(context, &uval, flag);
29447c478bd9Sstevel@tonic-gate 	}
29457c478bd9Sstevel@tonic-gate 
29467c478bd9Sstevel@tonic-gate 	return (returnstat);
29477c478bd9Sstevel@tonic-gate }
2948