Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ using ldap_bind from ldap.h

Tags:

c++

ldap

openldap

I'm trying to use ldap_bind, but get an this error.

error: âldap_bindâ was not declared in this scope

code:

#include <lber.h>
#include <ldap.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
    LDAP *ld;

    char *ldap_host = "ldap://localhost";
    int ldap_port   = 389;
    int auth_method = LDAP_AUTH_SIMPLE;
    int desired_version = LDAP_VERSION3;
    char *root_dn   = "ou=people,dc=localhost,dc=local";
    char *root_ps   = "password";

    int result;

    result = ldap_initialize(&ld, ldap_host);

    cout << "result: " << result << endl;

    result = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &desired_version);

    cout << "result: " << result << endl;

    result = ldap_bind_s(ld, root_dn, root_ps, auth_method);

    cout << "result: " << result << endl;
}

I'm compiling with this command

g++ ldap.cpp -llber -lldap -o prog

TIA

like image 417
Jeremiah Avatar asked Oct 11 '22 13:10

Jeremiah


1 Answers

I've no experience with OpenLDAP, but from the header it seems you need:

extern "C" {
# define LDAP_DEPRECATED
# include <ldap.h>
# include <lber.h>
}
like image 165
Fred Foo Avatar answered Oct 18 '22 01:10

Fred Foo