Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get LDAP lookup to skip aliases

Status
Not open for further replies.

jamescpp

IS-IT--Management
Aug 29, 2001
70
US
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);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top