FreeBSD/usr.sbin/ypldap/aldap.c
/*
 * Display a list of ber elements.
 *
 */
Display a list of ber elements.
Display a list of ber elements .
void
ldap_debug_elements(struct ber_element *root)
{
	static int	 indent = 0;
	long long	 v;
	int		 d;
	char		*buf;
	size_t		 len;
	u_int		 i;
	int		 constructed;
	struct ber_oid	 o;
	ber_calc_len(root);
	switch (root->be_encoding) {
	case BER_TYPE_SEQUENCE:
	case BER_TYPE_SET:
		constructed = root->be_encoding;
		break;
	default:
		constructed = 0;
		break;
	}
	fprintf(stderr, "%*slen %lu ", indent, "", root->be_len);
	switch (root->be_class) {
	case BER_CLASS_UNIVERSAL:
		fprintf(stderr, "class: universal(%u) type: ", root->be_class);
		switch (root->be_type) {
		case BER_TYPE_EOC:
			fprintf(stderr, "end-of-content");
			break;
		case BER_TYPE_BOOLEAN:
			fprintf(stderr, "boolean");
			break;
		case BER_TYPE_INTEGER:
			fprintf(stderr, "integer");
			break;
		case BER_TYPE_BITSTRING:
			fprintf(stderr, "bit-string");
			break;
		case BER_TYPE_OCTETSTRING:
			fprintf(stderr, "octet-string");
			break;
		case BER_TYPE_NULL:
			fprintf(stderr, "null");
			break;
		case BER_TYPE_OBJECT:
			fprintf(stderr, "object");
			break;
		case BER_TYPE_ENUMERATED:
			fprintf(stderr, "enumerated");
			break;
		case BER_TYPE_SEQUENCE:
			fprintf(stderr, "sequence");
			break;
		case BER_TYPE_SET:
			fprintf(stderr, "set");
			break;
		}
		break;
	case BER_CLASS_APPLICATION:
		fprintf(stderr, "class: application(%u) type: ",
		    root->be_class);
		switch (root->be_type) {
		case LDAP_REQ_BIND:
			fprintf(stderr, "bind");
			break;
		case LDAP_RES_BIND:
			fprintf(stderr, "bind");
			break;
		case LDAP_REQ_UNBIND_30:
			break;
		case LDAP_REQ_SEARCH:
			fprintf(stderr, "search");
			break;
		case LDAP_RES_SEARCH_ENTRY:
			fprintf(stderr, "search_entry");
			break;
		case LDAP_RES_SEARCH_RESULT:
			fprintf(stderr, "search_result");
			break;
		case LDAP_REQ_MODIFY:
			fprintf(stderr, "modify");
			break;
		case LDAP_RES_MODIFY:
			fprintf(stderr, "modify");
			break;
		case LDAP_REQ_ADD:
			fprintf(stderr, "add");
			break;
		case LDAP_RES_ADD:
			fprintf(stderr, "add");
			break;
		case LDAP_REQ_DELETE_30:
			fprintf(stderr, "delete");
			break;
		case LDAP_RES_DELETE:
			fprintf(stderr, "delete");
			break;
		case LDAP_REQ_MODRDN:
			fprintf(stderr, "modrdn");
			break;
		case LDAP_RES_MODRDN:
			fprintf(stderr, "modrdn");
			break;
		case LDAP_REQ_COMPARE:
			fprintf(stderr, "compare");
			break;
		case LDAP_RES_COMPARE:
			fprintf(stderr, "compare");
			break;
		case LDAP_REQ_ABANDON_30:
			fprintf(stderr, "abandon");
			break;
		}
		break;
	case BER_CLASS_PRIVATE:
		fprintf(stderr, "class: private(%u) type: ", root->be_class);
		fprintf(stderr, "encoding (%lu) type: ", root->be_encoding);
		break;
	case BER_CLASS_CONTEXT:
		fprintf(stderr, "class: context(%u) type: ", root->be_class);
		switch(root->be_type) {
		case LDAP_AUTH_SIMPLE:
			fprintf(stderr, "auth simple");
			break;
		}
		break;
	default:
		fprintf(stderr, "class: <INVALID>(%u) type: ", root->be_class);
		break;
	}
	fprintf(stderr, "(%lu) encoding %lu ",
	    root->be_type, root->be_encoding);
	if (constructed)
		root->be_encoding = constructed;
	switch (root->be_encoding) {
	case BER_TYPE_BOOLEAN:
		if (ber_get_boolean(root, &d) == -1) {
			fprintf(stderr, "<INVALID>\n");
			break;
		}
		fprintf(stderr, "%s(%d)\n", d ? "true" : "false", d);
		break;
	case BER_TYPE_INTEGER:
		if (ber_get_integer(root, &v) == -1) {
			fprintf(stderr, "<INVALID>\n");
			break;
		}
		fprintf(stderr, "value %lld\n", v);
		break;
	case BER_TYPE_ENUMERATED:
		if (ber_get_enumerated(root, &v) == -1) {
			fprintf(stderr, "<INVALID>\n");
			break;
		}
		fprintf(stderr, "value %lld\n", v);
		break;
	case BER_TYPE_BITSTRING:
		if (ber_get_bitstring(root, (void *)&buf, &len) == -1) {
			fprintf(stderr, "<INVALID>\n");
			break;
		}
		fprintf(stderr, "hexdump ");
		for (i = 0; i < len; i++)
			fprintf(stderr, "%02x", buf[i]);
		fprintf(stderr, "\n");
		break;
	case BER_TYPE_OBJECT:
		if (ber_get_oid(root, &o) == -1) {
			fprintf(stderr, "<INVALID>\n");
			break;
		}
		fprintf(stderr, "\n");
		break;
	case BER_TYPE_OCTETSTRING:
		if (ber_get_nstring(root, (void *)&buf, &len) == -1) {
			fprintf(stderr, "<INVALID>\n");
			break;
		}
		fprintf(stderr, "string \"%.*s\"\n",  len, buf);
		break;
	case BER_TYPE_NULL:	
	case BER_TYPE_EOC:
	case BER_TYPE_SEQUENCE:
	case BER_TYPE_SET:
	default:
		fprintf(stderr, "\n");
		break;
	}
	if (constructed && root->be_sub) {
		indent += 2;
		ldap_debug_elements(root->be_sub);
		indent -= 2;
	}
	if (root->be_next)
		ldap_debug_elements(root->be_next);
}
void ldap_debug_elements ( struct ber_element * root ) { static int indent = 0 ; long long v ; int d ; char * buf ; size_t len ; u_int i ; int constructed ; struct ber_oid o ; ber_calc_len ( root ) ; switch ( root -> be_encoding ) { case BER_TYPE_SEQUENCE : case BER_TYPE_SET : constructed = root -> be_encoding ; break ; default : constructed = 0 ; break ; } fprintf ( stderr , " " , indent , " " , root -> be_len ) ; switch ( root -> be_class ) { case BER_CLASS_UNIVERSAL : fprintf ( stderr , " " , root -> be_class ) ; switch ( root -> be_type ) { case BER_TYPE_EOC : fprintf ( stderr , " " ) ; break ; case BER_TYPE_BOOLEAN : fprintf ( stderr , " " ) ; break ; case BER_TYPE_INTEGER : fprintf ( stderr , " " ) ; break ; case BER_TYPE_BITSTRING : fprintf ( stderr , " " ) ; break ; case BER_TYPE_OCTETSTRING : fprintf ( stderr , " " ) ; break ; case BER_TYPE_NULL : fprintf ( stderr , " " ) ; break ; case BER_TYPE_OBJECT : fprintf ( stderr , " " ) ; break ; case BER_TYPE_ENUMERATED : fprintf ( stderr , " " ) ; break ; case BER_TYPE_SEQUENCE : fprintf ( stderr , " " ) ; break ; case BER_TYPE_SET : fprintf ( stderr , " " ) ; break ; } break ; case BER_CLASS_APPLICATION : fprintf ( stderr , " " , root -> be_class ) ; switch ( root -> be_type ) { case LDAP_REQ_BIND : fprintf ( stderr , " " ) ; break ; case LDAP_RES_BIND : fprintf ( stderr , " " ) ; break ; case LDAP_REQ_UNBIND_30 : break ; case LDAP_REQ_SEARCH : fprintf ( stderr , " " ) ; break ; case LDAP_RES_SEARCH_ENTRY : fprintf ( stderr , " " ) ; break ; case LDAP_RES_SEARCH_RESULT : fprintf ( stderr , " " ) ; break ; case LDAP_REQ_MODIFY : fprintf ( stderr , " " ) ; break ; case LDAP_RES_MODIFY : fprintf ( stderr , " " ) ; break ; case LDAP_REQ_ADD : fprintf ( stderr , " " ) ; break ; case LDAP_RES_ADD : fprintf ( stderr , " " ) ; break ; case LDAP_REQ_DELETE_30 : fprintf ( stderr , " " ) ; break ; case LDAP_RES_DELETE : fprintf ( stderr , " " ) ; break ; case LDAP_REQ_MODRDN : fprintf ( stderr , " " ) ; break ; case LDAP_RES_MODRDN : fprintf ( stderr , " " ) ; break ; case LDAP_REQ_COMPARE : fprintf ( stderr , " " ) ; break ; case LDAP_RES_COMPARE : fprintf ( stderr , " " ) ; break ; case LDAP_REQ_ABANDON_30 : fprintf ( stderr , " " ) ; break ; } break ; case BER_CLASS_PRIVATE : fprintf ( stderr , " " , root -> be_class ) ; fprintf ( stderr , " " , root -> be_encoding ) ; break ; case BER_CLASS_CONTEXT : fprintf ( stderr , " " , root -> be_class ) ; switch ( root -> be_type ) { case LDAP_AUTH_SIMPLE : fprintf ( stderr , " " ) ; break ; } break ; default : fprintf ( stderr , " " , root -> be_class ) ; break ; } fprintf ( stderr , " " , root -> be_type , root -> be_encoding ) ; if ( constructed ) root -> be_encoding = constructed ; switch ( root -> be_encoding ) { case BER_TYPE_BOOLEAN : if ( ber_get_boolean ( root , & d ) == -1 ) { fprintf ( stderr , " \n " ) ; break ; } fprintf ( stderr , " \n " , d ? " " : " " , d ) ; break ; case BER_TYPE_INTEGER : if ( ber_get_integer ( root , & v ) == -1 ) { fprintf ( stderr , " \n " ) ; break ; } fprintf ( stderr , " \n " , v ) ; break ; case BER_TYPE_ENUMERATED : if ( ber_get_enumerated ( root , & v ) == -1 ) { fprintf ( stderr , " \n " ) ; break ; } fprintf ( stderr , " \n " , v ) ; break ; case BER_TYPE_BITSTRING : if ( ber_get_bitstring ( root , ( void * ) & buf , & len ) == -1 ) { fprintf ( stderr , " \n " ) ; break ; } fprintf ( stderr , " " ) ; for ( i = 0 ; i < len ; i ++ ) fprintf ( stderr , " " , buf [ i ] ) ; fprintf ( stderr , " \n " ) ; break ; case BER_TYPE_OBJECT : if ( ber_get_oid ( root , & o ) == -1 ) { fprintf ( stderr , " \n " ) ; break ; } fprintf ( stderr , " \n " ) ; break ; case BER_TYPE_OCTETSTRING : if ( ber_get_nstring ( root , ( void * ) & buf , & len ) == -1 ) { fprintf ( stderr , " \n " ) ; break ; } fprintf ( stderr , " \" \" \n " , len , buf ) ; break ; case BER_TYPE_NULL : case BER_TYPE_EOC : case BER_TYPE_SEQUENCE : case BER_TYPE_SET : default : fprintf ( stderr , " \n " ) ; break ; } if ( constructed && root -> be_sub ) { indent += 2 ; ldap_debug_elements ( root -> be_sub ) ; indent -= 2 ; } if ( root -> be_next ) ldap_debug_elements ( root -> be_next ) ; }
Display a list of ber elements.
Display a list of ber elements .
/* calculate lengths */ /* XXX: this is not correct */ /* no payload */