LDAP_GET_OPTION(3)

πŸ’– LDAP_GET_OPTION(3) πŸ’–

okay so bestie, this page is from the Library Functions Manual, and the main character energy here is LDAP_GET_OPTION(3) β€” aka the option-handling routines. ✨

🌸 NAME 🌸

ldap_get_option, ldap_set_option β€” LDAP option handling routines. that's the whole name, and honestly it's giving exactly what it says. πŸ’…

πŸ“š LIBRARY πŸ“š

OpenLDAP LDAP (libldap, -lldap) β€” that's where these live.

✨ SYNOPSIS ✨

#include <ldap.h>

int ldap_get_option(LDAP *ld, int option, void *outvalue);

int ldap_set_option(LDAP *ld, int option, const void *invalue);

πŸ’… DESCRIPTION πŸ’…

okay so these routines provide access to options stored either in a LDAP handle or as global options, where applicable. They make use of a neutral interface, where the type of the value either retrieved by ldap_get_option(3) or set by ldap_set_option(3) is cast to void *. The actual type is determined based on the value of the option argument. Global options are set/retrieved by passing a NULL LDAP handle. LDAP handles inherit their default settings from the global options in effect at the time the handle is created.

now the options, bestie β€” every single one, no skipping:

  • LDAP_OPT_API_FEATURE_INFO β€” this one fills in a LDAPAPIFeatureInfo for you. outvalue has to be a LDAPAPIFeatureInfo * and it must point to an already-allocated struct. Before you call, initialize the struct's ldapaif_info_version field to LDAP_FEATURE_INFO_VERSION, and set ldapaif_name to the name of the feature you're asking about. it's read-only, periodt.
  • LDAP_OPT_API_INFO β€” fills in a LDAPAPIInfo; outvalue must be a LDAPAPIInfo * pointing to an already allocated struct. The struct's ldapai_info_version field must be initialized to LDAP_API_INFO_VERSION before the call. If the version you pass in does not match the current library version, the expected version number will be stored in the struct and the call will fail (rude, but that's the spec). The caller is responsible for freeing the elements of the ldapai_extensions array and the array itself using ldap_memfree(3). The caller must also free the ldapi_vendor_name. This is a read-only option.
  • LDAP_OPT_CLIENT_CONTROLS β€” sets/gets the client-side controls used for all operations. Heads up: this is now deprecated, because the modern LDAP C API provides replacements for all main operations which accepts client-side controls as explicit arguments β€” see for example ldap_search_ext(3), ldap_add_ext(3), ldap_modify_ext(3) and so on. outvalue must be LDAPControl ***, and the caller is responsible for freeing the returned controls, if any, by calling ldap_controls_free(3). invalue must be LDAPControl *const *; the library duplicates the controls passed via invalue.
  • LDAP_OPT_CONNECT_ASYNC β€” sets/gets the status of the asynchronous connect flag. invalue should either be LDAP_OPT_OFF or LDAP_OPT_ON; outvalue must be int *. When set, the library will call connect(2) and return, without waiting for response. This leaves the handle in a connecting state. Subsequent calls to library routines will poll for completion of the connect before performing further operations. As a consequence, library calls that need to establish a connection with a DSA do not block even for the network timeout (option LDAP_OPT_NETWORK_TIMEOUT). This option is OpenLDAP specific.
  • LDAP_OPT_CONNECT_CB β€” lets you set a connect callback. invalue must be a const struct ldap_conncb *. Callbacks are executed in last in-first served order. Handle-specific callbacks are executed first, followed by global ones. Right before freeing the callback structure, the lc_del callback handler is passed a NULL Sockbuf. Calling ldap_get_option(3) for this option removes the callback whose pointer matches outvalue (yes, the getter deletes β€” iconic behavior). This option is OpenLDAP specific.
  • LDAP_OPT_DEBUG_LEVEL β€” sets/gets the debug level of the client library. invalue must be a const int *; outvalue must be a int *. Valid debug levels are LDAP_DEBUG_ANY, LDAP_DEBUG_ARGS, LDAP_DEBUG_BER, LDAP_DEBUG_CONNS, LDAP_DEBUG_NONE, LDAP_DEBUG_PACKETS, LDAP_DEBUG_PARSE, and LDAP_DEBUG_TRACE. This option is OpenLDAP specific.
  • LDAP_OPT_DEFBASE β€” sets/gets a string containing the DN to be used as default base for search operations. outvalue must be a char **, and the caller is responsible for freeing the returned string by calling ldap_memfree(3). invalue must be a const char *; the library duplicates the corresponding string. This option is OpenLDAP specific.
  • LDAP_OPT_DEREF β€” sets/gets the value that defines when alias dereferencing must occur. invalue must be const int *; outvalue must be int *. They cannot be NULL. The value of *invalue should be one of LDAP_DEREF_NEVER (the default), LDAP_DEREF_SEARCHING, LDAP_DEREF_FINDING, or LDAP_DEREF_ALWAYS. Note that this has ever been the only means to determine alias dereferencing within search operations. (yes, "ever been" is doing a lot, but that's the note. πŸ‘€)
  • LDAP_OPT_DESC β€” returns the file descriptor associated to the socket buffer of the LDAP handle passed in as ld; outvalue must be a int *. This is a read-only, handle-specific option.
  • LDAP_OPT_DIAGNOSTIC_MESSAGE β€” sets/gets a string containing the error string associated to the LDAP handle. This option was formerly known as LDAP_OPT_ERROR_STRING. outvalue must be a char **, and the caller is responsible for freeing the returned string by calling ldap_memfree(3). invalue must be a char *; the library duplicates the corresponding string.
  • LDAP_OPT_HOST_NAME β€” sets/gets a space-separated list of hosts to be contacted by the library when trying to establish a connection. This is now deprecated in favor of LDAP_OPT_URI. outvalue must be a char **, and the caller is responsible for freeing the resulting string by calling ldap_memfree(3). invalue must be a const char *; the library duplicates the corresponding string.
  • LDAP_OPT_MATCHED_DN β€” sets/gets a string containing the matched DN associated to the LDAP handle. outvalue must be a char **, and the caller is responsible for freeing the returned string by calling ldap_memfree(3). invalue must be a const char *; the library duplicates the corresponding string.
  • LDAP_OPT_NETWORK_TIMEOUT β€” sets/gets the network timeout value after which poll(2)/select(2) following a connect(2) returns in case of no activity. outvalue must be a struct timeval ** (the caller has to free *outvalue using ldap_memfree(3)), and invalue must be a const struct timeval *. They cannot be NULL. Using a struct with seconds set to -1 results in an infinite timeout, which is the default. This option is OpenLDAP specific.
  • LDAP_OPT_PROTOCOL_VERSION β€” sets/gets the protocol version. outvalue and invalue must be int *.
  • LDAP_OPT_REFERRAL_URLS β€” sets/gets an array containing the referral URIs associated to the LDAP handle. outvalue must be a char ***, and the caller is responsible for freeing the returned string by calling ldap_memvfree(3). invalue must be a NULL-terminated char *const *; the library duplicates the corresponding string. This option is OpenLDAP specific.
  • LDAP_OPT_REFERRALS β€” determines whether the library should implicitly chase referrals or not. invalue must be const int *; its value should either be LDAP_OPT_OFF or LDAP_OPT_ON. outvalue must be int *.
  • LDAP_OPT_RESTART β€” determines whether the library should implicitly restart connections (FIXME). invalue must be const int *; its value should either be LDAP_OPT_OFF or LDAP_OPT_ON. outvalue must be int *.
  • LDAP_OPT_RESULT_CODE β€” sets/gets the LDAP result code associated to the handle. This option was formerly known as LDAP_OPT_ERROR_NUMBER. invalue must be a const int *. outvalue must be a int *.
  • LDAP_OPT_SERVER_CONTROLS β€” sets/gets the server-side controls to be used for all operations. This is now deprecated as modern LDAP C API provides replacements for all main operations which accepts server-side controls as explicit arguments; see for example ldap_search_ext(3), ldap_add_ext(3), ldap_modify_ext(3) and so on. outvalue must be LDAPControl ***, and the caller is responsible for freeing the returned controls, if any, by calling ldap_controls_free(3). invalue must be LDAPControl *const *; the library duplicates the controls passed via invalue.
  • LDAP_OPT_SESSION_REFCNT β€” returns the reference count associated with the LDAP handle passed in as ld; outvalue must be a int *. This is a read-only, handle-specific option. This option is OpenLDAP specific.
  • LDAP_OPT_SIZELIMIT β€” sets/gets the value that defines the maximum number of entries to be returned by a search operation. invalue must be const int *, while outvalue must be int *; they cannot be NULL.
  • LDAP_OPT_SOCKBUF β€” returns a pointer to the socket buffer of the LDAP handle passed in as ld; outvalue must be a Sockbuf **. This is a read-only, handle-specific option. This option is OpenLDAP specific.
  • LDAP_OPT_SOCKET_BIND_ADDRESSES β€” sets/gets a space-separated list of IP Addresses used as binding interface to remote server when trying to establish a connection. Only one valid IPv4 address and/or one valid IPv6 address are allowed in the list. outvalue must be a char **, and the caller is responsible for freeing the returned string by calling ldap_memfree(3). invalue must be a const char *; the library duplicates the corresponding string.
  • LDAP_OPT_TIMELIMIT β€” sets/gets the value that defines the time limit after which a search operation should be terminated by the server. invalue must be const int *, while outvalue must be int *, and they cannot be NULL.
  • LDAP_OPT_TIMEOUT β€” sets/gets a timeout value for the synchronous API calls. outvalue must be a struct timeval ** (the caller has to free *outvalue using ldap_memfree(3)), and invalue must be a struct timeval *, and they cannot be NULL. Using a struct with seconds set to -1 results in an infinite timeout, which is the default. This option is OpenLDAP specific πŸ’…
  • LDAP_OPT_URI β€” the ultimate ✨connection vision board✨, bestie. This sets/gets a comma- or space-separated list of URIs that the library is gonna go hit up when it's trying to establish a connection. outvalue has to be a char **, and you β€” yes you, the caller β€” are responsible for freeing the resulting string by calling ldap_memfree(3). Meanwhile invalue must be a const char *. Heads up tho: the library parses that string into a list of LDAPURLDesc structures, so your ldap_set_option(3) call may fail if URL parsing fails 😭. Also URIs may only contain the schema, the host, and the port fields β€” that's it, no extras. This option is OpenLDAP specific πŸ’….
  • LDAP_OPT_KEEPCONN β€” tells ldap_result(3) to keep the connection open on a read error or if a Notice of Disconnection shows up 🫢. In those cases, the connection should be closed by the caller (that's you, bestie, it's giving main character responsibility). This option is OpenLDAP specific.
  • LDAP_OPT_TCP_USER_TIMEOUT β€” lets you configure TCP_USER_TIMEOUT in milliseconds on the connection, overriding the operating system setting πŸ‘‘. This option is OpenLDAP specific and supported only on Linux 2.6.37 or higher. invalue must be a const unsigned int *; outvalue must be an unsigned int *.

🌸 SASL OPTIONS 🌸

The SASL options are OpenLDAP specific and β€” unless otherwise noted β€” they require an LDAP handle to be passed. No handle, no vibes ✨.

  • LDAP_OPT_X_SASL_AUTHCID β€” gets the SASL authentication identity πŸŽ€. outvalue must be a char **, and its content needs to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_SASL_AUTHZID β€” gets the SASL authorization identity πŸŽ€. outvalue must be a char **, and its content needs to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_SASL_MAXBUFSIZE β€” gets/sets the SASL maximum buffer size πŸ’–. invalue must be const ber_len_t *, while outvalue must be ber_len_t *. See also LDAP_OPT_X_SASL_SECPROPS.
  • LDAP_OPT_X_SASL_MECH β€” gets the SASL mechanism πŸ¦‹. outvalue must be a char **, and its content needs to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_SASL_MECHLIST β€” gets the list of available mechanisms, in the form of a NULL-terminated array of strings 🌈. outvalue must be char ***. The caller must not free or otherwise muck with it. This option can be used globally.
  • LDAP_OPT_X_SASL_NOCANON β€” sets/gets the NOCANON flag ⭐. When it's unset, the hostname is canonicalized. invalue must be const int *, and its value should either be LDAP_OPT_OFF or LDAP_OPT_ON. outvalue must be int *.
  • LDAP_OPT_X_SASL_REALM β€” gets the SASL realm πŸ‘‘. outvalue must be a char **, and its content needs to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_SASL_SECPROPS β€” sets the SASL secprops πŸ”₯. invalue must be a char * containing a comma-separated list of properties. Legal values are: none, nodict, noplain, noactive, passcred, forwardsec, noanonymous, minssf=<minssf>, maxssf=<maxssf>, maxbufsize=<maxbufsize>.
  • LDAP_OPT_X_SASL_SSF β€” gets the SASL SSF πŸ’œ. outvalue must be a ber_len_t *.
  • LDAP_OPT_X_SASL_SSF_EXTERNAL β€” sets the SASL SSF value related to an authentication performed using an EXTERNAL mechanism 🧚. invalue must be a const ber_len_t *.
  • LDAP_OPT_X_SASL_SSF_MAX β€” gets/sets the SASL maximum SSF πŸ“ˆ. invalue must be const ber_len_t *, while outvalue must be ber_len_t *. See also LDAP_OPT_X_SASL_SECPROPS.
  • LDAP_OPT_X_SASL_SSF_MIN β€” gets/sets the SASL minimum SSF πŸ“‰. invalue must be const ber_len_t *, while outvalue must be ber_len_t *. See also LDAP_OPT_X_SASL_SECPROPS.
  • LDAP_OPT_X_SASL_USERNAME β€” gets the SASL username πŸ’…. outvalue must be a char **. Its content needs to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_SASL_CBINDING β€” sets/gets the channel-binding type to use in SASL πŸ”, one of LDAP_OPT_X_SASL_CBINDING_NONE (the default), LDAP_OPT_X_SASL_CBINDING_TLS_UNIQUE β€” the "tls-unique" type from RFC 5929 β€” or LDAP_OPT_X_SASL_CBINDING_TLS_ENDPOINT, the "tls-server-end-point" from RFC 5929, which is compatible with Windows. invalue must be const int *; outvalue must be int *.

πŸ¦‹ TCP OPTIONS πŸ¦‹

The TCP options are OpenLDAP specific. They're mainly intended for use with Linux, so ngl they may not be portable πŸ™ˆ.

  • LDAP_OPT_X_KEEPALIVE_IDLE β€” sets/gets the number of seconds a connection needs to remain idle before TCP starts sending keepalive probes πŸ’€. invalue must be const int *; outvalue must be int *.
  • LDAP_OPT_X_KEEPALIVE_PROBES β€” sets/gets the maximum number of keepalive probes TCP should send before dropping the connection πŸ’€. invalue must be const int *; outvalue must be int *.
  • LDAP_OPT_X_KEEPALIVE_INTERVAL β€” sets/gets the interval in seconds between individual keepalive probes ⏰. invalue must be const int *; outvalue must be int *.

✨ TLS OPTIONS ✨

okay so these ones are OpenLDAP specific bestie β€” like, they're ours, not some universal LDAP thing. no cap. πŸ’…

  • LDAP_OPT_X_TLS_CACERTDIR β€” sets/gets the path of the directories that hold your CA certificates. you can give it multiple directories, just separate them with a semi-colon (;) 🫢. invalue must be const char *; outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_TLS_CACERTFILE β€” sets/gets the full-path of the CA certificate file. invalue must be const char *; outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_TLS_CERTFILE β€” sets/gets the full-path of the certificate file. invalue must be const char *; outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_TLS_CIPHER β€” gets the cipher being used on an established TLS session (note: gets only, no setting here, periodt). outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_TLS_CIPHER_SUITE β€” sets/gets the allowed cipher suite. invalue must be const char *; outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_TLS_CONNECT_ARG β€” sets/gets the connection callback argument. invalue must be const void *; outvalue must be void **.
  • LDAP_OPT_X_TLS_CONNECT_CB β€” sets/gets the connection callback handle. invalue must be const LDAP_TLS_CONNECT_CB *; outvalue must be LDAP_TLS_CONNECT_CB **.
  • LDAP_OPT_X_TLS_CRLCHECK β€” sets/gets the CRL evaluation strategy, one of LDAP_OPT_X_TLS_CRL_NONE, LDAP_OPT_X_TLS_CRL_PEER, or LDAP_OPT_X_TLS_CRL_ALL. invalue must be const int *; outvalue must be int *. 🚨 Requires OpenSSL.
  • LDAP_OPT_X_TLS_CRLFILE β€” sets/gets the full-path of the CRL file. invalue must be const char *; outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3). heads up: this option is only valid for GnuTLS πŸ™ˆ.
  • LDAP_OPT_X_TLS_CTX β€” sets/gets the TLS library context. new TLS sessions will inherit their default settings from this library context, iconic behavior tbh. invalue must be const void *; outvalue must be void **. when you're using the OpenSSL library this is an SSL_CTX*. when you're using other crypto libraries this is a pointer to an OpenLDAP private structure. applications generally should not use this option or attempt to manipulate this structure β€” like, hands off the goods bestie πŸ’€.
  • LDAP_OPT_X_TLS_DHFILE β€” gets/sets the full-path of the file containing the parameters for Diffie-Hellman ephemeral key exchange. invalue must be const char *; outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3). (yes it's written "gets/sets" here, not "sets/gets", and I'm preserving that luv, don't @ me 🌸)
  • LDAP_OPT_X_TLS_ECNAME β€” gets/sets the name of the curve(s) used for elliptic curve key exchanges. invalue must be const char *; outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3). ignored by GnuTLS. in GnuTLS a curve may be selected in the cipher suite specification πŸŒ€.
  • LDAP_OPT_X_TLS_KEYFILE β€” sets/gets the full-path of the certificate key file. invalue must be const char *; outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_TLS_NEWCTX β€” instructs the library to create a new TLS library context. invalue must be const int *. a non-zero value pointed to by invalue tells the library to create a context for a server πŸ–₯️.
  • LDAP_OPT_X_TLS_PEERCERT β€” gets the peer's certificate in DER format from an established TLS session. outvalue must be struct berval *, and the data it returns needs to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_TLS_PROTOCOL_MAX β€” sets/gets the maximum protocol version. invalue must be const int *; outvalue must be int *.
  • LDAP_OPT_X_TLS_PROTOCOL_MIN β€” sets/gets the minimum protocol version. invalue must be const int *; outvalue must be int *.
  • LDAP_OPT_X_TLS_RANDOM_FILE β€” sets/gets the random file when /dev/random and /dev/urandom are not available. invalue must be const char *; outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3). ignored by GnuTLS older than version 2.2 ⏳.
  • LDAP_OPT_X_TLS_REQUIRE_CERT β€” sets/gets the peer certificate checking strategy, one of LDAP_OPT_X_TLS_NEVER, LDAP_OPT_X_TLS_HARD, LDAP_OPT_X_TLS_DEMAND, LDAP_OPT_X_TLS_ALLOW, LDAP_OPT_X_TLS_TRY.
  • LDAP_OPT_X_TLS_REQUIRE_SAN β€” sets/gets the peer certificate subjectAlternativeName checking strategy, one of LDAP_OPT_X_TLS_NEVER, LDAP_OPT_X_TLS_HARD, LDAP_OPT_X_TLS_DEMAND, LDAP_OPT_X_TLS_ALLOW, LDAP_OPT_X_TLS_TRY. πŸͺͺ
  • LDAP_OPT_X_TLS_SSL_CTX β€” gets the TLS session context associated with this handle. outvalue must be void **. when using the OpenSSL library this is an SSL*. when using other crypto libraries this is a pointer to an OpenLDAP private structure. applications generally should not use this option. again: not for you, bestie πŸ™…β€β™€οΈ.
  • LDAP_OPT_X_TLS_VERSION β€” gets the TLS version being used on an established TLS session. outvalue must be char **, and its contents need to be freed by the caller using ldap_memfree(3).
  • LDAP_OPT_X_TLS_PEERKEY_HASH β€” sets the (public) key that the application expects the peer to be using πŸ”‘. invalue must be const char * containing the base64 encoding of the expected peer's key, or in the format <hashalg>:<peerkey hash base64 encoded> where, as a TLS session is established, the library will hash the peer's key with the provided hash algorithm and compare it with the value provided and will only allow the session to continue if they match. this happens regardless of certificate checking strategy. the list of supported hashalg values depends on the crypto library used β€” check its documentation to get a list, iykyk πŸ“–.

