1LDAP_BIND(3)               Library Functions Manual               LDAP_BIND(3)
2
3
4

NAME

6       ldap_bind,     ldap_bind_s,    ldap_simple_bind,    ldap_simple_bind_s,
7       ldap_sasl_bind,     ldap_sasl_bind_s,     ldap_sasl_interactive_bind_s,
8       ldap_parse_sasl_bind_result,         ldap_unbind,        ldap_unbind_s,
9       ldap_unbind_ext, ldap_unbind_ext_s, ldap_set_rebind_proc  -  LDAP  bind
10       routines
11

LIBRARY

13       OpenLDAP LDAP (libldap, -lldap)
14

SYNOPSIS

16       #include <ldap.h>
17
18       int ldap_bind(LDAP *ld, const char *who, const char *cred,
19              int method);
20
21       int ldap_bind_s(LDAP *ld, const char *who, const char *cred,
22              int method);
23
24       int ldap_simple_bind(LDAP *ld, const char *who, const char *passwd);
25
26       int ldap_simple_bind_s(LDAP *ld, const char *who, const char *passwd);
27
28       int ldap_sasl_bind(LDAP *ld, const char *dn, const char *mechanism,
29              struct berval *cred, LDAPControl *sctrls[],
30              LDAPControl *cctrls[], int *msgidp);
31
32       int ldap_sasl_bind_s(LDAP *ld, const char *dn, const char *mechanism,
33              struct berval *cred, LDAPControl *sctrls[],
34              LDAPControl *cctrls[], struct berval **servercredp);
35
36       int ldap_parse_sasl_bind_result(LDAP *ld, LDAPMessage *res,
37              struct berval **servercredp, int freeit);
38
39       int ldap_sasl_interactive_bind_s(LDAP *ld, const char *dn,
40              const char *mechs,
41              LDAPControl *sctrls[], LDAPControl *cctrls[],
42              unsigned flags, LDAP_SASL_INTERACT_PROC *interact,
43              void *defaults);
44
45       int ldap_sasl_interactive_bind(LDAP *ld, const char *dn,
46              const char *mechs,
47              LDAPControl *sctrls[], LDAPControl *cctrls[],
48              unsigned flags, LDAP_SASL_INTERACT_PROC *interact,
49              void *defaults, LDAPMessage *result,
50              const char **rmechp, int *msgidp);
51
52       int (LDAP_SASL_INTERACT_PROC)(LDAP *ld, unsigned flags, void *defaults, void *sasl_interact);
53
54       int ldap_unbind(LDAP *ld);
55
56       int ldap_unbind_s(LDAP *ld);
57
58       int ldap_unbind_ext(LDAP *ld, LDAPControl *sctrls[],
59              LDAPControl *cctrls[]);
60
61       int ldap_unbind_ext_s(LDAP *ld, LDAPControl *sctrls[],
62              LDAPControl *cctrls[]);
63
64       int ldap_set_rebind_proc (LDAP *ld, LDAP_REBIND_PROC *ldap_proc, void *params);
65
66       int (LDAP_REBIND_PROC)(LDAP *ld, LDAP_CONST char *url, ber_tag_t request, ber_int_t msgid, void *params);
67

DESCRIPTION

69       These  routines  provide various interfaces to the LDAP bind operation.
70       After an association with an LDAP server is made using ldap_init(3), an
71       LDAP  bind  operation  should  be performed before other operations are
72       attempted over the connection.  An LDAP bind  is  required  when  using
73       Version  2  of  the  LDAP protocol; it is optional for Version 3 but is
74       usually needed due to security considerations.
75
76       There are three types of bind calls, ones providing simple  authentica‐
77       tion,  ones providing SASL authentication, and general routines capable
78       of doing either simple or SASL authentication.
79
80       SASL (Simple Authentication and Security Layer) can  negotiate  one  of
81       many different kinds of authentication.  Both synchronous and asynchro‐
82       nous versions of each variant of the bind call are provided.  All  rou‐
83       tines take ld as their first parameter, as returned from ldap_init(3).
84

SIMPLE AUTHENTICATION

