1.lf 1 stdin 2.TH LDAP_BIND 3 "2020/04/28" "OpenLDAP 2.4.50" 3.\" $OpenLDAP$ 4.\" Copyright 1998-2020 The OpenLDAP Foundation All Rights Reserved. 5.\" Copying restrictions apply. See COPYRIGHT/LICENSE. 6.SH NAME 7ldap_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 8.SH LIBRARY 9OpenLDAP LDAP (libldap, \-lldap) 10.SH SYNOPSIS 11.nf 12.B #include <ldap.h> 13.LP 14.BI "int ldap_bind(LDAP *" ld ", const char *" who ", const char *" cred "," 15.RS 16.BI "int " method ");" 17.RE 18.LP 19.BI "int ldap_bind_s(LDAP *" ld ", const char *" who ", const char *" cred "," 20.RS 21.BI "int " method ");" 22.RE 23.LP 24.BI "int ldap_simple_bind(LDAP *" ld ", const char *" who ", const char *" passwd ");" 25.LP 26.BI "int ldap_simple_bind_s(LDAP *" ld ", const char *" who ", const char *" passwd ");" 27.LP 28.BI "int ldap_sasl_bind(LDAP *" ld ", const char *" dn ", const char *" mechanism "," 29.RS 30.BI "struct berval *" cred ", LDAPControl *" sctrls "[]," 31.BI "LDAPControl *" cctrls "[], int *" msgidp ");" 32.RE 33.LP 34.BI "int ldap_sasl_bind_s(LDAP *" ld ", const char *" dn ", const char *" mechanism "," 35.RS 36.BI "struct berval *" cred ", LDAPControl *" sctrls "[]," 37.BI "LDAPControl *" cctrls "[], struct berval **" servercredp ");" 38.RE 39.LP 40.BI "int ldap_parse_sasl_bind_result(LDAP *" ld ", LDAPMessage *" res "," 41.RS 42.BI "struct berval **" servercredp ", int " freeit ");" 43.RE 44.LP 45.BI "int ldap_sasl_interactive_bind_s(LDAP *" ld ", const char *" dn "," 46.RS 47.BI "const char *" mechs "," 48.BI "LDAPControl *" sctrls "[], LDAPControl *" cctrls "[]," 49.BI "unsigned " flags ", LDAP_SASL_INTERACT_PROC *" interact "," 50.BI "void *" defaults ");" 51.RE 52.LP 53.BI "int ldap_sasl_interactive_bind(LDAP *" ld ", const char *" dn "," 54.RS 55.BI "const char *" mechs "," 56.BI "LDAPControl *" sctrls "[], LDAPControl *" cctrls "[]," 57.BI "unsigned " flags ", LDAP_SASL_INTERACT_PROC *" interact "," 58.BI "void *" defaults ", LDAPMessage *" result "," 59.BI "const char **" rmechp ", int *" msgidp ");" 60.RE 61.LP 62.BI "int (LDAP_SASL_INTERACT_PROC)(LDAP *" ld ", unsigned " flags ", void *" defaults ", void *" sasl_interact ");" 63.LP 64.BI "int ldap_unbind(LDAP *" ld ");" 65.LP 66.BI "int ldap_unbind_s(LDAP *" ld ");" 67.LP 68.BI "int ldap_unbind_ext(LDAP *" ld ", LDAPControl *" sctrls "[]," 69.RS 70.BI "LDAPControl *" cctrls "[]);" 71.RE 72.LP 73.BI "int ldap_unbind_ext_s(LDAP *" ld ", LDAPControl *" sctrls "[]," 74.RS 75.BI "LDAPControl *" cctrls "[]);" 76.RE 77.LP 78.BI "int ldap_set_rebind_proc (LDAP *" ld ", LDAP_REBIND_PROC *" ldap_proc ", void *" params ");" 79.LP 80.BI "int (LDAP_REBIND_PROC)(LDAP *" ld ", LDAP_CONST char *" url ", ber_tag_t " request ", ber_int_t " msgid ", void *" params ");" 81.SH DESCRIPTION 82.LP 83These routines provide various interfaces to the LDAP bind operation. 84After an association with an LDAP server is made using 85.BR ldap_init (3), 86an LDAP bind operation should be performed before other operations are 87attempted over the connection. An LDAP bind is required when using 88Version 2 of the LDAP protocol; it is optional for Version 3 but is 89usually needed due to security considerations. 90.LP 91There are three types of bind calls, ones providing simple authentication, 92ones providing SASL authentication, and general routines capable of doing 93either simple or SASL authentication. 94.LP 95.B SASL 96(Simple Authentication and Security Layer) 97can negotiate one of many different kinds of authentication. 98Both synchronous and asynchronous versions of each variant of the bind 99call are provided. All routines 100take \fIld\fP as their first parameter, as returned from 101.BR ldap_init (3). 102.SH SIMPLE AUTHENTICATION 103The simplest form of the bind call is 104.BR ldap_simple_bind_s() . 105It takes the DN to bind as in \fIwho\fP, and the userPassword associated 106with the entry in \fIpasswd\fP. It returns an LDAP error indication 107(see 108.BR ldap_error (3)). 109The 110.B ldap_simple_bind() 111call is asynchronous, 112taking the same parameters but only initiating the bind operation and 113returning the message id of the request it sent. The result of the 114operation can be obtained by a subsequent call to 115.BR ldap_result (3). 116The 117.B ldap_sasl_bind_s() 118and asynchronous 119.B ldap_sasl_bind() 120functions can also be used to make a simple bind by using 121LDAP_SASL_SIMPLE as the SASL mechanism. 122.SH GENERAL AUTHENTICATION 123The 124.B ldap_bind() 125and 126.B ldap_bind_s() 127routines can be used when the 128authentication method to use needs to be selected at runtime. They 129both take an extra \fImethod\fP parameter selecting the authentication 130method to use. It should be set to LDAP_AUTH_SIMPLE 131to select simple authentication. 132.B ldap_bind() 133returns the message id of the request it initiates. 134.B ldap_bind_s() 135returns an LDAP error indication. 136.SH SASL AUTHENTICATION 137For SASL binds the server always ignores any provided DN, so the 138.I dn 139parameter should always be NULL. 140.BR ldap_sasl_bind_s () 141sends a single SASL bind request with the given SASL 142.I mechanism 143and credentials in the 144.I cred 145parameter. The format of the credentials depends on the particular 146SASL mechanism in use. For mechanisms that provide mutual authentication 147the server's credentials will be returned in the 148.I servercredp 149parameter. 150The routine returns an LDAP error indication (see 151.BR ldap_error (3)). 152The 153.BR ldap_sasl_bind () 154call is asynchronous, taking the same parameters but only sending the 155request and returning the message id of the request it sent. The result of 156the operation can be obtained by a subsequent 157call to 158.BR ldap_result (3). 159The result must be additionally parsed by 160.BR ldap_parse_sasl_bind_result () 161to obtain any server credentials sent from the server. 162.LP 163Many SASL mechanisms require multiple message exchanges to perform a 164complete authentication. Applications should generally use 165.BR ldap_sasl_interactive_bind_s () 166rather than calling the basic 167.BR ldap_sasl_bind () 168functions directly. The 169.I mechs 170parameter should contain a space-separated list of candidate mechanisms 171to use. If this parameter is NULL or empty the library will query 172the supportedSASLMechanisms attribute from the server's rootDSE 173for the list of SASL mechanisms the server supports. The 174.I flags 175parameter controls the interaction used to retrieve any necessary 176SASL authentication parameters and should be one of: 177.TP 178LDAP_SASL_AUTOMATIC 179use defaults if available, prompt otherwise 180.TP 181LDAP_SASL_INTERACTIVE 182always prompt 183.TP 184LDAP_SASL_QUIET 185never prompt 186.LP 187The 188.I interact 189function uses the provided 190.I defaults 191to handle requests from the SASL library for particular authentication 192parameters. There is no defined format for the 193.I defaults 194information; 195it is up to the caller to use whatever format is appropriate for the 196supplied 197.I interact 198function. 199The 200.I sasl_interact 201parameter comes from the underlying SASL library. When used with Cyrus SASL 202this is an array of 203.B sasl_interact_t 204structures. The Cyrus SASL library will prompt for a variety of inputs, 205including: 206.TP 207SASL_CB_GETREALM 208the realm for the authentication attempt 209.TP 210SASL_CB_AUTHNAME 211the username to authenticate 212.TP 213SASL_CB_PASS 214the password for the provided username 215.TP 216SASL_CB_USER 217the username to use for proxy authorization 218.TP 219SASL_CB_NOECHOPROMPT 220generic prompt for input with input echoing disabled 221.TP 222SASL_CB_ECHOPROMPT 223generic prompt for input with input echoing enabled 224.TP 225SASL_CB_LIST_END 226indicates the end of the array of prompts 227.LP 228See the Cyrus SASL documentation for more details. 229.LP 230Applications which need to manage connections asynchronously may use 231.BR ldap_sasl_interactive_bind () 232instead of the synchronous version. 233A valid mechs parameter must be supplied, otherwise the library will 234be forced to query the server for a list of supported mechanisms, 235and this query will be performed synchronously. 236The other parameters are the same as 237for the synchronous function, with three additional parameters. 238The actual SASL mechanism that was used, and the message ID for use 239with 240.BR ldap_result () 241will be returned in rmechp and msgidp, respectively. 242The value in rmechp must not be modified by the caller and must be 243passed back on each subsequent call. The message obtained from 244.BR ldap_result () 245must be passed in the result parameter. 246This parameter must be NULL when initiating a new Bind. The caller 247must free the result message after each call using 248.BR ldap_msgfree (). 249The 250.BR ldap_sasl_interactive_bind () 251function returns an LDAP result code. If the code is 252LDAP_SASL_BIND_IN_PROGRESS then the Bind is not complete yet, and 253this function must be called again with the next result from the server. 254.SH REBINDING 255.LP 256The 257.B ldap_set_rebind_proc 258function() sets the process to use for binding when an operation returns a 259referral. This function is used when an application needs to bind to another server 260in order to follow a referral or search continuation reference. 261.LP 262The function takes \fIld\fP, the \fIrebind\fP function, and the \fIparams\fP, 263the arbitrary data like state information which the client might need to properly rebind. 264The LDAP_OPT_REFERRALS option in the \fIld\fP must be set to ON for the libraries 265to use the rebind function. Use the 266.BR ldap_set_option 267function to set the value. 268.LP 269The rebind function parameters are as follows: 270.LP 271The \fIld\fP parameter must be used by the application when binding to the 272referred server if the application wants the libraries to follow the referral. 273.LP 274The \fIurl\fP parameter points to the URL referral string received from the LDAP server. 275The LDAP application can use the 276.BR ldap_url_parse (3) 277function to parse the string into its components. 278.LP 279The \fIrequest\fP parameter specifies the type of request that generated the referral. 280.LP 281The \fImsgid\fP parameter specifies the message ID of the request generating the referral. 282.LP 283The \fIparams\fP parameter is the same value as passed originally to the 284.BR ldap_set_rebind_proc () 285function. 286.LP 287The LDAP libraries set all the parameters when they call the rebind function. The application 288should not attempt to free either the ld or the url structures in the rebind function. 289.LP 290The application must supply to the rebind function the required authentication information such as, 291user name, password, and certificates. The rebind function must use a synchronous bind method. 292.SH UNBINDING 293The 294.B ldap_unbind() 295call is used to unbind from the directory, 296terminate the current association, and free the resources contained 297in the \fIld\fP structure. Once it is called, the connection to 298the LDAP server is closed, and the \fIld\fP structure is invalid. 299The 300.B ldap_unbind_s() 301call is just another name for 302.BR ldap_unbind() ; 303both of these calls are synchronous in nature. 304.LP 305The 306.B ldap_unbind_ext() 307and 308.B ldap_unbind_ext_s() 309allows the operations to specify controls. 310.SH ERRORS 311Asynchronous routines will return \-1 in case of error, setting the 312\fIld_errno\fP parameter of the \fIld\fP structure. Synchronous 313routines return whatever \fIld_errno\fP is set to. See 314.BR ldap_error (3) 315for more information. 316.SH NOTES 317If an anonymous bind is sufficient for the application, the rebind process 318need not be provided. The LDAP libraries with the LDAP_OPT_REFERRALS option 319set to ON (default value) will automatically follow referrals using an anonymous bind. 320.LP 321If the application needs stronger authentication than an anonymous bind, 322you need to provide a rebind process for that authentication method. 323The bind method must be synchronous. 324.SH SEE ALSO 325.BR ldap (3), 326.BR ldap_error (3), 327.BR ldap_open (3), 328.BR ldap_set_option (3), 329.BR ldap_url_parse (3) 330.B RFC 4422 331(http://www.rfc-editor.org), 332.B Cyrus SASL 333(http://asg.web.cmu.edu/sasl/) 334.SH ACKNOWLEDGEMENTS 335.lf 1 ./../Project 336.\" Shared Project Acknowledgement Text 337.B "OpenLDAP Software" 338is developed and maintained by The OpenLDAP Project <http://www.openldap.org/>. 339.B "OpenLDAP Software" 340is derived from the University of Michigan LDAP 3.3 Release. 341.lf 335 stdin 342