5

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

Jeremiah
  • 751
  • 9
  • 21

4 Answers4

2

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>
}
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
1

It leads to some compiling errors in current version, since in the ldap.h use #if LDAP_DEPRECATED instead of #ifdef, give the MACRO a value:

#define LDAP_DEPRECATED 1

And it is good to go.

Toribio
  • 3,963
  • 3
  • 34
  • 48
Jeff
  • 11
  • 1
1

Dont use ldap_bind. Its deprecated. Rather use ldap_sasl_bind.
ldap.h has deprecated a lot of functions for mostly security reasons

Check out the following command which lists all the deprecated functions

grep deprecate < /usr/include/ldap.h
Kaunteya
  • 3,107
  • 1
  • 35
  • 66
0

On *nix systems, or any system that let's you specify compilation flags, you can add the following to your list of flags:

-DLDAP_DEPRECATED  

This allows you to use the deprecated deprecated features without having to add defines to the top of all of your source/header files.

Dodzi Dzakuma
  • 1,406
  • 2
  • 21
  • 39