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