ldap_get_values() function returns a NULL-terminated array of an attribute's string values for a given entry. Use the ldap_get_values_len() function instead of this function if the attribute values are binary.
For more information, see "Getting the Values of an Attribute" on page 131.
#include <ldap.h>
char ** ldap_get_values( LDAP *ld, LDAPMessage *entry,
const char *target );
ld |
Connection handle, which is a pointer to an |
entry |
Result returned by the |
target |
Attribute returned by |
LDAP structure. To get the error code, call the ldap_get_lderrno() function. (See "Result Codes" on page 691 for a complete listing of error codes.) #include <stdio.h>
#include <ldap.h>
...
LDAP *ld;
LDAPMessage *result, *e;
BerElement *ber;
char *a;
char **vals;
char *my_searchbase = "o=Airius.com";
char *my_filter = "(sn=Jensen)";
int i;
...
/* Search the directory */
if ( ldap_search_s( ld, my_searchbase, LDAP_SCOPE_SUBTREE, my_filter,
NULL, 0, &result ) != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_search_s" );
return( 1 );
}
/* Get the first matching entry.*/
e = ldap_first_entry( ld, result );
/* Get the first matching attribute */
a = ldap_first_attribute( ld, e, &ber );
/* Get the values of the attribute */
if ( ( vals = ldap_get_values( ld, e, a ) ) != NULL ) { for ( i = 0; vals[i] != NULL; i++ ) {/* Print the name of the attribute and each value */
printf( "%s: %s\n", a, vals[i] );
}
/* Free the attribute values from memory when done. */
ldap_value_free( vals );
}
...
ldap_first_entry(), ldap_next_entry(), ldap_first_attribute(), ldap_next_attribute(), ldap_get_lang_values(), ldap_get_values_len().
Last Updated: 10/01/98 17:06:23