ldap_sasl_bind 函数的示例?
Example for ldap_sasl_bind function?
我一直在寻找如何实现OpenLDAP功能ldap_sasl_bind
,但没有找到。
正在开发的应用程序要求我使用 OpenLDAP 访问 Active Directory。我必须绑定到 AD,我查看过的每个示例程序都使用 ldap_simple_bind
或类似的功能,这些功能已被弃用,因此我无法使用它们。
ldap_sasl_bind
函数有一个用户凭据参数,我必须提供用户名和密码才能进行身份验证。问题是 cred 参数接受指向 struct berval
的指针,我不知道如何实现。
微软文档中berval
的定义如下:
typedef struct berval {
ULONG bv_len;
PCHAR bv_val;
} LDAP_BERVAL, *PLDAP_BERVAL, BERVAL, *PBERVAL, BerValue;
这是 OpenLDAP 中的 ldap_sasl_bind
函数定义:
int ldap_sasl_bind(LDAP *ld, const char *dn, const char
*mechanism, struct berval *cred, LDAPControl *sctrls[],
LDAPControl *cctrls[], int *msgidp);
我可以通过简单地访问 bv_val
并为其赋值来提供用户名,我可以在 bv_len
中提供用户名的长度。但是我该如何提供密码?
BerValue bv_val
应该是指向密码字符串的二进制表示的指针,您不需要在此 berval 中提供用户名,因为函数 ldap_sasl_bind
使用绑定 dn
作为第二个参数传入。
像下面这样的东西应该可以工作(C++):
berval cred;
cred.bv_val = (char*)password.c_str();
cred.bv_len = password.length();
res = ldap_sasl_bind(ld, dn, LDAP_SASL_SIMPLE, cred, sctrls, cctrls, msgidp);
常量 LDAP_SASL_SIMPLE
等价于 ''
或 NULL
.
我一直在寻找如何实现OpenLDAP功能ldap_sasl_bind
,但没有找到。
正在开发的应用程序要求我使用 OpenLDAP 访问 Active Directory。我必须绑定到 AD,我查看过的每个示例程序都使用 ldap_simple_bind
或类似的功能,这些功能已被弃用,因此我无法使用它们。
ldap_sasl_bind
函数有一个用户凭据参数,我必须提供用户名和密码才能进行身份验证。问题是 cred 参数接受指向 struct berval
的指针,我不知道如何实现。
微软文档中berval
的定义如下:
typedef struct berval {
ULONG bv_len;
PCHAR bv_val;
} LDAP_BERVAL, *PLDAP_BERVAL, BERVAL, *PBERVAL, BerValue;
这是 OpenLDAP 中的 ldap_sasl_bind
函数定义:
int ldap_sasl_bind(LDAP *ld, const char *dn, const char
*mechanism, struct berval *cred, LDAPControl *sctrls[],
LDAPControl *cctrls[], int *msgidp);
我可以通过简单地访问 bv_val
并为其赋值来提供用户名,我可以在 bv_len
中提供用户名的长度。但是我该如何提供密码?
BerValue bv_val
应该是指向密码字符串的二进制表示的指针,您不需要在此 berval 中提供用户名,因为函数 ldap_sasl_bind
使用绑定 dn
作为第二个参数传入。
像下面这样的东西应该可以工作(C++):
berval cred;
cred.bv_val = (char*)password.c_str();
cred.bv_len = password.length();
res = ldap_sasl_bind(ld, dn, LDAP_SASL_SIMPLE, cred, sctrls, cctrls, msgidp);
常量 LDAP_SASL_SIMPLE
等价于 ''
或 NULL
.