Search code examples
active-directorywindows-server-2012openldap

Ldap Search on the host server


I developed a small C++ application to bind a user in a server using active directory then return the name of his group. The probleme is when I run the application from a remote computer, it run with no probleme. When I try to run it at the host server, -the computer hosting the active directory- the binding process pass, but the searching function always return Operation error: this is a sample of my code.

 if ((rc = ldap_simple_bind_s( ld, loginDN, password )) != LDAP_SUCCESS )
{
    printf("ldap_simple_bind_s: %s\n", ldap_err2string( rc ));
    ldap_unbind_s( ld );
    return 10;
}
printf("Bind and authentication to the server successful\n");

string a="(&(objectclass=person)(cn="+prenom+" "+nom+"))";
rc = ldap_search_ext_s(
            ld,                    /* LDAP session handle */
            searchBase,            /* container to search */
            LDAP_SCOPE_ONELEVEL,   /* search scope */
            a.c_str(),             /*search filter*/
            NULL,                  /* return all attributes */
            0,                     /* return attributes and values */
            NULL,                  /* server controls */
            NULL,                  /* client controls */
            &timeOut,              /* search timeout */
            LDAP_NO_LIMIT,         /* no size limit */
            &searchResult );       /* returned results */
if ( rc != LDAP_SUCCESS )
{
    cout<<rc<<endl;
    printf("ldap_search_ext_s: %s\n", ldap_err2string( rc ));
    ldap_msgfree( searchResult );
    ldap_unbind_s( ld );
    return  20 ;
}

Solution

  • I found the answer I must use the port 3268 instead of 389