17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
5166fae4pk * Common Development and Distribution License (the "License").
6166fae4pk * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
21166fae4pk
227c478bdstevel@tonic-gate/*
23166fae4pk * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate#include <stdio.h>
307c478bdstevel@tonic-gate#include <ctype.h>
317c478bdstevel@tonic-gate#include <string.h>
327c478bdstevel@tonic-gate#include <fcntl.h>
337c478bdstevel@tonic-gate#include <string.h>
347c478bdstevel@tonic-gate#include <sys/types.h>
357c478bdstevel@tonic-gate#include <sys/time.h>
367c478bdstevel@tonic-gate#include <sys/stat.h>
377c478bdstevel@tonic-gate#include <sys/uio.h>
387c478bdstevel@tonic-gate#include <unistd.h>
397c478bdstevel@tonic-gate#include <signal.h>
407c478bdstevel@tonic-gate#include <errno.h>
417c478bdstevel@tonic-gate#include <stdlib.h>
427c478bdstevel@tonic-gate#include <sys/wait.h>
437c478bdstevel@tonic-gate#include <sys/socket.h>
447c478bdstevel@tonic-gate#include <sys/sockio.h>
457c478bdstevel@tonic-gate#include <net/if.h>
467c478bdstevel@tonic-gate#include <netinet/in_systm.h>
477c478bdstevel@tonic-gate#include <netinet/in.h>
487c478bdstevel@tonic-gate#include <netinet/ip.h>
497c478bdstevel@tonic-gate#include <netinet/if_ether.h>
507c478bdstevel@tonic-gate#include <netinet/udp.h>
517c478bdstevel@tonic-gate#include "snoop.h"
527c478bdstevel@tonic-gate
537c478bdstevel@tonic-gate#ifndef MIN
547c478bdstevel@tonic-gate#define	MIN(a, b) ((a) < (b) ? (a) : (b))
557c478bdstevel@tonic-gate#endif
567c478bdstevel@tonic-gate
577c478bdstevel@tonic-gateextern char *src_name;
587c478bdstevel@tonic-gateextern char *dst_name;
597c478bdstevel@tonic-gate#define	MAX_CTX  (10)
607c478bdstevel@tonic-gate#define	LINE_LEN (255)
617c478bdstevel@tonic-gate#define	BUF_SIZE (16000)
622e3b646kcpoonstatic int ldap = 0;		/* flag to control initialization */
637c478bdstevel@tonic-gatestruct ctx {
647c478bdstevel@tonic-gate	int src;
657c478bdstevel@tonic-gate	int dst;
667c478bdstevel@tonic-gate	char *src_name;
677c478bdstevel@tonic-gate	char *dst_name;
687c478bdstevel@tonic-gate};
697c478bdstevel@tonic-gatechar *osibuff = NULL;
707c478bdstevel@tonic-gateint osilen = 0;
717c478bdstevel@tonic-gatechar scrbuffer[BUF_SIZE];	/* buffer to accumulate data until a */
727c478bdstevel@tonic-gate				/* complete LDAPmessage is received  */
737c478bdstevel@tonic-gatechar resultcode[LINE_LEN];	/* These are used */
747c478bdstevel@tonic-gatechar operation[LINE_LEN];	/* by -V option.  */
757c478bdstevel@tonic-gatechar bb[LINE_LEN];
767c478bdstevel@tonic-gate
777c478bdstevel@tonic-gateint gi_osibuf[MAX_CTX];
787c478bdstevel@tonic-gateint otyp[MAX_CTX];
797c478bdstevel@tonic-gateint olen[MAX_CTX];
807c478bdstevel@tonic-gateint level[MAX_CTX];
817c478bdstevel@tonic-gate
827c478bdstevel@tonic-gatevoid decode_ldap(char *buf, int len);
837c478bdstevel@tonic-gate
847c478bdstevel@tonic-gate#define	X unsigned char
857c478bdstevel@tonic-gatetypedef	X * A;
867c478bdstevel@tonic-gate#define	INT(a) ((int)(a))
877c478bdstevel@tonic-gate#define	SCRUB (void) strcat(scrbuffer, bb);
887c478bdstevel@tonic-gate
892e3b646kcpoonstatic X	hex;		/* input hex octet */
907c478bdstevel@tonic-gatestatic A	*PTRaclass;	/* application tag table pointer */
917c478bdstevel@tonic-gate
927c478bdstevel@tonic-gate/*
932e3b646kcpoon * ASN.1 Message Printing Macros
942e3b646kcpoon */
957c478bdstevel@tonic-gate
967c478bdstevel@tonic-gate#define	asnshw1(a)				{(void)sprintf(bb, a); SCRUB }
977c478bdstevel@tonic-gate#define	asnshw2(a, b)			{(void)sprintf(bb, a, b); SCRUB }
987c478bdstevel@tonic-gate#define	asnshw3(a, b, c)		{(void)sprintf(bb, a, b, c); SCRUB }
997c478bdstevel@tonic-gate#define	asnshw4(a, b, c, d)		{(void)sprintf(bb, a, b, c, d); SCRUB }
1007c478bdstevel@tonic-gate#define	asnshw5(a, b, c, d, e)	{(void)sprintf(bb, a, b, c, d, e); SCRUB }
1017c478bdstevel@tonic-gate
1027c478bdstevel@tonic-gate/*
1032e3b646kcpoon * Local Types And Variables
1042e3b646kcpoon */
1057c478bdstevel@tonic-gate
1067c478bdstevel@tonic-gate/*
1072e3b646kcpoon * Object identifier oid to name mapping description type
1082e3b646kcpoon */
1097c478bdstevel@tonic-gate
1107c478bdstevel@tonic-gatetypedef struct {
1112e3b646kcpoon	A	oidname;	/* object identifier string name */
1127c478bdstevel@tonic-gate	X	oidcode[16];	/* object identifier hexa code */
1137c478bdstevel@tonic-gate}	oidelmT;
1147c478bdstevel@tonic-gatetypedef oidelmT *oidelmTp;
1157c478bdstevel@tonic-gate
1167c478bdstevel@tonic-gate/*
1172e3b646kcpoon * Snoop's entry point to ldap decoding
1182e3b646kcpoon */
1197c478bdstevel@tonic-gate
1207c478bdstevel@tonic-gatevoid
1217c478bdstevel@tonic-gateinterpret_ldap(flags, data, fraglen, src, dst)
1227c478bdstevel@tonic-gateint flags;
1237c478bdstevel@tonic-gatechar *data;
1247c478bdstevel@tonic-gateint fraglen;
1257c478bdstevel@tonic-gateint src;
1267c478bdstevel@tonic-gateint dst;
1277c478bdstevel@tonic-gate{
1287c478bdstevel@tonic-gate
1297c478bdstevel@tonic-gate	if (!ldap) {
1307c478bdstevel@tonic-gate		init_ldap();
1317c478bdstevel@tonic-gate		ldap = 1;
1327c478bdstevel@tonic-gate	}
1337c478bdstevel@tonic-gate
1347c478bdstevel@tonic-gate	(void) decode_ldap(data, fraglen);
1357c478bdstevel@tonic-gate
1367c478bdstevel@tonic-gate	if (flags & F_DTAIL) {
1377c478bdstevel@tonic-gate		/* i.e. when snoop is run with -v (verbose) */
1387c478bdstevel@tonic-gate		show_header("LDAP:  ",
1397c478bdstevel@tonic-gate		"Lightweight Directory Access Protocol Header", fraglen);
1407c478bdstevel@tonic-gate		show_space();
1417c478bdstevel@tonic-gate		printf("%s", scrbuffer);
1427c478bdstevel@tonic-gate	}
1437c478bdstevel@tonic-gate
1447c478bdstevel@tonic-gate	if (flags & F_SUM) {
1457c478bdstevel@tonic-gate	/* i.e. when snoop is run with -V (summary) */
1467c478bdstevel@tonic-gate		(void) strcpy(data, "");
1477c478bdstevel@tonic-gate
1487c478bdstevel@tonic-gate		if (strlen(operation) != 0) {
1497c478bdstevel@tonic-gate			(void) strcat(data, " ");
1507c478bdstevel@tonic-gate			(void) strncat(data, operation, 30);
1517c478bdstevel@tonic-gate			(void) strcpy(operation, "");
1527c478bdstevel@tonic-gate		}
1537c478bdstevel@tonic-gate
1547c478bdstevel@tonic-gate		if (strlen(resultcode) != 0) {
1557c478bdstevel@tonic-gate			(void) strcat(data, " ");
1567c478bdstevel@tonic-gate			(void) strncat(data, resultcode, 30);
1577c478bdstevel@tonic-gate			(void) strcpy(resultcode, "");
1587c478bdstevel@tonic-gate		}
1597c478bdstevel@tonic-gate
1607c478bdstevel@tonic-gate		if (dst == 389) {
1617c478bdstevel@tonic-gate			(void) sprintf(get_sum_line(),
1627c478bdstevel@tonic-gate				"LDAP C port=%d%s", src, data);
1637c478bdstevel@tonic-gate		}
1647c478bdstevel@tonic-gate		if (src == 389) {
1657c478bdstevel@tonic-gate			(void) sprintf(get_sum_line(),
1667c478bdstevel@tonic-gate				"LDAP R port=%d%s", dst, data);
1677c478bdstevel@tonic-gate		}
1687c478bdstevel@tonic-gate	}
1697c478bdstevel@tonic-gate
1707c478bdstevel@tonic-gate	(void) strcpy(scrbuffer, "");
1717c478bdstevel@tonic-gate}
1727c478bdstevel@tonic-gate
1737c478bdstevel@tonic-gate/*
1742e3b646kcpoon * Known object identifiers: customize to add your own oids
1752e3b646kcpoon */
1767c478bdstevel@tonic-gate
1777c478bdstevel@tonic-gatestatic oidelmT OidTab[] = {
1787c478bdstevel@tonic-gate/*
1792e3b646kcpoon *	X.500 Standardized Attribute Types
1802e3b646kcpoon */
1817c478bdstevel@tonic-gate{(A)"ObjectClass",				{ 0x03, 0x55, 0x04, 0x00 }},
1827c478bdstevel@tonic-gate{(A)"AliasObjectName",			{ 0x03, 0x55, 0x04, 0x01 }},
1837c478bdstevel@tonic-gate{(A)"KnowledgeInfo",			{ 0x03, 0x55, 0x04, 0x02 }},
1847c478bdstevel@tonic-gate{(A)"CommonName",				{ 0x03, 0x55, 0x04, 0x03 }},
1857c478bdstevel@tonic-gate{(A)"Surname",					{ 0x03, 0x55, 0x04, 0x04 }},
1867c478bdstevel@tonic-gate{(A)"SerialNumber",				{ 0x03, 0x55, 0x04, 0x05 }},
1877c478bdstevel@tonic-gate{(A)"CountryName",				{ 0x03, 0x55, 0x04, 0x06 }},
1887c478bdstevel@tonic-gate{(A)"LocalityName",				{ 0x03, 0x55, 0x04, 0x07 }},
1897c478bdstevel@tonic-gate{(A)"StateOrProvinceName",		{ 0x03, 0x55, 0x04, 0x08 }},
1907c478bdstevel@tonic-gate{(A)"StreetAddress",			{ 0x03, 0x55, 0x04, 0x09 }},
1917c478bdstevel@tonic-gate{(A)"OrganizationName",			{ 0x03, 0x55, 0x04, 0x0a }},
1927c478bdstevel@tonic-gate{(A)"OrganizationUnitName",		{ 0x03, 0x55, 0x04, 0x0b }},
1937c478bdstevel@tonic-gate{(A)"Title",					{ 0x03, 0x55, 0x04, 0x0c }},
1947c478bdstevel@tonic-gate{(A)"Description",				{ 0x03, 0x55, 0x04, 0x0d }},
1957c478bdstevel@tonic-gate{(A)"SearchGuide",				{ 0x03, 0x55, 0x04, 0x0e }},
1967c478bdstevel@tonic-gate{(A)"BusinessCategory",			{ 0x03, 0x55, 0x04, 0x0f }},
1977c478bdstevel@tonic-gate{(A)"PostalAddress",			{ 0x03, 0x55, 0x04, 0x10 }},
1987c478bdstevel@tonic-gate{(A)"PostalCode",				{ 0x03, 0x55, 0x04, 0x11 }},
1997c478bdstevel@tonic-gate{(A)"PostOfficeBox",			{ 0x03, 0x55, 0x04, 0x12 }},
2007c478bdstevel@tonic-gate{(A)"PhysicalDeliveryOffice",	{ 0x03, 0x55, 0x04, 0x13 }},
2017c478bdstevel@tonic-gate{(A)"TelephoneNUmber",			{ 0x03, 0x55, 0x04, 0x14 }},
2027c478bdstevel@tonic-gate{(A)"TelexNumber",				{ 0x03, 0x55, 0x04, 0x15 }},
2037c478bdstevel@tonic-gate{(A)"TeletexTerminalId",		{ 0x03, 0x55, 0x04, 0x16 }},
2047c478bdstevel@tonic-gate{(A)"FaxTelephoneNumber",		{ 0x03, 0x55, 0x04, 0x17 }},
2057c478bdstevel@tonic-gate{(A)"X121Address",				{ 0x03, 0x55, 0x04, 0x18 }},
2067c478bdstevel@tonic-gate{(A)"IsdnAddress",				{ 0x03, 0x55, 0x04, 0x19 }},
2077c478bdstevel@tonic-gate{(A)"RegisteredAddress",		{ 0x03, 0x55, 0x04, 0x1a }},
2087c478bdstevel@tonic-gate{(A)"DestinationIndicator",		{ 0x03, 0x55, 0x04, 0x1b }},
2097c478bdstevel@tonic-gate{(A)"PreferDeliveryMethod",		{ 0x03, 0x55, 0x04, 0x1c }},
2107c478bdstevel@tonic-gate{(A)"PresentationAddress",		{ 0x03, 0x55, 0x04, 0x1d }},
2117c478bdstevel@tonic-gate{(A)"SupportedApplContext",		{ 0x03, 0x55, 0x04, 0x1e }},
2127c478bdstevel@tonic-gate{(A)"Member",					{ 0x03, 0x55, 0x04, 0x1f }},
2137c478bdstevel@tonic-gate{(A)"Owner",					{ 0x03, 0x55, 0x04, 0x20 }},
2147c478bdstevel@tonic-gate{(A)"RoleOccupant",				{ 0x03, 0x55, 0x04, 0x21 }},
2157c478bdstevel@tonic-gate{(A)"SeeAlso",					{ 0x03, 0x55, 0x04, 0x22 }},
2167c478bdstevel@tonic-gate{(A)"Password",					{ 0x03, 0x55, 0x04, 0x23 }},
2177c478bdstevel@tonic-gate{(A)"UserCertificate",			{ 0x03, 0x55, 0x04, 0x24 }},
2187c478bdstevel@tonic-gate{(A)"CaCertificate",			{ 0x03, 0x55, 0x04, 0x25 }},
2197c478bdstevel@tonic-gate{(A)"AuthorityRevList",			{ 0x03, 0x55, 0x04, 0x26 }},
2207c478bdstevel@tonic-gate{(A)"CertificateRevList",		{ 0x03, 0x55, 0x04, 0x27 }},
2217c478bdstevel@tonic-gate{(A)"CrossCertificatePair",		{ 0x03, 0x55, 0x04, 0x28 }},
2227c478bdstevel@tonic-gate
2237c478bdstevel@tonic-gate/*
2242e3b646kcpoon *	X.500 Standardized Object Classes
2252e3b646kcpoon */
2267c478bdstevel@tonic-gate{(A)"Top",					{ 0x03, 0x55, 0x06, 0x00 }},
2277c478bdstevel@tonic-gate{(A)"Alias",				{ 0x03, 0x55, 0x06, 0x01 }},
2287c478bdstevel@tonic-gate{(A)"Country",				{ 0x03, 0x55, 0x06, 0x02 }},
2297c478bdstevel@tonic-gate{(A)"Locality",				{ 0x03, 0x55, 0x06, 0x03 }},
2307c478bdstevel@tonic-gate{(A)"Organization",			{ 0x03, 0x55, 0x06, 0x04 }},
2317c478bdstevel@tonic-gate{(A)"OrganizationUnit",		{ 0x03, 0x55, 0x06, 0x05 }},
2327c478bdstevel@tonic-gate{(A)"Person",				{ 0x03, 0x55, 0x06, 0x06 }},
2337c478bdstevel@tonic-gate{(A)"OrganizationPersion",	{ 0x03, 0x55, 0x06, 0x07 }},
2347c478bdstevel@tonic-gate{(A)"OrganizationRole",		{ 0x03, 0x55, 0x06, 0x08 }},
2357c478bdstevel@tonic-gate{(A)"Group",				{ 0x03, 0x55, 0x06, 0x09 }},
2367c478bdstevel@tonic-gate{(A)"ResidentialPerson",	{ 0x03, 0x55, 0x06, 0x0A }},
2377c478bdstevel@tonic-gate{(A)"ApplicationProcess",	{ 0x03, 0x55, 0x06, 0x0B }},
2387c478bdstevel@tonic-gate{(A)"ApplicationEntity",	{ 0x03, 0x55, 0x06, 0x0C }},
2397c478bdstevel@tonic-gate{(A)"Dsa",					{ 0x03, 0x55, 0x06, 0x0D }},
2407c478bdstevel@tonic-gate{(A)"Device",				{ 0x03, 0x55, 0x06, 0x0E }},
2417c478bdstevel@tonic-gate{(A)"StrongAuthenticUser",	{ 0x03, 0x55, 0x06, 0x0F }},
2427c478bdstevel@tonic-gate{(A)"CaAuthority",			{ 0x03, 0x55, 0x06, 0x10 }},
2437c478bdstevel@tonic-gate
2447c478bdstevel@tonic-gate/*
2452e3b646kcpoon *	ACSE Protocol Object Identifiers
2462e3b646kcpoon */
2477c478bdstevel@tonic-gate{(A)"Asn1BER-TS",		{ 0x02, 0x51, 0x01 }},
2487c478bdstevel@tonic-gate{(A)"Private-TS",		{ 0x06, 0x2b, 0xce, 0x06, 0x01, 0x04, 0x06 }},
2497c478bdstevel@tonic-gate{(A)"ACSE-AS",			{ 0x04, 0x52, 0x01, 0x00, 0x01 }},
2507c478bdstevel@tonic-gate
2517c478bdstevel@tonic-gate/*
2522e3b646kcpoon *	Directory Protocol Oids
2532e3b646kcpoon */
2547c478bdstevel@tonic-gate{(A)"DirAccess-AC",			{ 0x03, 0x55, 0x03, 0x01 }},
2557c478bdstevel@tonic-gate{(A)"DirSystem-AC",			{ 0x03, 0x55, 0x03, 0x02 }},
2567c478bdstevel@tonic-gate
2577c478bdstevel@tonic-gate{(A)"DirAccess-AS",			{ 0x03, 0x55, 0x09, 0x01 }},
2587c478bdstevel@tonic-gate{(A)"DirSystem-AS",			{ 0x03, 0x55, 0x09, 0x02 }},
2597c478bdstevel@tonic-gate
2607c478bdstevel@tonic-gate/*
2612e3b646kcpoon *	and add your private object identifiers here ...
2622e3b646kcpoon */
2637c478bdstevel@tonic-gate};
2647c478bdstevel@tonic-gate
2657c478bdstevel@tonic-gate#define	OIDNB (sizeof (OidTab) / sizeof (oidelmT))	/* total oid nb */
2667c478bdstevel@tonic-gate
2677c478bdstevel@tonic-gate/*
2682e3b646kcpoon *	asn.1 tag class definition
2692e3b646kcpoon */
2707c478bdstevel@tonic-gate
2717c478bdstevel@tonic-gatestatic A class[] = {	/* tag class */
2727c478bdstevel@tonic-gate	(A)"UNIV ",
2737c478bdstevel@tonic-gate	(A)"APPL ",
2747c478bdstevel@tonic-gate	(A)"CTXs ",
2757c478bdstevel@tonic-gate	(A)"PRIV "
2767c478bdstevel@tonic-gate};
2777c478bdstevel@tonic-gate
2787c478bdstevel@tonic-gate/*
2792e3b646kcpoon *	universal tag definition
2802e3b646kcpoon */
2817c478bdstevel@tonic-gate
2827c478bdstevel@tonic-gatestatic A uclass[] = {	/* universal tag assignment */
2837c478bdstevel@tonic-gate(A)"EndOfContents",			/* 0  */
2847c478bdstevel@tonic-gate(A)"Boolean",				/* 1  */
2857c478bdstevel@tonic-gate(A)"Integer",				/* 2  */
2867c478bdstevel@tonic-gate(A)"BitString",				/* 3  */
2877c478bdstevel@tonic-gate(A)"OctetString",			/* 4  */
2882e3b646kcpoon(A)"Null",				/* 5  */
2892e3b646kcpoon(A)"Oid",				/* 6  */
2907c478bdstevel@tonic-gate(A)"ObjDescriptor",			/* 7  */
2917c478bdstevel@tonic-gate(A)"External",				/* 8  */
2922e3b646kcpoon(A)"Real",				/* 9  */
2937c478bdstevel@tonic-gate(A)"Enumerated",			/* 10 */
2947c478bdstevel@tonic-gate(A)"Reserved",				/* 11 */
2957c478bdstevel@tonic-gate(A)"Reserved",				/* 12 */
2967c478bdstevel@tonic-gate(A)"Reserved",				/* 13 */
2977c478bdstevel@tonic-gate(A)"Reserved",				/* 14 */
2987c478bdstevel@tonic-gate(A)"Reserved",				/* 15 */
2997c478bdstevel@tonic-gate(A)"Sequence",				/* 16 */
3002e3b646kcpoon(A)"Set",				/* 17 */
3017c478bdstevel@tonic-gate(A)"NumericString",			/* 18 */
3022e3b646kcpoon(A)"PrintableString",			/* 19 */
3037c478bdstevel@tonic-gate(A)"T.61String",			/* 20 */
3042e3b646kcpoon(A)"VideotexString",			/* 21 */
3057c478bdstevel@tonic-gate(A)"IA5String",				/* 22 */
3067c478bdstevel@tonic-gate(A)"UTCTime",				/* 23 */
3072e3b646kcpoon(A)"GeneralizedTime",			/* 24 */
3087c478bdstevel@tonic-gate(A)"GraphicString",			/* 25 */
3097c478bdstevel@tonic-gate(A)"VisibleString",			/* 26 */
3107c478bdstevel@tonic-gate(A)"GeneralString",			/* 27 */
3117c478bdstevel@tonic-gate(A)"Reserved",				/* 28 */
3127c478bdstevel@tonic-gate(A)"Reserved",				/* 29 */
3137c478bdstevel@tonic-gate(A)"Reserved",				/* 30 */
3147c478bdstevel@tonic-gate(A)"Reserved" 				/* 31 */
3157c478bdstevel@tonic-gate};
3167c478bdstevel@tonic-gate
3177c478bdstevel@tonic-gatestatic A MHSaclass[] = {	/* mhs application tag assignment */
3182e3b646kcpoon(A)"Bind Request",			/* 0 */
3197c478bdstevel@tonic-gate(A)"Bind Response",
3207c478bdstevel@tonic-gate(A)"Unbind Request",
3217c478bdstevel@tonic-gate(A)"Search Request",
3227c478bdstevel@tonic-gate(A)"Search ResEntry",
3232e3b646kcpoon(A)"Search ResDone",			/* 5 */
3247c478bdstevel@tonic-gate(A)"Modify Request",
3257c478bdstevel@tonic-gate(A)"Modify Response",
3267c478bdstevel@tonic-gate(A)"Add Request",
3272e3b646kcpoon(A)"Add Response",			/* 9 */
3287c478bdstevel@tonic-gate(A)"Del Request",
3297c478bdstevel@tonic-gate(A)"Del Response",
3307c478bdstevel@tonic-gate(A)"ModDN Request",
3317c478bdstevel@tonic-gate(A)"ModDN Response",
3322e3b646kcpoon(A)"Compare Request",			/* 14 */
3337c478bdstevel@tonic-gate(A)"Compare Response",
3347c478bdstevel@tonic-gate(A)"Abandon Request",
3357c478bdstevel@tonic-gate(A)"",					/* 17 */
3367c478bdstevel@tonic-gate(A)"",					/* 18 */
3372e3b646kcpoon(A)"Search ResRef",			/* 19 */
3387c478bdstevel@tonic-gate(A)"",					/* 20 */
3397c478bdstevel@tonic-gate(A)"",					/* 21 */
3407c478bdstevel@tonic-gate(A)"",					/* 22 */
3417c478bdstevel@tonic-gate(A)"Extended Request",
3427c478bdstevel@tonic-gate(A)"Extended Response",
3437c478bdstevel@tonic-gate(A)"",					/* 25 */
3447c478bdstevel@tonic-gate(A)"",					/* 26 */
3457c478bdstevel@tonic-gate(A)"",					/* 27 */
3467c478bdstevel@tonic-gate(A)"",					/* 28 */
3477c478bdstevel@tonic-gate(A)"",					/* 29 */
3487c478bdstevel@tonic-gate(A)"",					/* 30 */
3497c478bdstevel@tonic-gate(A)"" 					/* 31 */
3507c478bdstevel@tonic-gate};
3517c478bdstevel@tonic-gate
3527c478bdstevel@tonic-gate
3537c478bdstevel@tonic-gatestatic A DFTaclass[] = {	/* Default Application Tag Assignment */
3547c478bdstevel@tonic-gate(A)"",				/* 0  */
3557c478bdstevel@tonic-gate(A)"",				/* 1  */
3567c478bdstevel@tonic-gate(A)"",				/* 2  */
3577c478bdstevel@tonic-gate(A)"",				/* 3  */
3587c478bdstevel@tonic-gate(A)"",				/* 4  */
3597c478bdstevel@tonic-gate(A)"",				/* 5  */
3607c478bdstevel@tonic-gate(A)"",				/* 6  */
3617c478bdstevel@tonic-gate(A)"",				/* 7  */
3627c478bdstevel@tonic-gate(A)"",				/* 8  */
3637c478bdstevel@tonic-gate(A)"",				/* 9  */
3647c478bdstevel@tonic-gate(A)"",				/* 10 */
3657c478bdstevel@tonic-gate(A)"",				/* 11 */
3667c478bdstevel@tonic-gate(A)"",				/* 12 */
3677c478bdstevel@tonic-gate(A)"",				/* 13 */
3687c478bdstevel@tonic-gate(A)"",				/* 14 */
3697c478bdstevel@tonic-gate(A)"",				/* 15 */
3707c478bdstevel@tonic-gate(A)"",				/* 16 */
3717c478bdstevel@tonic-gate(A)"",				/* 17 */
3727c478bdstevel@tonic-gate(A)"",				/* 18 */
3737c478bdstevel@tonic-gate(A)"",				/* 19 */
3747c478bdstevel@tonic-gate(A)"",				/* 20 */
3757c478bdstevel@tonic-gate(A)"",				/* 21 */
3767c478bdstevel@tonic-gate(A)"",				/* 22 */
3777c478bdstevel@tonic-gate(A)"",				/* 23 */
3787c478bdstevel@tonic-gate(A)"",				/* 24 */
3797c478bdstevel@tonic-gate(A)"",				/* 25 */
3807c478bdstevel@tonic-gate(A)"",				/* 26 */
3817c478bdstevel@tonic-gate(A)"",				/* 27 */
3827c478bdstevel@tonic-gate(A)"",				/* 28 */
3837c478bdstevel@tonic-gate(A)"",				/* 29 */
3847c478bdstevel@tonic-gate(A)"",				/* 30 */
3857c478bdstevel@tonic-gate(A)"" 				/* 31 */
3867c478bdstevel@tonic-gate};
3877c478bdstevel@tonic-gate
3887c478bdstevel@tonic-gatetypedef struct asndefS {
3897c478bdstevel@tonic-gatechar *name;
3907c478bdstevel@tonic-gateint type;
3917c478bdstevel@tonic-gateint application;
3927c478bdstevel@tonic-gateint nbson;
3937c478bdstevel@tonic-gatestruct {
3947c478bdstevel@tonic-gate	char *sonname;
3957c478bdstevel@tonic-gate	struct asndefS *sondef;
3967c478bdstevel@tonic-gate	long tag;
3977c478bdstevel@tonic-gate	} son[50];
3987c478bdstevel@tonic-gate} asndefT, * asndefTp;
3997c478bdstevel@tonic-gate
4007c478bdstevel@tonic-gate#define	SEQUENCE		0x0002
4017c478bdstevel@tonic-gate#define	SEQUENCEOF		0x0003
4027c478bdstevel@tonic-gate#define	SET				0x0004
4037c478bdstevel@tonic-gate#define	PRINTABLE		0x0008
4047c478bdstevel@tonic-gate#define	ENUM			0x0010
4057c478bdstevel@tonic-gate#define	BITSTRING		0x0020
4067c478bdstevel@tonic-gate#define	EXTENSION		0x0040
4077c478bdstevel@tonic-gate#define	CONTENTTYPE		0x0080
4087c478bdstevel@tonic-gate#define	CONTENT			0x0100
4097c478bdstevel@tonic-gate#define	CHOICE			0x0200
4107c478bdstevel@tonic-gate
4117c478bdstevel@tonic-gatestatic asndefT RTSpasswd = { "RTS Authentification data", SET,  -1, 2, {
4127c478bdstevel@tonic-gate			{"MTA Name", 0, 0},
4137c478bdstevel@tonic-gate			{"MTA Password", 0, 1}}};
4147c478bdstevel@tonic-gatestatic asndefT RTSudata = { "RTS User data", SET,  -1, 1, {
4157c478bdstevel@tonic-gate			{0, &RTSpasswd, 1}}};
4167c478bdstevel@tonic-gate
4177c478bdstevel@tonic-gatestatic asndefT baseObject = {"Base Object", PRINTABLE, -1, 0, {0}};
4187c478bdstevel@tonic-gate
4197c478bdstevel@tonic-gatestatic asndefT scope = {"Scope", ENUM, -1, 3, {
4207c478bdstevel@tonic-gate			{"BaseObject", 0, 0},
4217c478bdstevel@tonic-gate			{"singleLevel", 0, 1},
4227c478bdstevel@tonic-gate			{"wholeSubtree", 0, 2}}};
4237c478bdstevel@tonic-gate
4247c478bdstevel@tonic-gatestatic asndefT derefAliases = {"DerefAliases", ENUM, -1, 4, {
4257c478bdstevel@tonic-gate			{"neverDerefAliases", 0, 0},
4267c478bdstevel@tonic-gate			{"derefInSearching", 0, 1},
4277c478bdstevel@tonic-gate			{"derefFindingBaseObj", 0, 2},
4287c478bdstevel@tonic-gate			{"derefAlways", 0, 3}}};
4297c478bdstevel@tonic-gate
4307c478bdstevel@tonic-gatestatic asndefT filter;
4317c478bdstevel@tonic-gatestatic asndefT and = {"And", SET, -1, 1, {
4327c478bdstevel@tonic-gate			{0, &filter, -1}}};
4337c478bdstevel@tonic-gatestatic asndefT or = {"Or", SET, -1, 1, {
4347c478bdstevel@tonic-gate			{0, &filter, -1}}};
4357c478bdstevel@tonic-gatestatic asndefT not = {"Not", SET, -1, 1, {
4367c478bdstevel@tonic-gate			{0, &filter, -1}}};
4377c478bdstevel@tonic-gatestatic asndefT equalityMatch = {"Equality Match", SEQUENCE, -1, 2, {
4387c478bdstevel@tonic-gate			{"Attr Descr", 0, -1},
4397c478bdstevel@tonic-gate			{"Value", 0, -1}}};
4407c478bdstevel@tonic-gatestatic asndefT substrings = {"Substring", SEQUENCE, -1, 2, {
4417c478bdstevel@tonic-gate			{"Type", 0, -1},
4427c478bdstevel@tonic-gate			{"Substrings (initial)", 0, 0},
4437c478bdstevel@tonic-gate			{"Substrings (any)", 0, 1},
4447c478bdstevel@tonic-gate			{"Substring (final)", 0, 2}}};
4457c478bdstevel@tonic-gatestatic asndefT greaterOrEqual = {"Greater Or Equal", SEQUENCE, -1, 2, {
4467c478bdstevel@tonic-gate			{"Attr Descr", 0, -1},
4477c478bdstevel@tonic-gate			{"Value", 0, -1}}};
4487c478bdstevel@tonic-gatestatic asndefT lessOrEqual = {"Less Or Equal", SEQUENCE, -1, 2, {
4497c478bdstevel@tonic-gate			{"Attr Descr", 0, -1},
4507c478bdstevel@tonic-gate			{"Value", 0, -1}}};
4517c478bdstevel@tonic-gatestatic asndefT approxMatch = {"Approx Match", SEQUENCE, -1, 2, {
4527c478bdstevel@tonic-gate			{"Attr Descr", 0, -1},
4537c478bdstevel@tonic-gate			{"Value", 0, -1}}};
4547c478bdstevel@tonic-gatestatic asndefT extensibleMatch = {"Extensible Match", SEQUENCE, -1, 4, {
4557c478bdstevel@tonic-gate			{"MatchingRule", 0, 1},
4567c478bdstevel@tonic-gate			{"Type", 0, 2},
4577c478bdstevel@tonic-gate			{"MatchValue", 0, 3},
4587c478bdstevel@tonic-gate			{"dnAttributes", 0, 4}}};
4597c478bdstevel@tonic-gate
4607c478bdstevel@tonic-gatestatic asndefT filter = {"Filter", CHOICE, -1, 10, {
4617c478bdstevel@tonic-gate			{0, &and, 0},
4627c478bdstevel@tonic-gate			{0, &or, 1},
4637c478bdstevel@tonic-gate			{0, &not, 2},
4647c478bdstevel@tonic-gate			{0, &equalityMatch, 3},
4657c478bdstevel@tonic-gate			{0, &substrings, 4},
4667c478bdstevel@tonic-gate			{0, &greaterOrEqual, 5},
4677c478bdstevel@tonic-gate			{0, &lessOrEqual, 6},
4687c478bdstevel@tonic-gate			{"Filter: Present", 0, 7},
4697c478bdstevel@tonic-gate			{0, &approxMatch, 8},
4707c478bdstevel@tonic-gate			{0, &extensibleMatch, 9}}};
4717c478bdstevel@tonic-gate
4727c478bdstevel@tonic-gatestatic asndefT attributedescription = \
4737c478bdstevel@tonic-gate			{"Attribute Description", PRINTABLE, -1, 0, {0}};
4747c478bdstevel@tonic-gatestatic asndefT attributes = {"Attribute List", SEQUENCEOF, -1, 1, {
4757c478bdstevel@tonic-gate			{0, &attributedescription, -1}}};
4767c478bdstevel@tonic-gate
4777c478bdstevel@tonic-gatestatic asndefT searchRequest = {"Operation", SEQUENCE, 3, 8, {
4787c478bdstevel@tonic-gate			{0, &baseObject, -1},
4797c478bdstevel@tonic-gate			{0, &scope, -1},
4807c478bdstevel@tonic-gate			{0, &derefAliases, -1},
4817c478bdstevel@tonic-gate			{"SizeLimit", 0, -1},
4827c478bdstevel@tonic-gate			{"TimeLimit", 0, -1},
4837c478bdstevel@tonic-gate			{"TypesOnly", 0, -1},
4847c478bdstevel@tonic-gate			{0, &filter, -1},
4857c478bdstevel@tonic-gate			{0, &attributes, -1}}};
4867c478bdstevel@tonic-gate
4877c478bdstevel@tonic-gatestatic asndefT objectName = {"Object Name", PRINTABLE, -1, 0, {0}};
4887c478bdstevel@tonic-gate
4897c478bdstevel@tonic-gatestatic asndefT ldapEntry = {"Entry", PRINTABLE, -1, 0, {0}};
4907c478bdstevel@tonic-gatestatic asndefT relativeLdapEntry = \
4917c478bdstevel@tonic-gate			{"Relative LDAP Entry", PRINTABLE, -1, 0, {0}};
4927c478bdstevel@tonic-gatestatic asndefT newSuperior = {"New Superior", PRINTABLE, -1, 0, {0}};
4937c478bdstevel@tonic-gate
4947c478bdstevel@tonic-gatestatic asndefT vals = {"Vals", SET, -1, 1, {
4957c478bdstevel@tonic-gate			{"Value", 0, -1}}};
4967c478bdstevel@tonic-gate
4977c478bdstevel@tonic-gatestatic asndefT attribute = {"Attribute", SEQUENCE, -1, 2, {
4987c478bdstevel@tonic-gate			{"Type", 0, -1},
4997c478bdstevel@tonic-gate			{0, &vals, -1}}};
5007c478bdstevel@tonic-gate
5017c478bdstevel@tonic-gatestatic asndefT partialAttributes = {"Partial Attributes", SEQUENCEOF, -1, 1, {
5027c478bdstevel@tonic-gate			{0, &attribute, -1}}};
5037c478bdstevel@tonic-gate
5047c478bdstevel@tonic-gatestatic asndefT searchResEntry = {"Operation", SEQUENCE, 4, 2, {
5057c478bdstevel@tonic-gate			{0, &objectName, -1},
5067c478bdstevel@tonic-gate			{0, &partialAttributes, -1}}};
5077c478bdstevel@tonic-gate
5087c478bdstevel@tonic-gatestatic asndefT authChoice = {"Authentication Choice", CHOICE, -1, 2, {
5097c478bdstevel@tonic-gate			{"Authentication: Simple", 0, 0},
5107c478bdstevel@tonic-gate			{"Authentication: SASL", 0, 3}}};
5117c478bdstevel@tonic-gate
5127c478bdstevel@tonic-gatestatic asndefT bindRequest = {"Operation", SEQUENCE, 0, 3, {
5137c478bdstevel@tonic-gate			{"Version", 0, -1},
5147c478bdstevel@tonic-gate			{0, &objectName, -1},
5157c478bdstevel@tonic-gate			{0, &authChoice, -1}}};
5167c478bdstevel@tonic-gate
5177c478bdstevel@tonic-gatestatic asndefT resultCode = {"Result Code", ENUM, -1, 39, {
5187c478bdstevel@tonic-gate			{"Success", 0, 0},
5197c478bdstevel@tonic-gate			{"Operation Error", 0, 1},
5207c478bdstevel@tonic-gate			{"Protocol Error", 0, 2},
5217c478bdstevel@tonic-gate			{"Time Limit Exceeded", 0, 3},
5227c478bdstevel@tonic-gate			{"Size Limit Exceeded", 0, 4},
5237c478bdstevel@tonic-gate			{"Compare False", 0, 5},
5247c478bdstevel@tonic-gate			{"Compare True", 0, 6},
5257c478bdstevel@tonic-gate			{"Auth Method Not supported", 0, 7},
5267c478bdstevel@tonic-gate			{"Strong Auth Required", 0, 8},
5277c478bdstevel@tonic-gate			{"Referral", 0, 10},
5287c478bdstevel@tonic-gate			{"Admin Limit Exceeded", 0, 11},
5297c478bdstevel@tonic-gate			{"Unavailable Critical Extension", 0, 12},
5307c478bdstevel@tonic-gate			{"Confidentiality required", 0, 13},
5317c478bdstevel@tonic-gate			{"SASL Bind In Progress", 0, 14},
5327c478bdstevel@tonic-gate			{"No Such Attribute", 0, 16},
5337c478bdstevel@tonic-gate			{"Undefined Attribute Type", 0, 17},
5347c478bdstevel@tonic-gate			{"Inappropriate Matching", 0, 18},
5357c478bdstevel@tonic-gate			{"Constraint violation", 0, 19},
5367c478bdstevel@tonic-gate			{"Attribute or Value Exists", 0, 20},
5377c478bdstevel@tonic-gate			{"Invalid Attribute Syntax", 0, 21},
5387c478bdstevel@tonic-gate			{"No Such Object", 0, 32},
5397c478bdstevel@tonic-gate			{"Alias Problem", 0, 33},
5407c478bdstevel@tonic-gate			{"Invalid DN Syntax", 0, 34},
5417c478bdstevel@tonic-gate			{"Alias Dereferencing Problem", 0, 36},
5427c478bdstevel@tonic-gate			{"Inappropriate Authentication", 0, 48},
5437c478bdstevel@tonic-gate			{"Invalid Credentials", 0, 49},
5447c478bdstevel@tonic-gate			{"Insufficient Access Rights", 0, 50},
5457c478bdstevel@tonic-gate			{"Busy", 0, 51},
5467c478bdstevel@tonic-gate			{"Unavailable", 0, 52},
5477c478bdstevel@tonic-gate			{"Unwilling To Perform", 0, 53},
5487c478bdstevel@tonic-gate			{"Loop Detect", 0, 54},
5497c478bdstevel@tonic-gate			{"Naming Violation", 0, 64},
5507c478bdstevel@tonic-gate			{"ObjectClass violation", 0, 65},
5517c478bdstevel@tonic-gate			{"Not Allowed On Non Leaf", 0, 66},
5527c478bdstevel@tonic-gate			{"Not Allowed On RDN", 0, 67},
5537c478bdstevel@tonic-gate			{"Entry Already Exists", 0, 68},
5547c478bdstevel@tonic-gate			{"ObjectClass Mods Prohibited", 0, 69},
5557c478bdstevel@tonic-gate			{"Affects Multiple DSAs", 0, 71},
5567c478bdstevel@tonic-gate			{"Other", 0, 80}}};
5577c478bdstevel@tonic-gate
5587c478bdstevel@tonic-gate
5597c478bdstevel@tonic-gatestatic asndefT referral = {"Referral", SEQUENCEOF, -1, 1, {
5607c478bdstevel@tonic-gate			{"LDAP URL", 0, -1}}};
5617c478bdstevel@tonic-gate
5627c478bdstevel@tonic-gatestatic asndefT ldapResult = {"LDAP Result", SEQUENCE, -1, 4, {
5637c478bdstevel@tonic-gate			{0, &resultCode, -1},
5647c478bdstevel@tonic-gate			{"Matched DN", 0, -1},
5657c478bdstevel@tonic-gate			{"Error Message", 0, -1},
5667c478bdstevel@tonic-gate			{0, &referral, 3}}};
5677c478bdstevel@tonic-gate
5687c478bdstevel@tonic-gatestatic asndefT bindResponse = {"Operation", SEQUENCE, 1, 5, {
5697c478bdstevel@tonic-gate			{0, &resultCode, -1},
5707c478bdstevel@tonic-gate			{"Matched DN", 0, -1},
5717c478bdstevel@tonic-gate			{"Error Message", 0, -1},
5727c478bdstevel@tonic-gate			{0, &referral, 3},
5737c478bdstevel@tonic-gate			{"SASL Credentials", 0, 7}}};
5747c478bdstevel@tonic-gate
5757c478bdstevel@tonic-gatestatic asndefT unbindRequest = {"Operation", SEQUENCE, 2, 0, {0}};
5767c478bdstevel@tonic-gate
5777c478bdstevel@tonic-gatestatic asndefT searchResDone = {"Operation", SEQUENCE, 5, 4, {
5787c478bdstevel@tonic-gate			{0, &resultCode, -1},
5797c478bdstevel@tonic-gate			{"Matched DN", 0, -1},
5807c478bdstevel@tonic-gate			{"Error Message", 0, -1},
5817c478bdstevel@tonic-gate			{0, &referral, 3}}};
5827c478bdstevel@tonic-gate
5837c478bdstevel@tonic-gatestatic asndefT seqModOperation = {"Operation", ENUM, -1, 4, {
5847c478bdstevel@tonic-gate			{"Add", 0, 0},
5857c478bdstevel@tonic-gate			{"Delete", 0, 1},
5867c478bdstevel@tonic-gate			{"Replace", 0, 2}}};
5877c478bdstevel@tonic-gate
5887c478bdstevel@tonic-gatestatic asndefT seqModModification = {"Modification", SEQUENCE, -1, 1, {
5897c478bdstevel@tonic-gate			{0, &attribute, -1}}};
5907c478bdstevel@tonic-gate
5917c478bdstevel@tonic-gatestatic asndefT seqModification = {"", SEQUENCE, -1, 2, {
5927c478bdstevel@tonic-gate		    {0, &seqModOperation, -1},
5937c478bdstevel@tonic-gate			{0, &seqModModification, -1}}};
5947c478bdstevel@tonic-gate
5957c478bdstevel@tonic-gatestatic asndefT modification = {"Modification", SEQUENCEOF, -1, 1, {
5967c478bdstevel@tonic-gate			{0, &seqModification, -1}}};
5977c478bdstevel@tonic-gate
5987c478bdstevel@tonic-gatestatic asndefT modifyRequest = {"Operation", SEQUENCE, 6, 2, {
5997c478bdstevel@tonic-gate			{0, &objectName, -1},
6007c478bdstevel@tonic-gate			{0, &modification, -1}}};
6017c478bdstevel@tonic-gate
6027c478bdstevel@tonic-gatestatic asndefT modifyResponse = {"Operation", SEQUENCE, 7, 4, {
6037c478bdstevel@tonic-gate			{0, &resultCode, -1},
6047c478bdstevel@tonic-gate			{"Matched DN", 0, -1},
6057c478bdstevel@tonic-gate			{"Error Message", 0, -1},
6067c478bdstevel@tonic-gate			{0, &referral, 3}}};
6077c478bdstevel@tonic-gate
6087c478bdstevel@tonic-gatestatic asndefT addAttributes = {"Attributes", SEQUENCEOF, -1, 1, {
6097c478bdstevel@tonic-gate			{0, &attribute, -1}}};
6107c478bdstevel@tonic-gate
6117c478bdstevel@tonic-gatestatic asndefT addRequest = {"Operation", SEQUENCE, 8, 2, {
6127c478bdstevel@tonic-gate			{0, &ldapEntry, -1},
6137c478bdstevel@tonic-gate			{0, &addAttributes, -1}}};
6147c478bdstevel@tonic-gate
6157c478bdstevel@tonic-gatestatic asndefT addResponse = {"Operation", SEQUENCE, 9, 4, {
6167c478bdstevel@tonic-gate			{0, &resultCode, -1},
6177c478bdstevel@tonic-gate			{"Matched DN", 0, -1},
6187c478bdstevel@tonic-gate			{"Error Message", 0, -1},
6197c478bdstevel@tonic-gate			{0, &referral, 3}}};
6207c478bdstevel@tonic-gate
6217c478bdstevel@tonic-gatestatic asndefT delRequest = {"Operation", SEQUENCE, 10, 1, {
6227c478bdstevel@tonic-gate			{0, &ldapEntry, -1}}};
6237c478bdstevel@tonic-gate
6247c478bdstevel@tonic-gatestatic asndefT delResponse = {"Operation", SEQUENCE, 11, 4, {
6257c478bdstevel@tonic-gate			{0, &resultCode, -1},
6267c478bdstevel@tonic-gate			{"Matched DN", 0, -1},
6277c478bdstevel@tonic-gate			{"Error Message", 0, -1},
6287c478bdstevel@tonic-gate			{0, &referral, 3}}};
6297c478bdstevel@tonic-gate
6307c478bdstevel@tonic-gatestatic asndefT modifyDNRequest = {"Operation", SEQUENCE, 12, 4, {
6317c478bdstevel@tonic-gate			{0, &ldapEntry, -1},
6327c478bdstevel@tonic-gate			{0, &relativeLdapEntry, -1},
6337c478bdstevel@tonic-gate			{"Delete Old RDN", 0, -1},
6347c478bdstevel@tonic-gate			{0, &newSuperior, 0}}};
6357c478bdstevel@tonic-gate
6367c478bdstevel@tonic-gatestatic asndefT modifyDNResponse = {"Operation", SEQUENCE, 13, 4, {
6377c478bdstevel@tonic-gate			{0, &resultCode, -1},
6387c478bdstevel@tonic-gate			{"Matched DN", 0, -1},
6397c478bdstevel@tonic-gate			{"Error Message", 0, -1},
6407c478bdstevel@tonic-gate			{0, &referral, 3}}};
6417c478bdstevel@tonic-gate
6427c478bdstevel@tonic-gatestatic asndefT ava = {"Ava", SEQUENCE, -1, 2, {
6437c478bdstevel@tonic-gate			{"Attr Descr", 0, -1},
6447c478bdstevel@tonic-gate			{"Value", 0, -1}}};
6457c478bdstevel@tonic-gate
6467c478bdstevel@tonic-gatestatic asndefT compareRequest = {"Operation", SEQUENCE, 14, 2, {
6477c478bdstevel@tonic-gate			{0, &ldapEntry, -1},
6487c478bdstevel@tonic-gate			{0, &ava, 0}}};
6497c478bdstevel@tonic-gate
6507c478bdstevel@tonic-gatestatic asndefT compareResponse = {"Operation", SEQUENCE, 15, 4, {
6517c478bdstevel@tonic-gate			{0, &resultCode, -1},
6527c478bdstevel@tonic-gate			{"Matched DN", 0, -1},
6537c478bdstevel@tonic-gate			{"Error Message", 0, -1},
6547c478bdstevel@tonic-gate			{0, &referral, 3}}};
6557c478bdstevel@tonic-gate
6567c478bdstevel@tonic-gatestatic asndefT abandonRequest = {"Operation", SEQUENCE, 16, 1, {
6577c478bdstevel@tonic-gate		    {"Message ID", 0, -1}}};
6587c478bdstevel@tonic-gate
6597c478bdstevel@tonic-gatestatic asndefT searchResRef =  {"Operation", SEQUENCEOF, 19, 1, {
6607c478bdstevel@tonic-gate			{"LDAP URL", 0, -1}}};
6617c478bdstevel@tonic-gate
6627c478bdstevel@tonic-gatestatic asndefT extendedRequest = {"Operation", SEQUENCE, 14, 2, {
6637c478bdstevel@tonic-gate			{"Request Name", 0, 0},
6647c478bdstevel@tonic-gate			{"Request Value", 0, 1}}};
6657c478bdstevel@tonic-gate
6667c478bdstevel@tonic-gatestatic asndefT extendedResponse = {"Operation", SEQUENCE, 24, 6, {
6677c478bdstevel@tonic-gate			{0, &resultCode, -1},
6687c478bdstevel@tonic-gate			{"Matched DN", 0, -1},
6697c478bdstevel@tonic-gate			{"Error Message", 0, -1},
6707c478bdstevel@tonic-gate			{0, &referral, 3},
6717c478bdstevel@tonic-gate			{"Response Name", 0, 10},
6727c478bdstevel@tonic-gate			{"Response", 0, 11}}};
6737c478bdstevel@tonic-gate
6747c478bdstevel@tonic-gatestatic asndefT protocolOp = {"Protocol Op", CHOICE, -1, 20, {
6757c478bdstevel@tonic-gate			{0, &bindRequest, 0},
6767c478bdstevel@tonic-gate			{0, &bindResponse, 1},
6777c478bdstevel@tonic-gate			{0, &unbindRequest, 2},
6787c478bdstevel@tonic-gate			{0, &searchRequest, 3},
6797c478bdstevel@tonic-gate			{0, &searchResEntry, 4},
6807c478bdstevel@tonic-gate			{0, &searchResDone, 5},
6817c478bdstevel@tonic-gate			{0, &modifyRequest, 6},
6827c478bdstevel@tonic-gate			{0, &modifyResponse, 7},
6837c478bdstevel@tonic-gate			{0, &addRequest, 8},
6847c478bdstevel@tonic-gate			{0, &addResponse, 9},
6857c478bdstevel@tonic-gate			{0, &delRequest, 10},
6867c478bdstevel@tonic-gate			{0, &delResponse, 11},
6877c478bdstevel@tonic-gate			{0, &modifyDNRequest, 12},
6887c478bdstevel@tonic-gate			{0, &modifyDNResponse, 13},
6897c478bdstevel@tonic-gate			{0, &compareRequest, 14},
6907c478bdstevel@tonic-gate			{0, &compareResponse, 15},
6917c478bdstevel@tonic-gate			{0, &abandonRequest, 16},
6927c478bdstevel@tonic-gate			{0, &searchResRef, 19},
6937c478bdstevel@tonic-gate			{0, &extendedRequest, 23},
6947c478bdstevel@tonic-gate			{0, &extendedResponse, 24}}};
6957c478bdstevel@tonic-gate
6967c478bdstevel@tonic-gatestatic asndefT control = {"Control", SEQUENCE, -1, 3, {
6977c478bdstevel@tonic-gate			{"LDAP OID", 0, -1},
6987c478bdstevel@tonic-gate			{"Criticality", 0, -1},
6997c478bdstevel@tonic-gate			{"Control value", 0, -1}}};
7007c478bdstevel@tonic-gate
7017c478bdstevel@tonic-gatestatic asndefT controls = {"Controls List", SEQUENCEOF, -1, 1, {
7027c478bdstevel@tonic-gate	{0, &control, -1}}};
7037c478bdstevel@tonic-gate
7047c478bdstevel@tonic-gatestatic asndefT LDAPMessage = { "LDAPMessage", SEQUENCE, -1, 3, {
7057c478bdstevel@tonic-gate			{"Message ID", 0, -1},
7067c478bdstevel@tonic-gate			{0, &protocolOp, -1},
7077c478bdstevel@tonic-gate			{0, &controls, 0}}};
7087c478bdstevel@tonic-gate
7097c478bdstevel@tonic-gatestatic asndefT MPDU = { "MPDU", SET,  -1, 1,
7107c478bdstevel@tonic-gate			{{0, &LDAPMessage, 0}}};
7117c478bdstevel@tonic-gate
7127c478bdstevel@tonic-gatestatic int mytype[] = {
7137c478bdstevel@tonic-gate0,			/* EndOfContents	*/
7147c478bdstevel@tonic-gate0,			/* Boolean			*/
7157c478bdstevel@tonic-gate0,			/* Integer			*/
7167c478bdstevel@tonic-gateBITSTRING,	/* BitString		*/
7177c478bdstevel@tonic-gate0,			/* OctetString		*/
7187c478bdstevel@tonic-gate0,			/* Null				*/
7197c478bdstevel@tonic-gate0,			/* Oid				*/
7207c478bdstevel@tonic-gate0,			/* ObjDescriptor	*/
7217c478bdstevel@tonic-gate0,			/* External			*/
7227c478bdstevel@tonic-gate0,			/* Real				*/
7237c478bdstevel@tonic-gateENUM,		/* Enumerated		*/
7247c478bdstevel@tonic-gate0,			/* Reserved			*/
7257c478bdstevel@tonic-gate0,			/* Reserved			*/
7267c478bdstevel@tonic-gate0,			/* Reserved			*/
7277c478bdstevel@tonic-gate0,			/* Reserved			*/
7287c478bdstevel@tonic-gate0,			/* Reserved			*/
7297c478bdstevel@tonic-gateSEQUENCE,	/* Sequence			*/
7307c478bdstevel@tonic-gateSET,		/* Set				*/
7317c478bdstevel@tonic-gate0,			/* NumericString	*/
7327c478bdstevel@tonic-gate0,			/* PrintableString	*/
7337c478bdstevel@tonic-gate0,			/* T.61String		*/
7347c478bdstevel@tonic-gate0,			/* VideotexString	*/
7357c478bdstevel@tonic-gate0,			/* IA5String		*/
7367c478bdstevel@tonic-gate0,			/* UTCTime			*/
7377c478bdstevel@tonic-gate0,			/* GeneralizedTime	*/
7387c478bdstevel@tonic-gate0,			/* GraphicString	*/
7397c478bdstevel@tonic-gate0,			/* VisibleString	*/
7407c478bdstevel@tonic-gate0,			/* GeneralString	*/
7417c478bdstevel@tonic-gate0,			/* Reserved			*/
7427c478bdstevel@tonic-gate0,			/* Reserved			*/
7437c478bdstevel@tonic-gate0,			/* Reserved			*/
7447c478bdstevel@tonic-gate0,			/* Reserved			*/
7457c478bdstevel@tonic-gate};
7467c478bdstevel@tonic-gate
7477c478bdstevel@tonic-gate/*
7482e3b646kcpoon * Find object identifier in known oid table
7492e3b646kcpoon * A	oid - oid hexa string
7502e3b646kcpoon * int	olg - oid length
7512e3b646kcpoon */
7522e3b646kcpoonstatic int
7532e3b646kcpoonoidmap(A oid, int olg)
7547c478bdstevel@tonic-gate{
7557c478bdstevel@tonic-gate	register int ix, goon;
7567c478bdstevel@tonic-gate	register A oidptr, tabptr, tabend;
7577c478bdstevel@tonic-gate
7587c478bdstevel@tonic-gate/* returns (oid table size) if not found */
7597c478bdstevel@tonic-gate
7607c478bdstevel@tonic-gate	for (ix = 0; ix < OIDNB; ix++) {
7617c478bdstevel@tonic-gate		oidptr = oid; tabptr = (&(OidTab[ix].oidcode[0]));
7627c478bdstevel@tonic-gate		if (olg == INT(*tabptr++)) {
7632e3b646kcpoon			tabend = tabptr + olg;
7642e3b646kcpoon			goon = 1;
7652e3b646kcpoon			while (goon != 0 && tabptr < tabend) {
7662e3b646kcpoon				if (*tabptr++ != *oidptr++)
7672e3b646kcpoon					goon = 0;
7687c478bdstevel@tonic-gate			}
7692e3b646kcpoon			if (goon != 0)
7707c478bdstevel@tonic-gate				return (ix);
7717c478bdstevel@tonic-gate		}
7727c478bdstevel@tonic-gate	}
7737c478bdstevel@tonic-gate	return (OIDNB);
7747c478bdstevel@tonic-gate}
7757c478bdstevel@tonic-gate
7767c478bdstevel@tonic-gate/*
7772e3b646kcpoon * Read an hexacode and convert it into ASCII
7782e3b646kcpoon */
7797c478bdstevel@tonic-gatestatic int getnext(int ctxnum)
7807c478bdstevel@tonic-gate{
7817c478bdstevel@tonic-gate	static X c[3]; /* c[0-3] will contain ascii values on exit */
7827c478bdstevel@tonic-gate	hex = 0;
7837c478bdstevel@tonic-gate	if (gi_osibuf[ctxnum] == osilen)
7847c478bdstevel@tonic-gate		return (-1);
7857c478bdstevel@tonic-gate	hex = osibuff[gi_osibuf[ctxnum]++];
7867c478bdstevel@tonic-gate	(void) sprintf((char *)c, "%02x", (hex&0x00FF));
7877c478bdstevel@tonic-gate	return (0);
7887c478bdstevel@tonic-gate}
7897c478bdstevel@tonic-gate
7907c478bdstevel@tonic-gate/*
7912e3b646kcpoon * Skip everything that is not an LDAPMessage
7922e3b646kcpoon */
7937c478bdstevel@tonic-gatestatic char *skipjunk(len, pdu)
7947c478bdstevel@tonic-gateint len;
7957c478bdstevel@tonic-gatechar *pdu;
7967c478bdstevel@tonic-gate{
7977c478bdstevel@tonic-gate	int tag;
7987c478bdstevel@tonic-gate	char *buf = pdu;
7997c478bdstevel@tonic-gate	int offset = 0;
8007c478bdstevel@tonic-gate	while (len > 0) {
8017c478bdstevel@tonic-gate		/* size minumum for a sequence + integer = 5 */
8027c478bdstevel@tonic-gate		/* LDAPMessage::= SEQUENCE  */
8037c478bdstevel@tonic-gate		if ((len > 5) && (buf[0] == 0x30)) {
8047c478bdstevel@tonic-gate			tag = buf[1]&0x00ff;
8057c478bdstevel@tonic-gate			if (tag < 0x80) {
8067c478bdstevel@tonic-gate				/* length is one one octet */
8077c478bdstevel@tonic-gate				offset = 1;
8087c478bdstevel@tonic-gate			} else {
8097c478bdstevel@tonic-gate				/* length is multiple octet.  */
8107c478bdstevel@tonic-gate				offset = 1+ tag&0x007f;
8117c478bdstevel@tonic-gate			}
8127c478bdstevel@tonic-gate			/* Make sure we don't read past the end */
8137c478bdstevel@tonic-gate			/* of the buffer */
8147c478bdstevel@tonic-gate			if (len - (1+offset) > 0) {
8157c478bdstevel@tonic-gate				/* skip after the length */
8167c478bdstevel@tonic-gate				tag = buf[1+offset]&0x00ff;
8177c478bdstevel@tonic-gate				if (tag == 0x02) { /* INTEGER */
8187c478bdstevel@tonic-gate					/* looks like a valid PDU */
8197c478bdstevel@tonic-gate					return (buf);
8207c478bdstevel@tonic-gate				}
8217c478bdstevel@tonic-gate			}
8227c478bdstevel@tonic-gate		}
8237c478bdstevel@tonic-gate		len --;
8247c478bdstevel@tonic-gate		buf++;
8257c478bdstevel@tonic-gate	}
8267c478bdstevel@tonic-gate	return (buf);
8277c478bdstevel@tonic-gate}
8282e3b646kcpoon
8292e3b646kcpoon
8307c478bdstevel@tonic-gate#define	GETNEXT(a) (void)getnext(a);
8312e3b646kcpoon
8322e3b646kcpoon/*
8332e3b646kcpoon * main routine: decode a TLV; to be called recursively
8342e3b646kcpoon *
8352e3b646kcpoon * pdulen: current pdu's length
8362e3b646kcpoon */
8372e3b646kcpoonstatic int
8382e3b646kcpoondecpdu(int pdulen, asndefTp ASNDESC, int ctxnum)
8397c478bdstevel@tonic-gate{
8407c478bdstevel@tonic-gate	X		scrlin[99];	/* screen line */
8417c478bdstevel@tonic-gate	X		oidstr[80];	/* oid hexa string */
8427c478bdstevel@tonic-gate	int		slen;	/* screen line length */
8437c478bdstevel@tonic-gate	int		stlv;	/* sub-tlv length */
8447c478bdstevel@tonic-gate	int		oix;	/* oid table index */
8457c478bdstevel@tonic-gate	int		effnb;	/* effectively traced octet nb */
846166fae4pk	int		i = 0, j = 0;
8477c478bdstevel@tonic-gate	int		ai = -2;
8487c478bdstevel@tonic-gate	asndefTp SASNDESC = 0;
8497c478bdstevel@tonic-gate	asndefTp TMPDESC = 0;
8507c478bdstevel@tonic-gate	asndefTp GR_TMPDESC = 0;
8517c478bdstevel@tonic-gate	int tmpai = 0;
8527c478bdstevel@tonic-gate	int gr_tmpai = 0;
8537c478bdstevel@tonic-gate	int dontprint = 0;
8547c478bdstevel@tonic-gate	int already = 0;
8557c478bdstevel@tonic-gate	static int rlen = 0;	/* tlv's real length */
8567c478bdstevel@tonic-gate
8577c478bdstevel@tonic-gate	++level[ctxnum];	/* level indicator */
8587c478bdstevel@tonic-gate	effnb = 0;
8597c478bdstevel@tonic-gate
8607c478bdstevel@tonic-gate	/*
8612e3b646kcpoon	 * Decode the current TLV segment
8622e3b646kcpoon	 */
8637c478bdstevel@tonic-gate	while (pdulen > 1) {
8647c478bdstevel@tonic-gate
8657c478bdstevel@tonic-gate		if (getnext(ctxnum)) {
8667c478bdstevel@tonic-gate			break;
8677c478bdstevel@tonic-gate		}
8687c478bdstevel@tonic-gate		if (strlen(scrbuffer)) asnshw2("%s  ", "LDAP:");
8697c478bdstevel@tonic-gate		/* screen printing according to level indicator */
8707c478bdstevel@tonic-gate		for (i = 1; i < level[ctxnum]; ++i) asnshw1("   ");
8717c478bdstevel@tonic-gate
8727c478bdstevel@tonic-gate		/* get tag */
8737c478bdstevel@tonic-gate		otyp[ctxnum] = INT(hex); /* single octet type only */
8747c478bdstevel@tonic-gate		--pdulen;
8757c478bdstevel@tonic-gate		++effnb;
8767c478bdstevel@tonic-gate
8777c478bdstevel@tonic-gate		/* get length */
8787c478bdstevel@tonic-gate		GETNEXT(ctxnum);
8797c478bdstevel@tonic-gate		olen[ctxnum] = INT(hex);	/* tlv length */
8807c478bdstevel@tonic-gate		--pdulen;
8817c478bdstevel@tonic-gate		++effnb;
8827c478bdstevel@tonic-gate
8837c478bdstevel@tonic-gate		/* Continuing decoding of current TLV... */
8847c478bdstevel@tonic-gate		/*
8852e3b646kcpoon		 * Snoop's lower layers do not allow us
8862e3b646kcpoon		 * to know the true length for
8872e3b646kcpoon		 * datastream protocols like LDAP.
8882e3b646kcpoon		 */
8897c478bdstevel@tonic-gate
8902e3b646kcpoon		/*
8912e3b646kcpoon		 * if length is less than 128, we
8922e3b646kcpoon		 * already have the real TLV length.
8932e3b646kcpoon		 */
8947c478bdstevel@tonic-gate		if (olen[ctxnum] < 128) {	/* short length form */
8957c478bdstevel@tonic-gate			rlen = olen[ctxnum];
8967c478bdstevel@tonic-gate		} else {		/* long and any form length */
8977c478bdstevel@tonic-gate		/* else we do more getnext()'s */
8987c478bdstevel@tonic-gate			for (rlen = 0, olen[ctxnum] &= 0x0F;
8997c478bdstevel@tonic-gate			(olen[ctxnum]) && (pdulen > 0);
9007c478bdstevel@tonic-gate			--olen[ctxnum], --pdulen, ++effnb) {
9017c478bdstevel@tonic-gate				GETNEXT(ctxnum);
9027c478bdstevel@tonic-gate				rlen = (rlen << 8) | INT(hex);
9037c478bdstevel@tonic-gate			}
9047c478bdstevel@tonic-gate			if (!rlen) {
9057c478bdstevel@tonic-gate				pdulen = 0x7fffffff;
9067c478bdstevel@tonic-gate			}
9077c478bdstevel@tonic-gate		}
9087c478bdstevel@tonic-gate
9097c478bdstevel@tonic-gate		/*
9102e3b646kcpoon		 * print the tag class and number
9112e3b646kcpoon		 */
9127c478bdstevel@tonic-gate		i = otyp[ctxnum]&0x1F;
9137c478bdstevel@tonic-gate		switch (otyp[ctxnum] >> 6) {	/* class */
9147c478bdstevel@tonic-gate		case 0:	/* universal */
9157c478bdstevel@tonic-gate			if (ASNDESC && i != 0) {
9167c478bdstevel@tonic-gate				int dobreak = 0;
9177c478bdstevel@tonic-gate				switch (ASNDESC->type) {
9187c478bdstevel@tonic-gate				case CONTENT:
9197c478bdstevel@tonic-gate					SASNDESC = ASNDESC;
9207c478bdstevel@tonic-gate					break;
9217c478bdstevel@tonic-gate				case SET:
9227c478bdstevel@tonic-gate					for (ai = 0;
9237c478bdstevel@tonic-gate						ai < ASNDESC->nbson && i < 32 &&
9247c478bdstevel@tonic-gate						ASNDESC->son[ai].sondef &&
9257c478bdstevel@tonic-gate					/*
9262e3b646kcpoon					 * For this test SEQUENCE & SEQUENCE OF
9272e3b646kcpoon					 * are same, so suppress the last bit
9282e3b646kcpoon					 */
9297c478bdstevel@tonic-gate						(ASNDESC->son[ai].sondef
9307c478bdstevel@tonic-gate							->type&0xFE)
9317c478bdstevel@tonic-gate						!= mytype[i]; ++ai);
9327c478bdstevel@tonic-gate					if (ai < ASNDESC->nbson) {
9337c478bdstevel@tonic-gate						SASNDESC =
9342e3b646kcpoon						    ASNDESC->son[ai].sondef;
9352e3b646kcpoon					if (ASNDESC->son[ai].sonname != NULL) {
9362e3b646kcpoon
9372e3b646kcpoon					if (ASNDESC->son[ai].sondef != NULL &&
9382e3b646kcpoon					    ASNDESC->son[ai].sondef->name !=
9392e3b646kcpoon					    NULL) {
9402e3b646kcpoon						asnshw2("%s	", "LDAP:");
9412e3b646kcpoon						asnshw4(" %c[%s %s]",
9422e3b646kcpoon						((otyp[ctxnum]&0x20)?'*':' '),
9432e3b646kcpoon						ASNDESC->son[ai].sonname,
9442e3b646kcpoon						ASNDESC->son[ai].sondef->name);
9452e3b646kcpoon					} else {
9462e3b646kcpoon						asnshw2("%s	", "");
9472e3b646kcpoon						asnshw3(" %c[%s]",
9482e3b646kcpoon						((otyp[ctxnum]&0x20)?'*':' '),
9492e3b646kcpoon						ASNDESC->son[ai].sonname);
9502e3b646kcpoon					} /* end if */
9512e3b646kcpoon
9522e3b646kcpoon					dobreak = 1;
9532e3b646kcpoon
9542e3b646kcpoon					} else if (ASNDESC->son[ai].sondef !=
9552e3b646kcpoon					    NULL &&
9562e3b646kcpoon					    ASNDESC->son[ai].sondef->name !=
9572e3b646kcpoon					    NULL) {
9582e3b646kcpoon						asnshw2("%s	", "LDAP:");
9592e3b646kcpoon						asnshw3(" %c[%s]",
9602e3b646kcpoon						((otyp[ctxnum]&0x20)?'*':' '),
9612e3b646kcpoon						ASNDESC->son[ai].sondef->name);
9622e3b646kcpoon						dobreak = 1;
9632e3b646kcpoon					} /* end if */
9647c478bdstevel@tonic-gate					} /* end if */
9657c478bdstevel@tonic-gate						break;
9667c478bdstevel@tonic-gate				case CHOICE:
9677c478bdstevel@tonic-gate					if (GR_TMPDESC) {
9687c478bdstevel@tonic-gate						ASNDESC = TMPDESC;
9697c478bdstevel@tonic-gate						TMPDESC = GR_TMPDESC;
9707c478bdstevel@tonic-gate						GR_TMPDESC = 0;
9717c478bdstevel@tonic-gate					} else if (TMPDESC) {
9727c478bdstevel@tonic-gate						ASNDESC = TMPDESC;
9737c478bdstevel@tonic-gate						TMPDESC = 0;
9747c478bdstevel@tonic-gate					}
9757c478bdstevel@tonic-gate					if (gr_tmpai) {
9767c478bdstevel@tonic-gate						ai = tmpai;
9777c478bdstevel@tonic-gate						tmpai = gr_tmpai;
9787c478bdstevel@tonic-gate						gr_tmpai = 0;
9797c478bdstevel@tonic-gate					} else if (tmpai) {
9807c478bdstevel@tonic-gate						ai = tmpai;
9817c478bdstevel@tonic-gate						tmpai = 0;
9827c478bdstevel@tonic-gate					}
9837c478bdstevel@tonic-gate					break;
9847c478bdstevel@tonic-gate
9857c478bdstevel@tonic-gate				case SEQUENCE:
9867c478bdstevel@tonic-gate					if (ai == -2) {
9877c478bdstevel@tonic-gate						ai = 0;
9887c478bdstevel@tonic-gate					} else {
9897c478bdstevel@tonic-gate						do {
9907c478bdstevel@tonic-gate							ai++;
9917c478bdstevel@tonic-gate						} while \
9927c478bdstevel@tonic-gate			(ai < ASNDESC->nbson && i < 32 && mytype[i] && \
9937c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef &&
9947c478bdstevel@tonic-gate					/*
9952e3b646kcpoon					 * For this test SEQUENCE & SEQUENCE OF
9962e3b646kcpoon					 * are the same, so suppress last bit
9972e3b646kcpoon					 */
9987c478bdstevel@tonic-gate			(ASNDESC->son[ai].sondef->type&0xFE) != mytype[i]);
9997c478bdstevel@tonic-gate					} /* end if */
10007c478bdstevel@tonic-gate					if (ai < ASNDESC->nbson) {
10017c478bdstevel@tonic-gate						SASNDESC = \
10027c478bdstevel@tonic-gate						ASNDESC->son[ai].sondef;
10037c478bdstevel@tonic-gate						if (ASNDESC->son[ai].sonname) {
10047c478bdstevel@tonic-gate							if \
10057c478bdstevel@tonic-gate			(ASNDESC->son[ai].sondef &&
10067c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name) {
10077c478bdstevel@tonic-gate								asnshw4 \
10087c478bdstevel@tonic-gate			(" %c[%s %s]", ((otyp[ctxnum]&0x20)?'*':' '),
10097c478bdstevel@tonic-gate			ASNDESC->son[ai].sonname,
10107c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name);
10117c478bdstevel@tonic-gate							} else {
10127c478bdstevel@tonic-gate								asnshw3 \
10137c478bdstevel@tonic-gate			(" %c[%s]", ((otyp[ctxnum]&0x20)?'*':' '),
10147c478bdstevel@tonic-gate			ASNDESC->son[ai].sonname);
10157c478bdstevel@tonic-gate							} /* end if */
10167c478bdstevel@tonic-gate							dobreak = 1;
10177c478bdstevel@tonic-gate						} else if \
10187c478bdstevel@tonic-gate			(ASNDESC->son[ai].sondef &&
10197c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name) {
10207c478bdstevel@tonic-gate								asnshw3 \
10217c478bdstevel@tonic-gate			(" %c[%s]", ((otyp[ctxnum]&0x20)?'*':' '),
10227c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name);
10237c478bdstevel@tonic-gate							dobreak = 1;
10247c478bdstevel@tonic-gate						} /* end if */
10257c478bdstevel@tonic-gate					} /* end if */
10267c478bdstevel@tonic-gate					break;
10277c478bdstevel@tonic-gate				case SEQUENCEOF:
10287c478bdstevel@tonic-gate					ai = 0;
10297c478bdstevel@tonic-gate					SASNDESC = ASNDESC->son[ai].sondef;
10307c478bdstevel@tonic-gate					if (ASNDESC->son[ai].sonname) {
10317c478bdstevel@tonic-gate						if (ASNDESC->son[ai].sondef && \
10327c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name) {
10337c478bdstevel@tonic-gate								asnshw4 \
10347c478bdstevel@tonic-gate			(" %c[%s %s]", ((otyp[ctxnum]&0x20)?'*':' '),
10357c478bdstevel@tonic-gate			ASNDESC->son[ai].sonname,
10367c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name);
10377c478bdstevel@tonic-gate						} else {
10387c478bdstevel@tonic-gate							asnshw3 \
10397c478bdstevel@tonic-gate			(" %c[%s]", ((otyp[ctxnum]&0x20)?'*':' '),
10407c478bdstevel@tonic-gate			ASNDESC->son[ai].sonname);
10417c478bdstevel@tonic-gate						} /* end if */
10427c478bdstevel@tonic-gate						dobreak = 1;
10437c478bdstevel@tonic-gate					} else if \
10447c478bdstevel@tonic-gate			(ASNDESC->son[ai].sondef &&
10457c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name) {
10467c478bdstevel@tonic-gate							asnshw3 \
10477c478bdstevel@tonic-gate			(" %c[%s]", ((otyp[ctxnum]&0x20)?'*':' '),
10487c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name);
10497c478bdstevel@tonic-gate						dobreak = 1;
10507c478bdstevel@tonic-gate					} /* end if */
10517c478bdstevel@tonic-gate				} /* end switch */
10527c478bdstevel@tonic-gate				if (dobreak) {
10537c478bdstevel@tonic-gate					break;
10547c478bdstevel@tonic-gate				} /* end if */
10557c478bdstevel@tonic-gate			} /* end if */
10567c478bdstevel@tonic-gate			if (uclass[i]) {
10577c478bdstevel@tonic-gate				asnshw3 \
10587c478bdstevel@tonic-gate			(" %c[%s]", ((otyp[ctxnum]&0x20)?'*':' '), uclass[i]);
10597c478bdstevel@tonic-gate			} else {
10607c478bdstevel@tonic-gate				asnshw4 \
10617c478bdstevel@tonic-gate			(" %c[%s%d]", ((otyp[ctxnum]&0x20)?'*':' '),
10627c478bdstevel@tonic-gate			class[0], i);
10637c478bdstevel@tonic-gate			}
10647c478bdstevel@tonic-gate			break;
10657c478bdstevel@tonic-gate		case 1:		/* application */
10667c478bdstevel@tonic-gate
10677c478bdstevel@tonic-gate		if (ASNDESC) {
10687c478bdstevel@tonic-gate
10697c478bdstevel@tonic-gate				for (ai = 0; ai < ASNDESC->nbson; ++ai) {
10707c478bdstevel@tonic-gate					int i2 = 0;
10717c478bdstevel@tonic-gate
10727c478bdstevel@tonic-gate					if \
10737c478bdstevel@tonic-gate			(ASNDESC->son[ai].sondef &&
10747c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->type == CHOICE) {
10757c478bdstevel@tonic-gate						while \
10767c478bdstevel@tonic-gate			(i2 < ASNDESC->son[ai].sondef->nbson &&
10777c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->son[i2].sondef && \
10787c478bdstevel@tonic-gate	ASNDESC->son[ai].sondef->son[i2].sondef->application != i) {
10797c478bdstevel@tonic-gate							i2++;
10807c478bdstevel@tonic-gate							continue;
10817c478bdstevel@tonic-gate						}
10827c478bdstevel@tonic-gate						if \
10837c478bdstevel@tonic-gate			(i2 == ASNDESC->son[ai].sondef->nbson) {
10847c478bdstevel@tonic-gate							ai = ASNDESC->nbson;
10857c478bdstevel@tonic-gate							break;
10867c478bdstevel@tonic-gate						}
10877c478bdstevel@tonic-gate			if (TMPDESC) {
10887c478bdstevel@tonic-gate				GR_TMPDESC = TMPDESC;
10897c478bdstevel@tonic-gate				gr_tmpai = tmpai;
10907c478bdstevel@tonic-gate			}
10917c478bdstevel@tonic-gate					TMPDESC = ASNDESC;
10927c478bdstevel@tonic-gate					ASNDESC = ASNDESC->son[ai].sondef;
10937c478bdstevel@tonic-gate					tmpai = ai;
10947c478bdstevel@tonic-gate					ai = i2;
10957c478bdstevel@tonic-gate					}
10967c478bdstevel@tonic-gate
10977c478bdstevel@tonic-gate					if (ASNDESC->son[ai].sondef && \
10987c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->application == i) {
10997c478bdstevel@tonic-gate						SASNDESC = \
11007c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef;
11017c478bdstevel@tonic-gate						if (ASNDESC->son[ai].sonname) {
11027c478bdstevel@tonic-gate							if \
11037c478bdstevel@tonic-gate			(ASNDESC->son[ai].sondef->name) {
11047c478bdstevel@tonic-gate								asnshw3 \
11057c478bdstevel@tonic-gate			(" %s %s", ASNDESC->son[ai].sonname,
11067c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name);
11077c478bdstevel@tonic-gate							} else {
11087c478bdstevel@tonic-gate								asnshw2 \
11097c478bdstevel@tonic-gate			(" %s", ASNDESC->son[ai].sonname);
11107c478bdstevel@tonic-gate							} /* end if */
11117c478bdstevel@tonic-gate						} else if \
11127c478bdstevel@tonic-gate			(ASNDESC->son[ai].sondef->name) {
11137c478bdstevel@tonic-gate							asnshw2 \
11147c478bdstevel@tonic-gate			(" %s", ASNDESC->son[ai].sondef->name);
11157c478bdstevel@tonic-gate						} /* end if */
11167c478bdstevel@tonic-gate						break;
11177c478bdstevel@tonic-gate					} /* end if */
11187c478bdstevel@tonic-gate				} /* end for */
11197c478bdstevel@tonic-gate				if (ai >= ASNDESC->nbson) {
11207c478bdstevel@tonic-gate					ai = -1;	/* not found */
11217c478bdstevel@tonic-gate				} /* end if */
11227c478bdstevel@tonic-gate			} /* end if */
11237c478bdstevel@tonic-gate			if (PTRaclass[i]) {
11247c478bdstevel@tonic-gate				asnshw5 \
11257c478bdstevel@tonic-gate			(" %c[%s%d: %s]", ((otyp[ctxnum]&0x20)?'*':' '),
11267c478bdstevel@tonic-gate			class[1], i, PTRaclass[i]);
11277c478bdstevel@tonic-gate				(void) strcpy(operation, (char *)PTRaclass[i]);
11287c478bdstevel@tonic-gate			} else {
11297c478bdstevel@tonic-gate				asnshw4 \
11307c478bdstevel@tonic-gate			(" %c[%s%d]", ((otyp[ctxnum]&0x20)?'*':' '), \
11317c478bdstevel@tonic-gate			class[1], i);
11327c478bdstevel@tonic-gate			}
11337c478bdstevel@tonic-gate			break;
11347c478bdstevel@tonic-gate
11357c478bdstevel@tonic-gate		case 2:		/* context-specific */
11367c478bdstevel@tonic-gate
11377c478bdstevel@tonic-gate			if (TMPDESC) {
11387c478bdstevel@tonic-gate				ASNDESC = TMPDESC;
11397c478bdstevel@tonic-gate				TMPDESC = GR_TMPDESC;
11407c478bdstevel@tonic-gate				already = 1;
11417c478bdstevel@tonic-gate			}
11427c478bdstevel@tonic-gate			if (ASNDESC) {
11437c478bdstevel@tonic-gate
11447c478bdstevel@tonic-gate				for (ai = 0; ai < ASNDESC->nbson; ++ai) {
11457c478bdstevel@tonic-gate					if \
11467c478bdstevel@tonic-gate			(!already && ASNDESC->son[ai].sondef &&
11477c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->type == CHOICE) {
11487c478bdstevel@tonic-gate						int i2 = 0;
11497c478bdstevel@tonic-gate						while \
11507c478bdstevel@tonic-gate			(i2 < ASNDESC->son[ai].sondef->nbson &&
11517c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->son[i2].tag != i) {
11527c478bdstevel@tonic-gate							i2++;
11537c478bdstevel@tonic-gate							continue;
11547c478bdstevel@tonic-gate						}
11557c478bdstevel@tonic-gate						if (i2 == \
11567c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->nbson) {
11577c478bdstevel@tonic-gate							ai = ASNDESC->nbson;
11587c478bdstevel@tonic-gate							break;
11597c478bdstevel@tonic-gate						}
11607c478bdstevel@tonic-gate						if (TMPDESC) {
11617c478bdstevel@tonic-gate							GR_TMPDESC = TMPDESC;
11627c478bdstevel@tonic-gate							gr_tmpai = tmpai;
11637c478bdstevel@tonic-gate						}
11647c478bdstevel@tonic-gate						TMPDESC = ASNDESC;
11657c478bdstevel@tonic-gate						ASNDESC = \
11667c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef;
11677c478bdstevel@tonic-gate						tmpai = ai;
11687c478bdstevel@tonic-gate						ai = i2;
11697c478bdstevel@tonic-gate					}
11707c478bdstevel@tonic-gate
11717c478bdstevel@tonic-gate					if \
11727c478bdstevel@tonic-gate			(ASNDESC->son[ai].tag == i) {
11737c478bdstevel@tonic-gate						SASNDESC = \
11747c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef;
11757c478bdstevel@tonic-gate						if (ASNDESC->son[ai].sonname) {
11767c478bdstevel@tonic-gate							if \
11777c478bdstevel@tonic-gate			(ASNDESC->son[ai].sondef &&
11787c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name) {
11797c478bdstevel@tonic-gate								asnshw3 \
11807c478bdstevel@tonic-gate			(" %s %s", ASNDESC->son[ai].sonname,
11817c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name);
11827c478bdstevel@tonic-gate							} else {
11837c478bdstevel@tonic-gate								asnshw2 \
11847c478bdstevel@tonic-gate			(" %s", ASNDESC->son[ai].sonname);
11857c478bdstevel@tonic-gate							} /* end if */
11867c478bdstevel@tonic-gate						} else if \
11877c478bdstevel@tonic-gate			(ASNDESC->son[ai].sondef &&
11887c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef->name) {
11897c478bdstevel@tonic-gate							asnshw2 \
11907c478bdstevel@tonic-gate			(" %s", ASNDESC->son[ai].sondef->name);
11917c478bdstevel@tonic-gate						} /* end if */
11927c478bdstevel@tonic-gate						break;
11937c478bdstevel@tonic-gate					} /* end if */
11947c478bdstevel@tonic-gate				} /* end for */
11957c478bdstevel@tonic-gate				if (ai >= ASNDESC->nbson) {
11967c478bdstevel@tonic-gate					ai = -1;	/* not found */
11977c478bdstevel@tonic-gate				} /* end if */
11987c478bdstevel@tonic-gate			} /* end if */
11997c478bdstevel@tonic-gate			asnshw3 \
12007c478bdstevel@tonic-gate			(" %c[%d]", ((otyp[ctxnum]&0x20)?'*':' '), i);
12017c478bdstevel@tonic-gate			break;
12027c478bdstevel@tonic-gate
12037c478bdstevel@tonic-gate		case 3:		/* private */
12047c478bdstevel@tonic-gate			asnshw4 \
12057c478bdstevel@tonic-gate			(" %c[%s%d]", ((otyp[ctxnum]&0x20)?'*':' '), \
12067c478bdstevel@tonic-gate			class[3], i);
12077c478bdstevel@tonic-gate		} /* esac: tag */
12087c478bdstevel@tonic-gate
12097c478bdstevel@tonic-gate		/*
12102e3b646kcpoon		 * print the length - as a debug tool only.
12112e3b646kcpoon		 */
12127c478bdstevel@tonic-gate		/* asnshw2(" Length=%d ",rlen); */
12137c478bdstevel@tonic-gate		asnshw1("\n");
12147c478bdstevel@tonic-gate		if (rlen > pdulen) {
12157c478bdstevel@tonic-gate			asnshw1("*** Decode length error,");
12167c478bdstevel@tonic-gate			asnshw2(" PDU length = %d ***\n", pdulen);
12177c478bdstevel@tonic-gate			rlen = pdulen;
12187c478bdstevel@tonic-gate		}
12197c478bdstevel@tonic-gate
12207c478bdstevel@tonic-gate		/*
12212e3b646kcpoon		 * recursive interpretation of the value if constructor
12222e3b646kcpoon		 */
12237c478bdstevel@tonic-gate		if (otyp[ctxnum]&0x20) {		/* constructor */
12247c478bdstevel@tonic-gate
12257c478bdstevel@tonic-gate			stlv = decpdu((rlen?rlen:pdulen), \
12267c478bdstevel@tonic-gate			ASNDESC && ai != -1 ?(ai == -2 ? ASNDESC:
12277c478bdstevel@tonic-gate			ASNDESC->son[ai].sondef):0, ctxnum);
12287c478bdstevel@tonic-gate			/* recursive decoding */
12297c478bdstevel@tonic-gate			pdulen -= stlv;
12307c478bdstevel@tonic-gate			effnb += stlv;
12317c478bdstevel@tonic-gate		} else if (otyp[ctxnum] == 0x06) {
12327c478bdstevel@tonic-gate			/*
12332e3b646kcpoon			 * interpretation of the object identifier
12342e3b646kcpoon			 */
12357c478bdstevel@tonic-gate			for (j = 0; (rlen) && (pdulen > 0); \
12367c478bdstevel@tonic-gate			--rlen, --pdulen, ++effnb) {
12377c478bdstevel@tonic-gate				GETNEXT(ctxnum);
12387c478bdstevel@tonic-gate				oidstr[j++] = hex;
12397c478bdstevel@tonic-gate			}
12407c478bdstevel@tonic-gate
12417c478bdstevel@tonic-gate			/* interpret the object identifier */
12427c478bdstevel@tonic-gate			oidstr[j++] = '\0';
12437c478bdstevel@tonic-gate			oix = oidmap(oidstr, j-1);
12447c478bdstevel@tonic-gate			asnshw1("\n");
12457c478bdstevel@tonic-gate			if (oix >= 0 && oix < OIDNB) {	/* recognized obj id */
12467c478bdstevel@tonic-gate				asnshw2("%s\n", OidTab[oix].oidname);
12477c478bdstevel@tonic-gate			} else {
12487c478bdstevel@tonic-gate				asnshw1("Unknown Oid\n");
12497c478bdstevel@tonic-gate			}
12507c478bdstevel@tonic-gate		} else {
12517c478bdstevel@tonic-gate			/*
12522e3b646kcpoon			 * interpretation of other primitive tags
12532e3b646kcpoon			 */
12547c478bdstevel@tonic-gate			if (!otyp[ctxnum] && !rlen) {
12557c478bdstevel@tonic-gate			/* end of contents: any form length */
12567c478bdstevel@tonic-gate				pdulen = 0;
12577c478bdstevel@tonic-gate			} else {
12587c478bdstevel@tonic-gate				X   hexstr[5];
12597c478bdstevel@tonic-gate				int k = 0;
12607c478bdstevel@tonic-gate				int klen = rlen;
12617c478bdstevel@tonic-gate				if (SASNDESC && SASNDESC->type == CONTENT && \
12627c478bdstevel@tonic-gate			SASNDESC->nbson && SASNDESC->son[0].sondef) {
12637c478bdstevel@tonic-gate					(void)
12647c478bdstevel@tonic-gate			decpdu(rlen, SASNDESC->son[0].sondef, ctxnum);
12657c478bdstevel@tonic-gate				} else {
12667c478bdstevel@tonic-gate					if (rlen < 200) {
12677c478bdstevel@tonic-gate					for (j = 0, slen = 0; \
12687c478bdstevel@tonic-gate			(rlen) && (pdulen > 0);
12692e3b646kcpoon					--rlen, --pdulen, ++effnb) {
12707c478bdstevel@tonic-gate						if (!slen) {
12717c478bdstevel@tonic-gate						    (void) \
12727c478bdstevel@tonic-gate			strcpy((char *)scrlin, "LDAP:  "); j += 7;
12737c478bdstevel@tonic-gate						    for \
12747c478bdstevel@tonic-gate			(i = 0; i < level[ctxnum]; ++i) {
12757c478bdstevel@tonic-gate							scrlin[j++] = ' ';
12767c478bdstevel@tonic-gate							scrlin[j++] = ' ';
12777c478bdstevel@tonic-gate							scrlin[j++] = ' ';
12787c478bdstevel@tonic-gate							scrlin[j++] = ' ';
12797c478bdstevel@tonic-gate						    }
12807c478bdstevel@tonic-gate						}
12817c478bdstevel@tonic-gate
12827c478bdstevel@tonic-gate						GETNEXT(ctxnum);
12837c478bdstevel@tonic-gate						if (k < 5) {
12847c478bdstevel@tonic-gate							hexstr[k++] = hex;
12857c478bdstevel@tonic-gate						} /* end if */
12867c478bdstevel@tonic-gate						if (!isprint(hex)) {
12877c478bdstevel@tonic-gate							hex = '_';
12887c478bdstevel@tonic-gate							dontprint = 1;
12897c478bdstevel@tonic-gate						}
12907c478bdstevel@tonic-gate						scrlin[j++] = hex;
12917c478bdstevel@tonic-gate						if ((slen += 2) >= \
12927c478bdstevel@tonic-gate			(72 - (level[ctxnum] * 3))) {
12937c478bdstevel@tonic-gate							slen = 0;
12947c478bdstevel@tonic-gate							scrlin[j] = 0;
12957c478bdstevel@tonic-gate							if (!dontprint) {
12967c478bdstevel@tonic-gate								asnshw2 \
12977c478bdstevel@tonic-gate			("%s\n", scrlin);
12987c478bdstevel@tonic-gate							}
12997c478bdstevel@tonic-gate							j = 0;
13007c478bdstevel@tonic-gate						}
13017c478bdstevel@tonic-gate					} /* rof: primitive values */
13027c478bdstevel@tonic-gate					if (slen) {
13037c478bdstevel@tonic-gate						scrlin[j] = 0;
13047c478bdstevel@tonic-gate						if (!dontprint) {
13057c478bdstevel@tonic-gate							asnshw2("%s\n", scrlin);
13067c478bdstevel@tonic-gate						}
13077c478bdstevel@tonic-gate					}
13087c478bdstevel@tonic-gate					dontprint = 0;
13097c478bdstevel@tonic-gate				} else {
13107c478bdstevel@tonic-gate					asnshw2("%s  ", "LDAP:");
13117c478bdstevel@tonic-gate				    for (i = 0; i < level[ctxnum]; ++i) {
13127c478bdstevel@tonic-gate						asnshw1("   ");
13137c478bdstevel@tonic-gate						scrlin[j++] = ' ';
13147c478bdstevel@tonic-gate						scrlin[j++] = ' ';
13157c478bdstevel@tonic-gate						scrlin[j++] = ' ';
13167c478bdstevel@tonic-gate					}
13177c478bdstevel@tonic-gate
13187c478bdstevel@tonic-gate				    for (j = 0; (rlen) && (pdulen > 0); \
13197c478bdstevel@tonic-gate			--rlen, --pdulen, ++effnb) {
13207c478bdstevel@tonic-gate						GETNEXT(ctxnum);
13217c478bdstevel@tonic-gate						if (k < 5) {
13227c478bdstevel@tonic-gate							hexstr[k++] = hex;
13237c478bdstevel@tonic-gate						}
13247c478bdstevel@tonic-gate					}
13257c478bdstevel@tonic-gate				    (void) strcpy \
13267c478bdstevel@tonic-gate			((char *)scrlin, \
13277c478bdstevel@tonic-gate			"*** NOT PRINTED - Too long value ***");
13287c478bdstevel@tonic-gate						asnshw2("%s\n", scrlin);
13297c478bdstevel@tonic-gate					}
13307c478bdstevel@tonic-gate
13317c478bdstevel@tonic-gate					if \
13327c478bdstevel@tonic-gate			(SASNDESC && SASNDESC->type == BITSTRING &&\
13337c478bdstevel@tonic-gate			klen <= 5) {
13347c478bdstevel@tonic-gate						unsigned long bitstr = 0;
13357c478bdstevel@tonic-gate						for (i = 1; i < 5; ++i) {
13367c478bdstevel@tonic-gate							bitstr = \
13377c478bdstevel@tonic-gate			((bitstr) << 8) + ((i < klen)?hexstr[i]:0);
13387c478bdstevel@tonic-gate						} /* end for */
13397c478bdstevel@tonic-gate						for \
13407c478bdstevel@tonic-gate			(i = 0; i < SASNDESC->nbson; ++i) {
13417c478bdstevel@tonic-gate							if ((bitstr & \
13427c478bdstevel@tonic-gate			((unsigned long)SASNDESC->son[i].sondef)) ==
13437c478bdstevel@tonic-gate			((unsigned long)SASNDESC->son[i].tag)) {
13447c478bdstevel@tonic-gate								if \
13457c478bdstevel@tonic-gate			(SASNDESC->son[i].sonname) {
13467c478bdstevel@tonic-gate								int k;
13477c478bdstevel@tonic-gate								asnshw2 \
13487c478bdstevel@tonic-gate			("%s  ", "LDAP:");
13497c478bdstevel@tonic-gate								for \
13507c478bdstevel@tonic-gate			(k = 0; k < level[ctxnum]; ++k) {
13517c478bdstevel@tonic-gate								asnshw1("   ");
13527c478bdstevel@tonic-gate								}
13537c478bdstevel@tonic-gate								asnshw2 \
13547c478bdstevel@tonic-gate			("%s", SASNDESC->son[i].sonname);
13557c478bdstevel@tonic-gate								} /* end if */
13567c478bdstevel@tonic-gate							} /* end if */
13577c478bdstevel@tonic-gate						} /* end for */
13587c478bdstevel@tonic-gate					} /* end if */
13597c478bdstevel@tonic-gate					if (SASNDESC && \
13607c478bdstevel@tonic-gate			(SASNDESC->type == ENUM ||
13617c478bdstevel@tonic-gate			SASNDESC->type == CONTENTTYPE) && klen <= 5) {
13627c478bdstevel@tonic-gate						unsigned long value = 0;
13637c478bdstevel@tonic-gate						for (i = 0; i < klen; ++i) {
13647c478bdstevel@tonic-gate							value = \
13657c478bdstevel@tonic-gate			((value) << 8) + hexstr[i];
13667c478bdstevel@tonic-gate						} /* end for */
13677c478bdstevel@tonic-gate						for \
13687c478bdstevel@tonic-gate			(i = 0; i < SASNDESC->nbson; ++i) {
13697c478bdstevel@tonic-gate							if \
13707c478bdstevel@tonic-gate			(value == ((unsigned long)SASNDESC->son[i].tag)) {
13717c478bdstevel@tonic-gate								if \
13727c478bdstevel@tonic-gate			(SASNDESC->son[i].sonname) {
13737c478bdstevel@tonic-gate									int k;
13747c478bdstevel@tonic-gate								asnshw2 \
13757c478bdstevel@tonic-gate			("%s  ", "LDAP:");
13767c478bdstevel@tonic-gate									for \
13777c478bdstevel@tonic-gate			(k = 0; k < level[ctxnum]; ++k) {
13787c478bdstevel@tonic-gate								asnshw1("   ");
13797c478bdstevel@tonic-gate									}
13807c478bdstevel@tonic-gate								asnshw2 \
13817c478bdstevel@tonic-gate			("%s\n", SASNDESC->son[i].sonname);
13827c478bdstevel@tonic-gate									(void) \
13837c478bdstevel@tonic-gate			strcpy(resultcode, SASNDESC->son[i].sonname);
13847c478bdstevel@tonic-gate								} /* end if */
13857c478bdstevel@tonic-gate								break;
13867c478bdstevel@tonic-gate							} /* end if */
13877c478bdstevel@tonic-gate						} /* end for */
13887c478bdstevel@tonic-gate					} /* end if */
13897c478bdstevel@tonic-gate
13907c478bdstevel@tonic-gate				} /* end if */
13917c478bdstevel@tonic-gate			} /* fi: constructor/obj-id/primitive */
13927c478bdstevel@tonic-gate		} /* fi: tag analysis */
13937c478bdstevel@tonic-gate	} /* elihw: len>1 */
13947c478bdstevel@tonic-gate	--level[ctxnum];
13957c478bdstevel@tonic-gate	return (effnb);
13967c478bdstevel@tonic-gate}
13977c478bdstevel@tonic-gate
13987c478bdstevel@tonic-gate
13997c478bdstevel@tonic-gate/* init_ldap initializes various buffers and variables */
14007c478bdstevel@tonic-gate/* it is called one-time (in snoop_filter.c) only. */
14017c478bdstevel@tonic-gate
14027c478bdstevel@tonic-gatevoid
14037c478bdstevel@tonic-gateinit_ldap()
14047c478bdstevel@tonic-gate{
14057c478bdstevel@tonic-gate	int i;
14067c478bdstevel@tonic-gate
14077c478bdstevel@tonic-gate	for (i = 0; i < MAX_CTX; i++) {
14087c478bdstevel@tonic-gate		gi_osibuf[i] = 0;
14097c478bdstevel@tonic-gate		level[i] = 0;
14107c478bdstevel@tonic-gate	}
14117c478bdstevel@tonic-gate}
14127c478bdstevel@tonic-gatestatic void
14137c478bdstevel@tonic-gateldapdump(char *data, int datalen)
14147c478bdstevel@tonic-gate{
14157c478bdstevel@tonic-gate	char *p;
14167c478bdstevel@tonic-gate	ushort_t *p16 = (ushort_t *)data;
14177c478bdstevel@tonic-gate	char *p8 = data;
14187c478bdstevel@tonic-gate	int i, left, len;
14197c478bdstevel@tonic-gate	int chunk = 16;  /* 16 bytes per line */
14207c478bdstevel@tonic-gate
14217c478bdstevel@tonic-gate	asnshw1("LDAP: Skipping until next full LDAPMessage\n");
14227c478bdstevel@tonic-gate
14237c478bdstevel@tonic-gate	for (p = data; p < data + datalen; p += chunk) {
14247c478bdstevel@tonic-gate		asnshw2("LDAP:\t%4d: ", p - data);
14257c478bdstevel@tonic-gate		left = (data + datalen) - p;
14267c478bdstevel@tonic-gate		len = MIN(chunk, left);
14277c478bdstevel@tonic-gate		for (i = 0; i < (len / 2); i++)
14287c478bdstevel@tonic-gate			asnshw2("%04x ", ntohs(*p16++) & 0xffff);
14297c478bdstevel@tonic-gate		if (len % 2) {
14307c478bdstevel@tonic-gate			asnshw2("%02x   ", *((unsigned char *)p16));
14317c478bdstevel@tonic-gate		}
14327c478bdstevel@tonic-gate		for (i = 0; i < (chunk - left) / 2; i++)
14337c478bdstevel@tonic-gate			asnshw1("     ");
14347c478bdstevel@tonic-gate
14357c478bdstevel@tonic-gate		asnshw1("   ");
14367c478bdstevel@tonic-gate		for (i = 0; i < len; i++, p8++)
14377c478bdstevel@tonic-gate			asnshw2("%c", isprint(*p8) ? *p8 : '.');
14387c478bdstevel@tonic-gate		asnshw1("\n");
14397c478bdstevel@tonic-gate	}
14407c478bdstevel@tonic-gate
14417c478bdstevel@tonic-gate	asnshw1("LDAP:\n");
14427c478bdstevel@tonic-gate}
14437c478bdstevel@tonic-gate
14447c478bdstevel@tonic-gate/* decode_ldap is the entry point for the main decoding function */
14457c478bdstevel@tonic-gate/* decpdu(). decode_ldap() is only called by interpret_ldap. */
14467c478bdstevel@tonic-gate
14477c478bdstevel@tonic-gatevoid
14487c478bdstevel@tonic-gatedecode_ldap(char *buf, int len)
14497c478bdstevel@tonic-gate{
14507c478bdstevel@tonic-gate	asndefTp ASNDESC = 0;
14517c478bdstevel@tonic-gate	char *newbuf;
14527c478bdstevel@tonic-gate	int skipped = 0;
14537c478bdstevel@tonic-gate
14547c478bdstevel@tonic-gate	PTRaclass = MHSaclass;
14557c478bdstevel@tonic-gate	ASNDESC = &MPDU;
14567c478bdstevel@tonic-gate
14577c478bdstevel@tonic-gate
14587c478bdstevel@tonic-gate	newbuf =  skipjunk(len, buf);
14597c478bdstevel@tonic-gate	if (newbuf > buf) {
14607c478bdstevel@tonic-gate		skipped = newbuf-buf;
14617c478bdstevel@tonic-gate		ldapdump(buf, newbuf-buf);
14627c478bdstevel@tonic-gate	}
14637c478bdstevel@tonic-gate	buf = newbuf;
14647c478bdstevel@tonic-gate	len = len-skipped;
14657c478bdstevel@tonic-gate	osibuff = buf;	/* Undecoded buf is passed by interpret_ldap */
14667c478bdstevel@tonic-gate	osilen = len;	/* length of tcp data is also passed */
14677c478bdstevel@tonic-gate
14687c478bdstevel@tonic-gate	(void) decpdu(len, ASNDESC, 0);
14697c478bdstevel@tonic-gate	gi_osibuf[0] = 0;
14707c478bdstevel@tonic-gate}
1471