LDAP_OPEN(3)
β¨ NAME β¨
okay so this is LDAP_OPEN(3), a Library Functions Manual page, and it's literally the glow-up guide for four-ish little functions β ldap_init, ldap_initialize, ldap_open β whose whole job is to initialize the LDAP library and open a connection to an LDAP server. bestie, this is the "hello world" of talking to a directory. π
π LIBRARY π
OpenLDAP LDAP, aka libldap, and you link it with -lldap. no cap. π«Ά
π SYNOPSIS π
#include <ldap.h>
LDAP *ldap_open(host, port)
char *host;
int port;
LDAP *ldap_init(host, port)
char *host;
int port;
int ldap_initialize(ldp, uri)
LDAP **ldp;
char *uri;
int ldap_connect(ldp)
LDAP *ldp;
int ldap_set_urllist_proc(ld, proc, params)
LDAP *ld;
LDAP_URLLIST_PROC *proc;
void *params;
int (LDAP_URLLIST_PROC)(ld, urllist, url, params);
LDAP *ld;
LDAPURLDesc **urllist;
LDAPURLDesc **url;
void *params;
#include <openldap.h>
int ldap_init_fd(fd, proto, uri, ldp)
ber_socket_t fd;
int proto;
char *uri;
LDAP **ldp;
like, K&R style, we're respecting the elders. π§
π DESCRIPTION π
okay so the whole vibe: ldap_open() opens a connection to an LDAP server and allocates an LDAP structure, and that structure is the little main-character handle you use to identify the connection and to maintain per-connection information. iconic.
meanwhile:
ldap_init()β allocates an LDAP structure but does not open an initial connection. it's giving "I'm ready but I'm not texting first." πldap_initialize()β also allocates an LDAP structure but does not open an initial connection.ldap_init_fd()β allocates an LDAP structure using an existing connection on the provided socket. recycling era. β»οΈ
π¨ literally the one rule: one of these routines must be called before any operations are attempted. no handle, no operations. periodt.
πΈ ldap_open() β the original queen πΈ
ldap_open() takes host, the hostname on which the LDAP server is running, and port, the port number to which to connect. if you want the default IANA-assigned port of 389, you should specify LDAP_PORT for port. cute, right?
the host parameter may contain a blank-separated list of hosts to try to connect to, and each host may optionally be of the form host:port. if present, the :port overrides the port parameter to ldap_open(). so yes, she can be sneaky like that. π
upon successfully making a connection to an LDAP server, ldap_open() returns a pointer to an opaque LDAP structure, which should be passed to subsequent calls to ldap_bind(), ldap_search(), etc. certain fields in the LDAP structure can be set to indicate size limit, time limit, and how aliases are handled during operations β and read and write access to those fields must occur by calling ldap_get_option(3) and ldap_set_option(3) respectively, whenever possible. don't be out here poking fields directly, bestie. π
π¦ ldap_init() β same energy, zero commitment π¦
ldap_init() acts just like ldap_open(), but does not open a connection to the LDAP server. the actual connection open will occur when the first operation is attempted. she's "I'll get ready when we actually have plans." π
π ldap_initialize() β the upgrade π
ldap_initialize() acts like ldap_init(), but it returns an integer indicating either success or the failure reason, and it lets you specify details for the connection in the schema portion of the URI. huge.
the uri parameter may be a comma- or whitespace-separated list of URIs containing only the schema, the host, and the port fields. apart from ldap, the other (non-standard) recognized values of the schema field are:
ldapsβ LDAP over TLS πldapiβ LDAP over IPC πcldapβ connectionless LDAP π‘
β οΈ if other fields are present, the behavior is undefined. like, we don't know her. we've never met her. π
at this time, ldap_open() and ldap_init() are deprecated in favor of ldap_initialize(), essentially because the latter lets you specify a schema in the URI and it explicitly returns an error code. it's giving "your fave could never." π
π«Ά ldap_connect() β the introvert's bestie π«Ά
ldap_connect() causes a handle created by ldap_initialize() to connect to the server. this is useful in situations where a file descriptor is required before a request is performed. sometimes you just need the fd first, y'know? π
π§ ldap_init_fd() β bring-your-own-connection π§
ldap_init_fd() allows an LDAP structure to be initialized using an already-opened connection. the proto parameter should be one of:
LDAP_PROTO_TCPβ for a connection using TCPLDAP_PROTO_UDPβ for a connection using UDPLDAP_PROTO_IPCβ for a connection using IPC
the value LDAP_PROTO_EXT may also be specified if user-supplied sockbuf handlers are going to be used. note that support for UDP is not implemented unless libldap was built with LDAP_CONNECTIONLESS defined. so don't come for her about UDP unless you compiled her that way. π
the uri parameter may optionally be provided for informational purposes. purely vibes. β¨
β ldap_set_urllist_proc() β the list-manipulator β
ldap_set_urllist_proc() allows you to set a function proc of type LDAP_URLLIST_PROC that is called when a successful connection can be established. this function receives the list of URIs parsed from the uri string originally passed to ldap_initialize(), and the one that successfully connected.
the function may manipulate the URI list β the typical use consists in moving the successful URI to the head of the list, so that subsequent attempts to connect to one of the URIs using the same LDAP handle will try it first. she ate and left no crumbs. π₯
- if
ldis null,procis set as a global parameter that is inherited by all handlers within the process that are created after the call toldap_set_urllist_proc(). π - by default, no
LDAP_URLLIST_PROCis set. π - in a multithreaded environment,
ldap_set_urllist_proc()must be called before any concurrent operation using the LDAP handle is started. don't be messy about it. π
π’ NOTE: the first call into the LDAP library also initializes the global options for the library. as such, the first call should be single-threaded or otherwise protected to insure that only one call is active. it is recommended thatldap_get_option()orldap_set_option()be used in the program's main thread before any additional threads are created. seeldap_get_option(3). this is the "one at a time, ladies" rule and she is not joking. π
π ERRORS π
if an error occurs, ldap_open() and ldap_init() will return NULL and errno should be set appropriately.
ldap_initialize() and ldap_init_fd() will directly return the LDAP code associated to the error (or LDAP_SUCCESS in case of success); errno should be set as well whenever appropriate.
ldap_set_urllist_proc() returns LDAP_OPT_ERROR on error, and LDAP_OPT_SUCCESS on success.
so like, three different error-reporting personalities in one manpage. they contain multitudes. π¦
πΈ SEE ALSO πΈ
go read them, iykyk. ππ
π ACKNOWLEDGEMENTS π
OpenLDAP Software is developed and maintained by The OpenLDAP Project <http://www.openldap.org/>. OpenLDAP Software is derived from the University of Michigan LDAP 3.3 Release. shoutout the ancestors, fr fr. π«Άπ
and that's the whole page, bestie β OpenLDAP 2.6.16, dated 2026/10/21, LDAP_OPEN(3) forever. now go open a connection, slay, and remember: handle first, operations second. π
β¨π
π¦ where this page comes from
- fedora 44: openldap-devel 2.6.16-1.fc44 Β· OLDAP-2.8
- fedora 44: openldap-devel 2.6.16-1.fc44 Β· OLDAP-2.8
- Copyright 1998-2026 The OpenLDAP Foundation All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms