简体   繁体   English

C ++使用ldap.h中的ldap_bind

[英]C++ using ldap_bind from ldap.h

I'm trying to use ldap_bind, but get an this error. 我正在尝试使用ldap_bind,但是得到了这个错误。

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 TIA

I've no experience with OpenLDAP, but from the header it seems you need: 我没有使用OpenLDAP的经验,但从标题看,您似乎需要:

extern "C" {
# define LDAP_DEPRECATED
# include <ldap.h>
# include <lber.h>
}

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: 它导致当前版本中的一些编译错误,因为在ldap.h使用#if LDAP_DEPRECATED而不是#ifdef ,给MACRO一个值:

#define LDAP_DEPRECATED 1

And it is good to go. 去吧很好。

Dont use ldap_bind. 不要使用ldap_bind。 Its deprecated. 它被弃用了。 Rather use ldap_sasl_bind . 而是使用ldap_sasl_bind
ldap.h has deprecated a lot of functions for mostly security reasons ldap.h主要出于安全原因弃用了许多函数

Check out the following command which lists all the deprecated functions 查看以下命令,其中列出了所有已弃用的函数

grep deprecate < /usr/include/ldap.h

On *nix systems, or any system that let's you specify compilation flags, you can add the following to your list of flags: 在* nix系统或任何允许您指定编译标志的系统上,可以将以下内容添加到标志列表中:

-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. 这允许您使用已弃用的已弃用功能,而无需在所有源/头文件的顶部添加定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM