如果我正在寻找所有组
,我会得到太多垃圾。
如果我试图缩小基础,我得到的就太少了。
这是一个例子:
CN=A Team,OU=Groups,OU=Americas,DC=example,DC=com
CN=B TEAM,OU=Groups,OU=EMEA,DC=example,DC=com
CN=C Team,OU=Legacy Groups,DC=example,DC=com
CN=D Team,OU=Groups,OU=Bangalore,OU=APAC,DC=example,DC=com
CN=E Team,OU=Common Groups,DC=example,DC=com
我正在寻找一个返回 A B D E(没有 C)的 LDAP filter
- 主要逻辑是让我获得所有具有最后一个 OU=Groups
或 OU=公共(public)组
我当前的搜索正在使用:
Search base: CN=Users,DC=citrite,DC=net
Filter: (objectCategory=Group)
最佳答案
首先,在 Microsoft Active Directory 上不可能通过单个搜索来完成此操作,这是因为 AD 不完全兼容 LDAP。
兼容 LDAP 的服务器支持可扩展匹配
过滤器,该过滤器提供必要的
过滤。来自 RFC4511 :
If the dnAttributes field is set to TRUE, the match is additionally applied against all the AttributeValueAssertions in an entry's distinguished name, and it evaluates to TRUE if there is at least one attribute or subtype in the distinguished name for which the filter item evaluates to TRUE. The dnAttributes field is present to alleviate the need for multiple versions of generic matching rules (such as word matching), where one applies to entries and another applies to entries and DN attributes as well.
请注意,可扩展匹配过滤技术仅适用于符合 LDAP 标准的服务器, 其中 AD 不是其中之一。
例如,我将以下条目添加到服务器:
dn: ou=legacy groups,o=training
objectClass: top
objectClass: organizationalUnit
ou: legacy groups
dn: ou=common groups,o=training
objectClass: top
objectClass: organizationalUnit
ou: common groups
dn: ou=groups,o=training
objectClass: top
objectClass: organizationalUnit
ou: groups
dn: cn=a,ou=common groups,o=training
objectClass: top
objectClass: groupOfUniqueNames
uniqueMember: uid=user.0,ou=people,o=training
cn: a
dn: cn=b,ou=groups,o=training
objectClass: top
objectClass: groupOfUniqueNames
uniqueMember: uid=user.0,ou=people,o=training
cn: b
dn: cn=c,ou=legacy groups,o=training
objectClass: top
objectClass: groupOfUniqueNames
uniqueMember: uid=user.0,ou=people,o=training
cn: c
添加上述条目后,检查以下搜索中的过滤器:
ldapsearch --propertiesFilePath ds-setup/11389/ldap-connection.properties \
--baseDN o=training \
--searchScope sub '(|(ou:dn:=groups)(ou:dn:=common groups))' 1.1
dn: ou=common groups,o=training
dn: cn=a,ou=common groups,o=training
dn: ou=groups,o=training
dn: cn=b,ou=groups,o=training
请注意,会返回 ou=common groups
、ou=groups
及其下级,但不会返回
ou=legacy groups
和下属。
此示例使用 ldapsearch 命令行工具的现代语法。如果用户是 利用旧版 OpenLDAP 版本的 ldapsearch,命令行工具的参数是 略有不同,但这并不重要。重要的是过滤器。
关于ldap - 如何进行 LDAP 查询以仅返回所有级别中具有 OU=Groups 的组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10035030/