我的 LDAP 查询返回零结果,即使我可以看到属性 DistinguishedName 包含查询中的字符串
My LDAP query is returning zero results even though I can see that the attribute DistinguishedName contains the string in the query
我有一个非常简单的查询:(distinguishedName=*Inactive*)
返回零结果,但我确实看到字符串 "Inactive" 包含在 AD 的某些对象中。
我想要做的是能够在那些用户 OU 中进行搜索,但排除该非活动 OU 内的用户 OU。执行之前的查询是(我认为)我的问题的答案,但我没有得到任何结果,
提前感谢您的帮助。
通常你不能为distinguishedName
做子串匹配规则
如 this thread 中所述。
此外,许多 LDAP 服务器实现支持 ExtensibleMatch 但是,
Microsoft Active Directory 不支持此功能,仅支持:Microsoft Active Directory Extensible Match Rules
经过大量研究,我发现了这个:
我可以按 LDAP 属性过滤 userAccountControl...
根据 Microsoft 支持人员的解释:
This attribute is composed of a combination of different
flags. The flag for setting the object that you want to disable is
UF_ACCOUNTDISABLE, which has a value of 0x02 (2 decimal). The bitwise
comparison filter that specifies userAccountControl with the
UF_ACCOUNTDISABLED bit set would resemble this:
(!(UserAccountControl:1.2.840.113556.1.4.803:=2))
您可能会问自己,那个数字是多少,它们的含义是什么?
答案如下:
和标志选项:
https://blogs.technet.microsoft.com/mempson/2011/08/24/useraccountcontrol-flags/
Active Directory 不允许您在 distinguishedName
上搜索部分匹配项。如果查询中有distinguishedName
,则只能是完全匹配。
如果您只想搜索特定的 OU,您需要:
- 通过将
SearchRoot
to the OU rather than the domain. You can also set the SearchScope
设置为 SearchScope.OneLevel
来搜索单个 OU,如果需要则不搜索子 OU。对要包括的每个 OU 重复搜索。
- 用你想要的结果搜索最顶层的 OU,遍历结果,并通过查看
distinguishedName
丢弃非活动 OU 中的那些(因为此时你已经有了结果, distinguishedName
只是一个字符串,您可以随意使用它,包括部分匹配)。
我推荐#2,因为它意味着针对 AD 进行一次搜索而不是多次搜索。会更快。
是的,您可以使用 userAccountControl
作为过滤器来排除禁用的帐户,但这取决于您是否可以排除可能不在非活动 OU 中的禁用帐户,或包括启用的帐户可能已在非活动 OU 中结束。
我有一个非常简单的查询:(distinguishedName=*Inactive*)
返回零结果,但我确实看到字符串 "Inactive" 包含在 AD 的某些对象中。
我想要做的是能够在那些用户 OU 中进行搜索,但排除该非活动 OU 内的用户 OU。执行之前的查询是(我认为)我的问题的答案,但我没有得到任何结果,
提前感谢您的帮助。
通常你不能为distinguishedName
做子串匹配规则如 this thread 中所述。
此外,许多 LDAP 服务器实现支持 ExtensibleMatch 但是, Microsoft Active Directory 不支持此功能,仅支持:Microsoft Active Directory Extensible Match Rules
经过大量研究,我发现了这个:
我可以按 LDAP 属性过滤 userAccountControl...
根据 Microsoft 支持人员的解释:
This attribute is composed of a combination of different flags. The flag for setting the object that you want to disable is UF_ACCOUNTDISABLE, which has a value of 0x02 (2 decimal). The bitwise comparison filter that specifies userAccountControl with the UF_ACCOUNTDISABLED bit set would resemble this:
(!(UserAccountControl:1.2.840.113556.1.4.803:=2))
您可能会问自己,那个数字是多少,它们的含义是什么?
答案如下:
和标志选项: https://blogs.technet.microsoft.com/mempson/2011/08/24/useraccountcontrol-flags/
Active Directory 不允许您在 distinguishedName
上搜索部分匹配项。如果查询中有distinguishedName
,则只能是完全匹配。
如果您只想搜索特定的 OU,您需要:
- 通过将
SearchRoot
to the OU rather than the domain. You can also set theSearchScope
设置为SearchScope.OneLevel
来搜索单个 OU,如果需要则不搜索子 OU。对要包括的每个 OU 重复搜索。 - 用你想要的结果搜索最顶层的 OU,遍历结果,并通过查看
distinguishedName
丢弃非活动 OU 中的那些(因为此时你已经有了结果,distinguishedName
只是一个字符串,您可以随意使用它,包括部分匹配)。
我推荐#2,因为它意味着针对 AD 进行一次搜索而不是多次搜索。会更快。
是的,您可以使用 userAccountControl
作为过滤器来排除禁用的帐户,但这取决于您是否可以排除可能不在非活动 OU 中的禁用帐户,或包括启用的帐户可能已在非活动 OU 中结束。