86       The  simplest  form of the bind call is ldap_simple_bind_s().  It takes
87       the DN to bind as in who, and  the  userPassword  associated  with  the
88       entry   in   passwd.    It   returns  an  LDAP  error  indication  (see
89       ldap_error(3)).  The ldap_simple_bind() call  is  asynchronous,  taking
90       the  same parameters but only initiating the bind operation and return‐
91       ing the message id of the request it sent.  The result of the operation
92       can   be   obtained  by  a  subsequent  call  to  ldap_result(3).   The
93       ldap_sasl_bind_s() and asynchronous ldap_sasl_bind() functions can also
94       be  used  to  make  a simple bind by using LDAP_SASL_SIMPLE as the SASL
95       mechanism.
96

GENERAL AUTHENTICATION

98       The ldap_bind() and ldap_bind_s() routines can be used when the authen‐
99       tication method to use needs to be selected at runtime.  They both take
100       an extra method parameter selecting the authentication method  to  use.
101       It  should  be set to LDAP_AUTH_SIMPLE to select simple authentication.
102       ldap_bind() returns  the  message  id  of  the  request  it  initiates.
103       ldap_bind_s() returns an LDAP error indication.
104

SASL AUTHENTICATION

106       For  SASL  binds  the  server always ignores any provided DN, so the dn
107       parameter should always be NULL.   ldap_sasl_bind_s()  sends  a  single
108       SASL  bind request with the given SASL mechanism and credentials in the
109       cred parameter. The format of the credentials depends on the particular
110       SASL  mechanism  in use. For mechanisms that provide mutual authentica‐
111       tion the server's credentials  will  be  returned  in  the  servercredp
112       parameter.    The   routine  returns  an  LDAP  error  indication  (see
113       ldap_error(3)).  The ldap_sasl_bind() call is asynchronous, taking  the
114       same  parameters but only sending the request and returning the message
115       id of the request it sent. The result of the operation can be  obtained
116       by  a  subsequent call to ldap_result(3).  The result must be addition‐
117       ally parsed by ldap_parse_sasl_bind_result() to obtain any server  cre‐
118       dentials sent from the server.
119
120       Many  SASL  mechanisms  require multiple message exchanges to perform a
121       complete   authentication.   Applications    should    generally    use
122       ldap_sasl_interactive_bind_s()    rather   than   calling   the   basic
123       ldap_sasl_bind() functions directly. The mechs parameter should contain
124       a  space-separated list of candidate mechanisms to use. If this parame‐
125       ter is NULL or empty the library will query the supportedSASLMechanisms
126       attribute from the server's rootDSE for the list of SASL mechanisms the
127       server supports. The flags parameter controls the interaction  used  to
128       retrieve any necessary SASL authentication parameters and should be one
129       of:
130
131       LDAP_SASL_AUTOMATIC
132              use defaults if available, prompt otherwise
133
134       LDAP_SASL_INTERACTIVE
135              always prompt
136
137       LDAP_SASL_QUIET
138              never prompt
139
140       The interact function uses the provided  defaults  to  handle  requests
141       from  the  SASL library for particular authentication parameters. There
142       is no defined format for the defaults information;  it  is  up  to  the
143       caller  to use whatever format is appropriate for the supplied interact
144       function.  The sasl_interact parameter comes from the  underlying  SASL
145       library.  When used with Cyrus SASL this is an array of sasl_interact_t
146       structures. The Cyrus SASL library will prompt for a variety of inputs,
147       including:
148
149       SASL_CB_GETREALM
150              the realm for the authentication attempt
151
152       SASL_CB_AUTHNAME
153              the username to authenticate
154
155       SASL_CB_PASS
156              the password for the provided username
157
158       SASL_CB_USER
159              the username to use for proxy authorization
160
161       SASL_CB_NOECHOPROMPT
162              generic prompt for input with input echoing disabled
163
164       SASL_CB_ECHOPROMPT
165              generic prompt for input with input echoing enabled
166
167       SASL_CB_LIST_END
168              indicates the end of the array of prompts
169
170       See the Cyrus SASL documentation for more details.
171
172       Applications  which  need  to manage connections asynchronously may use
173       ldap_sasl_interactive_bind() instead of  the  synchronous  version.   A
174       valid  mechs  parameter must be supplied, otherwise the library will be
175       forced to query the server for a list of supported mechanisms, and this
176       query  will  be  performed synchronously.  The other parameters are the
177       same as for the synchronous function, with three additional parameters.
178       The  actual  SASL  mechanism  that was used, and the message ID for use
179       with ldap_result() will be returned in rmechp and msgidp, respectively.
180       The  value  in  rmechp  must  not be modified by the caller and must be
181       passed  back  on  each  subsequent  call.  The  message  obtained  from
182       ldap_result()  must  be passed in the result parameter.  This parameter
183       must be NULL when initiating a new  Bind.  The  caller  must  free  the
184       result   message   after   each   call   using   ldap_msgfree().    The
185       ldap_sasl_interactive_bind() function returns an LDAP result  code.  If
186       the  code  is  LDAP_SASL_BIND_IN_PROGRESS then the Bind is not complete
187       yet, and this function must be called again with the next  result  from
188       the server.
189

