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; }