Get a thread-safe handle to an LDAP connection.
#include "slapi-plugin.h"
LDAP *slapi_ldap_init(char *ldaphost, int ldapport, int secure,
    int shared);
This function takes the following parameters:
Host on which the LDAP server is running
Port on which the LDAP server is listening
1 for a secure connection over SSL, NULL otherwise
If not NULL, then the connection may be shared between threads
This function allows a plug-in to retrieve a thread-safe handle to an LDAP connection. When done with the handle, call slapi_ldap_unbind().
A timeout may be set for the connection using the Directory SDK for C provided as part of Directory Server Resource Kit. Example 16–1 demonstrates how to set a timeout.
#include "slapi-plugin.h"
#include "ldap.h"
void
my_ldap_function(void)
{
    LDAP * ld;
    int    to = 5000;                  /* 5000 ms == 5 s timeout */
    if ((ld = slapi_ldap_init(host, port, 0, 1)) == NULL) {
        /* error trying to create an LDAP session */
        return -1;
    }
    if (ldap_set_option(ld, LDAP_X_OPT_CONNECT_TIMEOUT, &to) != 0) {
        /* error setting timeout                                 */
        slapi_ldap_unbind(ld);
        return -1;
    }
    /* Use the handle for a search for example.                  */
    slapi_ldap_unbind(ld);
    return 0;
}
This function returns an LDAP connection handle if successful. Otherwise, it returns NULL.