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,   ldap_un‐
9       bind_ext, ldap_unbind_ext_s, ldap_set_rebind_proc - LDAP bind routines
10

LIBRARY

12       OpenLDAP LDAP (libldap, -lldap)
13

SYNOPSIS

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

DESCRIPTION

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

SIMPLE AUTHENTICATION

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

GENERAL AUTHENTICATION

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

SASL AUTHENTICATION

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

REBINDING

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

UNBINDING

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

ERRORS

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

NOTES

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

SEE ALSO

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

ACKNOWLEDGEMENTS

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