ldap_search_s returns LDAP_OPERATIONS_ERROR
ldap_search_s returns LDAP_OPERATIONS_ERROR
我有带有基本Active Directory的Windows Server 2016,我正在尝试通过WinApi(Wldap32,Winldap.h
(使用C++登录并检查用户组。
身份验证似乎有效,但我在ldap_search_s
(ldap_search_sW
(后得到LDAP_OPERATIONS_ERROR
。
const std::wstring addressStr = L"192.168.78.3";
const std::wstring usernameStr = L"myuser"; // the same as in the filter below
const std::wstring passwordStr = L"";
ULONG version = LDAP_VERSION3;
LDAP *pLdapConnection = ldap_init(const_cast<wchar_t *>(addressStr.c_str()), static_cast<ULONG>(config_.adPort()));
if (pLdapConnection == nullptr) {
throw ...;
}
ULONG ret = ldap_set_option(pLdapConnection, LDAP_OPT_PROTOCOL_VERSION, static_cast<void *>(&version));
if (ret != LDAP_SUCCESS) {
throw ...;
}
ret = ldap_connect(pLdapConnection, nullptr);
if (ret != LDAP_SUCCESS) {
throw ...;
}
ret = ldap_bind_s(pLdapConnection, const_cast<wchar_t *>(usernameStr.c_str()), const_cast<wchar_t *>(passwordStr.c_str()),
LDAP_AUTH_SIMPLE);
if (ret != LDAP_SUCCESS) {
if (ret == 0x31) {
throw ...;
}
throw ...;
}
LDAPMessage *pSearchResult = nullptr;
std::wstring filter = L"(&(sAMAccountName=myuser)(memberof=CN=Administrators))";
std::wstring dn = L"dc=whatever,dc=net";
ret = ldap_search_s(pLdapConnection, const_cast<wchar_t *>(dn.c_str()), LDAP_SCOPE_SUBTREE, const_cast<wchar_t *>(filter.c_str()),
nullptr, 0, &pSearchResult);
// ret == 1 == LDAP_OPERATIONS_ERROR;
这些例子可能会对你有所帮助。
//Example DN
const std::wstring usernameStr = L"uid=user,ou=People,dc=company,dc=com"
//Example UPN
const std::wstring usernameStr = L"user@company.com"
//Example NT-style login
const std::wstring usernameStr = L"COMPANY\user"
这个问题实际上与身份验证有关,而不是与搜索查询有关。
我使用了空密码,ldap_bind_s
没有报告任何错误,因为显然在这种情况下它是匿名绑定的(看起来 MSDN 中没有提到它(https://stackoverflow.com/a/27873735/964478。(这是一个测试虚拟机,我不记得密码,但记得早些时候我尝试为此用户设置空密码,尽管可能没有成功(
相关文章:
- "error: no matching function for call to"构造函数错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- Codecademy - Vectors: Operations
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- C++错误:"error: int aaa::bbb is protected within this context"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- C++ "error: invalid use of void expression"
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- 对象声明中的模板"error: expected expression"
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- OpenCV 3.4.1 error readNetFromTensorflow 无法在 cv::d nn::ReadProtoFromBinaryFile 中打开 .pb
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- 为什么我会"error: expected expression"?
- CMake Error at modules/videoio/cmake/detect_ffmpeg.cmake:16
- Winldap,Qt,ldap_search_ext_s在ldap_sasl_bind_s后返回"Operations Error"