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