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