1LDAP_OPEN(3) Library Functions Manual LDAP_OPEN(3)
2
3
4
6 ldap_init, ldap_initialize, ldap_open - Initialize the LDAP library and
7 open a connection to an LDAP server
8
10 OpenLDAP LDAP (libldap, -lldap)
11
13 #include <ldap.h>
14
15 LDAP *ldap_open(host, port)
16 char *host;
17 int port;
18
19 LDAP *ldap_init(host, port)
20 char *host;
21 int port;
22
23 int ldap_initialize(ldp, uri)
24 LDAP **ldp;
25 char *uri;
26
27 int ldap_set_urllist_proc(ld, proc, params)
28 LDAP *ld;
29 LDAP_URLLIST_PROC *proc;
30 void *params;
31
32 int (LDAP_URLLIST_PROC)(ld, urllist, url, params);
33 LDAP *ld;
34 LDAPURLDesc **urllist;
35 LDAPURLDesc **url;
36 void *params;
37
38 #include <ldap_pvt.h>
39
40 int ldap_init_fd(fd, proto, uri, ldp)
41 ber_socket_t fd;
42 int proto;
43 char *uri;
44 LDAP **ldp;
45
47 ldap_open() opens a connection to an LDAP server and allocates an LDAP
48 structure which is used to identify the connection and to maintain per-
49 connection information. ldap_init() allocates an LDAP structure but
50 does not open an initial connection. ldap_initialize() allocates an
51 LDAP structure but does not open an initial connection. ldap_init_fd()
52 allocates an LDAP structure using an existing connection on the pro‐
53 vided socket. One of these routines must be called before any opera‐
54 tions are attempted.
55
56 ldap_open() takes host, the hostname on which the LDAP server is run‐
57 ning, and port, the port number to which to connect. If the default
58 IANA-assigned port of 389 is desired, LDAP_PORT should be specified for
59 port. The host parameter may contain a blank-separated list of hosts
60 to try to connect to, and each host may optionally by of the form
61 host:port. If present, the :port overrides the port parameter to
62 ldap_open(). Upon successfully making a connection to an LDAP server,
63 ldap_open() returns a pointer to an opaque LDAP structure, which should
64 be passed to subsequent calls to ldap_bind(), ldap_search(), etc. Cer‐
65 tain fields in the LDAP structure can be set to indicate size limit,
66 time limit, and how aliases are handled during operations; read and
67 write access to those fields must occur by calling ldap_get_option(3)
68 and ldap_set_option(3) respectively, whenever possible.
69
70 ldap_init() acts just like ldap_open(), but does not open a connection
71 to the LDAP server. The actual connection open will occur when the
72 first operation is attempted.
73
74 ldap_initialize() acts like ldap_init(), but it returns an integer
75 indicating either success or the failure reason, and it allows to spec‐
76 ify details for the connection in the schema portion of the URI. The
77 uri parameter may be a comma- or whitespace-separated list of URIs con‐
78 taining only the schema, the host, and the port fields. Apart from
79 ldap, other (non-standard) recognized values of the schema field are
80 ldaps (LDAP over TLS), ldapi (LDAP over IPC), and cldap (connectionless
81 LDAP). If other fields are present, the behavior is undefined.
82
83 At this time, ldap_open() and ldap_init() are deprecated in favor of
84 ldap_initialize(), essentially because the latter allows to specify a
85 schema in the URI and it explicitly returns an error code.
86
87 ldap_init_fd() allows an LDAP structure to be initialized using an
88 already-opened connection. The proto parameter should be one of
89 LDAP_PROTO_TCP, LDAP_PROTO_UDP, or LDAP_PROTO_IPC for a connection
90 using TCP, UDP, or IPC, respectively. The value LDAP_PROTO_EXT may also
91 be specified if user-supplied sockbuf handlers are going to be used.
92 Note that support for UDP is not implemented unless libldap was built
93 with LDAP_CONNECTIONLESS defined. The uri parameter may optionally be
94 provided for informational purposes.
95
96 ldap_set_urllist_proc() allows to set a function proc of type LDAP_URL‐
97 LIST_PROC that is called when a successful connection can be estab‐
98 lished. This function receives the list of URIs parsed from the uri
99 string originally passed to ldap_initialize(), and the one that suc‐
100 cessfully connected. The function may manipulate the URI list; the
101 typical use consists in moving the successful URI to the head of the
102 list, so that subsequent attempts to connect to one of the URIs using
103 the same LDAP handle will try it first. If ld is null, proc is set as
104 a global parameter that is inherited by all handlers within the process
105 that are created after the call to ldap_set_urllist_proc(). By
106 default, no LDAP_URLLIST_PROC is set. In a multithreaded environment,
107 ldap_set_urllist_proc() must be called before any concurrent operation
108 using the LDAP handle is started.
109
110 Note: the first call into the LDAP library also initializes the global
111 options for the library. As such the first call should be single-
112 threaded or otherwise protected to insure that only one call is active.
113 It is recommended that ldap_get_option() or ldap_set_option() be used
114 in the program's main thread before any additional threads are created.
115 See ldap_get_option(3).
116
117
119 If an error occurs, ldap_open() and ldap_init() will return NULL and
120 errno should be set appropriately. ldap_initialize() and
121 ldap_init_fd() will directly return the LDAP code associated to the
122 error (or LDAP_SUCCESS in case of success); errno should be set as well
123 whenever appropriate. ldap_set_urllist_proc() returns LDAP_OPT_ERROR
124 on error, and LDAP_OPT_SUCCESS on success.
125
127 ldap(3), ldap_bind(3), ldap_get_option(3), ldap_set_option(3), lber-
128 sockbuf(3), errno(3)
129
131 OpenLDAP Software is developed and maintained by The OpenLDAP Project
132 <http://www.openldap.org/>. OpenLDAP Software is derived from the Uni‐
133 versity of Michigan LDAP 3.3 Release.
134
135
136
137OpenLDAP 2.4.47 2018/12/19 LDAP_OPEN(3)