Anyone familar with using LDAP in a c program? I have a program that looks up the CN. The problem I'm having is that sometimes the program is finding aliases instead of the actual object itself.
I've seen references to LDAP_ALIAS_PROBLEM, and LDAP_ALIAS_DEREF_PROBLEM, but I can't find any examples on how to use them, or if they are what I need.
Is there any way for the code to skip aliases? I've included some of the code below. Please provide example code if you can.
Thanks,
James
ld = ldap_init(MY_HOST, MY_PORT);
/* get a handle to an LDAP connection */
if (ld == NULL)
return;
//else
//fprintf (fp,"Got handle to LDAP Connection.\n"
/*
* Authenticate to the directory to do the search.
*/
if ( ldap_simple_bind_s( ld, NULL, NULL ) != LDAP_SUCCESS)
return;
//else
//fprintf (fp,"Bind to LDAP successful.\n"
sprintf(search, "%s", MY_PEOPLEBASE);
sprintf(filter, "(cn=%s)", user);
if (ldap_search_s(ld, search, LDAP_SCOPE_SUBTREE,
filter, NULL, 0, &result) != LDAP_SUCCESS)
return;
//else
//fprintf (fp,"LDAP Search Successful.\n"
/*
* Run through the attributes of each entry looking for a match.
*/
valid = FALSE;
found = FALSE;
email = NULL;
for (e = ldap_first_entry(ld, result); e != NULL; e = ldap_next_entry(ld, e))
{
found = TRUE;
dn = ldap_get_dn(ld, e);
if (dn == NULL)
{
continue;
}
//if ((dn[0] == '\0') || (password[0] == '\0')) //original line
if ((dn[0] == '\0') || (password == NULL) || (password[0] == '\0'))
{
continue;
}
if (ldap_simple_bind_s(ld, dn, password) != LDAP_SUCCESS)
{
continue;
}
valid = TRUE;
}
ldap_unbind(ld);
I've seen references to LDAP_ALIAS_PROBLEM, and LDAP_ALIAS_DEREF_PROBLEM, but I can't find any examples on how to use them, or if they are what I need.
Is there any way for the code to skip aliases? I've included some of the code below. Please provide example code if you can.
Thanks,
James
ld = ldap_init(MY_HOST, MY_PORT);
/* get a handle to an LDAP connection */
if (ld == NULL)
return;
//else
//fprintf (fp,"Got handle to LDAP Connection.\n"
/*
* Authenticate to the directory to do the search.
*/
if ( ldap_simple_bind_s( ld, NULL, NULL ) != LDAP_SUCCESS)
return;
//else
//fprintf (fp,"Bind to LDAP successful.\n"
sprintf(search, "%s", MY_PEOPLEBASE);
sprintf(filter, "(cn=%s)", user);
if (ldap_search_s(ld, search, LDAP_SCOPE_SUBTREE,
filter, NULL, 0, &result) != LDAP_SUCCESS)
return;
//else
//fprintf (fp,"LDAP Search Successful.\n"
/*
* Run through the attributes of each entry looking for a match.
*/
valid = FALSE;
found = FALSE;
email = NULL;
for (e = ldap_first_entry(ld, result); e != NULL; e = ldap_next_entry(ld, e))
{
found = TRUE;
dn = ldap_get_dn(ld, e);
if (dn == NULL)
{
continue;
}
//if ((dn[0] == '\0') || (password[0] == '\0')) //original line
if ((dn[0] == '\0') || (password == NULL) || (password[0] == '\0'))
{
continue;
}
if (ldap_simple_bind_s(ld, dn, password) != LDAP_SUCCESS)
{
continue;
}
valid = TRUE;
}
ldap_unbind(ld);