[Date Prev][Date Next] [Chronological] [Thread] [Top]

ldap_search_s fails?

Problem trying to find users in LDAP using the following code...

   printf("Enter ID to search for:\n");

   sprintf(buffer, "(CN=%s)", &unid);
   printf("Searching for: %s\n", buffer);

   if(ldap_search_s(ld, "ou=users,dc=domain,dc=com", LDAP_SCOPE_BASE,
                    buffer, NULL, 0, &res) != LDAP_SUCCESS) {
       printf("Search failed\n");

   printf("Search made\n");

   if(ldap_first_entry(ld, res) == 0) {
       printf("No results found for %s\n", buffer);

I have done the following, verified the user does indeed exist in the default DN to search within', verified the "buffer" var is formated correctly using the sprint() call. If I use "\"(CN=%s)\"", buffer I recieve search filter and application termination errors. but if I remove the var "buffer" and hard code the ID as "(CN=username)" it works fine and returns the results.

Am I missing something?

Jason Gerfen

"...Sometimes I just yell at myself. And it
makes me sad, sometimes I make myself cry..."
			~ My nephew Dawsyn