C++使用 ldap.h 中的 ldap_bind
我正在尝试使用 ldap_bind,但出现此错误。
error: âldap_bindâ was not declared in this scope
代码:
#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;
}
我正在使用此命令
g++ ldap.cpp -llber -lldap -o prog
TIA进行编译
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我没有使用 OpenLDAP 的经验,但从标题看来你需要:
I've no experience with OpenLDAP, but from the header it seems you need:
它会导致当前版本中的一些编译错误,因为在
ldap.h
中使用#if LDAP_DEPRECATED
而不是#ifdef
,给 MACRO价值:而且很好走。
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:And it is good to go.
不要使用 ldap_bind。它已被弃用。而是使用
ldap_sasl_bind
。出于安全原因,ldap.h 已弃用了许多函数。
查看以下命令,其中列出了所有已弃用的函数
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
在 *nix 系统或任何允许您指定编译标志的系统上,您可以将以下内容添加到标志列表中:
这允许您使用已弃用的已弃用功能,而无需将定义添加到所有源代码/标头的顶部文件。
On *nix systems, or any system that let's you specify compilation flags, you can add the following to your list of flags:
This allows you to use the deprecated deprecated features without having to add defines to the top of all of your source/header files.