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 aLDAPAPIFeatureInfofor you.outvaluehas to be aLDAPAPIFeatureInfo *and it must point to an already-allocated struct. Before you call, initialize the struct'sldapaif_info_versionfield toLDAP_FEATURE_INFO_VERSION, and setldapaif_nameto the name of the feature you're asking about. it's read-only, periodt.LDAP_OPT_API_INFOβ fills in aLDAPAPIInfo;outvaluemust be aLDAPAPIInfo *pointing to an already allocated struct. The struct'sldapai_info_versionfield must be initialized toLDAP_API_INFO_VERSIONbefore 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 theldapai_extensionsarray and the array itself usingldap_memfree(3). The caller must also free theldapi_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 exampleldap_search_ext(3),ldap_add_ext(3),ldap_modify_ext(3)and so on.outvaluemust beLDAPControl ***, and the caller is responsible for freeing the returned controls, if any, by callingldap_controls_free(3).invaluemust beLDAPControl *const *; the library duplicates the controls passed viainvalue.LDAP_OPT_CONNECT_ASYNCβ sets/gets the status of the asynchronous connect flag.invalueshould either beLDAP_OPT_OFForLDAP_OPT_ON;outvaluemust beint *. When set, the library will callconnect(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 (optionLDAP_OPT_NETWORK_TIMEOUT). This option is OpenLDAP specific.LDAP_OPT_CONNECT_CBβ lets you set a connect callback.invaluemust be aconst 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, thelc_delcallback handler is passed aNULLSockbuf. Callingldap_get_option(3)for this option removes the callback whose pointer matchesoutvalue(yes, the getter deletes β iconic behavior). This option is OpenLDAP specific.LDAP_OPT_DEBUG_LEVELβ sets/gets the debug level of the client library.invaluemust be aconst int *;outvaluemust be aint *. Valid debug levels areLDAP_DEBUG_ANY,LDAP_DEBUG_ARGS,LDAP_DEBUG_BER,LDAP_DEBUG_CONNS,LDAP_DEBUG_NONE,LDAP_DEBUG_PACKETS,LDAP_DEBUG_PARSE, andLDAP_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.outvaluemust be achar **, and the caller is responsible for freeing the returned string by callingldap_memfree(3).invaluemust be aconst 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.invaluemust beconst int *;outvaluemust beint *. They cannot beNULL. The value of*invalueshould be one ofLDAP_DEREF_NEVER(the default),LDAP_DEREF_SEARCHING,LDAP_DEREF_FINDING, orLDAP_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 asld;outvaluemust be aint *. 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 asLDAP_OPT_ERROR_STRING.outvaluemust be achar **, and the caller is responsible for freeing the returned string by callingldap_memfree(3).invaluemust be achar *; 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 ofLDAP_OPT_URI.outvaluemust be achar **, and the caller is responsible for freeing the resulting string by callingldap_memfree(3).invaluemust be aconst char *; the library duplicates the corresponding string.LDAP_OPT_MATCHED_DNβ sets/gets a string containing the matched DN associated to the LDAP handle.outvaluemust be achar **, and the caller is responsible for freeing the returned string by callingldap_memfree(3).invaluemust be aconst char *; the library duplicates the corresponding string.LDAP_OPT_NETWORK_TIMEOUTβ sets/gets the network timeout value after whichpoll(2)/select(2)following aconnect(2)returns in case of no activity.outvaluemust be astruct timeval **(the caller has to free*outvalueusingldap_memfree(3)), andinvaluemust be aconst struct timeval *. They cannot beNULL. Using a struct with seconds set to-1results in an infinite timeout, which is the default. This option is OpenLDAP specific.LDAP_OPT_PROTOCOL_VERSIONβ sets/gets the protocol version.outvalueandinvaluemust beint *.LDAP_OPT_REFERRAL_URLSβ sets/gets an array containing the referral URIs associated to the LDAP handle.outvaluemust be achar ***, and the caller is responsible for freeing the returned string by callingldap_memvfree(3).invaluemust be aNULL-terminatedchar *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.invaluemust beconst int *; its value should either beLDAP_OPT_OFForLDAP_OPT_ON.outvaluemust beint *.LDAP_OPT_RESTARTβ determines whether the library should implicitly restart connections (FIXME).invaluemust beconst int *; its value should either beLDAP_OPT_OFForLDAP_OPT_ON.outvaluemust beint *.LDAP_OPT_RESULT_CODEβ sets/gets the LDAP result code associated to the handle. This option was formerly known asLDAP_OPT_ERROR_NUMBER.invaluemust be aconst int *.outvaluemust be aint *.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 exampleldap_search_ext(3),ldap_add_ext(3),ldap_modify_ext(3)and so on.outvaluemust beLDAPControl ***, and the caller is responsible for freeing the returned controls, if any, by callingldap_controls_free(3).invaluemust beLDAPControl *const *; the library duplicates the controls passed viainvalue.LDAP_OPT_SESSION_REFCNTβ returns the reference count associated with the LDAP handle passed in asld;outvaluemust be aint *. 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.invaluemust beconst int *, whileoutvaluemust beint *; they cannot beNULL.LDAP_OPT_SOCKBUFβ returns a pointer to the socket buffer of the LDAP handle passed in asld;outvaluemust be aSockbuf **. 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.outvaluemust be achar **, and the caller is responsible for freeing the returned string by callingldap_memfree(3).invaluemust be aconst 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.invaluemust beconst int *, whileoutvaluemust beint *, and they cannot beNULL.LDAP_OPT_TIMEOUTβ sets/gets a timeout value for the synchronous API calls.outvaluemust be astruct timeval **(the caller has to free*outvalueusingldap_memfree(3)), andinvaluemust be astruct timeval *, and they cannot beNULL. Using a struct with seconds set to-1results 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.outvaluehas to be achar **, and you β yes you, the caller β are responsible for freeing the resulting string by callingldap_memfree(3). Meanwhileinvaluemust be aconst char *. Heads up tho: the library parses that string into a list ofLDAPURLDescstructures, so yourldap_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β tellsldap_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 configureTCP_USER_TIMEOUTin milliseconds on the connection, overriding the operating system setting π. This option is OpenLDAP specific and supported only on Linux 2.6.37 or higher.invaluemust be aconst unsigned int *;outvaluemust be anunsigned 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 π.outvaluemust be achar **, and its content needs to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_SASL_AUTHZIDβ gets the SASL authorization identity π.outvaluemust be achar **, and its content needs to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_SASL_MAXBUFSIZEβ gets/sets the SASL maximum buffer size π.invaluemust beconst ber_len_t *, whileoutvaluemust beber_len_t *. See alsoLDAP_OPT_X_SASL_SECPROPS.LDAP_OPT_X_SASL_MECHβ gets the SASL mechanism π¦.outvaluemust be achar **, and its content needs to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_SASL_MECHLISTβ gets the list of available mechanisms, in the form of a NULL-terminated array of strings π.outvaluemust bechar ***. The caller must not free or otherwise muck with it. This option can be used globally.LDAP_OPT_X_SASL_NOCANONβ sets/gets theNOCANONflag β. When it's unset, the hostname is canonicalized.invaluemust beconst int *, and its value should either beLDAP_OPT_OFForLDAP_OPT_ON.outvaluemust beint *.LDAP_OPT_X_SASL_REALMβ gets the SASL realm π.outvaluemust be achar **, and its content needs to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_SASL_SECPROPSβ sets the SASL secprops π₯.invaluemust be achar *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 π.outvaluemust be aber_len_t *.LDAP_OPT_X_SASL_SSF_EXTERNALβ sets the SASL SSF value related to an authentication performed using anEXTERNALmechanism π§.invaluemust be aconst ber_len_t *.LDAP_OPT_X_SASL_SSF_MAXβ gets/sets the SASL maximum SSF π.invaluemust beconst ber_len_t *, whileoutvaluemust beber_len_t *. See alsoLDAP_OPT_X_SASL_SECPROPS.LDAP_OPT_X_SASL_SSF_MINβ gets/sets the SASL minimum SSF π.invaluemust beconst ber_len_t *, whileoutvaluemust beber_len_t *. See alsoLDAP_OPT_X_SASL_SECPROPS.LDAP_OPT_X_SASL_USERNAMEβ gets the SASL username π .outvaluemust be achar **. Its content needs to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_SASL_CBINDINGβ sets/gets the channel-binding type to use in SASL π, one ofLDAP_OPT_X_SASL_CBINDING_NONE(the default),LDAP_OPT_X_SASL_CBINDING_TLS_UNIQUEβ the"tls-unique"type from RFC 5929 β orLDAP_OPT_X_SASL_CBINDING_TLS_ENDPOINT, the"tls-server-end-point"from RFC 5929, which is compatible with Windows.invaluemust beconst int *;outvaluemust beint *.
π¦ 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 π€.invaluemust beconst int *;outvaluemust beint *.LDAP_OPT_X_KEEPALIVE_PROBESβ sets/gets the maximum number of keepalive probes TCP should send before dropping the connection π.invaluemust beconst int *;outvaluemust beint *.LDAP_OPT_X_KEEPALIVE_INTERVALβ sets/gets the interval in seconds between individual keepalive probes β°.invaluemust beconst int *;outvaluemust beint *.
β¨ 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 (;) π«Ά.invaluemust beconst char *;outvaluemust bechar **, and its contents need to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_TLS_CACERTFILEβ sets/gets the full-path of the CA certificate file.invaluemust beconst char *;outvaluemust bechar **, and its contents need to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_TLS_CERTFILEβ sets/gets the full-path of the certificate file.invaluemust beconst char *;outvaluemust bechar **, and its contents need to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_TLS_CIPHERβ gets the cipher being used on an established TLS session (note: gets only, no setting here, periodt).outvaluemust bechar **, and its contents need to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_TLS_CIPHER_SUITEβ sets/gets the allowed cipher suite.invaluemust beconst char *;outvaluemust bechar **, and its contents need to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_TLS_CONNECT_ARGβ sets/gets the connection callback argument.invaluemust beconst void *;outvaluemust bevoid **.LDAP_OPT_X_TLS_CONNECT_CBβ sets/gets the connection callback handle.invaluemust beconst LDAP_TLS_CONNECT_CB *;outvaluemust beLDAP_TLS_CONNECT_CB **.LDAP_OPT_X_TLS_CRLCHECKβ sets/gets the CRL evaluation strategy, one ofLDAP_OPT_X_TLS_CRL_NONE,LDAP_OPT_X_TLS_CRL_PEER, orLDAP_OPT_X_TLS_CRL_ALL.invaluemust beconst int *;outvaluemust beint *. π¨ Requires OpenSSL.LDAP_OPT_X_TLS_CRLFILEβ sets/gets the full-path of the CRL file.invaluemust beconst char *;outvaluemust bechar **, and its contents need to be freed by the caller usingldap_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.invaluemust beconst void *;outvaluemust bevoid **. when you're using the OpenSSL library this is anSSL_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.invaluemust beconst char *;outvaluemust bechar **, and its contents need to be freed by the caller usingldap_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.invaluemust beconst char *;outvaluemust bechar **, and its contents need to be freed by the caller usingldap_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.invaluemust beconst char *;outvaluemust bechar **, and its contents need to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_TLS_NEWCTXβ instructs the library to create a new TLS library context.invaluemust beconst int *. a non-zero value pointed to byinvaluetells 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.outvaluemust bestruct berval *, and the data it returns needs to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_TLS_PROTOCOL_MAXβ sets/gets the maximum protocol version.invaluemust beconst int *;outvaluemust beint *.LDAP_OPT_X_TLS_PROTOCOL_MINβ sets/gets the minimum protocol version.invaluemust beconst int *;outvaluemust beint *.LDAP_OPT_X_TLS_RANDOM_FILEβ sets/gets the random file when/dev/randomand/dev/urandomare not available.invaluemust beconst char *;outvaluemust bechar **, and its contents need to be freed by the caller usingldap_memfree(3). ignored by GnuTLS older than version 2.2 β³.LDAP_OPT_X_TLS_REQUIRE_CERTβ sets/gets the peer certificate checking strategy, one ofLDAP_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 certificatesubjectAlternativeNamechecking strategy, one ofLDAP_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.outvaluemust bevoid **. when using the OpenSSL library this is anSSL*. 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.outvaluemust bechar **, and its contents need to be freed by the caller usingldap_memfree(3).LDAP_OPT_X_TLS_PEERKEY_HASHβ sets the (public) key that the application expects the peer to be using π.invaluemust beconst 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 supportedhashalgvalues 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
- fedora 44: openldap-devel 2.6.16-1.fc44 Β· OLDAP-2.8
- fedora 44: openldap-devel 2.6.16-1.fc44 Β· OLDAP-2.8
- Copyright 1998-2026 The OpenLDAP Foundation All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms