I am trying to run this code:

(...)
 char *baseDN= "o=myorg";
 char *filter = "(cn=*)";
 ld = ldap_init(LDAP_HOSTNAME, LDAP_PORT);
 if (ld != NULL){
  rc = ldap_search_ext_s(ld, baseDN, LDAP_SCOPE_SUBTREE,
   filter, NULL, FALSE, NULL, NULL,LDAP_NO_LIMIT, LDAP_NO_LIMIT,
   &res);
  if (rc == LDAP_SUCCESS){
   int n = ldap_count_entries(ld, res);
   printf("N. entries: %d\n", n);
   n = ldap_count_messages(ld, res);
   printf("N messages: %d\n", n);
   if (n >= 1){
    e = ldap_first_message(ld, res);
    if (e != NULL){
     msgtype = ldap_msgtype(e);
     switch(msgtype){
      case LDAP_RES_SEARCH_ENTRY:
       printf("Is an entry\n");
       break;
      case LDAP_RES_SEARCH_REFERENCE:
       printf("Is a referral\n");
       break;
      case LDAP_RES_SEARCH_RESULT:
       parse_rc = ldap_parse_result(ld, e, &rc,
        &matched_msg, &error_msg, NULL,
        &serverCtrls, 0);
       printf("ldap_parse_result: %s\n", ldap_err2string(rc));
       printf("ldap_parse_result: %s\n", ldap_err2string(parse_rc));
       printf("Error: %s\n", error_msg);
       printf("Matched DN: %s\n", matched_msg);
       if (error_msg != NULL & *error_msg != '\0'){
        printf("%s\n", error_msg);
       }
       if (matched_msg != NULL && *matched_msg != '\0') {
        printf("Parte de DN que concuerda: %s\n", matched_msg);
       }
       break;
     }
(...)

It seems to be ok, but I always get a LDAP_RESULT message instead of the
entries of my tree....
And when I try to find out the information, I always receive "Success!"

Could somebody give me some guideline to solve this problem?

Thank you

Gregorio Pati�o
e-mail: [EMAIL PROTECTED]





Reply via email to