LDAP search with winldap.h on AD server

I am trying to do an LDAP search and it does not work on my test Active Directory server. I am using this code:

#include <winldap.h> ... LDAP* ld = ldap_init("AD-servername", 389); int myVersion =LDAP_VERSION3; ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &myVersion); ldap_connect(ld, NULL); //ldap_simple_bind_s(ld, NULL, NULL); I tried using this line too. but got the same error LDAPMessage *pMsg = NULL; int retVal = ldap_search_s(ld, "dc=myDomain,dc=extension", LDAP_SCOPE_SUBTREE, "(samAccountName=testaccount)", NULL, NULL, &pMsg); //retVal = 1 which is LDAP_OPERATIONS_ERROR 

What am I doing wrong?

+2
source share
1 answer

Unless otherwise specified, you must communicate using a valid account name and password for Microsoft Active Directory servers, otherwise it will return an operation error for all requests except a very small number .

i.e. what:

 ldap_simple_bind_s(ld, NULL, NULL); 

It needs to be replaced with something like:

 char *username = "cn=aUser,ou=Users,dc=myDomain,dc=extension"; char *password = "this is the password"; ldap_simple_bind_s(ld, username, password); 
+3
source

Source: https://habr.com/ru/post/1445425/


All Articles