1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 15:16:36 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2021-01-12 03:25:53 +08:00
|
|
|
* Copyright 1998-2021 The OpenLDAP Foundation.
|
2003-11-26 15:16:36 +08:00
|
|
|
* All rights reserved.
|
1998-08-09 08:43:13 +08:00
|
|
|
*
|
2003-11-26 15:16:36 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* Portions Copyright (c) 1990 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
1998-08-09 08:43:13 +08:00
|
|
|
*/
|
|
|
|
|
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-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;
|
1999-05-22 14:11:48 +08:00
|
|
|
char *attr;
|
1998-08-09 08:43:13 +08:00
|
|
|
int found = 0;
|
|
|
|
char **vals;
|
|
|
|
|
1999-06-22 06:38:00 +08:00
|
|
|
assert( ld != NULL );
|
|
|
|
assert( LDAP_VALID( ld ) );
|
|
|
|
assert( entry != NULL );
|
|
|
|
assert( target != NULL );
|
|
|
|
|
2019-02-16 00:47:40 +08:00
|
|
|
Debug0( LDAP_DEBUG_TRACE, "ldap_get_values\n" );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
ber = *entry->lm_ber;
|
|
|
|
|
|
|
|
/* skip sequence, dn, sequence of, and snag the first attr */
|
1999-06-19 07:53:05 +08:00
|
|
|
if ( ber_scanf( &ber, "{x{{a" /*}}}*/, &attr ) == LBER_ERROR ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
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 ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE(attr);
|
1999-05-22 14:11:48 +08:00
|
|
|
attr = NULL;
|
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( target, attr ) == 0 )
|
|
|
|
break;
|
1999-05-22 14:11:48 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE(attr);
|
1999-05-22 14:11:48 +08:00
|
|
|
attr = NULL;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
|
|
|
* 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;
|
1999-05-22 14:11:48 +08:00
|
|
|
char *attr;
|
1998-08-09 08:43:13 +08:00
|
|
|
int found = 0;
|
|
|
|
struct berval **vals;
|
|
|
|
|
1999-06-22 06:38:00 +08:00
|
|
|
assert( ld != NULL );
|
|
|
|
assert( LDAP_VALID( ld ) );
|
|
|
|
assert( entry != NULL );
|
|
|
|
assert( target != NULL );
|
|
|
|
|
2019-02-16 00:47:40 +08:00
|
|
|
Debug0( LDAP_DEBUG_TRACE, "ldap_get_values_len\n" );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
ber = *entry->lm_ber;
|
|
|
|
|
|
|
|
/* skip sequence, dn, sequence of, and snag the first attr */
|
1999-06-19 07:53:05 +08:00
|
|
|
if ( ber_scanf( &ber, "{x{{a" /* }}} */, &attr ) == LBER_ERROR ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
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 ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( attr );
|
1999-05-22 14:11:48 +08:00
|
|
|
attr = NULL;
|
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_DECODING_ERROR;
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( target, attr ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( attr );
|
1999-05-22 14:11:48 +08:00
|
|
|
attr = NULL;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
|
|
|
* 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 )
|
|
|
|
{
|
1999-06-02 03:08:27 +08:00
|
|
|
LDAP_VFREE( vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldap_value_free_len( struct berval **vals )
|
|
|
|
{
|
1999-06-02 03:08:27 +08:00
|
|
|
ber_bvecfree( vals );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2002-10-03 03:14:02 +08:00
|
|
|
|
|
|
|
char **
|
|
|
|
ldap_value_dup( char *const *vals )
|
|
|
|
{
|
|
|
|
char **new;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if( vals == NULL ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i=0; vals[i]; i++ ) {
|
|
|
|
; /* Count the number of values */
|
|
|
|
}
|
|
|
|
|
|
|
|
if( i == 0 ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
new = LDAP_MALLOC( (i+1)*sizeof(char *) ); /* Alloc array of pointers */
|
|
|
|
if( new == NULL ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i=0; vals[i]; i++ ) {
|
|
|
|
new[i] = LDAP_STRDUP( vals[i] ); /* Dup each value */
|
|
|
|
if( new[i] == NULL ) {
|
|
|
|
LDAP_VFREE( new );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new[i] = NULL;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|