1LDAP_OPEN(3)               Library Functions Manual               LDAP_OPEN(3)
2
3
4

NAME

6       ldap_init, ldap_initialize, ldap_open - Initialize the LDAP library and
7       open a connection to an LDAP server
8

LIBRARY

10       OpenLDAP LDAP (libldap, -lldap)
11

SYNOPSIS

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_connect(ldp)
28       LDAP *ldp;
29
30       int ldap_set_urllist_proc(ld, proc, params)
31       LDAP *ld;
32       LDAP_URLLIST_PROC *proc;
33       void *params;
34
35       int (LDAP_URLLIST_PROC)(ld, urllist, url, params);
36       LDAP *ld;
37       LDAPURLDesc **urllist;
38       LDAPURLDesc **url;
39       void *params;
40
41       #include <openldap.h>
42
43       int ldap_init_fd(fd, proto, uri, ldp)
44       ber_socket_t fd;
45       int proto;
46       char *uri;
47       LDAP **ldp;
48

DESCRIPTION

50       ldap_open() opens a connection to an LDAP server and allocates an  LDAP
51       structure which is used to identify the connection and to maintain per-
52       connection information.  ldap_init() allocates an  LDAP  structure  but
53       does  not  open  an initial connection.  ldap_initialize() allocates an
54       LDAP structure but does not open an initial connection.  ldap_init_fd()
55       allocates  an  LDAP  structure using an existing connection on the pro‐
56       vided socket.  One of these routines must be called before  any  opera‐
57       tions are attempted.
58
59       ldap_open()  takes  host, the hostname on which the LDAP server is run‐
60       ning, and port, 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       port.  The host parameter may contain a blank-separated list  of  hosts
63       to  try  to  connect  to,  and  each host may optionally by of the form
64       host:port.  If present, the  :port  overrides  the  port  parameter  to
65       ldap_open().   Upon successfully making a connection to an LDAP server,
66       ldap_open() returns a pointer to an opaque LDAP structure, which should
67       be  passed to subsequent calls to ldap_bind(), ldap_search(), etc. Cer‐
68       tain fields in the LDAP structure can be set to  indicate  size  limit,
69       time  limit,  and  how  aliases are handled during operations; read and
70       write access to those fields must occur by  calling  ldap_get_option(3)
71       and ldap_set_option(3) respectively, whenever possible.
72
73       ldap_init()  acts just like ldap_open(), but does not open a connection
74       to the LDAP server.  The actual connection open  will  occur  when  the
75       first operation is attempted.
76
77       ldap_initialize()  acts like ldap_init(), but it returns an integer in‐
78       dicating either success or the failure reason, and it allows to specify
79       details  for  the connection in the schema portion of the URI.  The uri
80       parameter may be a comma- or whitespace-separated list of URIs contain‐
81       ing  only  the schema, the host, and the port fields.  Apart from ldap,
82       other (non-standard) recognized values of the schema  field  are  ldaps
83       (LDAP  over  TLS),  ldapi  (LDAP  over  IPC), and cldap (connectionless
84       LDAP).  If other fields are present, the behavior is undefined.
85
86       At this time, ldap_open() and ldap_init() are deprecated  in  favor  of
87       ldap_initialize(),  essentially  because the latter allows to specify a
88       schema in the URI and it explicitly returns an error code.
89
90       ldap_connect() causes a handle created by ldap_initialize() to  connect
91       to  the server. This is useful in situations where a file descriptor is
92       required before a request is performed.
93
94       ldap_init_fd() allows an LDAP structure to be initialized using an  al‐
95       ready-opened   connection.   The  proto  parameter  should  be  one  of
96       LDAP_PROTO_TCP, LDAP_PROTO_UDP, or LDAP_PROTO_IPC for a connection  us‐
97       ing  TCP,  UDP, or IPC, respectively. The value LDAP_PROTO_EXT may also
98       be specified if user-supplied sockbuf handlers are going  to  be  used.
99       Note  that  support for UDP is not implemented unless libldap was built
100       with LDAP_CONNECTIONLESS defined.  The uri parameter may optionally  be
101       provided for informational purposes.
102
103       ldap_set_urllist_proc() allows to set a function proc of type LDAP_URL‐
104       LIST_PROC that is called when a successful  connection  can  be  estab‐
105       lished.   This  function  receives the list of URIs parsed from the uri
106       string originally passed to ldap_initialize(), and the  one  that  suc‐
107       cessfully  connected.   The  function  may manipulate the URI list; the
108       typical use consists in moving the successful URI to the  head  of  the
109       list,  so  that subsequent attempts to connect to one of the URIs using
110       the same LDAP handle will try it first.  If ld is null, proc is set  as
111       a global parameter that is inherited by all handlers within the process
112       that are created after the call  to  ldap_set_urllist_proc().   By  de‐
113       fault,  no  LDAP_URLLIST_PROC  is set.  In a multithreaded environment,
114       ldap_set_urllist_proc() must be called before any concurrent  operation
115       using the LDAP handle is started.
116
117       Note:  the first call into the LDAP library also initializes the global
118       options for the library. As such  the  first  call  should  be  single-
119       threaded or otherwise protected to insure that only one call is active.
120       It is recommended that ldap_get_option() or ldap_set_option()  be  used
121       in the program's main thread before any additional threads are created.
122       See ldap_get_option(3).
123
124

ERRORS

126       If an error occurs, ldap_open() and ldap_init() will  return  NULL  and
127       errno    should    be   set   appropriately.    ldap_initialize()   and
128       ldap_init_fd() will directly return the LDAP code associated to the er‐
129       ror  (or  LDAP_SUCCESS in case of success); errno should be set as well
130       whenever appropriate.  ldap_set_urllist_proc()  returns  LDAP_OPT_ERROR
131       on error, and LDAP_OPT_SUCCESS on success.
132

SEE ALSO

134       ldap(3),  ldap_bind(3),  ldap_get_option(3),  ldap_set_option(3), lber-
135       sockbuf(3), errno(3)
136

ACKNOWLEDGEMENTS

138       OpenLDAP Software is developed and maintained by The  OpenLDAP  Project
139       <http://www.openldap.org/>.  OpenLDAP Software is derived from the Uni‐
140       versity of Michigan LDAP 3.3 Release.
141
142
143
144OpenLDAP 2.6.2                    2022/05/04                      LDAP_OPEN(3)
Impressum