openldap/libraries/libldap/getattr.c

124 lines
2.4 KiB
C
Raw Normal View History

/* $OpenLDAP$ */
1998-08-09 08:43:13 +08:00
/*
2000-05-13 10:36:07 +08:00
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
1998-12-29 04:53:15 +08:00
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
1998-08-09 08:43:13 +08:00
* Copyright (c) 1990 Regents of the University of Michigan.
* All rights reserved.
*
* getattr.c
*/
1998-10-25 09:41:42 +08:00
#include "portable.h"
1998-08-09 08:43:13 +08:00
#include <stdio.h>
1999-06-03 08:37:44 +08:00
#include <ac/stdlib.h>
1998-10-25 09:41:42 +08:00
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
1998-08-09 08:43:13 +08:00
#include "ldap-int.h"
char *
ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **berout )
1998-08-09 08:43:13 +08:00
{
2000-09-22 09:40:57 +08:00
#if LBER_SEQORSET_AVOID_OVERRUN
int rc;
2000-09-22 09:40:57 +08:00
#endif
ber_tag_t tag;
ber_len_t len;
char *attr;
BerElement *ber;
Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
assert( ld != NULL );
assert( LDAP_VALID( ld ) );
assert( entry != NULL );
assert( berout != NULL );
1998-08-09 08:43:13 +08:00
*berout = NULL;
ber = ldap_alloc_ber_with_options( ld );
if( ber == NULL ) {
return NULL;
1998-08-09 08:43:13 +08:00
}
*ber = *entry->lm_ber;
1998-08-09 08:43:13 +08:00
/*
* Skip past the sequence, dn, sequence of sequence leaving
* us at the first attribute.
1998-08-09 08:43:13 +08:00
*/
tag = ber_scanf( ber, "{xl{" /*}}*/, &attr, &len );
if( tag == LBER_ERROR ) {
1998-08-09 08:43:13 +08:00
ld->ld_errno = LDAP_DECODING_ERROR;
ber_free( ber, 0 );
return NULL;
}
2000-09-30 13:35:44 +08:00
#ifdef LBER_SEQORSET_AVOID_OVERRUN
/* set the length to avoid overrun */
rc = ber_set_option( ber, LBER_OPT_REMAINING_BYTES, &len );
if( rc != LBER_OPT_SUCCESS ) {
ld->ld_errno = LDAP_LOCAL_ERROR;
ber_free( ber, 0 );
return NULL;
1998-08-09 08:43:13 +08:00
}
2000-09-30 13:35:44 +08:00
#ifdef LDAP_SEQORSET_BAILOUT
if ( ber_pvt_ber_remaining( ber ) == 0 ) {
assert( len == 0 );
return NULL;
}
assert( len != 0 );
#endif
#endif
1998-08-09 08:43:13 +08:00
/* snatch the first attribute */
tag = ber_scanf( ber, "{ax}", &attr );
if( tag == LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
ber_free( ber, 0 );
return NULL;
}
*berout = ber;
return attr;
1998-08-09 08:43:13 +08:00
}
/* ARGSUSED */
char *
ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
{
ber_tag_t tag;
char *attr;
Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );
assert( ld != NULL );
assert( LDAP_VALID( ld ) );
assert( entry != NULL );
assert( ber != NULL );
1998-08-09 08:43:13 +08:00
2000-09-30 13:35:44 +08:00
#ifdef LBER_SEQORSET_AVOID_OVERRUN
#ifdef LDAP_SEQORSET_BAILOUT
if ( ber_pvt_ber_remaining( ber ) == 0 ) {
return NULL;
}
2000-09-30 13:35:44 +08:00
#endif
#endif
1998-08-09 08:43:13 +08:00
/* skip sequence, snarf attribute type, skip values */
tag = ber_scanf( ber, "{ax}", &attr );
if( tag == LBER_ERROR ) {
1998-08-09 08:43:13 +08:00
ld->ld_errno = LDAP_DECODING_ERROR;
return NULL;
1998-08-09 08:43:13 +08:00
}
return attr;
1998-08-09 08:43:13 +08:00
}