]> git.sur5r.net Git - openldap/blob - doc/man/man3/ldap_open.3
66b0b98f82a8988f8372eb9d2d12f43e908ceebf
[openldap] / doc / man / man3 / ldap_open.3
1 .TH LDAP_OPEN 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_init, ldap_initialize, ldap_open \- Initialize the LDAP library and open a connection to an LDAP server
7 .SH LIBRARY
8 OpenLDAP LDAP (libldap, \-lldap)
9 .SH SYNOPSIS
10 .nf
11 .ft B
12 #include <ldap.h>
13 .LP
14 .ft B
15 LDAP *ldap_open(host, port)
16 .ft
17 char *host;
18 int port;
19 .LP
20 .ft B
21 LDAP *ldap_init(host, port)
22 .ft
23 char *host;
24 int port;
25 .LP
26 .ft B
27 int ldap_initialize(ldp, uri)
28 .ft
29 LDAP **ldp;
30 char *uri;
31 .LP
32 .ft B
33 int ldap_connect(ldp)
34 .ft
35 LDAP *ldp;
36 .LP
37 .ft B
38 int ldap_set_urllist_proc(ld, proc, params)
39 .ft
40 LDAP *ld;
41 LDAP_URLLIST_PROC *proc;
42 void *params;
43 .LP
44 .ft B
45 int (LDAP_URLLIST_PROC)(ld, urllist, url, params);
46 .ft
47 LDAP *ld;
48 LDAPURLDesc **urllist;
49 LDAPURLDesc **url;
50 void *params;
51 .LP
52 .ft B
53 #include <ldap_pvt.h>
54 .LP
55 .ft B
56 int ldap_init_fd(fd, proto, uri, ldp)
57 .ft
58 ber_socket_t fd;
59 int proto;
60 char *uri;
61 LDAP **ldp;
62 .SH DESCRIPTION
63 .LP
64 .B ldap_open()
65 opens a connection to an LDAP server and allocates an LDAP
66 structure which is used to identify
67 the connection and to maintain per-connection information.
68 .B ldap_init()
69 allocates an LDAP structure but does not open an initial connection.
70 .B ldap_initialize()
71 allocates an LDAP structure but does not open an initial connection.
72 .B ldap_init_fd()
73 allocates an LDAP structure using an existing connection on the
74 provided socket.
75 One
76 of these routines must be called before any operations are attempted.
77 .LP
78 .B ldap_open()
79 takes \fIhost\fP, the hostname on which the LDAP server is
80 running, and \fIport\fP, the port number to which to connect.  If the default
81 IANA-assigned port of 389 is desired, LDAP_PORT should be specified for
82 \fIport\fP.  The \fIhost\fP parameter may contain a blank-separated list
83 of hosts to try to connect to, and each host may optionally by of the form
84 \fIhost:port\fP.  If present, the \fI:port\fP overrides the \fIport\fP
85 parameter to
86 .BR ldap_open() .
87 Upon successfully making a connection to an
88 LDAP server,
89 .B ldap_open()
90 returns a pointer to an opaque LDAP structure, which should be passed
91 to subsequent calls to
92 .BR ldap_bind() ,
93 .BR ldap_search() ,
94 etc. Certain fields in the LDAP structure can be set to indicate size limit,
95 time limit, and how aliases are handled during operations; read and write access 
96 to those fields must occur by calling
97 .BR ldap_get_option (3) 
98 and
99 .BR ldap_set_option (3)
100 respectively, whenever possible.
101 .LP
102 .B
103 ldap_init()
104 acts just like
105 .BR ldap_open() ,
106 but does not open a connection
107 to the LDAP server.  The actual connection open will occur when the
108 first operation is attempted.
109 .LP
110 .B ldap_initialize()
111 acts like
112 .BR ldap_init() ,
113 but it returns an integer indicating either success or the failure reason,
114 and it allows to specify details for the connection in the schema portion
115 of the URI.
116 The
117 .I uri
118 parameter may be a comma- or whitespace-separated list of URIs
119 containing only the
120 .IR schema ,
121 the
122 .IR host ,
123 and the
124 .I port
125 fields.
126 Apart from
127 .BR ldap ,
128 other (non-standard) recognized values of the
129 .I schema
130 field are
131 .B ldaps
132 (LDAP over TLS),
133 .B ldapi
134 (LDAP over IPC),
135 and
136 .B cldap
137 (connectionless LDAP).
138 If other fields are present, the behavior is undefined.
139 .LP
140 At this time,
141 .B ldap_open()
142 and 
143 .B ldap_init()
144 are deprecated in favor of
145 .BR ldap_initialize() ,
146 essentially because the latter allows to specify a schema in the URI
147 and it explicitly returns an error code.
148 .LP
149 .B ldap_connect()
150 causes a handle created by
151 .B ldap_initialize()
152 to connect to the server. This is useful in situations where a file
153 descriptor is required before a request is performed.
154 .LP
155 .B ldap_init_fd()
156 allows an LDAP structure to be initialized using an already-opened
157 connection. The
158 .I proto
159 parameter should be one of LDAP_PROTO_TCP, LDAP_PROTO_UDP,
160 or LDAP_PROTO_IPC
161 for a connection using TCP, UDP, or IPC, respectively. The value
162 LDAP_PROTO_EXT
163 may also be specified if user-supplied sockbuf handlers are going to
164 be used. Note that support for UDP is not implemented unless libldap
165 was built with LDAP_CONNECTIONLESS defined.
166 The
167 .I uri
168 parameter may optionally be provided for informational purposes.
169 .LP
170 .B ldap_set_urllist_proc()
171 allows to set a function
172 .I proc
173 of type
174 .I LDAP_URLLIST_PROC
175 that is called when a successful connection can be established.
176 This function receives the list of URIs parsed from the
177 .I uri
178 string originally passed to
179 .BR ldap_initialize() ,
180 and the one that successfully connected.
181 The function may manipulate the URI list; the typical use consists
182 in moving the successful URI to the head of the list,
183 so that subsequent attempts to connect to one of the URIs using the same LDAP handle
184 will try it first.
185 If
186 .I ld
187 is null,
188 .I proc
189 is set as a global parameter that is inherited by all handlers
190 within the process that are created after the call to
191 .BR ldap_set_urllist_proc() .
192 By default, no 
193 .I LDAP_URLLIST_PROC
194 is set.
195 In a multithreaded environment,
196 .B ldap_set_urllist_proc()
197 must be called before any concurrent operation using the LDAP handle is started.
198
199 Note: the first call into the LDAP library also initializes the global
200 options for the library. As such the first call should be single-threaded
201 or otherwise protected to insure that only one call is active. It is
202 recommended that
203 .BR ldap_get_option ()
204 or
205 .BR ldap_set_option ()
206 be used in the program's main thread before any additional threads are created.
207 See
208 .BR ldap_get_option (3).
209
210 .SH ERRORS
211 If an error occurs,
212 .B ldap_open()
213 and
214 .B ldap_init()
215 will return NULL and 
216 .I errno
217 should be set appropriately.
218 .B ldap_initialize()
219 and
220 .B ldap_init_fd()
221 will directly return the LDAP code associated to the error (or
222 .I LDAP_SUCCESS
223 in case of success);
224 .I errno
225 should be set as well whenever appropriate.
226 .B ldap_set_urllist_proc()
227 returns LDAP_OPT_ERROR on error, and LDAP_OPT_SUCCESS on success.
228 .SH SEE ALSO
229 .BR ldap (3),
230 .BR ldap_bind (3),
231 .BR ldap_get_option (3),
232 .BR ldap_set_option (3),
233 .BR lber-sockbuf (3),
234 .BR errno (3)
235 .SH ACKNOWLEDGEMENTS
236 .so ../Project