xref: /titanic_53/usr/src/lib/auditd_plugins/syslog/systoken.c (revision 33f5ff17089e3a43e6e730bf80384c233123dbd9)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22dfc7be02SJan Friedel  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*33f5ff17SMilan Jurik  * Copyright 2012 Milan Jurik. All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * Token processing for sysupd; each token function does one
307c478bd9Sstevel@tonic-gate  * or more operations.  All of them bump the buffer pointer
317c478bd9Sstevel@tonic-gate  * to the next token; some of them extract one or more data
327c478bd9Sstevel@tonic-gate  * from the token.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #define	DEBUG	0
367c478bd9Sstevel@tonic-gate #if DEBUG
37dfc7be02SJan Friedel #define	DPRINT(x) { (void) fprintf x; }
387c478bd9Sstevel@tonic-gate #else
397c478bd9Sstevel@tonic-gate #define	DPRINT(x)
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <locale.h>
437c478bd9Sstevel@tonic-gate #include <stdlib.h>
447c478bd9Sstevel@tonic-gate #include <stdio.h>
457c478bd9Sstevel@tonic-gate #include <string.h>
467c478bd9Sstevel@tonic-gate #include <sys/types.h>
477c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
4845916cd2Sjpk #include <sys/tsol/label.h>
497c478bd9Sstevel@tonic-gate #include "toktable.h"	/* ../praudit */
507c478bd9Sstevel@tonic-gate #include "sysplugin.h"
517c478bd9Sstevel@tonic-gate #include "systoken.h"
527c478bd9Sstevel@tonic-gate #include <audit_plugin.h>
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #if DEBUG
557c478bd9Sstevel@tonic-gate static FILE	*dbfp;			/* debug file */
567c478bd9Sstevel@tonic-gate #endif
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate static void	anchor_path(char *);
597c478bd9Sstevel@tonic-gate static size_t	collapse_path(char *, size_t);
607c478bd9Sstevel@tonic-gate static void	get_bytes_to_string(parse_context_t *, size_t *, char **,
617c478bd9Sstevel@tonic-gate 		    size_t);
627c478bd9Sstevel@tonic-gate static void	skip_bytes(parse_context_t *);
637c478bd9Sstevel@tonic-gate static void	skip_string(parse_context_t *);
647c478bd9Sstevel@tonic-gate static int	xgeneric(parse_context_t *);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * Process a token in a record to (1) extract data of interest if any
687c478bd9Sstevel@tonic-gate  * and (2) point to the next token.
697c478bd9Sstevel@tonic-gate  *
707c478bd9Sstevel@tonic-gate  * returns 0 if ok.  + or - values are of debug value:
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  *	returns -1 if the parsing of the token failed.
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  *	returns +<previous id> if the token is not found.  This value
757c478bd9Sstevel@tonic-gate  *	is used to help determine where in the record the problem
767c478bd9Sstevel@tonic-gate  *	occurred.  The common failure case is that the parsing of
777c478bd9Sstevel@tonic-gate  *	token M is incorrect and the buffer pointer ends up pointing
787c478bd9Sstevel@tonic-gate  *	to garbage.  The positive error value of M *may* be the id of
797c478bd9Sstevel@tonic-gate  *	the incorrectly parsed token.
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate int
parse_token(parse_context_t * ctx)837c478bd9Sstevel@tonic-gate parse_token(parse_context_t *ctx)
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate 	char		tokenid;
867c478bd9Sstevel@tonic-gate 	static char	prev_tokenid = -1;
877c478bd9Sstevel@tonic-gate 	int		rc;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #if DEBUG
907c478bd9Sstevel@tonic-gate 	static boolean_t	first = 1;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	if (first) {
937c478bd9Sstevel@tonic-gate 		dbfp = __auditd_debug_file_open();
947c478bd9Sstevel@tonic-gate 		first = 0;
957c478bd9Sstevel@tonic-gate 	}
967c478bd9Sstevel@tonic-gate #endif
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	adrm_char(&(ctx->adr), &tokenid, 1);
997c478bd9Sstevel@tonic-gate 
1007883e825Spaulson 	if ((tokenid > 0) && (tokentable[tokenid].func != NOFUNC)) {
1017c478bd9Sstevel@tonic-gate 		rc = (*tokentable[tokenid].func)(ctx);
1027c478bd9Sstevel@tonic-gate 		prev_tokenid = tokenid;
1037c478bd9Sstevel@tonic-gate 		return (rc);
1047c478bd9Sstevel@tonic-gate 	}
1057c478bd9Sstevel@tonic-gate 	/* here if token id is not in table */
1067c478bd9Sstevel@tonic-gate 	return (prev_tokenid);
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /* There should not be any file tokens in the middle of a record */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /* ARGSUSED */
1127c478bd9Sstevel@tonic-gate int
file_token(parse_context_t * ctx)1137c478bd9Sstevel@tonic-gate file_token(parse_context_t *ctx)
1147c478bd9Sstevel@tonic-gate {
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	return (-1);
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /* ARGSUSED */
1207c478bd9Sstevel@tonic-gate int
file64_token(parse_context_t * ctx)1217c478bd9Sstevel@tonic-gate file64_token(parse_context_t *ctx)
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate 	return (-1);
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate static void
common_header(parse_context_t * ctx)1277c478bd9Sstevel@tonic-gate common_header(parse_context_t *ctx)
1287c478bd9Sstevel@tonic-gate {
1297c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), &(ctx->out.sf_reclen), 1);
1307c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (char);		/* version number */
131d0fa49b7STony Nguyen 	adrm_u_short(&(ctx->adr), &(ctx->out.sf_eventid), 1);
1327c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (short);		/* modifier */
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate  * 32bit header
1377c478bd9Sstevel@tonic-gate  */
1387c478bd9Sstevel@tonic-gate int
header_token(parse_context_t * ctx)1397c478bd9Sstevel@tonic-gate header_token(parse_context_t *ctx)
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate 	common_header(ctx);
1427c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += 2 * sizeof (int32_t);	/* time */
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	return (0);
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate int
header32_ex_token(parse_context_t * ctx)1497c478bd9Sstevel@tonic-gate header32_ex_token(parse_context_t *ctx)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate 	int32_t	type;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	common_header(ctx);
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &type, 1);		/* tid type */
1567c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += type * sizeof (char);	/* ip address */
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += 2 * sizeof (int32_t);	/* time */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	return (0);
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate int
header64_ex_token(parse_context_t * ctx)1657c478bd9Sstevel@tonic-gate header64_ex_token(parse_context_t *ctx)
1667c478bd9Sstevel@tonic-gate {
1677c478bd9Sstevel@tonic-gate 	int32_t	type;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	common_header(ctx);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &type, 1);		/* tid type */
1727c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += type * sizeof (char);	/* ip address */
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += 2 * sizeof (int64_t);	/* time */
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	return (0);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate int
header64_token(parse_context_t * ctx)1817c478bd9Sstevel@tonic-gate header64_token(parse_context_t *ctx)
1827c478bd9Sstevel@tonic-gate {
1837c478bd9Sstevel@tonic-gate 	common_header(ctx);
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += 2 * sizeof (int64_t);	/* time */
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	return (0);
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * ======================================================
1937c478bd9Sstevel@tonic-gate  *  The following token processing routines return
1947c478bd9Sstevel@tonic-gate  *  0: if parsed ok
1957c478bd9Sstevel@tonic-gate  * -1: can't parse and can't determine location of next token
1967c478bd9Sstevel@tonic-gate  * ======================================================
1977c478bd9Sstevel@tonic-gate  */
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate int
trailer_token(parse_context_t * ctx)2007c478bd9Sstevel@tonic-gate trailer_token(parse_context_t *ctx)
2017c478bd9Sstevel@tonic-gate {
2027c478bd9Sstevel@tonic-gate 	short	magic_number;
2037c478bd9Sstevel@tonic-gate 	uint32_t bytes;
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	adrm_u_short(&(ctx->adr), (ushort_t *)&magic_number, 1);
2067c478bd9Sstevel@tonic-gate 	if (magic_number != AUT_TRAILER_MAGIC)
2077c478bd9Sstevel@tonic-gate 		return (-1);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), &bytes, 1);
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	return (0);
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate /*
2167c478bd9Sstevel@tonic-gate  * Format of arbitrary data token:
2177c478bd9Sstevel@tonic-gate  *	arbitrary data token id	&(ctx->adr) char
2187c478bd9Sstevel@tonic-gate  * 	how to print		adr_char
2197c478bd9Sstevel@tonic-gate  *	basic unit		adr_char
2207c478bd9Sstevel@tonic-gate  *	unit count		adr_char, specifying number of units of
2217c478bd9Sstevel@tonic-gate  *	data items		depends on basic unit
2227c478bd9Sstevel@tonic-gate  *
2237c478bd9Sstevel@tonic-gate  */
2247c478bd9Sstevel@tonic-gate int
arbitrary_data_token(parse_context_t * ctx)2257c478bd9Sstevel@tonic-gate arbitrary_data_token(parse_context_t *ctx)
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate 	char	basic_unit, unit_count;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (char); /* how to print */
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	adrm_char(&(ctx->adr), &basic_unit, 1);
2327c478bd9Sstevel@tonic-gate 	adrm_char(&(ctx->adr), &unit_count, 1);
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	switch (basic_unit) {
2357c478bd9Sstevel@tonic-gate 	case AUR_CHAR: /* same as AUR_BYTE */
2367c478bd9Sstevel@tonic-gate 		ctx->adr.adr_now += unit_count * sizeof (char);
2377c478bd9Sstevel@tonic-gate 		break;
2387c478bd9Sstevel@tonic-gate 	case AUR_SHORT:
2397c478bd9Sstevel@tonic-gate 		ctx->adr.adr_now += unit_count * sizeof (short);
2407c478bd9Sstevel@tonic-gate 		break;
2417c478bd9Sstevel@tonic-gate 	case AUR_INT32:	/* same as AUR_INT */
2427c478bd9Sstevel@tonic-gate 		ctx->adr.adr_now += unit_count * sizeof (int32_t);
2437c478bd9Sstevel@tonic-gate 		break;
2447c478bd9Sstevel@tonic-gate 	case AUR_INT64:
2457c478bd9Sstevel@tonic-gate 		ctx->adr.adr_now += unit_count * sizeof (int64_t);
2467c478bd9Sstevel@tonic-gate 		break;
2477c478bd9Sstevel@tonic-gate 	default:
2487c478bd9Sstevel@tonic-gate 		return (-1);
2497c478bd9Sstevel@tonic-gate 	}
2507c478bd9Sstevel@tonic-gate 	return (0);
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate  * Format of opaque token:
2567c478bd9Sstevel@tonic-gate  *	opaque token id		adr_char
2577c478bd9Sstevel@tonic-gate  *	size			adr_short
2587c478bd9Sstevel@tonic-gate  *	data			adr_char, size times
2597c478bd9Sstevel@tonic-gate  *
2607c478bd9Sstevel@tonic-gate  */
2617c478bd9Sstevel@tonic-gate int
opaque_token(parse_context_t * ctx)2627c478bd9Sstevel@tonic-gate opaque_token(parse_context_t *ctx)
2637c478bd9Sstevel@tonic-gate {
2647c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
2657c478bd9Sstevel@tonic-gate 	return (0);
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate  * Format of return32 value token:
2717c478bd9Sstevel@tonic-gate  * 	return value token id	adr_char
2727c478bd9Sstevel@tonic-gate  *	error number		adr_char
2737c478bd9Sstevel@tonic-gate  *	return value		adr_u_int32
2747c478bd9Sstevel@tonic-gate  *
2757c478bd9Sstevel@tonic-gate  */
2767c478bd9Sstevel@tonic-gate int
return_value32_token(parse_context_t * ctx)2777c478bd9Sstevel@tonic-gate return_value32_token(parse_context_t *ctx)
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate 	char		errnum;
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	adrm_char(&(ctx->adr), &errnum, 1);	/* pass / fail */
2827c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (int32_t);	/* error code */
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	ctx->out.sf_pass = (errnum == 0) ? 1 : -1;
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	return (0);
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate /*
2907c478bd9Sstevel@tonic-gate  * Format of return64 value token:
2917c478bd9Sstevel@tonic-gate  * 	return value token id	adr_char
2927c478bd9Sstevel@tonic-gate  *	error number		adr_char
2937c478bd9Sstevel@tonic-gate  *	return value		adr_u_int64
2947c478bd9Sstevel@tonic-gate  *
2957c478bd9Sstevel@tonic-gate  */
2967c478bd9Sstevel@tonic-gate int
return_value64_token(parse_context_t * ctx)2977c478bd9Sstevel@tonic-gate return_value64_token(parse_context_t *ctx)
2987c478bd9Sstevel@tonic-gate {
2997c478bd9Sstevel@tonic-gate 	char		errnum;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	adrm_char(&(ctx->adr), &errnum, 1);	/* pass / fail */
3027c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (int64_t);	/* error code */
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	ctx->out.sf_pass = (errnum == 0) ? 1 : -1;
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	return (0);
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate /*
3117c478bd9Sstevel@tonic-gate  * Format of sequence token:
3127c478bd9Sstevel@tonic-gate  *	sequence token id	adr_char
3137c478bd9Sstevel@tonic-gate  *	audit_count		int32_t
3147c478bd9Sstevel@tonic-gate  *
3157c478bd9Sstevel@tonic-gate  */
3167c478bd9Sstevel@tonic-gate int
sequence_token(parse_context_t * ctx)3177c478bd9Sstevel@tonic-gate sequence_token(parse_context_t *ctx)
3187c478bd9Sstevel@tonic-gate {
3197c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &(ctx->out.sf_sequence), 1);
3207c478bd9Sstevel@tonic-gate 	return (0);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate /*
3257c478bd9Sstevel@tonic-gate  * Format of text token:
3267c478bd9Sstevel@tonic-gate  *	text token id		adr_char
3277c478bd9Sstevel@tonic-gate  * 	text			adr_string
3287c478bd9Sstevel@tonic-gate  */
3297c478bd9Sstevel@tonic-gate int
text_token(parse_context_t * ctx)3307c478bd9Sstevel@tonic-gate text_token(parse_context_t *ctx)
3317c478bd9Sstevel@tonic-gate {
3327c478bd9Sstevel@tonic-gate 	ushort_t	len;
3337c478bd9Sstevel@tonic-gate 	size_t		separator_sz = 0;
3347c478bd9Sstevel@tonic-gate 	char		*bp;	/* pointer to output string */
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 	adrm_u_short(&(ctx->adr), &len, 1);
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	if (ctx->out.sf_textlen > 0)
3397c478bd9Sstevel@tonic-gate 		separator_sz = sizeof (AU_TEXT_NAME) - 1;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "text_token: start length=%d, add length=%d+%d\n",
3427c478bd9Sstevel@tonic-gate 	    ctx->out.sf_textlen, (size_t)len, separator_sz));
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 	ctx->out.sf_text = realloc(ctx->out.sf_text,
3457c478bd9Sstevel@tonic-gate 	    ctx->out.sf_textlen + (size_t)len + separator_sz);
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	if (ctx->out.sf_text == NULL)
3487c478bd9Sstevel@tonic-gate 		return (-1);
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	bp = ctx->out.sf_text;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	if (ctx->out.sf_textlen != 0) {	/* concatenation? */
3537c478bd9Sstevel@tonic-gate 		bp += ctx->out.sf_textlen;
3547c478bd9Sstevel@tonic-gate 		bp += strlcpy(bp, AU_TEXT_NAME, separator_sz + 1);
3557c478bd9Sstevel@tonic-gate 		ctx->out.sf_textlen += separator_sz;
3567c478bd9Sstevel@tonic-gate 		DPRINT((dbfp, "text_token: l is %d\n%s\n", ctx->out.sf_textlen,
3577c478bd9Sstevel@tonic-gate 		    ctx->out.sf_text));
3587c478bd9Sstevel@tonic-gate 	}
3597c478bd9Sstevel@tonic-gate 	adrm_char(&(ctx->adr), bp, len);
3607c478bd9Sstevel@tonic-gate 	len--;		/* includes EOS */
3617c478bd9Sstevel@tonic-gate 	*(bp + len) = '\0';
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	ctx->out.sf_textlen += len;
3647c478bd9Sstevel@tonic-gate 	DPRINT((dbfp, "text_token: l=%d\n%s\n", ctx->out.sf_textlen,
3657c478bd9Sstevel@tonic-gate 	    ctx->out.sf_text));
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	return (0);
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate /*
3717c478bd9Sstevel@tonic-gate  * Format of tid token:
3727c478bd9Sstevel@tonic-gate  *	ip token id	adr_char
3737c478bd9Sstevel@tonic-gate  *	terminal type	adr_char
3747c478bd9Sstevel@tonic-gate  *  terminal type = AU_IPADR:
3757c478bd9Sstevel@tonic-gate  *	remote port:	ushort
3767c478bd9Sstevel@tonic-gate  *	local port:	ushort
3777c478bd9Sstevel@tonic-gate  *	IP type:	int32 -- AU_IPv4 or AU_IPv6
3787c478bd9Sstevel@tonic-gate  *	address:	int32 if IPv4, else 4 * int32
3797c478bd9Sstevel@tonic-gate  */
3807c478bd9Sstevel@tonic-gate int
tid_token(parse_context_t * ctx)3817c478bd9Sstevel@tonic-gate tid_token(parse_context_t *ctx)
3827c478bd9Sstevel@tonic-gate {
3837c478bd9Sstevel@tonic-gate 	uchar_t		type;
3847c478bd9Sstevel@tonic-gate 	int32_t		ip_length;
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	adrm_char(&(ctx->adr), (char *)&type, 1);
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 	switch (type) {
3897c478bd9Sstevel@tonic-gate 	default:
3907c478bd9Sstevel@tonic-gate 		return (-1);	/* other than IP type is not implemented */
3917c478bd9Sstevel@tonic-gate 	case AU_IPADR:
3927c478bd9Sstevel@tonic-gate 		ctx->adr.adr_now += 2 * sizeof (ushort_t);
3937c478bd9Sstevel@tonic-gate 		adrm_int32(&(ctx->adr), &ip_length, 1);
3947c478bd9Sstevel@tonic-gate 		ctx->adr.adr_now += ip_length;
3957c478bd9Sstevel@tonic-gate 		break;
3967c478bd9Sstevel@tonic-gate 	}
3977c478bd9Sstevel@tonic-gate 	return (0);
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate /*
4017c478bd9Sstevel@tonic-gate  * Format of ip_addr token:
4027c478bd9Sstevel@tonic-gate  *	ip token id	adr_char
4037c478bd9Sstevel@tonic-gate  *	address		adr_int32
4047c478bd9Sstevel@tonic-gate  *
4057c478bd9Sstevel@tonic-gate  */
4067c478bd9Sstevel@tonic-gate int
ip_addr_token(parse_context_t * ctx)4077c478bd9Sstevel@tonic-gate ip_addr_token(parse_context_t *ctx)
4087c478bd9Sstevel@tonic-gate {
4097c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (int32_t);
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate 	return (0);
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate /*
4157c478bd9Sstevel@tonic-gate  * Format of ip_addr_ex token:
4167c478bd9Sstevel@tonic-gate  *	ip token id	adr_char
4177c478bd9Sstevel@tonic-gate  *	ip type		adr_int32
4188249a45fSJan Friedel  *	ip address	adr_u_char*type
4197c478bd9Sstevel@tonic-gate  *
4207c478bd9Sstevel@tonic-gate  */
4217c478bd9Sstevel@tonic-gate int
ip_addr_ex_token(parse_context_t * ctx)4227c478bd9Sstevel@tonic-gate ip_addr_ex_token(parse_context_t *ctx)
4237c478bd9Sstevel@tonic-gate {
4248249a45fSJan Friedel 	int32_t	type;
4258249a45fSJan Friedel 
4268249a45fSJan Friedel 	adrm_int32(&(ctx->adr), &type, 1);		/* ip type */
4278249a45fSJan Friedel 	ctx->adr.adr_now += type * sizeof (uchar_t);	/* ip address */
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 	return (0);
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * Format of ip token:
4347c478bd9Sstevel@tonic-gate  *	ip header token id	adr_char
4357c478bd9Sstevel@tonic-gate  *	version			adr_char
4367c478bd9Sstevel@tonic-gate  *	type of service		adr_char
4377c478bd9Sstevel@tonic-gate  *	length			adr_short
4387c478bd9Sstevel@tonic-gate  *	id			adr_u_short
4397c478bd9Sstevel@tonic-gate  *	offset			adr_u_short
4407c478bd9Sstevel@tonic-gate  *	ttl			adr_char
4417c478bd9Sstevel@tonic-gate  *	protocol		adr_char
4427c478bd9Sstevel@tonic-gate  *	checksum		adr_u_short
4437c478bd9Sstevel@tonic-gate  *	source address		adr_int32
4447c478bd9Sstevel@tonic-gate  *	destination address	adr_int32
4457c478bd9Sstevel@tonic-gate  *
4467c478bd9Sstevel@tonic-gate  */
4477c478bd9Sstevel@tonic-gate int
ip_token(parse_context_t * ctx)4487c478bd9Sstevel@tonic-gate ip_token(parse_context_t *ctx)
4497c478bd9Sstevel@tonic-gate {
45042103d7eSdanmcd 	ctx->adr.adr_now += (2 * sizeof (char)) + (3 * sizeof (short)) +
45142103d7eSdanmcd 	    (2 * sizeof (char)) + sizeof (short) + (2 * sizeof (int32_t));
4527c478bd9Sstevel@tonic-gate 	return (0);
4537c478bd9Sstevel@tonic-gate }
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate /*
4577c478bd9Sstevel@tonic-gate  * Format of iport token:
4587c478bd9Sstevel@tonic-gate  *	ip port address token id	adr_char
4597c478bd9Sstevel@tonic-gate  *	port address			adr_short
4607c478bd9Sstevel@tonic-gate  *
4617c478bd9Sstevel@tonic-gate  */
4627c478bd9Sstevel@tonic-gate int
iport_token(parse_context_t * ctx)4637c478bd9Sstevel@tonic-gate iport_token(parse_context_t *ctx)
4647c478bd9Sstevel@tonic-gate {
4657c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (short);
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	return (0);
4687c478bd9Sstevel@tonic-gate }
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate /*
4727c478bd9Sstevel@tonic-gate  * Format of groups token:
4737c478bd9Sstevel@tonic-gate  *	group token id		adr_char
4747c478bd9Sstevel@tonic-gate  *	group list		adr_int32, 16 times
4757c478bd9Sstevel@tonic-gate  *
4767c478bd9Sstevel@tonic-gate  */
4777c478bd9Sstevel@tonic-gate int
group_token(parse_context_t * ctx)4787c478bd9Sstevel@tonic-gate group_token(parse_context_t *ctx)
4797c478bd9Sstevel@tonic-gate {
4807c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += 16 * sizeof (int32_t);
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 	return (0);
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate /*
4867c478bd9Sstevel@tonic-gate  * Format of newgroups token:
4877c478bd9Sstevel@tonic-gate  *	group token id		adr_char
4887c478bd9Sstevel@tonic-gate  *	number of groups	adr_short
4897c478bd9Sstevel@tonic-gate  *	group list		adr_int32, "number" times
4907c478bd9Sstevel@tonic-gate  *
4917c478bd9Sstevel@tonic-gate  */
4927c478bd9Sstevel@tonic-gate int
newgroup_token(parse_context_t * ctx)4937c478bd9Sstevel@tonic-gate newgroup_token(parse_context_t *ctx)
4947c478bd9Sstevel@tonic-gate {
4957c478bd9Sstevel@tonic-gate 	short int   number;
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 	adrm_short(&(ctx->adr), &number, 1);
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += number * sizeof (int32_t);
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	return (0);
5027c478bd9Sstevel@tonic-gate }
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate /*
5057c478bd9Sstevel@tonic-gate  * Format of argument32 token:
5067c478bd9Sstevel@tonic-gate  *	argument token id	adr_char
5077c478bd9Sstevel@tonic-gate  *	argument number		adr_char
5087c478bd9Sstevel@tonic-gate  *	argument value		adr_int32
5097c478bd9Sstevel@tonic-gate  *	argument description	adr_string
5107c478bd9Sstevel@tonic-gate  *
5117c478bd9Sstevel@tonic-gate  */
5127c478bd9Sstevel@tonic-gate int
argument32_token(parse_context_t * ctx)5137c478bd9Sstevel@tonic-gate argument32_token(parse_context_t *ctx)
5147c478bd9Sstevel@tonic-gate {
5157c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (char) + sizeof (int32_t);
5167c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 	return (0);
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate /*
5227c478bd9Sstevel@tonic-gate  * Format of argument64 token:
5237c478bd9Sstevel@tonic-gate  *	argument token id	adr_char
5247c478bd9Sstevel@tonic-gate  *	argument number		adr_char
5257c478bd9Sstevel@tonic-gate  *	argument value		adr_int64
5267c478bd9Sstevel@tonic-gate  *	argument description	adr_string
5277c478bd9Sstevel@tonic-gate  *
5287c478bd9Sstevel@tonic-gate  */
5297c478bd9Sstevel@tonic-gate int
argument64_token(parse_context_t * ctx)5307c478bd9Sstevel@tonic-gate argument64_token(parse_context_t *ctx)
5317c478bd9Sstevel@tonic-gate {
5327c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (char) + sizeof (int64_t);
5337c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	return (0);
5367c478bd9Sstevel@tonic-gate }
5377c478bd9Sstevel@tonic-gate 
538a7746f66Stz204579 /*
539a7746f66Stz204579  * Format of acl token:
540a7746f66Stz204579  * 	acl token id		adr_char
541a7746f66Stz204579  *	type			adr_u_int32
542a7746f66Stz204579  *	value			adr_u_int32
543a7746f66Stz204579  *	mode			adr_u_int32
544a7746f66Stz204579  */
5457c478bd9Sstevel@tonic-gate int
acl_token(parse_context_t * ctx)5467c478bd9Sstevel@tonic-gate acl_token(parse_context_t *ctx)
5477c478bd9Sstevel@tonic-gate {
548a7746f66Stz204579 	ctx->adr.adr_now += 3 * sizeof (uint32_t);
549a7746f66Stz204579 
550a7746f66Stz204579 	return (0);
551a7746f66Stz204579 }
552a7746f66Stz204579 
553a7746f66Stz204579 /*
554a7746f66Stz204579  * Format of ace token:
555a7746f66Stz204579  * 	ace token id		adr_char
556a7746f66Stz204579  *	id			adr_u_int32
557a7746f66Stz204579  *	access_mask		adr_u_int32
558a7746f66Stz204579  *	flags			adr_u_short
559a7746f66Stz204579  *	type			adr_u_short
560a7746f66Stz204579  */
561a7746f66Stz204579 int
ace_token(parse_context_t * ctx)562a7746f66Stz204579 ace_token(parse_context_t *ctx)
563a7746f66Stz204579 {
564a7746f66Stz204579 	ctx->adr.adr_now += 2 * sizeof (uint32_t) + 2 * sizeof (ushort_t);
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate 	return (0);
5677c478bd9Sstevel@tonic-gate }
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate /*
5707c478bd9Sstevel@tonic-gate  * Format of attribute token: (old pre SunOS 5.7 format)
5717c478bd9Sstevel@tonic-gate  *	attribute token id	adr_char
5727c478bd9Sstevel@tonic-gate  * 	mode			adr_int32 (printed in octal)
5737c478bd9Sstevel@tonic-gate  *	uid			adr_int32
5747c478bd9Sstevel@tonic-gate  *	gid			adr_int32
5757c478bd9Sstevel@tonic-gate  *	file system id		adr_int32
5767c478bd9Sstevel@tonic-gate  *	node id			adr_int32
5777c478bd9Sstevel@tonic-gate  *	device			adr_int32
5787c478bd9Sstevel@tonic-gate  *
5797c478bd9Sstevel@tonic-gate  */
5807c478bd9Sstevel@tonic-gate int
attribute_token(parse_context_t * ctx)5817c478bd9Sstevel@tonic-gate attribute_token(parse_context_t *ctx)
5827c478bd9Sstevel@tonic-gate {
5837c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += 6 * sizeof (int32_t);
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 	return (0);
5867c478bd9Sstevel@tonic-gate }
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate /*
5897c478bd9Sstevel@tonic-gate  * Format of attribute32 token:
5907c478bd9Sstevel@tonic-gate  *	attribute token id	adr_char
5917c478bd9Sstevel@tonic-gate  * 	mode			adr_int32 (printed in octal)
5927c478bd9Sstevel@tonic-gate  *	uid			adr_int32
5937c478bd9Sstevel@tonic-gate  *	gid			adr_int32
5947c478bd9Sstevel@tonic-gate  *	file system id		adr_int32
5957c478bd9Sstevel@tonic-gate  *	node id			adr_int64
5967c478bd9Sstevel@tonic-gate  *	device			adr_int32
5977c478bd9Sstevel@tonic-gate  *
5987c478bd9Sstevel@tonic-gate  */
5997c478bd9Sstevel@tonic-gate int
attribute32_token(parse_context_t * ctx)6007c478bd9Sstevel@tonic-gate attribute32_token(parse_context_t *ctx)
6017c478bd9Sstevel@tonic-gate {
6027c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += (5 * sizeof (int32_t)) + sizeof (int64_t);
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 	return (0);
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate /*
6087c478bd9Sstevel@tonic-gate  * Format of attribute64 token:
6097c478bd9Sstevel@tonic-gate  *	attribute token id	adr_char
6107c478bd9Sstevel@tonic-gate  * 	mode			adr_int32 (printed in octal)
6117c478bd9Sstevel@tonic-gate  *	uid			adr_int32
6127c478bd9Sstevel@tonic-gate  *	gid			adr_int32
6137c478bd9Sstevel@tonic-gate  *	file system id		adr_int32
6147c478bd9Sstevel@tonic-gate  *	node id			adr_int64
6157c478bd9Sstevel@tonic-gate  *	device			adr_int64
6167c478bd9Sstevel@tonic-gate  *
6177c478bd9Sstevel@tonic-gate  */
6187c478bd9Sstevel@tonic-gate int
attribute64_token(parse_context_t * ctx)6197c478bd9Sstevel@tonic-gate attribute64_token(parse_context_t *ctx)
6207c478bd9Sstevel@tonic-gate {
6217c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += (4 * sizeof (int32_t)) + (2 * sizeof (int64_t));
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 	return (0);
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate /*
6287c478bd9Sstevel@tonic-gate  * Format of command token:
6297c478bd9Sstevel@tonic-gate  *	attribute token id	adr_char
6307c478bd9Sstevel@tonic-gate  *	argc			adr_short
6317c478bd9Sstevel@tonic-gate  *	argv len		adr_short	variable amount of argv len
6327c478bd9Sstevel@tonic-gate  *	argv text		argv len	and text
6337c478bd9Sstevel@tonic-gate  *	.
6347c478bd9Sstevel@tonic-gate  *	.
6357c478bd9Sstevel@tonic-gate  *	.
6367c478bd9Sstevel@tonic-gate  *	envp count		adr_short	variable amount of envp len
6377c478bd9Sstevel@tonic-gate  *	envp len		adr_short	and text
6387c478bd9Sstevel@tonic-gate  *	envp text		envp		len
6397c478bd9Sstevel@tonic-gate  *	.
6407c478bd9Sstevel@tonic-gate  *	.
6417c478bd9Sstevel@tonic-gate  *	.
6427c478bd9Sstevel@tonic-gate  *
6437c478bd9Sstevel@tonic-gate  */
6447c478bd9Sstevel@tonic-gate int
cmd_token(parse_context_t * ctx)6457c478bd9Sstevel@tonic-gate cmd_token(parse_context_t *ctx)
6467c478bd9Sstevel@tonic-gate {
6477c478bd9Sstevel@tonic-gate 	short	cnt;
6487c478bd9Sstevel@tonic-gate 	short	i;
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate 	adrm_short(&(ctx->adr), &cnt, 1);
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate 	for (i = 0; i < cnt; i++)
6537c478bd9Sstevel@tonic-gate 		skip_bytes(ctx);
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 	adrm_short(&(ctx->adr), &cnt, 1);
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 	for (i = 0; i < cnt; i++)
6587c478bd9Sstevel@tonic-gate 		skip_bytes(ctx);
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	return (0);
6617c478bd9Sstevel@tonic-gate }
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate /*
6657c478bd9Sstevel@tonic-gate  * Format of exit token:
6667c478bd9Sstevel@tonic-gate  *	attribute token id	adr_char
6677c478bd9Sstevel@tonic-gate  *	return value		adr_int32
6687c478bd9Sstevel@tonic-gate  *	errno			adr_int32
6697c478bd9Sstevel@tonic-gate  *
6707c478bd9Sstevel@tonic-gate  */
6717c478bd9Sstevel@tonic-gate int
exit_token(parse_context_t * ctx)6727c478bd9Sstevel@tonic-gate exit_token(parse_context_t *ctx)
6737c478bd9Sstevel@tonic-gate {
6747c478bd9Sstevel@tonic-gate 	int32_t	retval;
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &retval, 1);
6777c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (int32_t);
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 	ctx->out.sf_pass = (retval == 0) ? 1 : -1;
6807c478bd9Sstevel@tonic-gate 	return (0);
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate /*
6847c478bd9Sstevel@tonic-gate  * Format of exec_args token:
6857c478bd9Sstevel@tonic-gate  *	attribute token id	adr_char
6867c478bd9Sstevel@tonic-gate  *	count value		adr_int32
6877c478bd9Sstevel@tonic-gate  *	strings			null terminated strings
6887c478bd9Sstevel@tonic-gate  *
6897c478bd9Sstevel@tonic-gate  */
6907c478bd9Sstevel@tonic-gate int
exec_args_token(parse_context_t * ctx)6917c478bd9Sstevel@tonic-gate exec_args_token(parse_context_t *ctx)
6927c478bd9Sstevel@tonic-gate {
6937c478bd9Sstevel@tonic-gate 	int count, i;
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), (int32_t *)&count, 1);
6967c478bd9Sstevel@tonic-gate 	for (i = 1; i <= count; i++) {
6977c478bd9Sstevel@tonic-gate 		skip_string(ctx);
6987c478bd9Sstevel@tonic-gate 	}
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 	return (0);
7017c478bd9Sstevel@tonic-gate }
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate /*
7047c478bd9Sstevel@tonic-gate  * Format of exec_env token:
7057c478bd9Sstevel@tonic-gate  *	attribute token id	adr_char
7067c478bd9Sstevel@tonic-gate  *	count value		adr_int32
7077c478bd9Sstevel@tonic-gate  *	strings			null terminated strings
7087c478bd9Sstevel@tonic-gate  *
7097c478bd9Sstevel@tonic-gate  */
7107c478bd9Sstevel@tonic-gate int
exec_env_token(parse_context_t * ctx)7117c478bd9Sstevel@tonic-gate exec_env_token(parse_context_t *ctx)
7127c478bd9Sstevel@tonic-gate {
7137c478bd9Sstevel@tonic-gate 	int count, i;
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), (int32_t *)&count, 1);
7167c478bd9Sstevel@tonic-gate 	for (i = 1; i <= count; i++)
7177c478bd9Sstevel@tonic-gate 		skip_string(ctx);
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate 	return (0);
7207c478bd9Sstevel@tonic-gate }
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate /*
7237c478bd9Sstevel@tonic-gate  * Format of liaison token:
7247c478bd9Sstevel@tonic-gate  */
7257c478bd9Sstevel@tonic-gate int
liaison_token(parse_context_t * ctx)7267c478bd9Sstevel@tonic-gate liaison_token(parse_context_t *ctx)
7277c478bd9Sstevel@tonic-gate {
7287c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (int32_t);
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate 	return (0);
7317c478bd9Sstevel@tonic-gate }
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate /*
7357c478bd9Sstevel@tonic-gate  * Format of path token:
7367c478bd9Sstevel@tonic-gate  *	path				adr_string
7377c478bd9Sstevel@tonic-gate  */
7387c478bd9Sstevel@tonic-gate int
path_token(parse_context_t * ctx)7397c478bd9Sstevel@tonic-gate path_token(parse_context_t *ctx)
7407c478bd9Sstevel@tonic-gate {
7417c478bd9Sstevel@tonic-gate 	get_bytes_to_string(ctx, &(ctx->out.sf_pathlen), &(ctx->out.sf_path),
7427c478bd9Sstevel@tonic-gate 	    0);
7437c478bd9Sstevel@tonic-gate 	if (ctx->out.sf_path == NULL)
7447c478bd9Sstevel@tonic-gate 		return (-1);
7457c478bd9Sstevel@tonic-gate 	/*
7467c478bd9Sstevel@tonic-gate 	 * anchor the path because collapse_path needs it
7477c478bd9Sstevel@tonic-gate 	 */
7487c478bd9Sstevel@tonic-gate 	if (*(ctx->out.sf_path) != '/') {
7497c478bd9Sstevel@tonic-gate 		anchor_path(ctx->out.sf_path);
7507c478bd9Sstevel@tonic-gate 		ctx->out.sf_pathlen++;
7517c478bd9Sstevel@tonic-gate 	}
7527c478bd9Sstevel@tonic-gate 	ctx->out.sf_pathlen = collapse_path(ctx->out.sf_path,
7537c478bd9Sstevel@tonic-gate 	    ctx->out.sf_pathlen);
7547c478bd9Sstevel@tonic-gate 
7557c478bd9Sstevel@tonic-gate 	return (0);
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate /*
7597c478bd9Sstevel@tonic-gate  * path attr token / AUT_XATPATH
7607c478bd9Sstevel@tonic-gate  *
7617c478bd9Sstevel@tonic-gate  * Format of path attr token:
7627c478bd9Sstevel@tonic-gate  *	token id		adr_char
7637c478bd9Sstevel@tonic-gate  *	string count		adr_int32
7647c478bd9Sstevel@tonic-gate  *	strings			adr_string
7657c478bd9Sstevel@tonic-gate  *
7667c478bd9Sstevel@tonic-gate  * the sequence of strings is converted to a single string with
7677c478bd9Sstevel@tonic-gate  * a blank separator replacing the EOS for all but the last
7687c478bd9Sstevel@tonic-gate  * string.
7697c478bd9Sstevel@tonic-gate  */
7707c478bd9Sstevel@tonic-gate int
path_attr_token(parse_context_t * ctx)7717c478bd9Sstevel@tonic-gate path_attr_token(parse_context_t *ctx)
7727c478bd9Sstevel@tonic-gate {
7737c478bd9Sstevel@tonic-gate 	int	count, i;
7747c478bd9Sstevel@tonic-gate 	int	last_len;
7757c478bd9Sstevel@tonic-gate 	size_t	offset;
7767c478bd9Sstevel@tonic-gate 	char	*p;
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &count, 1);
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate 	offset = ctx->out.sf_atpathlen;
7817c478bd9Sstevel@tonic-gate 	p = ctx->adr.adr_now;
7827c478bd9Sstevel@tonic-gate 	for (i = 0; i <= count; i++) {
7837c478bd9Sstevel@tonic-gate 		last_len = strlen(p);
7847c478bd9Sstevel@tonic-gate 		ctx->out.sf_atpathlen += last_len + 1;
7857c478bd9Sstevel@tonic-gate 		p += last_len + 1;
7867c478bd9Sstevel@tonic-gate 	}
7877c478bd9Sstevel@tonic-gate 	ctx->out.sf_atpath = realloc(ctx->out.sf_atpath, ctx->out.sf_atpathlen);
7887c478bd9Sstevel@tonic-gate 	ctx->out.sf_atpath += offset;
7897c478bd9Sstevel@tonic-gate 	p = ctx->out.sf_atpath;		/* save for fix up, below */
7907c478bd9Sstevel@tonic-gate 	(void) memcpy(ctx->out.sf_atpath, ctx->adr.adr_now,
7917c478bd9Sstevel@tonic-gate 	    ctx->out.sf_atpathlen - offset);
7927c478bd9Sstevel@tonic-gate 	ctx->out.sf_atpathlen--;
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 	/* fix up: replace each eos except the last with ' ' */
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate 	for (i = 0; i < count; i++) {
79742103d7eSdanmcd 		while (*p++ != '\0')
79842103d7eSdanmcd 			;
7997c478bd9Sstevel@tonic-gate 		*(p - 1) = ' ';
8007c478bd9Sstevel@tonic-gate 	}
8017c478bd9Sstevel@tonic-gate 	return (0);
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate /*
8067c478bd9Sstevel@tonic-gate  * Format of System V IPC permission token:
8077c478bd9Sstevel@tonic-gate  *	System V IPC permission token id	adr_char
8087c478bd9Sstevel@tonic-gate  * 	uid					adr_int32
8097c478bd9Sstevel@tonic-gate  *	gid					adr_int32
8107c478bd9Sstevel@tonic-gate  *	cuid					adr_int32
8117c478bd9Sstevel@tonic-gate  *	cgid					adr_int32
8127c478bd9Sstevel@tonic-gate  *	mode					adr_int32
8137c478bd9Sstevel@tonic-gate  *	seq					adr_int32
8147c478bd9Sstevel@tonic-gate  *	key					adr_int32
8157c478bd9Sstevel@tonic-gate  */
8167c478bd9Sstevel@tonic-gate int
s5_IPC_perm_token(parse_context_t * ctx)8177c478bd9Sstevel@tonic-gate s5_IPC_perm_token(parse_context_t *ctx)
8187c478bd9Sstevel@tonic-gate {
8197c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += (7 * sizeof (int32_t));
8207c478bd9Sstevel@tonic-gate 	return (0);
8217c478bd9Sstevel@tonic-gate }
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate static void
common_process(parse_context_t * ctx)8247c478bd9Sstevel@tonic-gate common_process(parse_context_t *ctx)
8257c478bd9Sstevel@tonic-gate {
8267c478bd9Sstevel@tonic-gate 	int32_t	ruid, rgid, egid, pid;
8277c478bd9Sstevel@tonic-gate 	uint32_t asid;
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), (uint32_t *)&(ctx->out.sf_pauid), 1);
8307c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), (uint32_t *)&(ctx->out.sf_peuid), 1);
8317c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &egid, 1);
8327c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &ruid, 1);
8337c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &rgid, 1);
8347c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &pid, 1);
8357c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), &asid, 1);
8367c478bd9Sstevel@tonic-gate }
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate /*
8397c478bd9Sstevel@tonic-gate  * Format of process32 token:
8407c478bd9Sstevel@tonic-gate  *	process token id	adr_char
8417c478bd9Sstevel@tonic-gate  *	auid			adr_int32
8427c478bd9Sstevel@tonic-gate  *	euid			adr_int32
8437c478bd9Sstevel@tonic-gate  *	egid 			adr_int32
8447c478bd9Sstevel@tonic-gate  * 	ruid			adr_int32
8457c478bd9Sstevel@tonic-gate  *	rgid			adr_int32
8467c478bd9Sstevel@tonic-gate  * 	pid			adr_int32
8477c478bd9Sstevel@tonic-gate  * 	sid			adr_int32
8487c478bd9Sstevel@tonic-gate  * 	termid			adr_int32*2
8497c478bd9Sstevel@tonic-gate  *
8507c478bd9Sstevel@tonic-gate  */
8517c478bd9Sstevel@tonic-gate int
process32_token(parse_context_t * ctx)8527c478bd9Sstevel@tonic-gate process32_token(parse_context_t *ctx)
8537c478bd9Sstevel@tonic-gate {
8547c478bd9Sstevel@tonic-gate 	int32_t port, machine;
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate 	common_process(ctx);
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &port, 1);
8597c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &machine, 1);
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate 	return (0);
8627c478bd9Sstevel@tonic-gate }
8637c478bd9Sstevel@tonic-gate 
8647c478bd9Sstevel@tonic-gate /*
8657c478bd9Sstevel@tonic-gate  * Format of process32_ex token:
8667c478bd9Sstevel@tonic-gate  *	process token id	adr_char
8677c478bd9Sstevel@tonic-gate  *	auid			adr_int32
8687c478bd9Sstevel@tonic-gate  *	euid			adr_int32
8697c478bd9Sstevel@tonic-gate  *	egid 			adr_int32
8707c478bd9Sstevel@tonic-gate  * 	ruid			adr_int32
8717c478bd9Sstevel@tonic-gate  *	rgid			adr_int32
8727c478bd9Sstevel@tonic-gate  * 	pid			adr_int32
8737c478bd9Sstevel@tonic-gate  * 	sid			adr_int32
8748249a45fSJan Friedel  * 	termid
8758249a45fSJan Friedel  *		port		adr_int32
8768249a45fSJan Friedel  *		type		adr_int32
8778249a45fSJan Friedel  *		ip address	adr_u_char*type
8787c478bd9Sstevel@tonic-gate  *
8797c478bd9Sstevel@tonic-gate  */
8807c478bd9Sstevel@tonic-gate int
process32_ex_token(parse_context_t * ctx)8817c478bd9Sstevel@tonic-gate process32_ex_token(parse_context_t *ctx)
8827c478bd9Sstevel@tonic-gate {
8838249a45fSJan Friedel 	int32_t port, type;
8848249a45fSJan Friedel 	uchar_t addr[16];
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate 	common_process(ctx);
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &port, 1);
8897c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &type, 1);
8908249a45fSJan Friedel 	adrm_u_char(&(ctx->adr), addr, type);
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate 	return (0);
8937c478bd9Sstevel@tonic-gate }
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate /*
8967c478bd9Sstevel@tonic-gate  * Format of process64 token:
8977c478bd9Sstevel@tonic-gate  *	process token id	adr_char
8987c478bd9Sstevel@tonic-gate  *	auid			adr_int32
8997c478bd9Sstevel@tonic-gate  *	euid			adr_int32
9007c478bd9Sstevel@tonic-gate  *	egid 			adr_int32
9017c478bd9Sstevel@tonic-gate  * 	ruid			adr_int32
9027c478bd9Sstevel@tonic-gate  *	rgid			adr_int32
9037c478bd9Sstevel@tonic-gate  * 	pid			adr_int32
9047c478bd9Sstevel@tonic-gate  * 	sid			adr_int32
9057c478bd9Sstevel@tonic-gate  * 	termid			adr_int64+adr_int32
9067c478bd9Sstevel@tonic-gate  *
9077c478bd9Sstevel@tonic-gate  */
9087c478bd9Sstevel@tonic-gate int
process64_token(parse_context_t * ctx)9097c478bd9Sstevel@tonic-gate process64_token(parse_context_t *ctx)
9107c478bd9Sstevel@tonic-gate {
9117c478bd9Sstevel@tonic-gate 	int64_t port;
9127c478bd9Sstevel@tonic-gate 	int32_t machine;
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 	common_process(ctx);
9157c478bd9Sstevel@tonic-gate 
9167c478bd9Sstevel@tonic-gate 	adrm_int64(&(ctx->adr), &port, 1);
9177c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &machine, 1);
9187c478bd9Sstevel@tonic-gate 
9197c478bd9Sstevel@tonic-gate 	return (0);
9207c478bd9Sstevel@tonic-gate }
9217c478bd9Sstevel@tonic-gate 
9227c478bd9Sstevel@tonic-gate /*
9238249a45fSJan Friedel  * Format of process64_ex token:
9247c478bd9Sstevel@tonic-gate  *	process token id	adr_char
9257c478bd9Sstevel@tonic-gate  *	auid			adr_int32
9267c478bd9Sstevel@tonic-gate  *	euid			adr_int32
9277c478bd9Sstevel@tonic-gate  *	egid 			adr_int32
9287c478bd9Sstevel@tonic-gate  * 	ruid			adr_int32
9297c478bd9Sstevel@tonic-gate  *	rgid			adr_int32
9307c478bd9Sstevel@tonic-gate  * 	pid			adr_int32
9317c478bd9Sstevel@tonic-gate  * 	sid			adr_int32
9328249a45fSJan Friedel  * 	termid
9338249a45fSJan Friedel  *		port		adr_int64
9348249a45fSJan Friedel  *		type		adr_int32
9358249a45fSJan Friedel  *		ip address	adr_u_char*type
9367c478bd9Sstevel@tonic-gate  *
9377c478bd9Sstevel@tonic-gate  */
9387c478bd9Sstevel@tonic-gate int
process64_ex_token(parse_context_t * ctx)9397c478bd9Sstevel@tonic-gate process64_ex_token(parse_context_t *ctx)
9407c478bd9Sstevel@tonic-gate {
9417c478bd9Sstevel@tonic-gate 	int64_t port;
9428249a45fSJan Friedel 	int32_t type;
9438249a45fSJan Friedel 	uchar_t	addr[16];
9447c478bd9Sstevel@tonic-gate 
9457c478bd9Sstevel@tonic-gate 	common_process(ctx);
9467c478bd9Sstevel@tonic-gate 
9477c478bd9Sstevel@tonic-gate 	adrm_int64(&(ctx->adr), &port, 1);
9487c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &type, 1);
9498249a45fSJan Friedel 	adrm_u_char(&(ctx->adr), addr, type);
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate 	return (0);
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate /*
9557c478bd9Sstevel@tonic-gate  * Format of System V IPC token:
9567c478bd9Sstevel@tonic-gate  *	System V IPC token id	adr_char
9577c478bd9Sstevel@tonic-gate  *	System V IPC type	adr_char
9587c478bd9Sstevel@tonic-gate  *	object id		adr_int32
9597c478bd9Sstevel@tonic-gate  *
9607c478bd9Sstevel@tonic-gate  */
9617c478bd9Sstevel@tonic-gate int
s5_IPC_token(parse_context_t * ctx)9627c478bd9Sstevel@tonic-gate s5_IPC_token(parse_context_t *ctx)
9637c478bd9Sstevel@tonic-gate {
9647c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (char);
9657c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (int32_t);
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate 	return (0);
9687c478bd9Sstevel@tonic-gate }
9697c478bd9Sstevel@tonic-gate 
9707c478bd9Sstevel@tonic-gate 
9717c478bd9Sstevel@tonic-gate /*
9727c478bd9Sstevel@tonic-gate  * Format of socket token:
9737c478bd9Sstevel@tonic-gate  *	socket_type		adrm_short
9747c478bd9Sstevel@tonic-gate  *	remote_port		adrm_short
9757c478bd9Sstevel@tonic-gate  *	remote_inaddr		adrm_int32
9767c478bd9Sstevel@tonic-gate  *
9777c478bd9Sstevel@tonic-gate  */
9787c478bd9Sstevel@tonic-gate int
socket_token(parse_context_t * ctx)9797c478bd9Sstevel@tonic-gate socket_token(parse_context_t *ctx)
9807c478bd9Sstevel@tonic-gate {
9817c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += (2 * sizeof (short)) + sizeof (int32_t);
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 	return (0);
9847c478bd9Sstevel@tonic-gate }
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 
9877c478bd9Sstevel@tonic-gate /*
9888249a45fSJan Friedel  * Format of socket_ex token:
9898249a45fSJan Friedel  *	socket_domain		adrm_short
9908249a45fSJan Friedel  *	socket_type		adrm_short
9918249a45fSJan Friedel  *	address_type		adrm_short
9928249a45fSJan Friedel  *	local_port		adrm_short
9938249a45fSJan Friedel  *	local_inaddr		adrm_u_char*address_type
9948249a45fSJan Friedel  *	remote_port		adrm_short
9958249a45fSJan Friedel  *	remote_inaddr		adrm_u_char*address_type
9967c478bd9Sstevel@tonic-gate  *
9977c478bd9Sstevel@tonic-gate  */
9987c478bd9Sstevel@tonic-gate int
socket_ex_token(parse_context_t * ctx)9997c478bd9Sstevel@tonic-gate socket_ex_token(parse_context_t *ctx)
10007c478bd9Sstevel@tonic-gate {
10017c478bd9Sstevel@tonic-gate 	short	ip_size;
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += (2 * sizeof (short));
10047c478bd9Sstevel@tonic-gate 	adrm_short(&(ctx->adr), &ip_size, 1);
10057c478bd9Sstevel@tonic-gate 
100642103d7eSdanmcd 	ctx->adr.adr_now += sizeof (short) + (ip_size * sizeof (char)) +
100742103d7eSdanmcd 	    sizeof (short) + (ip_size * sizeof (char));
10087c478bd9Sstevel@tonic-gate 	return (0);
10097c478bd9Sstevel@tonic-gate }
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate 
10127c478bd9Sstevel@tonic-gate static void
common_subject(parse_context_t * ctx)10137c478bd9Sstevel@tonic-gate common_subject(parse_context_t *ctx)
10147c478bd9Sstevel@tonic-gate {
10157c478bd9Sstevel@tonic-gate 	int32_t	ruid, rgid, pid;
10167c478bd9Sstevel@tonic-gate 
10177c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), (uint32_t *)&(ctx->out.sf_auid), 1);
10187c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), (uint32_t *)&(ctx->out.sf_euid), 1);
10197c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), (uint32_t *)&(ctx->out.sf_egid), 1);
10207c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &ruid, 1);
10217c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &rgid, 1);
10227c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &pid, 1);
10237c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), (uint32_t *)&(ctx->out.sf_asid), 1);
10247c478bd9Sstevel@tonic-gate }
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate /*
10277c478bd9Sstevel@tonic-gate  * Format of subject32 token:
10287c478bd9Sstevel@tonic-gate  *	subject token id	adr_char
10297c478bd9Sstevel@tonic-gate  *	auid			adr_int32
10307c478bd9Sstevel@tonic-gate  *	euid			adr_int32
10317c478bd9Sstevel@tonic-gate  *	egid 			adr_int32
10327c478bd9Sstevel@tonic-gate  * 	ruid			adr_int32
10337c478bd9Sstevel@tonic-gate  *	rgid			adr_int32
10347c478bd9Sstevel@tonic-gate  * 	pid			adr_int32
10357c478bd9Sstevel@tonic-gate  * 	sid			adr_int32
10367c478bd9Sstevel@tonic-gate  * 	termid			adr_int32*2
10377c478bd9Sstevel@tonic-gate  *
10387c478bd9Sstevel@tonic-gate  */
10397c478bd9Sstevel@tonic-gate int
subject32_token(parse_context_t * ctx)10407c478bd9Sstevel@tonic-gate subject32_token(parse_context_t *ctx)
10417c478bd9Sstevel@tonic-gate {
10427c478bd9Sstevel@tonic-gate 	int32_t port;	/* not used in output */
10437c478bd9Sstevel@tonic-gate 
10447c478bd9Sstevel@tonic-gate 	common_subject(ctx);
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &port, 1);
10477c478bd9Sstevel@tonic-gate 	ctx->out.sf_tid.at_type = AU_IPv4;
104842103d7eSdanmcd 	adrm_u_char(&(ctx->adr), (uchar_t *)&(ctx->out.sf_tid.at_addr[0]), 4);
10497c478bd9Sstevel@tonic-gate 
10507c478bd9Sstevel@tonic-gate 	return (0);
10517c478bd9Sstevel@tonic-gate }
10527c478bd9Sstevel@tonic-gate 
10537c478bd9Sstevel@tonic-gate /*
10547c478bd9Sstevel@tonic-gate  * Format of subject32_ex token:
10557c478bd9Sstevel@tonic-gate  *	subject token id	adr_char
10567c478bd9Sstevel@tonic-gate  *	auid			adr_int32
10577c478bd9Sstevel@tonic-gate  *	euid			adr_int32
10587c478bd9Sstevel@tonic-gate  *	egid 			adr_int32
10597c478bd9Sstevel@tonic-gate  * 	ruid			adr_int32
10607c478bd9Sstevel@tonic-gate  *	rgid			adr_int32
10617c478bd9Sstevel@tonic-gate  * 	pid			adr_int32
10627c478bd9Sstevel@tonic-gate  * 	sid			adr_int32
10638249a45fSJan Friedel  * 	termid
10648249a45fSJan Friedel  *		port		adr_int32
10658249a45fSJan Friedel  *		type		adr_int32
10668249a45fSJan Friedel  *		ip address	adr_u_char*type
10677c478bd9Sstevel@tonic-gate  *
10687c478bd9Sstevel@tonic-gate  */
10697c478bd9Sstevel@tonic-gate int
subject32_ex_token(parse_context_t * ctx)10707c478bd9Sstevel@tonic-gate subject32_ex_token(parse_context_t *ctx)
10717c478bd9Sstevel@tonic-gate {
10727c478bd9Sstevel@tonic-gate 	int32_t port;	/* not used in output */
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 	common_subject(ctx);
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 	adrm_int32(&(ctx->adr), &port, 1);
10777c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), &(ctx->out.sf_tid.at_type), 1);
10788249a45fSJan Friedel 	adrm_u_char(&(ctx->adr), (uchar_t *)&(ctx->out.sf_tid.at_addr[0]),
10798249a45fSJan Friedel 	    ctx->out.sf_tid.at_type);
10807c478bd9Sstevel@tonic-gate 
10817c478bd9Sstevel@tonic-gate 	return (0);
10827c478bd9Sstevel@tonic-gate }
10837c478bd9Sstevel@tonic-gate 
10847c478bd9Sstevel@tonic-gate /*
10857c478bd9Sstevel@tonic-gate  * Format of subject64 token:
10867c478bd9Sstevel@tonic-gate  *	subject token id	adr_char
10877c478bd9Sstevel@tonic-gate  *	auid			adr_int32
10887c478bd9Sstevel@tonic-gate  *	euid			adr_int32
10897c478bd9Sstevel@tonic-gate  *	egid 			adr_int32
10907c478bd9Sstevel@tonic-gate  * 	ruid			adr_int32
10917c478bd9Sstevel@tonic-gate  *	rgid			adr_int32
10927c478bd9Sstevel@tonic-gate  * 	pid			adr_int32
10937c478bd9Sstevel@tonic-gate  * 	sid			adr_int32
10947c478bd9Sstevel@tonic-gate  * 	termid			adr_int64+adr_int32
10957c478bd9Sstevel@tonic-gate  *
10967c478bd9Sstevel@tonic-gate  */
10977c478bd9Sstevel@tonic-gate int
subject64_token(parse_context_t * ctx)10987c478bd9Sstevel@tonic-gate subject64_token(parse_context_t *ctx)
10997c478bd9Sstevel@tonic-gate {
11007c478bd9Sstevel@tonic-gate 	int64_t port;
11017c478bd9Sstevel@tonic-gate 
11027c478bd9Sstevel@tonic-gate 	common_subject(ctx);
11037c478bd9Sstevel@tonic-gate 
11047c478bd9Sstevel@tonic-gate 	adrm_int64(&(ctx->adr), &port, 1);
11057c478bd9Sstevel@tonic-gate 	ctx->out.sf_tid.at_type = AU_IPv4;
110642103d7eSdanmcd 	adrm_u_char(&(ctx->adr), (uchar_t *)&(ctx->out.sf_tid.at_addr[0]), 4);
11077c478bd9Sstevel@tonic-gate 
11087c478bd9Sstevel@tonic-gate 	return (0);
11097c478bd9Sstevel@tonic-gate }
11107c478bd9Sstevel@tonic-gate 
11117c478bd9Sstevel@tonic-gate /*
11128249a45fSJan Friedel  * Format of subject64_ex token:
11137c478bd9Sstevel@tonic-gate  *	subject token id	adr_char
11147c478bd9Sstevel@tonic-gate  *	auid			adr_int32
11157c478bd9Sstevel@tonic-gate  *	euid			adr_int32
11167c478bd9Sstevel@tonic-gate  *	egid 			adr_int32
11177c478bd9Sstevel@tonic-gate  * 	ruid			adr_int32
11187c478bd9Sstevel@tonic-gate  *	rgid			adr_int32
11197c478bd9Sstevel@tonic-gate  * 	pid			adr_int32
11207c478bd9Sstevel@tonic-gate  * 	sid			adr_int32
11218249a45fSJan Friedel  * 	termid
11228249a45fSJan Friedel  *		port		adr_int64
11238249a45fSJan Friedel  *		type		adr_int32
11248249a45fSJan Friedel  *		ip address	adr_u_char*type
11257c478bd9Sstevel@tonic-gate  *
11267c478bd9Sstevel@tonic-gate  */
11277c478bd9Sstevel@tonic-gate int
subject64_ex_token(parse_context_t * ctx)11287c478bd9Sstevel@tonic-gate subject64_ex_token(parse_context_t *ctx)
11297c478bd9Sstevel@tonic-gate {
11307c478bd9Sstevel@tonic-gate 	int64_t port;
11317c478bd9Sstevel@tonic-gate 
11327c478bd9Sstevel@tonic-gate 	common_subject(ctx);
11337c478bd9Sstevel@tonic-gate 
11347c478bd9Sstevel@tonic-gate 	adrm_int64(&(ctx->adr), &port, 1);
11357c478bd9Sstevel@tonic-gate 	adrm_u_int32(&(ctx->adr), &(ctx->out.sf_tid.at_type), 1);
11368249a45fSJan Friedel 	adrm_u_char(&(ctx->adr), (uchar_t *)&(ctx->out.sf_tid.at_addr[0]),
11378249a45fSJan Friedel 	    ctx->out.sf_tid.at_type);
11387c478bd9Sstevel@tonic-gate 
11397c478bd9Sstevel@tonic-gate 	return (0);
11407c478bd9Sstevel@tonic-gate }
11417c478bd9Sstevel@tonic-gate 
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate int
xatom_token(parse_context_t * ctx)11447c478bd9Sstevel@tonic-gate xatom_token(parse_context_t *ctx)
11457c478bd9Sstevel@tonic-gate {
11467c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
11477c478bd9Sstevel@tonic-gate 
11487c478bd9Sstevel@tonic-gate 	return (0);
11497c478bd9Sstevel@tonic-gate }
11507c478bd9Sstevel@tonic-gate 
11517c478bd9Sstevel@tonic-gate 
11527c478bd9Sstevel@tonic-gate int
xselect_token(parse_context_t * ctx)11537c478bd9Sstevel@tonic-gate xselect_token(parse_context_t *ctx)
11547c478bd9Sstevel@tonic-gate {
11557c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
11567c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
11577c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate 	return (0);
11607c478bd9Sstevel@tonic-gate }
11617c478bd9Sstevel@tonic-gate 
11627c478bd9Sstevel@tonic-gate /*
11637c478bd9Sstevel@tonic-gate  * anchor a path name with a slash
11647c478bd9Sstevel@tonic-gate  * assume we have enough space
11657c478bd9Sstevel@tonic-gate  */
11667c478bd9Sstevel@tonic-gate static void
anchor_path(char * path)11677c478bd9Sstevel@tonic-gate anchor_path(char *path)
11687c478bd9Sstevel@tonic-gate {
11697c478bd9Sstevel@tonic-gate 
11707c478bd9Sstevel@tonic-gate 	(void) memmove((void *)(path + 1), (void *)path, strlen(path) + 1);
11717c478bd9Sstevel@tonic-gate 	*path = '/';
11727c478bd9Sstevel@tonic-gate }
11737c478bd9Sstevel@tonic-gate 
11747c478bd9Sstevel@tonic-gate 
11757c478bd9Sstevel@tonic-gate /*
11767c478bd9Sstevel@tonic-gate  * copy path to collapsed path.
11777c478bd9Sstevel@tonic-gate  * collapsed path does not contain:
11787c478bd9Sstevel@tonic-gate  *	successive slashes
11797c478bd9Sstevel@tonic-gate  *	instances of dot-slash
11807c478bd9Sstevel@tonic-gate  *	instances of dot-dot-slash
11817c478bd9Sstevel@tonic-gate  * passed path must be anchored with a '/'
11827c478bd9Sstevel@tonic-gate  */
11837c478bd9Sstevel@tonic-gate static size_t
collapse_path(char * s,size_t ls)11847c478bd9Sstevel@tonic-gate collapse_path(char *s, size_t ls)
11857c478bd9Sstevel@tonic-gate {
11867c478bd9Sstevel@tonic-gate 	int	id;	/* index of where we are in destination string */
11877c478bd9Sstevel@tonic-gate 	int	is;	/* index of where we are in source string */
11887c478bd9Sstevel@tonic-gate 	int	slashseen;	/* have we seen a slash */
11897c478bd9Sstevel@tonic-gate 
11907c478bd9Sstevel@tonic-gate 	ls++; /* source length including '\0' */
11917c478bd9Sstevel@tonic-gate 
11927c478bd9Sstevel@tonic-gate 	slashseen = 0;
11937c478bd9Sstevel@tonic-gate 	for (is = 0, id = 0; is < ls; is++) {
11947c478bd9Sstevel@tonic-gate 		if (s[is] == '\0') {
11957c478bd9Sstevel@tonic-gate 			if (id > 1 && s[id-1] == '/') {
11967c478bd9Sstevel@tonic-gate 				--id;
11977c478bd9Sstevel@tonic-gate 			}
11987c478bd9Sstevel@tonic-gate 			s[id++] = '\0';
11997c478bd9Sstevel@tonic-gate 			break;
12007c478bd9Sstevel@tonic-gate 		}
12017c478bd9Sstevel@tonic-gate 		/* previous character was a / */
12027c478bd9Sstevel@tonic-gate 		if (slashseen) {
12037c478bd9Sstevel@tonic-gate 			if (s[is] == '/')
12047c478bd9Sstevel@tonic-gate 				continue;	/* another slash, ignore it */
12057c478bd9Sstevel@tonic-gate 		} else if (s[is] == '/') {
12067c478bd9Sstevel@tonic-gate 			/* we see a /, just copy it and try again */
12077c478bd9Sstevel@tonic-gate 			slashseen = 1;
12087c478bd9Sstevel@tonic-gate 			s[id++] = '/';
12097c478bd9Sstevel@tonic-gate 			continue;
12107c478bd9Sstevel@tonic-gate 		}
12117c478bd9Sstevel@tonic-gate 		/* /./ seen */
12127c478bd9Sstevel@tonic-gate 		if (s[is] == '.' && s[is+1] == '/') {
12137c478bd9Sstevel@tonic-gate 			is += 1;
12147c478bd9Sstevel@tonic-gate 			continue;
12157c478bd9Sstevel@tonic-gate 		}
12167c478bd9Sstevel@tonic-gate 		/* XXX/. seen */
12177c478bd9Sstevel@tonic-gate 		if (s[is] == '.' && s[is+1] == '\0') {
12187c478bd9Sstevel@tonic-gate 			if (id > 1)
12197c478bd9Sstevel@tonic-gate 				id--;
12207c478bd9Sstevel@tonic-gate 			continue;
12217c478bd9Sstevel@tonic-gate 		}
12227c478bd9Sstevel@tonic-gate 		/* XXX/.. seen */
12237c478bd9Sstevel@tonic-gate 		if (s[is] == '.' && s[is+1] == '.' && s[is+2] == '\0') {
12247c478bd9Sstevel@tonic-gate 			is += 1;
12257c478bd9Sstevel@tonic-gate 			if (id > 0)
12267c478bd9Sstevel@tonic-gate 				id--;
122742103d7eSdanmcd 			while (id > 0 && s[--id] != '/')
122842103d7eSdanmcd 				;
12297c478bd9Sstevel@tonic-gate 			id++;
12307c478bd9Sstevel@tonic-gate 			continue;
12317c478bd9Sstevel@tonic-gate 		}
12327c478bd9Sstevel@tonic-gate 		/* XXX/../ seen */
12337c478bd9Sstevel@tonic-gate 		if (s[is] == '.' && s[is+1] == '.' && s[is+2] == '/') {
12347c478bd9Sstevel@tonic-gate 			is += 2;
12357c478bd9Sstevel@tonic-gate 			if (id > 0)
12367c478bd9Sstevel@tonic-gate 				id--;
123742103d7eSdanmcd 			while (id > 0 && s[--id] != '/')
123842103d7eSdanmcd 				;
12397c478bd9Sstevel@tonic-gate 			id++;
12407c478bd9Sstevel@tonic-gate 			continue;
12417c478bd9Sstevel@tonic-gate 		}
124242103d7eSdanmcd 		while (is < ls && (s[id++] = s[is++]) != '/')
124342103d7eSdanmcd 			;
12447c478bd9Sstevel@tonic-gate 		is--;
12457c478bd9Sstevel@tonic-gate 	}
12467c478bd9Sstevel@tonic-gate 	return ((size_t)id - 1);
12477c478bd9Sstevel@tonic-gate }
12487c478bd9Sstevel@tonic-gate 
12497c478bd9Sstevel@tonic-gate /*
12507c478bd9Sstevel@tonic-gate  * for tokens with sub-fields that include a length, this
12517c478bd9Sstevel@tonic-gate  * skips the sub-field.
12527c478bd9Sstevel@tonic-gate  */
12537c478bd9Sstevel@tonic-gate 
12547c478bd9Sstevel@tonic-gate static void
skip_bytes(parse_context_t * ctx)12557c478bd9Sstevel@tonic-gate skip_bytes(parse_context_t *ctx)
12567c478bd9Sstevel@tonic-gate {
12577c478bd9Sstevel@tonic-gate 	ushort_t	c;
12587c478bd9Sstevel@tonic-gate 
12597c478bd9Sstevel@tonic-gate 	adrm_u_short(&(ctx->adr), &c, 1);
12607c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += c;
12617c478bd9Sstevel@tonic-gate }
12627c478bd9Sstevel@tonic-gate 
12637c478bd9Sstevel@tonic-gate static void
skip_string(parse_context_t * ctx)12647c478bd9Sstevel@tonic-gate skip_string(parse_context_t *ctx)
12657c478bd9Sstevel@tonic-gate {
12667c478bd9Sstevel@tonic-gate 	char	c;
12677c478bd9Sstevel@tonic-gate 
12687c478bd9Sstevel@tonic-gate 	do {
12697c478bd9Sstevel@tonic-gate 		adrm_char(&(ctx->adr), &c, 1);
12707c478bd9Sstevel@tonic-gate 	} while (c != (char)0);
12717c478bd9Sstevel@tonic-gate }
12727c478bd9Sstevel@tonic-gate 
12737c478bd9Sstevel@tonic-gate /*
12747c478bd9Sstevel@tonic-gate  * add a byte to specified length so there can be a prefix of
12757c478bd9Sstevel@tonic-gate  * '/' added (if needed for paths).  Another is added for '\0'
12767c478bd9Sstevel@tonic-gate  *
12777c478bd9Sstevel@tonic-gate  * if offset is zero, new data overwrites old, if any.  Otherwise
12787c478bd9Sstevel@tonic-gate  * new data is appended to the end.
12797c478bd9Sstevel@tonic-gate  */
12807c478bd9Sstevel@tonic-gate 
12817c478bd9Sstevel@tonic-gate static void
get_bytes_to_string(parse_context_t * ctx,size_t * l,char ** p,size_t offset)12827c478bd9Sstevel@tonic-gate get_bytes_to_string(parse_context_t *ctx, size_t *l, char **p,
12837c478bd9Sstevel@tonic-gate     size_t offset)
12847c478bd9Sstevel@tonic-gate {
12857c478bd9Sstevel@tonic-gate 	ushort_t	len;
12867c478bd9Sstevel@tonic-gate 	char		*bp;
12877c478bd9Sstevel@tonic-gate 
12887c478bd9Sstevel@tonic-gate 	adrm_u_short(&(ctx->adr), &len, 1);
12897c478bd9Sstevel@tonic-gate 
12907c478bd9Sstevel@tonic-gate 	len++;	/* in case need to add '/' prefix */
12917c478bd9Sstevel@tonic-gate 	*p = realloc(*p, 1 + (size_t)len + offset);
12927c478bd9Sstevel@tonic-gate 	if (*p == NULL) {
12937c478bd9Sstevel@tonic-gate 		perror("audit_sysudp.so");
12947c478bd9Sstevel@tonic-gate 		return;
12957c478bd9Sstevel@tonic-gate 	}
12967c478bd9Sstevel@tonic-gate 	if (offset > 0)
12977c478bd9Sstevel@tonic-gate 		offset--;	/* overwrite end of string */
12987c478bd9Sstevel@tonic-gate 
12997c478bd9Sstevel@tonic-gate 	*l = (size_t)len - 2 + offset;
13007c478bd9Sstevel@tonic-gate 
13017c478bd9Sstevel@tonic-gate 	bp = *p + offset;
13027c478bd9Sstevel@tonic-gate 	adrm_char(&(ctx->adr), bp, len - 1);
13037c478bd9Sstevel@tonic-gate 	*(bp + len - 1) = '\0';
13047c478bd9Sstevel@tonic-gate }
13057c478bd9Sstevel@tonic-gate 
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate /*
13087c478bd9Sstevel@tonic-gate  * Format of host token:
13097c478bd9Sstevel@tonic-gate  *	host  		adr_uint32
13107c478bd9Sstevel@tonic-gate  */
13117c478bd9Sstevel@tonic-gate int
host_token(parse_context_t * ctx)13127c478bd9Sstevel@tonic-gate host_token(parse_context_t *ctx)
13137c478bd9Sstevel@tonic-gate {
13147c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (int32_t);
13157c478bd9Sstevel@tonic-gate 
13167c478bd9Sstevel@tonic-gate 	return (0);
13177c478bd9Sstevel@tonic-gate }
13187c478bd9Sstevel@tonic-gate 
13197c478bd9Sstevel@tonic-gate /*
13207c478bd9Sstevel@tonic-gate  * Format of useofauth token:
13217c478bd9Sstevel@tonic-gate  *	uauth token id		adr_char
13227c478bd9Sstevel@tonic-gate  * 	uauth			adr_string
13237c478bd9Sstevel@tonic-gate  *
13247c478bd9Sstevel@tonic-gate  */
13257c478bd9Sstevel@tonic-gate int
useofauth_token(parse_context_t * ctx)13267c478bd9Sstevel@tonic-gate useofauth_token(parse_context_t *ctx)
13277c478bd9Sstevel@tonic-gate {
13287c478bd9Sstevel@tonic-gate 	get_bytes_to_string(ctx, &(ctx->out.sf_uauthlen),
13297c478bd9Sstevel@tonic-gate 	    &(ctx->out.sf_uauth), 0);
13307c478bd9Sstevel@tonic-gate 
13317c478bd9Sstevel@tonic-gate 	return (0);
13327c478bd9Sstevel@tonic-gate }
13337c478bd9Sstevel@tonic-gate 
13347c478bd9Sstevel@tonic-gate /*
1335047f6e6fSgww  * Format of user token:
1336047f6e6fSgww  *	user token id		adr_char
1337047f6e6fSgww  *	uid			adr_uid
1338047f6e6fSgww  * 	username		adr_string
1339047f6e6fSgww  *
1340047f6e6fSgww  */
1341047f6e6fSgww int
user_token(parse_context_t * ctx)1342047f6e6fSgww user_token(parse_context_t *ctx)
1343047f6e6fSgww {
1344047f6e6fSgww 	ctx->adr.adr_now += sizeof (uid_t);
1345047f6e6fSgww 	skip_bytes(ctx);
1346047f6e6fSgww 
1347047f6e6fSgww 	return (0);
1348047f6e6fSgww }
1349047f6e6fSgww 
1350047f6e6fSgww /*
13517c478bd9Sstevel@tonic-gate  * Format of zonename token:
13527c478bd9Sstevel@tonic-gate  *	zonename token id		adr_char
13537c478bd9Sstevel@tonic-gate  * 	zonename			adr_string
13547c478bd9Sstevel@tonic-gate  *
13557c478bd9Sstevel@tonic-gate  */
13567c478bd9Sstevel@tonic-gate int
zonename_token(parse_context_t * ctx)13577c478bd9Sstevel@tonic-gate zonename_token(parse_context_t *ctx)
13587c478bd9Sstevel@tonic-gate {
13597c478bd9Sstevel@tonic-gate 	get_bytes_to_string(ctx,
13607c478bd9Sstevel@tonic-gate 	    &(ctx->out.sf_zonelen),
13617c478bd9Sstevel@tonic-gate 	    &(ctx->out.sf_zonename),
13627c478bd9Sstevel@tonic-gate 	    0);
13637c478bd9Sstevel@tonic-gate 
13647c478bd9Sstevel@tonic-gate 	return (0);
13657c478bd9Sstevel@tonic-gate }
13667c478bd9Sstevel@tonic-gate 
1367103b2b15Sgww /*
1368103b2b15Sgww  * Format of fmri token:
1369103b2b15Sgww  *	fmri token id		adr_char
1370103b2b15Sgww  *	fmri			adr_string
1371103b2b15Sgww  */
1372103b2b15Sgww int
fmri_token(parse_context_t * ctx)1373103b2b15Sgww fmri_token(parse_context_t *ctx)
1374103b2b15Sgww {
1375103b2b15Sgww 	skip_bytes(ctx);
1376103b2b15Sgww 
1377103b2b15Sgww 	return (0);
1378103b2b15Sgww }
1379103b2b15Sgww 
13807c478bd9Sstevel@tonic-gate int
xcolormap_token(parse_context_t * ctx)13817c478bd9Sstevel@tonic-gate xcolormap_token(parse_context_t *ctx)
13827c478bd9Sstevel@tonic-gate {
13837c478bd9Sstevel@tonic-gate 	return (xgeneric(ctx));
13847c478bd9Sstevel@tonic-gate }
13857c478bd9Sstevel@tonic-gate 
13867c478bd9Sstevel@tonic-gate int
xcursor_token(parse_context_t * ctx)13877c478bd9Sstevel@tonic-gate xcursor_token(parse_context_t *ctx)
13887c478bd9Sstevel@tonic-gate {
13897c478bd9Sstevel@tonic-gate 	return (xgeneric(ctx));
13907c478bd9Sstevel@tonic-gate }
13917c478bd9Sstevel@tonic-gate 
13927c478bd9Sstevel@tonic-gate int
xfont_token(parse_context_t * ctx)13937c478bd9Sstevel@tonic-gate xfont_token(parse_context_t *ctx)
13947c478bd9Sstevel@tonic-gate {
13957c478bd9Sstevel@tonic-gate 	return (xgeneric(ctx));
13967c478bd9Sstevel@tonic-gate }
13977c478bd9Sstevel@tonic-gate 
13987c478bd9Sstevel@tonic-gate int
xgc_token(parse_context_t * ctx)13997c478bd9Sstevel@tonic-gate xgc_token(parse_context_t *ctx)
14007c478bd9Sstevel@tonic-gate {
14017c478bd9Sstevel@tonic-gate 	return (xgeneric(ctx));
14027c478bd9Sstevel@tonic-gate }
14037c478bd9Sstevel@tonic-gate 
14047c478bd9Sstevel@tonic-gate int
xpixmap_token(parse_context_t * ctx)14057c478bd9Sstevel@tonic-gate xpixmap_token(parse_context_t *ctx)
14067c478bd9Sstevel@tonic-gate {
14077c478bd9Sstevel@tonic-gate 	return (xgeneric(ctx));
14087c478bd9Sstevel@tonic-gate }
14097c478bd9Sstevel@tonic-gate 
14107c478bd9Sstevel@tonic-gate int
xwindow_token(parse_context_t * ctx)14117c478bd9Sstevel@tonic-gate xwindow_token(parse_context_t *ctx)
14127c478bd9Sstevel@tonic-gate {
14137c478bd9Sstevel@tonic-gate 	return (xgeneric(ctx));
14147c478bd9Sstevel@tonic-gate }
14157c478bd9Sstevel@tonic-gate /*
14167c478bd9Sstevel@tonic-gate  * Format of xgeneric token:
14177c478bd9Sstevel@tonic-gate  *	XID			adr_int32
14187c478bd9Sstevel@tonic-gate  *	creator UID		adr_int32
14197c478bd9Sstevel@tonic-gate  *
14207c478bd9Sstevel@tonic-gate  * Includes:  xcolormap, xcursor, xfont, xgc, xpixmap, and xwindow
14217c478bd9Sstevel@tonic-gate  */
14227c478bd9Sstevel@tonic-gate static int
xgeneric(parse_context_t * ctx)14237c478bd9Sstevel@tonic-gate xgeneric(parse_context_t *ctx)
14247c478bd9Sstevel@tonic-gate {
14257c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += 2 * sizeof (int32_t);
14267c478bd9Sstevel@tonic-gate 
14277c478bd9Sstevel@tonic-gate 	return (0);
14287c478bd9Sstevel@tonic-gate }
14297c478bd9Sstevel@tonic-gate /*
14307c478bd9Sstevel@tonic-gate  * Format of xproperty token:
14317c478bd9Sstevel@tonic-gate  *	XID			adr_int32
14327c478bd9Sstevel@tonic-gate  *	creator UID		adr_int32
14337c478bd9Sstevel@tonic-gate  *	atom string		adr_string
14347c478bd9Sstevel@tonic-gate  */
14357c478bd9Sstevel@tonic-gate int
xproperty_token(parse_context_t * ctx)14367c478bd9Sstevel@tonic-gate xproperty_token(parse_context_t *ctx)
14377c478bd9Sstevel@tonic-gate {
14387c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += 2 * sizeof (int32_t);
14397c478bd9Sstevel@tonic-gate 
14407c478bd9Sstevel@tonic-gate 	return (0);
14417c478bd9Sstevel@tonic-gate }
14427c478bd9Sstevel@tonic-gate /*
14437c478bd9Sstevel@tonic-gate  * Format of xclient token:
14447c478bd9Sstevel@tonic-gate  * 	xclient id		adr_int32
14457c478bd9Sstevel@tonic-gate  */
14467c478bd9Sstevel@tonic-gate int
xclient_token(parse_context_t * ctx)14477c478bd9Sstevel@tonic-gate xclient_token(parse_context_t *ctx)
14487c478bd9Sstevel@tonic-gate {
14497c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (int32_t);
14507c478bd9Sstevel@tonic-gate 
14517c478bd9Sstevel@tonic-gate 	return (0);
14527c478bd9Sstevel@tonic-gate }
14537c478bd9Sstevel@tonic-gate 
14547c478bd9Sstevel@tonic-gate /*
14557c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
14567c478bd9Sstevel@tonic-gate  * privilege_token()	: Process privilege token and display contents
14577c478bd9Sstevel@tonic-gate  *
14587c478bd9Sstevel@tonic-gate  * Format of privilege token:
14597c478bd9Sstevel@tonic-gate  *	privilege token id	adr_char
14607c478bd9Sstevel@tonic-gate  *	privilege type		adr_string
14617c478bd9Sstevel@tonic-gate  *	privilege		adr_string
14627c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
14637c478bd9Sstevel@tonic-gate  */
14647c478bd9Sstevel@tonic-gate 
14657c478bd9Sstevel@tonic-gate int
privilege_token(parse_context_t * ctx)14667c478bd9Sstevel@tonic-gate privilege_token(parse_context_t *ctx)
14677c478bd9Sstevel@tonic-gate {
14687c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
14697c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
14707c478bd9Sstevel@tonic-gate 
14717c478bd9Sstevel@tonic-gate 	return (0);
14727c478bd9Sstevel@tonic-gate }
14737c478bd9Sstevel@tonic-gate 
14747c478bd9Sstevel@tonic-gate 
14757c478bd9Sstevel@tonic-gate /*
1476a13cf099Sgww  * Format of label token:
147745916cd2Sjpk  *	label ID                1 byte
147845916cd2Sjpk  *	compartment length      1 byte
147945916cd2Sjpk  *	classification          2 bytes
148045916cd2Sjpk  *	compartment words       <compartment length> * 4 bytes
14817c478bd9Sstevel@tonic-gate  */
14827c478bd9Sstevel@tonic-gate int
label_token(parse_context_t * ctx)1483a13cf099Sgww label_token(parse_context_t *ctx)
14847c478bd9Sstevel@tonic-gate {
148545916cd2Sjpk 	char	c;
14867c478bd9Sstevel@tonic-gate 
148745916cd2Sjpk 	ctx->adr.adr_now += sizeof (char);	/* label ID */
148845916cd2Sjpk 	adrm_char(&(ctx->adr), &c, 1);
148945916cd2Sjpk 
149045916cd2Sjpk 	ctx->adr.adr_now += sizeof (ushort_t);	/* classification */
149145916cd2Sjpk 	ctx->adr.adr_now += 4 * c;		/* compartments */
14927c478bd9Sstevel@tonic-gate 
14937c478bd9Sstevel@tonic-gate 	return (0);
14947c478bd9Sstevel@tonic-gate }
14957c478bd9Sstevel@tonic-gate 
14967c478bd9Sstevel@tonic-gate /*
14977c478bd9Sstevel@tonic-gate  * Format of useofpriv token:
14987c478bd9Sstevel@tonic-gate  *	priv_type			adr_char
14997c478bd9Sstevel@tonic-gate  *	priv_set_t			adr_short
15007c478bd9Sstevel@tonic-gate  *	priv_set			adr_char*(sizeof (priv_set_t))
15017c478bd9Sstevel@tonic-gate  */
15027c478bd9Sstevel@tonic-gate int
useofpriv_token(parse_context_t * ctx)15037c478bd9Sstevel@tonic-gate useofpriv_token(parse_context_t *ctx)
15047c478bd9Sstevel@tonic-gate {
15057c478bd9Sstevel@tonic-gate 	ctx->adr.adr_now += sizeof (char); /* success / fail */
15067c478bd9Sstevel@tonic-gate 	skip_bytes(ctx);
15077c478bd9Sstevel@tonic-gate 
15087c478bd9Sstevel@tonic-gate 	return (0);
15097c478bd9Sstevel@tonic-gate }
1510