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

Connecting to Active DIrectory using ldap-c api



Hi,

I am trying to perform a query on active directory with the following code -

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <winldap.h>

#define BASEDN "DC=shalom,DC=com"
#define SCOPE LDAP_SCOPE_SUBTREE
#define FILTER "(sn=Eyal)"

int main(int argc, char** argv)
{
	LDAP*	ldap_con;
	char	*dn;
	int		rc, version;
	LDAPMessage	*result, *e;

	version = LDAP_VERSION3;
	
	ldap_con=ldap_init("shalom",389);
	if(ldap_con==NULL)
	{
		printf("ldap_init error - %u\n",LdapGetLastError());
	}
	else
	{
		printf("ldap_init succeded\n");
	}

	if(ldap_simple_bind_s(ldap_con,NULL,NULL)==-1)
	{
		printf("ldap_simple_bind error - %u\n",LdapGetLastError());
	}
	else
	{
		printf("ldap_simple_bind succeded\n");
	}

	rc = ldap_search_ext_s( ldap_con, BASEDN, SCOPE, FILTER, NULL, 0,
NULL, NULL, NULL, 0, &result );

	if ( rc != LDAP_SUCCESS ) 
	{
		printf("ldap_search_ext_s: %s\n", ldap_err2string(rc));
		return( 1 );
	}

	for ( e = ldap_first_entry( ldap_con, result ); e != NULL; e =
ldap_next_entry( ldap_con, e ) ) 
	{
		if ( (dn = ldap_get_dn( ldap_con, e )) != NULL )
		{
			printf( "dn: %s\n", dn );
			ldap_memfree( dn );
		}
	}

	ldap_msgfree( result );
	ldap_unbind( ldap_con );

	return (1);
}

I keep getting "ldap_search_ext_s: Unavailable"

What am i doing wrong ?

Any help/suggestion will be appreciated

Thanks,