1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  *
3*0Sstevel@tonic-gate  * Portions Copyright %G% Sun Microsystems, Inc.
4*0Sstevel@tonic-gate  * All Rights Reserved
5*0Sstevel@tonic-gate  *
6*0Sstevel@tonic-gate  */
7*0Sstevel@tonic-gate 
8*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
9*0Sstevel@tonic-gate 
10*0Sstevel@tonic-gate /*
11*0Sstevel@tonic-gate  *  Copyright (c) 1990 Regents of the University of Michigan.
12*0Sstevel@tonic-gate  *  All rights reserved.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  *  getattr.c
15*0Sstevel@tonic-gate  */
16*0Sstevel@tonic-gate 
17*0Sstevel@tonic-gate #ifndef lint
18*0Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
19*0Sstevel@tonic-gate #endif
20*0Sstevel@tonic-gate 
21*0Sstevel@tonic-gate #include <stdio.h>
22*0Sstevel@tonic-gate #include <ctype.h>
23*0Sstevel@tonic-gate #include <string.h>
24*0Sstevel@tonic-gate #ifdef MACOS
25*0Sstevel@tonic-gate #include <stdlib.h>
26*0Sstevel@tonic-gate #include "macos.h"
27*0Sstevel@tonic-gate #else /* MACOS */
28*0Sstevel@tonic-gate #if defined( DOS ) || defined( _WIN32 )
29*0Sstevel@tonic-gate #include <malloc.h>
30*0Sstevel@tonic-gate #include "msdos.h"
31*0Sstevel@tonic-gate #else /* DOS */
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <sys/socket.h>
34*0Sstevel@tonic-gate #endif /* DOS */
35*0Sstevel@tonic-gate #endif /* MACOS */
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #include "lber.h"
38*0Sstevel@tonic-gate #include "ldap.h"
39*0Sstevel@tonic-gate #include "ldap-private.h"
40*0Sstevel@tonic-gate #include "ldap-int.h"
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate char *
43*0Sstevel@tonic-gate ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **ber )
44*0Sstevel@tonic-gate {
45*0Sstevel@tonic-gate 	int	len;
46*0Sstevel@tonic-gate 	char	*attrbuffer;
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate 	if ((attrbuffer = (char *)malloc(LDAP_MAX_ATTR_LEN)) == NULL) {
49*0Sstevel@tonic-gate 		return (NULL);
50*0Sstevel@tonic-gate 	}
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate 	Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 179, "ldap_first_attribute\n"), 0, 0, 0 );
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate 	if ( (*ber = alloc_ber_with_options( ld )) == NULLBER ) {
55*0Sstevel@tonic-gate 		free(attrbuffer);
56*0Sstevel@tonic-gate 		return( NULL );
57*0Sstevel@tonic-gate 	}
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate 	**ber = *entry->lm_ber;
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate 	/*
62*0Sstevel@tonic-gate 	 * Skip past the sequence, dn, sequence of sequence, snarf the
63*0Sstevel@tonic-gate 	 * attribute type, and skip the set of values, leaving us
64*0Sstevel@tonic-gate 	 * positioned right before the next attribute type/value sequence.
65*0Sstevel@tonic-gate 	 */
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate 	len = LDAP_MAX_ATTR_LEN;
68*0Sstevel@tonic-gate 	if ( ber_scanf( *ber, "{x{{sx}", attrbuffer, &len )
69*0Sstevel@tonic-gate 	    == LBER_ERROR ) {
70*0Sstevel@tonic-gate 		ld->ld_errno = LDAP_DECODING_ERROR;
71*0Sstevel@tonic-gate 		ber_free( *ber, 0 );
72*0Sstevel@tonic-gate 		*ber = NULL;
73*0Sstevel@tonic-gate 		free(attrbuffer);
74*0Sstevel@tonic-gate 		return( NULL );
75*0Sstevel@tonic-gate 	}
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate 	return( attrbuffer );
78*0Sstevel@tonic-gate }
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate /* ARGSUSED */
81*0Sstevel@tonic-gate char *
82*0Sstevel@tonic-gate ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
83*0Sstevel@tonic-gate {
84*0Sstevel@tonic-gate 	int	len;
85*0Sstevel@tonic-gate 	char	*attrbuffer;
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate 	if ((attrbuffer = (char *)malloc(LDAP_MAX_ATTR_LEN)) == NULL) {
88*0Sstevel@tonic-gate 		return (NULL);
89*0Sstevel@tonic-gate 	}
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate 	Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 180, "ldap_next_attribute\n"), 0, 0, 0 );
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate 	/* skip sequence, snarf attribute type, skip values */
94*0Sstevel@tonic-gate 	len = LDAP_MAX_ATTR_LEN;
95*0Sstevel@tonic-gate 	if ( ber_scanf( ber, "{sx}", attrbuffer, &len )
96*0Sstevel@tonic-gate 	    == LBER_ERROR ) {
97*0Sstevel@tonic-gate 		ld->ld_errno = LDAP_DECODING_ERROR;
98*0Sstevel@tonic-gate 		free(attrbuffer);
99*0Sstevel@tonic-gate 		return( NULL );
100*0Sstevel@tonic-gate 	}
101*0Sstevel@tonic-gate 	ld->ld_errno = LDAP_SUCCESS;
102*0Sstevel@tonic-gate 	return( attrbuffer );
103*0Sstevel@tonic-gate }
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate void ldap_memfree(char *mem)
106*0Sstevel@tonic-gate {
107*0Sstevel@tonic-gate 	free(mem);
108*0Sstevel@tonic-gate }
109*0Sstevel@tonic-gate 
110