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,
9 ldap_unbind_ext, ldap_unbind_ext_s, ldap_set_rebind_proc - LDAP bind
10 routines
11
13 OpenLDAP LDAP (libldap, -lldap)
14
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
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
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).
93
95 The ldap_bind() and ldap_bind_s() routines can be used when the authen‐
96 tication method to use needs to be selected at runtime. They both take
97 an extra method parameter selecting the authentication method to use.
98 It should be set to LDAP_AUTH_SIMPLE to select simple authentication.
99 ldap_bind() returns the message id of the request it initiates.
100 ldap_bind_s() returns an LDAP error indication.
101
103 For SASL binds the server always ignores any provided DN, so the dn
104 parameter should always be NULL. ldap_sasl_bind_s() sends a single
105 SASL bind request with the given SASL mechanism and credentials in the
106 cred parameter. The format of the credentials depends on the particular
107 SASL mechanism in use. For mechanisms that provide mutual authentica‐
108 tion the server's credentials will be returned in the servercredp
109 parameter. The routine returns an LDAP error indication (see
110 ldap_error(3)). The ldap_sasl_bind() call is asynchronous, taking the
111 same parameters but only sending the request and returning the message
112 id of the request it sent. The result of the operation can be obtained
113 by a subsequent call to ldap_result(3). The result must be addition‐
114 ally parsed by ldap_parse_sasl_bind_result() to obtain any server cre‐
115 dentials sent from the server.
116
117 Many SASL mechanisms require multiple message exchanges to perform a
118 complete authentication. Applications should generally use
119 ldap_sasl_interactive_bind_s() rather than calling the basic
120 ldap_sasl_bind() functions directly. The mechs parameter should contain
121 a space-separated list of candidate mechanisms to use. If this parame‐
122 ter is NULL or empty the library will query the supportedSASLMechanisms
123 attribute from the server's rootDSE for the list of SASL mechanisms the
124 server supports. The flags parameter controls the interaction used to
125 retrieve any necessary SASL authentication parameters and should be one
126 of:
127
128 LDAP_SASL_AUTOMATIC
129 use defaults if available, prompt otherwise
130
131 LDAP_SASL_INTERACTIVE
132 always prompt
133
134 LDAP_SASL_QUIET
135 never prompt
136
137 The interact function uses the provided defaults to handle requests
138 from the SASL library for particular authentication parameters. There
139 is no defined format for the defaults information; it is up to the
140 caller to use whatever format is appropriate for the supplied interact
141 function. The sasl_interact parameter comes from the underlying SASL
142 library. When used with Cyrus SASL this is an array of sasl_interact_t
143 structures. The Cyrus SASL library will prompt for a variety of inputs,
144 including:
145
146 SASL_CB_GETREALM
147 the realm for the authentication attempt
148
149 SASL_CB_AUTHNAME
150 the username to authenticate
151
152 SASL_CB_PASS
153 the password for the provided username
154
155 SASL_CB_USER
156 the username to use for proxy authorization
157
158 SASL_CB_NOECHOPROMPT
159 generic prompt for input with input echoing disabled
160
161 SASL_CB_ECHOPROMPT
162 generic prompt for input with input echoing enabled
163
164 SASL_CB_LIST_END
165 indicates the end of the array of prompts
166
167 See the Cyrus SASL documentation for more details.
168
169 Applications which need to manage connections asynchronously may use
170 ldap_sasl_interactive_bind() instead of the synchronous version. A
171 valid mechs parameter must be supplied, otherwise the library will be
172 forced to query the server for a list of supported mechanisms, and this
173 query will be performed synchronously. The other parameters are the
174 same as for the synchronous function, with three additional parameters.
175 The actual SASL mechanism that was used, and the message ID for use
176 with ldap_result() will be returned in rmechp and msgidp, respectively.
177 The value in rmechp must not be modified by the caller and must be
178 passed back on each subsequent call. The message obtained from
179 ldap_result() must be passed in the result parameter. This parameter
180 must be NULL when initiating a new Bind. The caller must free the
181 result message after each call using ldap_msgfree(). The
182 ldap_sasl_interactive_bind() function returns an LDAP result code. If
183 the code is LDAP_SASL_BIND_IN_PROGRESS then the Bind is not complete
184 yet, and this function must be called again with the next result from
185 the server.
186
188 The ldap_set_rebind_proc function() sets the process to use for binding
189 when an operation returns a referral. This function is used when an
190 application needs to bind to another server in order to follow a refer‐
191 ral or search continuation reference.
192
193 The function takes ld, the rebind function, and the params, the arbi‐
194 trary data like state information which the client might need to prop‐
195 erly rebind. The LDAP_OPT_REFERRALS option in the ld must be set to ON
196 for the libraries to use the rebind function. Use the ldap_set_option
197 function to set the value.
198
199 The rebind function parameters are as follows:
200
201 The ld parameter must be used by the application when binding to the
202 referred server if the application wants the libraries to follow the
203 referral.
204
205 The url parameter points to the URL referral string received from the
206 LDAP server. The LDAP application can use the ldap_url_parse(3) func‐
207 tion to parse the string into its components.
208
209 The request parameter specifies the type of request that generated the
210 referral.
211
212 The msgid parameter specifies the message ID of the request generating
213 the referral.
214
215 The params parameter is the same value as passed originally to the
216 ldap_set_rebind_proc() function.
217
218 The LDAP libraries set all the parameters when they call the rebind
219 function. The application should not attempt to free either the ld or
220 the url structures in the rebind function.
221
222 The application must supply to the rebind function the required authen‐
223 tication information such as, user name, password, and certificates.
224 The rebind function must use a synchronous bind method.
225
227 The ldap_unbind() call is used to unbind from the directory, terminate
228 the current association, and free the resources contained in the ld
229 structure. Once it is called, the connection to the LDAP server is
230 closed, and the ld structure is invalid. The ldap_unbind_s() call is
231 just another name for ldap_unbind(); both of these calls are synchro‐
232 nous in nature.
233
234 The ldap_unbind_ext() and ldap_unbind_ext_s() allows the operations to
235 specify controls.
236
238 Asynchronous routines will return -1 in case of error, setting the
239 ld_errno parameter of the ld structure. Synchronous routines return
240 whatever ld_errno is set to. See ldap_error(3) for more information.
241
243 If an anonymous bind is sufficient for the application, the rebind
244 process need not be provided. The LDAP libraries with the
245 LDAP_OPT_REFERRALS option set to ON (default value) will automatically
246 follow referrals using an anonymous bind.
247
248 If the application needs stronger authentication than an anonymous
249 bind, you need to provide a rebind process for that authentication
250 method. The bind method must be synchronous.
251
253 ldap(3), ldap_error(3), ldap_open(3), ldap_set_option(3),
254 ldap_url_parse(3) RFC 4422 (http://www.rfc-editor.org), Cyrus SASL
255 (http://asg.web.cmu.edu/sasl/)
256
258 OpenLDAP Software is developed and maintained by The OpenLDAP Project
259 <http://www.openldap.org/>. OpenLDAP Software is derived from Univer‐
260 sity of Michigan LDAP 3.3 Release.
261
262
263
264OpenLDAP 2.4.40 2014/09/20 LDAP_BIND(3)