1998-08-09 08:43:13 +08:00
|
|
|
/*
|
1998-12-29 04:53:15 +08:00
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* getvalues.c
|
|
|
|
*/
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-08-21 03:42:38 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
#include "ldap-int.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
char **
|
1999-05-19 09:12:33 +08:00
|
|
|
ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
BerElement ber;
|
|
|
|
char attr[LDAP_MAX_ATTR_LEN];
|
|
|
|
int found = 0;
|
|
|
|
long len;
|
|
|
|
char **vals;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
ber = *entry->lm_ber;
|
|
|
|
|
|
|
|
/* skip sequence, dn, sequence of, and snag the first attr */
|
|
|
|
len = sizeof(attr);
|
|
|
|
if ( ber_scanf( &ber, "{x{{s", attr, &len ) == LBER_ERROR ) {
|
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( target, attr ) == 0 )
|
|
|
|
found = 1;
|
|
|
|
|
|
|
|
/* break out on success, return out on error */
|
|
|
|
while ( ! found ) {
|
|
|
|
len = sizeof(attr);
|
|
|
|
if ( ber_scanf( &ber, "x}{s", attr, &len ) == LBER_ERROR ) {
|
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( target, attr ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we get this far, we've found the attribute and are sitting
|
|
|
|
* just before the set of values.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ber_scanf( &ber, "[v]", &vals ) == LBER_ERROR ) {
|
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( vals );
|
|
|
|
}
|
|
|
|
|
|
|
|
struct berval **
|
1999-05-19 09:12:33 +08:00
|
|
|
ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
BerElement ber;
|
|
|
|
char attr[LDAP_MAX_ATTR_LEN];
|
|
|
|
int found = 0;
|
|
|
|
long len;
|
|
|
|
struct berval **vals;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
ber = *entry->lm_ber;
|
|
|
|
|
|
|
|
/* skip sequence, dn, sequence of, and snag the first attr */
|
|
|
|
len = sizeof(attr);
|
|
|
|
if ( ber_scanf( &ber, "{x{{s", attr, &len ) == LBER_ERROR ) {
|
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( target, attr ) == 0 )
|
|
|
|
found = 1;
|
|
|
|
|
|
|
|
/* break out on success, return out on error */
|
|
|
|
while ( ! found ) {
|
|
|
|
len = sizeof(attr);
|
|
|
|
if ( ber_scanf( &ber, "x}{s", attr, &len ) == LBER_ERROR ) {
|
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( target, attr ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we get this far, we've found the attribute and are sitting
|
|
|
|
* just before the set of values.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ber_scanf( &ber, "[V]", &vals ) == LBER_ERROR ) {
|
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( vals );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_count_values( char **vals )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( vals == NULL )
|
|
|
|
return( 0 );
|
|
|
|
|
|
|
|
for ( i = 0; vals[i] != NULL; i++ )
|
|
|
|
; /* NULL */
|
|
|
|
|
|
|
|
return( i );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_count_values_len( struct berval **vals )
|
|
|
|
{
|
|
|
|
return( ldap_count_values( (char **) vals ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldap_value_free( char **vals )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( vals == NULL )
|
|
|
|
return;
|
|
|
|
for ( i = 0; vals[i] != NULL; i++ )
|
|
|
|
free( vals[i] );
|
|
|
|
free( (char *) vals );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldap_value_free_len( struct berval **vals )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( vals == NULL )
|
|
|
|
return;
|
|
|
|
for ( i = 0; vals[i] != NULL; i++ ) {
|
|
|
|
free( vals[i]->bv_val );
|
|
|
|
free( vals[i] );
|
|
|
|
}
|
|
|
|
free( (char *) vals );
|
|
|
|
}
|