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