2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2005 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
16 * All rights reserved.
22 #include <ac/stdlib.h>
24 #include <ac/socket.h>
25 #include <ac/string.h>
31 ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **berout )
40 LDAP_LOG ( OPERATION, ENTRY, "ldap_first_attribute\n", 0, 0, 0 );
42 Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
46 assert( LDAP_VALID( ld ) );
47 assert( entry != NULL );
48 assert( berout != NULL );
52 ber = ldap_alloc_ber_with_options( ld );
57 *ber = *entry->lm_ber;
60 * Skip past the sequence, dn, sequence of sequence leaving
61 * us at the first attribute.
64 tag = ber_scanf( ber, "{xl{" /*}}*/, &len );
65 if( tag == LBER_ERROR ) {
66 ld->ld_errno = LDAP_DECODING_ERROR;
71 /* set the length to avoid overrun */
72 rc = ber_set_option( ber, LBER_OPT_REMAINING_BYTES, &len );
73 if( rc != LBER_OPT_SUCCESS ) {
74 ld->ld_errno = LDAP_LOCAL_ERROR;
79 if ( ber_pvt_ber_remaining( ber ) == 0 ) {
86 /* snatch the first attribute */
87 tag = ber_scanf( ber, "{ax}", &attr );
88 if( tag == LBER_ERROR ) {
89 ld->ld_errno = LDAP_DECODING_ERROR;
100 ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
106 LDAP_LOG ( OPERATION, ENTRY, "ldap_next_attribute\n", 0, 0, 0 );
108 Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );
111 assert( ld != NULL );
112 assert( LDAP_VALID( ld ) );
113 assert( entry != NULL );
114 assert( ber != NULL );
116 if ( ber_pvt_ber_remaining( ber ) == 0 ) {
120 /* skip sequence, snarf attribute type, skip values */
121 tag = ber_scanf( ber, "{ax}", &attr );
122 if( tag == LBER_ERROR ) {
123 ld->ld_errno = LDAP_DECODING_ERROR;
130 /* Fetch attribute type and optionally fetch values. The type
131 * and values are referenced in-place from the BerElement, they are
132 * not dup'd into malloc'd memory.
136 ldap_get_attribute_ber( LDAP *ld, LDAPMessage *entry, BerElement *ber,
137 BerValue *attr, BerVarray *vals )
140 int rc = LDAP_SUCCESS;
143 LDAP_LOG ( OPERATION, ENTRY, "ldap_get_attribute_ber\n", 0, 0, 0 );
145 Debug( LDAP_DEBUG_TRACE, "ldap_get_attribute_ber\n", 0, 0, 0 );
148 assert( ld != NULL );
149 assert( LDAP_VALID( ld ) );
150 assert( entry != NULL );
151 assert( ber != NULL );
152 assert( attr != NULL );
157 if ( ber_pvt_ber_remaining( ber ) ) {
158 ber_len_t siz = sizeof( BerValue );
160 /* skip sequence, snarf attribute type */
161 tag = ber_scanf( ber, vals ? "{mM}" : "{mx}", attr, vals,
163 if( tag == LBER_ERROR ) {
164 rc = ld->ld_errno = LDAP_DECODING_ERROR;