[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
OpenLDAP API
I apologize for the duplicate message, I forgot to use the subject line.
Hello,
I use Solaris 8 and openldap 2.0.23. The following short program crashes
on the ldap_unbind() call. I tried various different versions of this
program without success. Am I doing something wrong here?
Your help will be greatly appreciated.
-Igor
#include <sys/types.h>
#include <stdlib.h>
#include <lber.h>
#include <ldap.h>
int main() {
int rc;
LDAP *ldi;
struct timeval tv;
LDAPMessage *res = NULL;
LDAPMessage *msg = NULL;
char *dn;
char *server = "ldap://10.1.1.197/";
char *base_dn = "o=pb";
char *filter = "uid=igor";
char *attrs[] = {"dn",NULL};
rc = ldap_initialize(&ldi, server);
if (rc != LDAP_SUCCESS) {
exit (2);
}
rc = ldap_simple_bind_s(ldi, "", "");
if (rc != LDAP_SUCCESS) {
exit (2);
}
// If the ldap server is no longer available at this point
tv.tv_sec = 5;
tv.tv_usec = 0;
rc = ldap_search_st(ldi, base_dn, LDAP_SCOPE_SUBTREE, filter,
(char **) attrs, 0, &tv, &res);
if (rc != LDAP_SUCCESS) {
ldap_get_option(ldi, LDAP_OPT_ERROR_NUMBER, &rc);
printf("ldap_search_st() error %s\n", ldap_err2string(rc));
ldap_msgfree(res);
ldap_unbind(ldi);
// ldap_unbind will cause a dump here
exit(2);
}
msg = ldap_first_entry(ldi, res);
dn = ldap_get_dn(ldi, msg);
printf("DN: %s\n", dn);
ldap_msgfree(msg);
free(dn);
ldap_unbind_s(ldi);
exit (1);
}