REBINDING

191       The ldap_set_rebind_proc function() sets the process to use for binding
192       when an operation returns a referral. This function  is  used  when  an
193       application needs to bind to another server in order to follow a refer‐
194       ral or search continuation reference.
195
196       The function takes ld, the rebind function, and the params,  the  arbi‐
197       trary  data like state information which the client might need to prop‐
198       erly rebind.  The LDAP_OPT_REFERRALS option in the ld must be set to ON
199       for  the  libraries to use the rebind function. Use the ldap_set_option
200       function to set the value.
201
202       The rebind function parameters are as follows:
203
204       The ld parameter must be used by the application when  binding  to  the
205       referred  server  if  the application wants the libraries to follow the
206       referral.
207
208       The url parameter points to the URL referral string received  from  the
209       LDAP  server.  The LDAP application can use the ldap_url_parse(3) func‐
210       tion to parse the string into its components.
211
212       The request parameter specifies the type of request that generated  the
213       referral.
214
215       The  msgid parameter specifies the message ID of the request generating
216       the referral.
217
218       The params parameter is the same value  as  passed  originally  to  the
219       ldap_set_rebind_proc() function.
220
221       The  LDAP  libraries  set  all the parameters when they call the rebind
222       function. The application should not attempt to free either the  ld  or
223       the url structures in the rebind function.
224
225       The application must supply to the rebind function the required authen‐
226       tication information such as, user name,  password,  and  certificates.
227       The rebind function must use a synchronous bind method.
228

UNBINDING

230       The  ldap_unbind() call is used to unbind from the directory, terminate
231       the current association, and free the resources  contained  in  the  ld
232       structure.   Once  it  is  called, the connection to the LDAP server is
233       closed, and the ld structure is invalid.  The ldap_unbind_s()  call  is
234       just  another  name for ldap_unbind(); both of these calls are synchro‐
235       nous in nature.
236
237       The ldap_unbind_ext() and ldap_unbind_ext_s() allows the operations  to
238       specify  controls.
239

ERRORS

241       Asynchronous  routines  will  return  -1  in case of error, setting the
242       ld_errno parameter of the ld structure.   Synchronous  routines  return
243       whatever ld_errno is set to.  See ldap_error(3) for more information.
244

NOTES

246       If  an  anonymous  bind  is  sufficient for the application, the rebind
247       process  need  not  be  provided.   The   LDAP   libraries   with   the
248       LDAP_OPT_REFERRALS  option set to ON (default value) will automatically
249       follow referrals using an anonymous bind.
250
251       If the application needs  stronger  authentication  than  an  anonymous
252       bind,  you  need  to  provide  a rebind process for that authentication
253       method.  The bind method must be synchronous.
254

SEE ALSO

256       ldap(3),     ldap_error(3),      ldap_open(3),      ldap_set_option(3),
257       ldap_url_parse(3)  RFC  4422  (http://www.rfc-editor.org),  Cyrus  SASL
258       (http://asg.web.cmu.edu/sasl/)
259

ACKNOWLEDGEMENTS

261       OpenLDAP Software is developed and maintained by The  OpenLDAP  Project
262       <http://www.openldap.org/>.  OpenLDAP Software is derived from the Uni‐
263       versity of Michigan LDAP 3.3 Release.
264
265
266
267OpenLDAP 2.4.46                   2018/03/22                      LDAP_BIND(3)
Impressum