1999-09-09 03:06:24 +08:00
|
|
|
/* $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 *
|
2000-09-15 09:16:09 +08:00
|
|
|
ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **berout )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
2000-09-16 09:05:14 +08:00
|
|
|
int rc;
|
|
|
|
ber_tag_t tag;
|
2000-09-30 14:57:23 +08:00
|
|
|
ber_len_t len = 0;
|
1999-05-22 14:11:48 +08:00
|
|
|
char *attr;
|
2000-09-15 09:16:09 +08:00
|
|
|
BerElement *ber;
|
1999-05-22 14:11:48 +08:00
|
|
|
|
1999-06-06 04:18:32 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
|
|
|
|
|
1999-05-22 14:11:48 +08:00
|
|
|
assert( ld != NULL );
|
1999-06-06 04:18:32 +08:00
|
|
|
assert( LDAP_VALID( ld ) );
|
1999-05-22 14:11:48 +08:00
|
|
|
assert( entry != NULL );
|
2000-09-15 09:16:09 +08:00
|
|
|
assert( berout != NULL );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-09-16 09:05:14 +08:00
|
|
|
*berout = NULL;
|
|
|
|
|
2000-09-15 09:16:09 +08:00
|
|
|
ber = ldap_alloc_ber_with_options( ld );
|
|
|
|
if( ber == NULL ) {
|
|
|
|
return NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2000-09-15 09:16:09 +08:00
|
|
|
*ber = *entry->lm_ber;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/*
|
2000-09-15 09:16:09 +08:00
|
|
|
* Skip past the sequence, dn, sequence of sequence leaving
|
|
|
|
* us at the first attribute.
|
1998-08-09 08:43:13 +08:00
|
|
|
*/
|
|
|
|
|
2000-09-30 14:57:23 +08:00
|
|
|
tag = ber_scanf( ber, "{xl{" /*}}*/, &len );
|
2000-09-16 09:05:14 +08:00
|
|
|
if( tag == LBER_ERROR ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
2000-09-15 09:16:09 +08:00
|
|
|
ber_free( ber, 0 );
|
2000-09-30 14:57:23 +08:00
|
|
|
return NULL;
|
2000-09-15 09:16:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
if ( ber_pvt_ber_remaining( ber ) == 0 ) {
|
|
|
|
assert( len == 0 );
|
2001-02-03 09:49:12 +08:00
|
|
|
ber_free( ber, 0 );
|
2000-09-30 13:35:44 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
assert( len != 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-09-15 09:16:09 +08:00
|
|
|
/* snatch the first attribute */
|
2000-09-16 09:05:14 +08:00
|
|
|
tag = ber_scanf( ber, "{ax}", &attr );
|
|
|
|
if( tag == LBER_ERROR ) {
|
2000-09-15 09:16:09 +08:00
|
|
|
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 )
|
|
|
|
{
|
2000-09-16 09:05:14 +08:00
|
|
|
ber_tag_t tag;
|
1999-05-22 14:11:48 +08:00
|
|
|
char *attr;
|
|
|
|
|
1999-06-06 04:18:32 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );
|
|
|
|
|
1999-05-22 14:11:48 +08:00
|
|
|
assert( ld != NULL );
|
1999-06-06 04:18:32 +08:00
|
|
|
assert( LDAP_VALID( ld ) );
|
1999-05-22 14:11:48 +08:00
|
|
|
assert( entry != NULL );
|
|
|
|
assert( ber != NULL );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-09-15 13:56:37 +08:00
|
|
|
if ( ber_pvt_ber_remaining( ber ) == 0 ) {
|
2000-09-15 09:16:09 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* skip sequence, snarf attribute type, skip values */
|
2000-09-16 09:05:14 +08:00
|
|
|
tag = ber_scanf( ber, "{ax}", &attr );
|
|
|
|
if( tag == LBER_ERROR ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
2000-09-15 09:16:09 +08:00
|
|
|
return NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2000-09-15 09:16:09 +08:00
|
|
|
return attr;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|