C++LDAP检查用户是否是特定组的成员
C++ LDAP Checking if a user is a member of a specific group
到目前为止,我已经尝试了一段时间,但没有成功,所以希望有人能帮上忙(我也不远了!(。我只想通过LDAP返回用户是否是特定组的成员。到目前为止,我有以下代码;
int authMethod = LDAP_AUTH_SIMPLE;
LDAP* pLdapConnection = NULL;
ULONG version = LDAP_VERSION3;
ULONG getOptSuccess = 0;
ULONG connectSuccess = 0;
INT returnCode = 0;
int retSearch = 0;
LDAPMessage *res;
int num_entries = 0, num_refs = 0;
pLdapConnection = ldap_init((char*)m_Hostname.GetString(), LDAP_PORT);
returnCode = ldap_set_option(pLdapConnection,
LDAP_OPT_PROTOCOL_VERSION,
(void*)&version);
// Connect to the server.
connectSuccess = ldap_connect(pLdapConnection, NULL);
// Bind
returnCode = ldap_bind_s(pLdapConnection, (char*)m_Username.GetString(), (char*)m_Password.GetString(), authMethod);
// Attempt to search for user
retSearch = ldap_search_s(pLdapConnection, "dc=as,dc=local", LDAP_SCOPE_SUBTREE, "(&(sAMAccountName = examplename))", NULL, NULL, &res);
到目前为止,所有这些都有效,直到搜索部分,例如-我想搜索一个用户";用户名";在组"中;技术";。我试过下面这样的东西;
retSearch = ldap_search_s(pLdapConnection, "dc=as,dc=local", LDAP_SCOPE_SUBTREE, "(&(sAMAccountName=username)(memberof=CN=Technical))",
nullptr, 0, &pSearchResult);
这不会返回任何内容,所以我尝试了更多的搜索,我发现的唯一类似的东西是-LDAPFinding Members of a group PHP,但它在PHP中,到目前为止我似乎无法将其转移到C++。
任何正确方向的帮助都会很有帮助,因为我无法解决。:-(
您的过滤器应该类似于:
(&(objectClass=user)(sAMAccountName=yourUserName)
(memberOf=CN=YourGroup,OU=Users,DC=YourDomain,DC=com))
由于组嵌套而包括成员身份:
(&(objectClass=user)(sAMAccountName=yourUserName)
(memberOf:1.2.840.113556.1.4.1941:=cn=YourGroup,ou=Users,dc=YourDomain,dc=com))
数字1.2.840.113556.1.4.1941
是一个扩展匹配。
相关文章:
- C++LDAP检查用户是否是特定组的成员
- 模板化检查是否存在带有参数列表的类成员函数?
- 成员变量与函数概念检查
- 检查私有成员变量是否在一定范围内,如果没有调整
- 如何检查一个模板是否是另一个模板的类成员
- 从模板检查成员函数重载是否存在
- 检查类型 T 是否具有成员函数 SFINAE 的任何重载
- 是否可以动态检查文本字符串是否是 C++ 中给定类的成员?
- 统一检查成员函数、自由函数和算子是否存在的方式
- 如何检查派生类的可调用成员函数是否存在
- 检查成员函数是否返回临时对象或数组对象
- 如何检查是否调用了成员方法
- C 检查值是否分配给了类的成员
- 如何检查静态成员变量模板?
- C++ - 检查所有成员变量的条件
- 检查成员是否在类中声明
- 使用未来wait_for时无法检查成员变量,但是如果我睡在线程中,它可以工作
- 给定仅包含布尔类型成员的结构的两个对象 s1 和 s2,只要 s1 的成员为 true,请检查 s2 的每个成员是否为真
- 检查类是否在继承层次结构中显式定义了成员类型
- 元编程成员检查器不适用于返回具有基类的类型的函数成员