LDAP_BIND(3)
π LDAP_BIND(3) π
Library Functions Manual Β· LDAP_BIND(3) Β· part 1 of 2
πΈ NAME πΈ
okay bestie, meet the whole bind squad:
ldap_bind,ldap_bind_s,ldap_simple_bind,ldap_simple_bind_s,ldap_sasl_bind,ldap_sasl_bind_s,ldap_sasl_interactive_bind_s,ldap_parse_sasl_bind_result,ldap_unbind,ldap_unbind_s,ldap_unbind_ext,ldap_unbind_ext_s,ldap_set_rebind_procβ LDAP bind routines
π LIBRARY π
OpenLDAP LDAP (libldap, -lldap) periodt.
β¨ SYNOPSIS β¨
here's the exact lineup, no paraphrasing, no games:
#include <ldap.h>
int ldap_bind(LDAP *ld, const char *who, const char *cred,
int method);
int ldap_bind_s(LDAP *ld, const char *who, const char *cred,
int method);
int ldap_simple_bind(LDAP *ld, const char *who, const char *passwd);
int ldap_simple_bind_s(LDAP *ld, const char *who, const char *passwd);
int ldap_sasl_bind(LDAP *ld, const char *dn, const char *mechanism,
struct berval *cred, LDAPControl *sctrls[],
LDAPControl *cctrls[], int *msgidp);
int ldap_sasl_bind_s(LDAP *ld, const char *dn, const char *mechanism,
struct berval *cred, LDAPControl *sctrls[],
LDAPControl *cctrls[], struct berval **servercredp);
int ldap_parse_sasl_bind_result(LDAP *ld, LDAPMessage *res,
struct berval **servercredp, int freeit);
int ldap_sasl_interactive_bind_s(LDAP *ld, const char *dn,
const char *mechs,
LDAPControl *sctrls[], LDAPControl *cctrls[],
unsigned flags, LDAP_SASL_INTERACT_PROC *interact,
void *defaults);
int ldap_sasl_interactive_bind(LDAP *ld, const char *dn,
const char *mechs,
LDAPControl *sctrls[], LDAPControl *cctrls[],
unsigned flags, LDAP_SASL_INTERACT_PROC *interact,
void *defaults, LDAPMessage *result,
const char **rmechp, int *msgidp);
int (LDAP_SASL_INTERACT_PROC)(LDAP *ld, unsigned flags, void *defaults, void *sasl_interact);
int ldap_unbind(LDAP *ld);
int ldap_unbind_s(LDAP *ld);
int ldap_unbind_ext(LDAP *ld, LDAPControl *sctrls[],
LDAPControl *cctrls[]);
int ldap_unbind_ext_s(LDAP *ld, LDAPControl *sctrls[],
LDAPControl *cctrls[]);
int ldap_set_rebind_proc (LDAP *ld, LDAP_REBIND_PROC *ldap_proc, void *params);
int (LDAP_REBIND_PROC)(LDAP *ld, LDAP_CONST char *url, ber_tag_t request, ber_int_t msgid, void *params);
π DESCRIPTION π
okay so these routines are all different little doorways into the LDAP bind operation. After you've made an association with an LDAP server using ldap_init(3), you should perform an LDAP bind before you attempt other operations over that connection. An LDAP bind is required when you're using Version 2 of the LDAP protocol. For Version 3 it's optional, but security considerations mean it's usually needed anyway. iykyk
There are three types of bind calls: ones that provide simple authentication, ones that provide SASL authentication, and general routines that can do either simple or SASL authentication.
SASL β that's Simple Authentication and Security Layer β can negotiate one of many different kinds of authentication. Both synchronous and asynchronous versions of each variant of the bind call are provided. All routines take ld as their first parameter, as returned from ldap_init(3). slay.
π SIMPLE AUTHENTICATION π
The simplest form of the bind call is ldap_simple_bind_s(). It takes the DN to bind as in who, and the userPassword associated with the entry in passwd. It returns an LDAP error indication β see ldap_error(3).
The ldap_simple_bind() call is asynchronous. It takes the same parameters, but it only initiates the bind operation and returns the message id of the request it sent. You can get the result of the operation by making a subsequent call to ldap_result(3). <butterfly>π¦</butterfly>
The ldap_sasl_bind_s() and asynchronous ldap_sasl_bind() functions can also be used to make a simple bind by using LDAP_SASL_SIMPLE as the SASL mechanism. cute little crossover moment.
π¦ GENERAL AUTHENTICATION π¦
The ldap_bind() and ldap_bind_s() routines are your go-to when the authentication method to use needs to be selected at runtime. They both take an extra method parameter selecting the authentication method to use. It should be set to LDAP_AUTH_SIMPLE to select simple authentication. easy.
ldap_bind() returns the message id of the request it initiates. ldap_bind_s() returns an LDAP error indication.
π₯ SASL AUTHENTICATION π₯
For SASL binds the server always ignores any provided DN, so the dn parameter should always be NULL. do not fight this.
ldap_sasl_bind_s() sends a single SASL bind request with the given SASL mechanism and credentials in the cred parameter. The format of the credentials depends on the particular SASL mechanism in use. For mechanisms that provide mutual authentication, the server's credentials will be returned in the servercredp parameter. The routine returns an LDAP error indication β see ldap_error(3).
The ldap_sasl_bind() call is asynchronous. It takes the same parameters, but it only sends the request and returns the message id of the request it sent. You can get the result of the operation by making a subsequent call to ldap_result(3). The result must be additionally parsed by ldap_parse_sasl_bind_result() to obtain any server credentials sent from the server. extra step, but make it make sense.
Any returned server credentials should be freed using ber_bvfree().
Many SASL mechanisms require multiple message exchanges to perform a complete authentication. Applications should generally use ldap_sasl_interactive_bind_s() rather than calling the basic ldap_sasl_bind() functions directly. this is the main character of SASL binds, fr fr.
The mechs parameter should contain a space-separated list of candidate mechanisms to use. If this parameter is NULL or empty, the library will query the supportedSASLMechanisms attribute from the server's rootDSE for the list of SASL mechanisms the server supports.
The flags parameter controls the interaction used to retrieve any necessary SASL authentication parameters and should be one of:
LDAP_SASL_AUTOMATICβ use defaults if available, prompt otherwiseLDAP_SASL_INTERACTIVEβ always promptLDAP_SASL_QUIETβ never prompt
The interact function uses the provided defaults to handle requests from the SASL library for particular authentication parameters. There is no defined format for the defaults information; it is up to the caller to use whatever format is appropriate for the supplied interact function. The sasl_interact parameter comes from the underlying SASL library. When used with Cyrus SASL this is an array of sasl_interact_t structures. The Cyrus SASL library will prompt for a variety of inputs, including:
SASL_CB_GETREALMβ the realm for the authentication attemptSASL_CB_AUTHNAMEβ the username to authenticateSASL_CB_PASSβ the password for the provided usernameSASL_CB_USERβ the username to use for proxy authorizationSASL_CB_NOECHOPROMPTβ generic prompt for input with input echoing disabledSASL_CB_ECHOPROMPTβ generic prompt for input with input echoing enabledSASL_CB_LIST_ENDβ indicates the end of the array of prompts
See the Cyrus SASL documentation for more details. homework, but make it fashion.
Applications which need to manage connections asynchronously may use ldap_sasl_interactive_bind() instead of the synchronous version. A valid mechs parameter must be supplied, otherwise the library will be forced to query the server for a list of supported mechanisms, and this query will be performed synchronously. not the vibe for async girlies.
The other parameters are the same as for the synchronous function, with three additional parameters. The actual SASL mechanism that was used, and the message ID for use with ldap_result(), will be returned in rmechp and msgidp, respectively. The value in rmechp must not be modified by the caller and must be passed back on each subsequent call. The message obtained from ldap_result() must be passed in the result parameter. This parameter must be NULL when initiating a new Bind. The caller must free the result message after each call using ldap_msgfree().
The ldap_sasl_interactive_bind() function returns an LDAP result code. If the code is LDAP_SASL_BIND_IN_PROGRESS then the Bind is not complete yet, and this function must be called again with the next result from the server. round two, bestie.
π REBINDING π
The ldap_set_rebind_proc() function sets the process to use for binding when an operation returns a referral. This function is used when an application needs to bind to another server in order to follow a referral or search continuation reference.
The function takes ld, the rebind function, and the params, the arbitrary data like state information which the client might need to properly rebind. The LDAP_OPT_REFERRALS option in the ld must be set to ON for the libraries to use the rebind function. Use the ldap_set_option function to set the value. flip the switch, bestie.
The rebind function parameters are as follows:
ldβ must be used by the application when binding to the referred server if the application wants the libraries to follow the referral.urlβ points to the URL referral string received from the LDAP server. The LDAP application can use theldap_url_parse(3)function to parse the string into its components.requestβ specifies the type of request that generated the referral.msgidβ specifies the message ID of the request generating the referral.paramsβ is the same value as passed originally to theldap_set_rebind_proc()function.
The LDAP libraries set all the parameters when they call the rebind function. The application should not attempt to free either the ld or the url structures in the rebind function. hands off those pointers.
The application must supply to the rebind function the required authentication information such as user name, password, and certificates. The rebind function must use a synchronous bind method.
π UNBINDING π
The ldap_unbind() call is used to unbind from the directory, terminate the current association, and free the resources contained in the ld structure. Once it is called, the connection to the LDAP server is closed, and the ld structure is invalid. gone. invalid. do not touch.
The ldap_unbind_s() call is just another name for ldap_unbind(); both of these calls are synchronous in nature.
The ldap_unbind_ext() and ldap_unbind_ext_s() allows the operations to specify controls. fancy exit.
π ERRORS π
Asynchronous routines will return -1 in case of error, setting the ld_errno parameter of the ld structure. Synchronous routines return whatever ld_errno is set to. See ldap_error(3) for more information. check the error, bestie.
β NOTES β
If an anonymous bind is sufficient for the application, the rebind process need not be provided. The LDAP libraries with the LDAP_OPT_REFERRALS option set to ON (default value) will automatically follow referrals using an anonymous bind. low-effort but valid.
If the application needs stronger authentication than an anonymous bind, you need to provide a rebind process for that authentication method. The bind method must be synchronous. no cap.
β¨ SEE ALSO β¨
okay bestie, when you're done here and you're like "wait I need MORE", these are your girls π :
ldap(3)β the whole big picture, the main character herself β¨ldap_error(3)β for when stuff goes sideways and you need to know why πldap_open(3)β making the connection happen in the first place π«Άldap_set_option(3)β tweaking all the knobs and settings, very customizable of you πldap_url_parse(3)β decoding those LDAP URLs like the icon it is πΈ- RFC 4422 (
http://www.rfc-editor.org) β the actual spec for SASL, iykyk π - Cyrus SASL (
http://asg.web.cmu.edu/sasl/) β the SASL implementation, lowkey essential π¦
π ACKNOWLEDGEMENTS π
Real talk, none of this would exist without the people behind it, so let's give credit where credit is SO due π:
OpenLDAP Software is developed and maintained by The OpenLDAP Project (http://www.openldap.org/) β literal queens of the LDAP game π.
And plot twist: OpenLDAP Software is derived from the University of Michigan LDAP 3.3 Release. History! iconic behavior fr fr π
so yeah, that's the whole page bestie, you're officially an LDAP bind expert now, no cap π go forth and authenticate responsibly π β¨
this was LDAP_BIND(3) from OpenLDAP 2.6.16, dated 2026/10/21 β mwah, drink some water, and see you in the next manpage π«Άπ
π¦ 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