J
Jagadishwer
Hi Friends,
I am having some problems with the search operation using ldap.
From my box which is not in an activedirectory domain, I am trying to
connect to Active directory using LDAP api.
Here is the code. The same code works some times and gives
Operations error at some other time.
int version1 = LDAP_VERSION3;
ldap_set_option( NULL, LDAP_OPT_PROTOCOL_VERSION, &version1);
LDAP* pLdapConnection = NULL;
pLdapConnection = ldap_open(Server, LDAP_PORT); // this was SUCCESSed
if (pLdapConnection == NULL)
{
printf("ldap_init failed with 0x%x.\n",LdapGetLastError());
ldap_unbind(pLdapConnection);
return -1;
}
else
printf("ldap_init succeeded \n");
ULONG numReturns = 10;
ULONG lRtn = 0;
PCHAR pMyDN = "DC=netkey,DC=com";
lRtn = ldap_simple_bind_s(pLdapConnection, domainname,passwd);
if(lRtn == LDAP_SUCCESS)
printf("ldap_bind_s succeeded \n");
else
{
printf("LDAP Error Msg : %s\n", ldap_err2string(lRtn));
ldap_unbind(pLdapConnection);
return -1;
}
ULONG errorCode = LDAP_SUCCESS;
LDAPMessage* pSearchResult;
char pMyFilter[256] = "(cn1=jhalovatch)";
errorCode = ldap_search_s (
pLdapConnection , "DC=netkey,DC=com",LDAP_SCOPE_SUBTREE, pMyFilter,
NULL,0, &pSearchResult);
errorCode is returning 1 which is Operations Error. This is not
happening always. The same code gives me the deatils of the user and
again after some time gives error 1 which is Operations error.
Please someone tell me what I am doing wrong.
I am using ldap_open and not ladp_init. does this matters.
I am new to this LDAP programming. Please someone help me.
Thanks in advance for the help.
Thanks,
Jagadish.
I am having some problems with the search operation using ldap.
From my box which is not in an activedirectory domain, I am trying to
connect to Active directory using LDAP api.
Here is the code. The same code works some times and gives
Operations error at some other time.
int version1 = LDAP_VERSION3;
ldap_set_option( NULL, LDAP_OPT_PROTOCOL_VERSION, &version1);
LDAP* pLdapConnection = NULL;
pLdapConnection = ldap_open(Server, LDAP_PORT); // this was SUCCESSed
if (pLdapConnection == NULL)
{
printf("ldap_init failed with 0x%x.\n",LdapGetLastError());
ldap_unbind(pLdapConnection);
return -1;
}
else
printf("ldap_init succeeded \n");
ULONG numReturns = 10;
ULONG lRtn = 0;
PCHAR pMyDN = "DC=netkey,DC=com";
lRtn = ldap_simple_bind_s(pLdapConnection, domainname,passwd);
if(lRtn == LDAP_SUCCESS)
printf("ldap_bind_s succeeded \n");
else
{
printf("LDAP Error Msg : %s\n", ldap_err2string(lRtn));
ldap_unbind(pLdapConnection);
return -1;
}
ULONG errorCode = LDAP_SUCCESS;
LDAPMessage* pSearchResult;
char pMyFilter[256] = "(cn1=jhalovatch)";
errorCode = ldap_search_s (
pLdapConnection , "DC=netkey,DC=com",LDAP_SCOPE_SUBTREE, pMyFilter,
NULL,0, &pSearchResult);
errorCode is returning 1 which is Operations Error. This is not
happening always. The same code gives me the deatils of the user and
again after some time gives error 1 which is Operations error.
Please someone tell me what I am doing wrong.
I am using ldap_open and not ladp_init. does this matters.
I am new to this LDAP programming. Please someone help me.
Thanks in advance for the help.
Thanks,
Jagadish.