ldap linux 客户端工具,Linux C++利用openldap实现ldap客户端

1.编译

由于我们不需要服务端,屏蔽掉服务端的编译,可以跳过很多依赖。

./configure --prefix=/opt/openldap --enable-slapd=no --enable-backends=no --enable-overlays=no

后面就是按照INSTALL上的来:

make depend

make

make test

make install

大功告成,只需要取include目录和lib目录下的libldap-2.4.so.2.10.3、liblber-2.4.so.2.10.3

2.核心调用

//初始化

ldap_initialize(&m_ldap, m_strURL.c_str());

//设置3代协议

ldap_set_option(m_ldap, LDAP_OPT_PROTOCOL_VERSION, (const void*) &m_nProtocolVer);

//设置超时时间

timeval time;

time.tv_sec = m_lTimeoutSeconds;

time.tv_usec = 0;

nRet = ldap_set_option(m_ldap, LDAP_OPT_NETWORK_TIMEOUT, (const void*) &time);

//登录

berval cred;

cred.bv_val = new char[strEncPassword.size() + 1];

if(cred.bv_val == NULL)

break;

strncpy(cred.bv_val,strEncPassword.c_str(),strEncPassword.size());

cred.bv_len = strEncPassword.size();

nRet = ldap_sasl_bind_s(m_ldap, szUserName,

strAuthMethod.size() > 0 ?strAuthMethod.c_str() : LDAP_SASL_SIMPLE,

&cred,NULL,NULL,NULL

);

delete cred.bv_val;

//登出

ldap_unbind_ext_s(m_ldap,NULL,NULL);

3.Makefile

LDLIBS += -Llib \

-lldap \

-llber \

如果使用了过时的函数,就需要CFLAGS += -DLDAP_DEPRECATED=1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值