1LDAP_BIND(3) Library Functions Manual LDAP_BIND(3)
2
3
4
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
12 OpenLDAP LDAP (libldap, -lldap)
13
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
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
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
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
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 Any returned server credentials should be freed using ber_bvfree().
120
121 Many SASL mechanisms require multiple message exchanges to perform a
122 complete authentication. Applications should generally use
123 ldap_sasl_interactive_bind_s() rather than calling the basic
124 ldap_sasl_bind() functions directly. The mechs parameter should contain
125 a space-separated list of candidate mechanisms to use. If this parame‐
126 ter is NULL or empty the library will query the supportedSASLMechanisms
127 attribute from the server's rootDSE for the list of SASL mechanisms the
128 server supports. The flags parameter controls the interaction used to
129 retrieve any necessary SASL authentication parameters and should be one
130 of:
131
132 LDAP_SASL_AUTOMATIC
133 use defaults if available, prompt otherwise
134
135 LDAP_SASL_INTERACTIVE
136 always prompt
137
138 LDAP_SASL_QUIET
139 never prompt
140
141 The interact function uses the provided defaults to handle requests
142 from the SASL library for particular authentication parameters. There
143 is no defined format for the defaults information; it is up to the
144 caller to use whatever format is appropriate for the supplied interact
145 function. The sasl_interact parameter comes from the underlying SASL
146 library. When used with Cyrus SASL this is an array of sasl_interact_t
147 structures. The Cyrus SASL library will prompt for a variety of inputs,
148 including:
149
150 SASL_CB_GETREALM
151 the realm for the authentication attempt
152
153 SASL_CB_AUTHNAME
154 the username to authenticate
155
156 SASL_CB_PASS
157 the password for the provided username
158
159 SASL_CB_USER
160 the username to use for proxy authorization
161
162 SASL_CB_NOECHOPROMPT
163 generic prompt for input with input echoing disabled
164
165 SASL_CB_ECHOPROMPT
166 generic prompt for input with input echoing enabled
167
168 SASL_CB_LIST_END
169 indicates the end of the array of prompts
170
171 See the Cyrus SASL documentation for more details.
172
173 Applications which need to manage connections asynchronously may use
174 ldap_sasl_interactive_bind() instead of the synchronous version. A
175 valid mechs parameter must be supplied, otherwise the library will be
176 forced to query the server for a list of supported mechanisms, and this
177 query will be performed synchronously. The other parameters are the
178 same as for the synchronous function, with three additional parameters.
179 The actual SASL mechanism that was used, and the message ID for use
180 with ldap_result() will be returned in rmechp and msgidp, respectively.
181 The value in rmechp must not be modified by the caller and must be
182 passed back on each subsequent call. The message obtained from ldap_re‐
183 sult() must be passed in the result parameter. This parameter must be
184 NULL when initiating a new Bind. The caller must free the result mes‐
185 sage after each call using ldap_msgfree(). The ldap_sasl_interac‐
186 tive_bind() function returns an LDAP result code. If the code is
187 LDAP_SASL_BIND_IN_PROGRESS then the Bind is not complete yet, and this
188 function must be called again with the next result from the server.
189
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 ap‐
193 plication needs to bind to another server in order to follow a referral
194 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
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
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
246 If an anonymous bind is sufficient for the application, the rebind
247 process need not be provided. The LDAP libraries with the LDAP_OPT_RE‐
248 FERRALS option set to ON (default value) will automatically follow re‐
249 ferrals 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
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
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.6.6 2023/07/31 LDAP_BIND(3)