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

Re: ldap_search_s fails?




On Wed, 4 Aug 2004, Jason Gerfen wrote:

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

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

  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");
      ldap_perror(ld,"ldap_search_s");
  }

  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

Remove \" and it will work. (Your code above looks correct)

and application termination errors.

As it should because "(CN=%s)" ( ldapserch '"(CN=blah)"' ) is a bad filter.


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?



-- Igor