[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Newbie Question regarding Search API's
Hi,
I tried to write a search program using C pasted in
the end of the mail. What I intended is that I just
pass the IP and read the server DN using the response
message.
Here are the scenarios and result:
i) Tried to connect to AD (Active Directory)using Prog
Search Results:
- Referral is returned when openldap server is not
running on local machine. DOn't Know why?
- Local LDAP servers DN is returned when openldap is
running on local machine. DOn't Know why?
ii) Tried to connect another LDAP Server running
OpenLDAP
Search Result:
- No such Object
Please guide me or show me the path how to move
forward. Why the above behavior is coming and how to
handle the referral or "No such object" to move
forward.
Few things to note in the code:
i) Anonymous Bind
ii) In ldap_search_s, I am passing Base as NULL i.e.
ldap_search_s(ld,NULL,LDAP_SCOPE_SUBTREE,"objectClass=*",NULL,0,&resul)
When I am using the "ldapsearch" command its working
fine. I didn't pass the Base and it shows me the entry
but when I am using the search API's I don't know how
to do it.
CODE SNIPPET:
-----------
protocolVersion= LDAP_VERSION3;
if((result=ldap_set_option(ld,LDAP_OPT_REFERRALS,LDAP_OPT_OFF))==
-1)
{
printf("%s\n",ldap_err2string(result));
return(2);
}
printf("Successfully set referrals\n");
result =
ldap_set_option(ld,LDAP_OPT_PROTOCOL_VERSION,&protocolVersion);
printf("Verison: %d\n",LDAP_VERSION3);
//BIND OPERATION
if((result=ldap_simple_bind_s(ld,NULL,NULL))!=LDAP_SUCCESS)
{
printf("Error in ldap_simple_bind_s:-
%s\n",ldap_err2string(result));
return(2);
}
printf("LDAP Result:- %s\n",ldap_err2string(result));
//Search Through the tree
if((result=ldap_search_s(ld,NULL,LDAP_SCOPE_SUBTREE,"objectClass=*",NULL,0,&resul))!=LDAP_SUCCESS)
{
printf("lDAP Search:- %s\n",ldap_err2string(result));
// result =
ber_printf(ber,"t{V}",LDAP_TAG_REFERRAL,resul);
printf("RESULT AGAIN:-
%d\n",ldap_count_references(ld,resul));
if(result == LDAP_REFERRAL)
{
printf("REferral Returned\n");
}
// return(2);
}
printf("LDAP Search Result:-
%s\n",ldap_err2string(result));
printf("Number of Entries Returned:-
%d\n",ldap_count_entries(ld,resul));
for(entry=ldap_first_entry(ld,resul);entry!=NULL;entry=ldap_next_entry(ld,entry))
THANKS & REGARDS,
BHISHM
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail