#include <stdio.h>
#include "ldap.h"
#include <iostream.h>
#include <string.h>
using namespace std;
#define SEARCHBASE "DC=uci,DC=cu"
int main()
{
LDAP *ld;
LDAPMessage *res;
// int numfound;
char *User = "cn=ad search, ou=Systems, ou=UCI Domain Impersonals, dc=uci, dc=cu";
char *Passwd = "uF2SODWAHiW0eJboFFQEAvVzJ";
char *search = "samaccountname=ocampanioni";
// char ** attrib[] = {"uid"}
/* initiate a connection */
if ((ld = ldap_init("10.0.0.3", LDAP_PORT)) == NULL)
exit(1);
/* authenticate as nobody */
if (ldap_simple_bind_s(ld, User, Passwd) != LDAP_SUCCESS) {
ldap_perror(ld, "ldap_simple_bind_s");
exit(1);
}
/* search the database */
if (ldap_search_s(ld, SEARCHBASE, LDAP_SCOPE_SUBTREE,search,NULL,
0, &res) != LDAP_SUCCESS) {
ldap_perror(ld, "ldap_search_s");
exit(1);
}
/* did we get anything ? */
int numfound;
if ((numfound = ldap_count_entries(ld, res)) == -1) {
ldap_perror(ld, "ldap_count_entries");
exit(1);
}
cout<<numfound;
/* close and free connection resources */
ldap_unbind(ld);
return 0;
}
El error que me da es :
ldap_search_s: Operations error (1)
additional info: 00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece
Cualquier ayuda sera provechosa
Saludos orlando