]> git.sur5r.net Git - openldap/blob - doc/man/man3/ldap_open.3
3402eb7862b4bc72957dbabea51705008ba33d68
[openldap] / doc / man / man3 / ldap_open.3
1 .TH LDAP_OPEN 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_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 .LP
97 At this time,
98 .B ldap_open()
99 and 
100 .B ldap_init()
101 are deprecated in favor of
102 .BR ldap_initialize() ,
103 essentially because the latter allows to specify a schema in the URI
104 and it explicitly returns an error code.
105 .LP
106 .B ldap_init_fd()
107 allows an LDAP structure to be initialized using an already-opened
108 connection. The
109 .I proto
110 parameter should be one of LDAP_PROTO_TCP, LDAP_PROTO_UDP,
111 or LDAP_PROTO_IPC
112 for a connection using TCP, UDP, or IPC, respectively. The value
113 LDAP_PROTO_EXT
114 may also be specified if user-supplied sockbuf handlers are going to
115 be used. Note that support for UDP is not implemented unless libldap
116 was built with LDAP_CONNECTIONLESS defined.
117 The
118 .I uri
119 parameter may optionally be provided for informational purposes.
120
121 Note: the first call into the LDAP library also initializes the global
122 options for the library. As such the first call should be single-threaded
123 or otherwise protected to insure that only one call is active. It is
124 recommended that
125 .BR ldap_get_option ()
126 or
127 .BR ldap_set_option ()
128 be used in the program's main thread before any additional threads are created.
129 See
130 .BR ldap_get_option (3).
131
132 .SH ERRORS
133 If an error occurs,
134 .B ldap_open()
135 and
136 .B ldap_init()
137 will return NULL and errno should be set appropriately.
138 .B ldap_initialize()
139 and
140 .B ldap_init_fd()
141 will directly return the LDAP code associated to the error (or
142 .I LDAP_SUCCESS
143 in case of success);
144 errno should be set as well whenever appropriate.
145 .SH SEE ALSO
146 .BR ldap (3),
147 .BR ldap_bind (3),
148 .BR ldap_get_option (3),
149 .BR ldap_set_option (3),
150 .BR lber-sockbuf (3),
151 .BR errno (3)
152 .SH ACKNOWLEDGEMENTS
153 .so ../Project