πŸ’– ERRORS πŸ’–

on success, the functions return LDAP_OPT_SUCCESS ✨ β€” while they may return LDAP_OPT_ERROR to indicate a generic option handling error 😭. occasionally, more specific errors can be returned, like LDAP_NO_MEMORY to indicate a failure in memory allocation. sad but true bestie.


πŸŽ€ NOTES πŸŽ€

the LDAP libraries with the LDAP_OPT_REFERRALS option set to LDAP_OPT_ON (default value) automatically follow referrals using an anonymous bind. application developers are encouraged to either implement consistent referral chasing features, or explicitly disable referral chasing by setting that option to LDAP_OPT_OFF. like, pick a lane 🫢.

fr fr, that anonymous-bind referral chasing is the default and it will surprise you if you forget about it.

the protocol version used by the library defaults to LDAPv2 (now historic πŸ’€), which corresponds to the LDAP_VERSION2 macro. application developers are encouraged to explicitly set LDAP_OPT_PROTOCOL_VERSION to LDAPv3, using the LDAP_VERSION3 macro, or to allow users to select the protocol version. bestie please set v3, v2 is giving museum exhibit πŸ›οΈ.


πŸ‘€ SEE ALSO πŸ‘€

ldap(3), ldap_error(3), RFC 4422 (http://www.rfc-editor.org),


🌈 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 whole page, bestie β€” this edition of the manpage is OpenLDAP 2.6.16, dated 2026/10/21, filed under LDAP_GET_OPTION(3). go forth and set your options correctly, ily πŸ’œπŸ¦‹

πŸ“¦ where this page comes from