LDAP_GET_VALUES(3)

πŸ’… ldap_get_values(3) β€” like, the whole attribute-values situation

okay bestie, so this one is ldap_get_values(3) from the Library Functions Manual, and it's literally the page that teaches you how to grab attribute values out of an LDAP entry and then, you know, clean up after yourself. it's giving responsible queen energy πŸŽ€


✨ NAME ✨

ldap_get_values, ldap_get_values_len, ldap_count_values β€” the LDAP attribute value handling routines. that's the whole vibe. πŸ’–

🫢 LIBRARY 🫢

OpenLDAP LDAP (libldap, -lldap)

🌸 SYNOPSIS 🌸

#include <ldap.h>

char **ldap_get_values(ld, entry, attr)
LDAP *ld;
LDAPMessage *entry;
char *attr;

struct berval **ldap_get_values_len(ld, entry, attr)
LDAP *ld;
LDAPMessage *entry;
char *attr;

int ldap_count_values(vals)
char **vals;

int ldap_count_values_len(vals)
struct berval **vals;

void ldap_value_free(vals)
char **vals;

void ldap_value_free_len(vals)
struct berval **vals;

yes the synopsis is long. no we are not skipping any of it. every single line is here and every single line stays. 😌


πŸ¦‹ DESCRIPTION πŸ¦‹

so these routines exist for retrieving and manipulating attribute values from an LDAP entry β€” specifically an entry you got back from ldap_first_entry(3) or ldap_next_entry(3). main character entry energy honestly.

ldap_get_values() takes the entry plus the attribute attr whose values you're obsessed with, and returns a NULL-terminated array of that attribute's values. and here's the cute part: attr can totally be an attribute type as returned from ldap_first_attribute(3) or ldap_next_attribute(3) β€” or, if you already know the attribute type, you can just... hand it over. lowkey convenient fr fr. πŸ’…

wanna know how many values are in that array? call ldap_count_values(). iconic. and when you're done with the array of values? free it with ldap_value_free(). because we are not leaving memory lying around, no ma'am.


now. if your attribute values are binary in nature β€” which means they're just not suitable to be returned as an array of char *'s, like it's simply not their moment β€” you use ldap_get_values_len() instead. she takes the same parameters as ldap_get_values() but returns a NULL-terminated array of pointers to berval structures, and each one contains the length of and a pointer to a value. struct girlies rise 🧚

you count those with ldap_count_values_len(), and you free the returned array with ldap_value_free_len(). matching set, absolutely ate. ⭐

😭 ERRORS 😭

if something goes wrong in ldap_get_values() or ldap_get_values_len(), they return NULL and the ld_errno field in the ld parameter gets set to indicate the error. so check your ld_errno, bestie. see ldap_error(3) for a description of possible error codes. πŸ’€

πŸ‘‘ NOTES πŸ‘‘

these routines dynamically allocate memory which the caller must free using the supplied routines. like, that's on you. the supplied routines are right there. use them. 🫢

🌈 SEE ALSO 🌈

ldap(3), ldap_first_entry(3), ldap_first_attribute(3), ldap_error(3)

πŸ”₯ ACKNOWLEDGEMENTS πŸ”₯

OpenLDAP Software is developed and maintained by The OpenLDAP Project <http://www.openldap.org/>. OpenLDAP Software is derived from the University of Michigan LDAP 3.3 Release.


and that's the page, periodt. πŸ’œ this was OpenLDAP 2.6.16, dated 2026/10/21 β€” mwah, go forth and free your values πŸŽ€βœ¨

πŸ“¦ where this page comes from