无法使用Python ldap3获取LDAP组的递归用户

问题描述 投票:0回答:1

我正在使用 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 确实支持可扩展匹配规则
  • 该规则未在我的 LDAP 上停用
  • 我正在使用最新版本的ldap3(2.9)

感谢您的帮助:-)

python python-3.x ldap ldap3
1个回答
0
投票

终于找到问题根源了:

使用扩展匹配规则

LDAP_MATCHING_RULE_IN_CHAIN
时,LDAP服务器地址必须与搜索库匹配(无子域)。

我实际上是在“subdomain.domain.com”中搜索对象,并且 LDAP 服务器设置为“domain.com”。

要使其发挥作用:

  • 如果要搜索的对象位于“subdomain.domain.com”中
  • => 将 LDAP 服务器设置为“subdomain.domain.com”
© www.soinside.com 2019 - 2024. All rights reserved.