LDAP_COMPARE(3)

πŸ’… LDAP_COMPARE(3) β€” the compare glow-up

okay so this is LDAP_COMPARE(3) from the Library Functions Manual, and bestie, it's literally all about performing an LDAP compare operation. Four functions, one job: does this entry have this value or not. iykyk.


πŸŽ€ NAME

ldap_compare, ldap_compare_s, ldap_compare_ext, ldap_compare_ext_s β€” perform an LDAP compare operation. that's it, that's the whole vibe.


πŸ“š LIBRARY

OpenLDAP LDAP (libldap, -lldap) β€” yeah, you gotta link the lib, no cap.


✨ SYNOPSIS

#include <ldap.h>

int ldap_compare_ext(
       LDAP *ld,
       char *dn,
       char *attr,
       const struct berval *bvalue,
       LDAPControl **serverctrls,
       LDAPControl **clientctrls,
       int *msgidp );

int ldap_compare_ext_s(
       LDAP *ld,
       char *dn,
       char *attr,
       const struct berval *bvalue,
       LDAPControl **serverctrls,
       LDAPControl **clientctrls );

like, copy these exactly, please. const struct berval *bvalue is not a suggestion πŸ’€


πŸ¦‹ DESCRIPTION

so ldap_compare_ext_s() is the synchronous one β€” it does the LDAP compare operation and just... waits. icon behavior, honestly. it takes dn, the DN of the entry you're comparing against, plus attr and value, the attribute description and the value you want to compare to whatever's actually sitting in that entry. and then it returns a code:

  • LDAP_COMPARE_TRUE if the entry contains the attribute value β€” slay πŸ’–
  • LDAP_COMPARE_FALSE if it does not β€” tragic, but valid 🌸
  • otherwise you get an error code telling you what kind of problem it is. see ldap(3) for the deets, bestie.

and ldap_compare_ext() is the asynchronous one, main character energy ✨. same parameters as ldap_compare_ext_s(), but it hands you back the message id of the request it just kicked off, in the integer that msgidp points to. wanna know the result of the compare? that's a whole separate call to ldap_result(3) later. patience, queen πŸ‘‘

both routines let you specify server and client controls to extend the compare request. fancy πŸŽ€


πŸ’€ DEPRECATED INTERFACES

okay so listen β€” ldap_compare() and ldap_compare_s() are deprecated in favor of ldap_compare_ext() and ldap_compare_ext_s(), respectively. retired. past their era. we don't stan πŸ‘‘

deprecated interfaces generally remain in the library though (they're lurking, not gone). you can define the macro LDAP_DEPRECATED to a non-zero value (e.g., -DLDAP_DEPRECATED=1) when compiling a program designed to use deprecated interfaces β€” that's how you get them to show up.

and like, genuinely: it is recommended that developers writing new programs, or updating old programs, avoid use of deprecated interfaces. over time it's expected that documentation (and, eventually, support) for deprecated interfaces gets eliminated. so... don't get attached 😭

🌈 SEE ALSO

go read those, fr fr 🫢


πŸ‘‘ 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. giving credit where it's due, as always πŸŽ€


⭐ and that's the tea! this little beauty is from OpenLDAP 2.6.16, dated 2026/10/21 β€” LDAP_COMPARE(3) out πŸ’…βœ¨

πŸ“¦ where this page comes from