]> git.sur5r.net Git - openldap/blob - doc/man/man3/ldap_open.3
ITS#6435
[openldap] / doc / man / man3 / ldap_open.3
1 .TH LDAP_OPEN 3 "RELEASEDATE" "OpenLDAP LDVERSION"
2 .\" $OpenLDAP$
3 .\" Copyright 1998-2010 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 #include <ldap_pvt.h>
34 .LP
35 .ft B
36 int ldap_init_fd(fd, proto, uri, ldp)
37 .ft
38 ber_socket_t fd;
39 int proto;
40 char *uri;
41 LDAP **ldp;
42 .SH DESCRIPTION
43 .LP
44 .B ldap_open()
45 opens a connection to an LDAP server and allocates an LDAP
46 structure which is used to identify
47 the connection and to maintain per-connection information.
48 .B ldap_init()
49 allocates an LDAP structure but does not open an initial connection.
50 .B ldap_initialize()
51 allocates an LDAP structure but does not open an initial connection.
52 .B ldap_init_fd()
53 allocates an LDAP structure using an existing connection on the
54 provided socket.
55 One
56 of these routines must be called before any operations are attempted.
57 .LP
58 .B ldap_open()
59 takes \fIhost\fP, the hostname on which the LDAP server is
60 running, and \fIport\fP, the port number to which to connect.  If the default
61 IANA-assigned port of 389 is desired, LDAP_PORT should be specified for
62 \fIport\fP.  The \fIhost\fP parameter may contain a blank-separated list
63 of hosts to try to connect to, and each host may optionally by of the form
64 \fIhost:port\fP.  If present, the \fI:port\fP overrides the \fIport\fP
65 parameter to
66 .BR ldap_open() .
67 Upon successfully making a connection to an
68 LDAP server,
69 .B ldap_open()
70 returns a pointer to an opaque LDAP structure, which should be passed
71 to subsequent calls to
72 .BR ldap_bind() ,
73 .BR ldap_search() ,
74 etc. Certain fields in the LDAP structure can be set to indicate size limit,
75 time limit, and how aliases are handled during operations; read and write access 
76 to those fields must occur by calling
77 .BR ldap_get_option (3) 
78 and
79 .BR ldap_set_option (3)
80 respectively, whenever possible.
81 .LP
82 .B
83 ldap_init()
84 acts just like
85 .BR ldap_open() ,
86 but does not open a connection
87 to the LDAP server.  The actual connection open will occur when the
88 first operation is attempted.
89 .LP
90 .B ldap_initialize()
91 acts like
92 .BR ldap_init() ,
93 but it returns an integer indicating either success or the failure reason,
94 and it allows to specify details for the connection in the schema portion
95 of the URI.
96 The
97 .I uri
98 parameter may be a comma- or whitespace-separated list of URIs
99 containing only the
100 .IR schema ,
101 the
102 .IR host ,
103 and the
104 .I port
105 fields.
106 Apart from
107 .BR ldap ,
108 other (non-standard) recognized values of the
109 .I schema
110 field are
111 .B ldaps
112 (LDAP over TLS),
113 .B ldapi
114 (LDAP over IPC),
115 and
116 .B cldap
117 (connectionless LDAP).
118 If other fields are present, the behavior is undefined.
119 .LP
120 At this time,
121 .B ldap_open()
122 and 
123 .B ldap_init()
124 are deprecated in favor of
125 .BR ldap_initialize() ,
126 essentially because the latter allows to specify a schema in the URI
127 and it explicitly returns an error code.
128 .LP
129 .B ldap_init_fd()
130 allows an LDAP structure to be initialized using an already-opened
131 connection. The
132 .I proto
133 parameter should be one of LDAP_PROTO_TCP, LDAP_PROTO_UDP,
134 or LDAP_PROTO_IPC
135 for a connection using TCP, UDP, or IPC, respectively. The value
136 LDAP_PROTO_EXT
137 may also be specified if user-supplied sockbuf handlers are going to
138 be used. Note that support for UDP is not implemented unless libldap
139 was built with LDAP_CONNECTIONLESS defined.
140 The
141 .I uri
142 parameter may optionally be provided for informational purposes.
143
144 Note: the first call into the LDAP library also initializes the global
145 options for the library. As such the first call should be single-threaded
146 or otherwise protected to insure that only one call is active. It is
147 recommended that
148 .BR ldap_get_option ()
149 or
150 .BR ldap_set_option ()
151 be used in the program's main thread before any additional threads are created.
152 See
153 .BR ldap_get_option (3).
154
155 .SH ERRORS
156 If an error occurs,
157 .B ldap_open()
158 and
159 .B ldap_init()
160 will return NULL and 
161 .I errno
162 should be set appropriately.
163 .B ldap_initialize()
164 and
165 .B ldap_init_fd()
166 will directly return the LDAP code associated to the error (or
167 .I LDAP_SUCCESS
168 in case of success);
169 .I errno
170 should be set as well whenever appropriate.
171 .SH SEE ALSO
172 .BR ldap (3),
173 .BR ldap_bind (3),
174 .BR ldap_get_option (3),
175 .BR ldap_set_option (3),
176 .BR lber-sockbuf (3),
177 .BR errno (3)
178 .SH ACKNOWLEDGEMENTS
179 .so ../Project