我正在使用 Python3 ldap3 库来查询我的企业的 LDAP (AD)。
查询组和组成员工作正常,但当我尝试使用可扩展匹配规则“LDAP_MATCHING_RULE_IN_CHAIN”(1.2.840.113556.1.4.1941)进行递归组成员查询时除外。
这样做每次都会出现以下错误:
ldap3.core.exceptions.LDAPAttributeError: invalid attribute ExtensibleMatch:
matchingRule
这是我正在使用的代码:
import ldap3
s = ldap3.Server(host="<ldapServerAddress>", port=636, use_ssl=True, get_info=ldap3.ALL)
c = ldap3.Connection(s, user='<user>', password='<password>', client_strategy="SYNC", read_only=True)
c.bind()
base = '<baseDC>'
# Get "MYGROUP" distinguished name
c.search(search_base=base, search_filter="(sAMAccountName=MYGROUP)", attributes=["distinguishedName"])
dj_son = json.loads(c.response_to_json())
distinguished_name = dj_son["entries"][0]["attributes"]["distinguishedName"]
# Works fine
c.search(base, '(&(objectclass=user)(memberOf={}))'.format(distinguished_name), attributes=["sAMAccountName"])
# Raises an error "LDAPAttributeError: invalid attribute ExtensibleMatch: matchingRule"
c.search(base, '(&(objectclass=user)(memberOf:1.2.840.113556.1.4.1941:={}))'.format(distinguished_name), attributes=["sAMAccountName"])
你们能发现任何错误吗?
感谢您的帮助:-)
终于找到问题根源了:
使用扩展匹配规则
LDAP_MATCHING_RULE_IN_CHAIN
时,LDAP服务器地址必须与搜索库匹配(无子域)。
我实际上是在“subdomain.domain.com”中搜索对象,并且 LDAP 服务器设置为“domain.com”。
要使其发挥作用: