Share via


Establishing an LDAP Session

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

To establish a session with an LDAP server, you first need to create a connection block to the server. If you want to specify an option, such as a time-out value, that affects how you establish the connection, call the ldap_init function to create and initialize the connection block. To create a connection block to an LDAP server using a Secure Sockets Layer (SSL) connection, call the ldap_sslinit function and set the PortNumber parameter to LDAP_SSL_PORT. Then, using the connection handle, call the ldap_set_option function with the appropriate option and value.

When ldap_set_option returns, you can call the ldap_connect function to verify that the server is available. However, if a connection does not already exist, the first call to an operation function that requires an open connection will call ldap_connect internally.

You should specify which LDAP version you are using to access the full functionality of LDAP. You do this when you call ldap_set_option as demonstrated by the following code example.

ULONG version = LDAP_VERSION3;
ldap_set_option(ld, LDAP_OPT_VERSION, &version);

You must call ldap_set_option after calling ldap_init, and before calling ldap_bind.

To take full advantage of LDAP, your client should use LDAP version 3 unless connecting to a server that supports only version 2. Microsoft Active Directory supports LDAP versions 2 and 3.

See Also

Concepts

Using the LDAP API