gpt4 book ai didi

python - 如何在 ldap3 中读取给定 DN 的属性(如果没有过滤器,如何使用 ldap3 进行搜索)

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:25 25 4
gpt4 key购买 nike

如果我已经有一个 LDAP DN,我如何使用 ldap3.Connection.search() 获取该 DN 的属性?没有其他搜索条件,我已经有了 DN...

我尝试搜索 dn 属性,但未找到任何对象。我还尝试将 search_filter 强制为 '''()'None,它们都返回格式错误的过滤器字符串.

我也找不到用抽象阅读器来做到这一点的方法......

ldapsearch 中,如果您正在执行 baseDN 查找,则无需指定搜索过滤器...

import ldap3

ldap_conn = ldap3.Connection('ldapserver', raise_exceptions=True,
auto_bind=True, user='me', password='mypassword')

my_dn = "attrib1=blahblah, ou=org1, dc=dc1, dc=dcroot"

ldap_conn.search(
search_base=my_dn,
search_filter= '(????)', # required
search_scope=ldap3.BASE,
attributes='*'
)

print(ldap_conn.response)

最佳答案

我刚刚意识到 objectClass 将始终存在,因此将其设置为通配符应该填充 search_filter 以返回与基本 DN 关联的 1 个条目:

ldap_conn.search(
search_base=my_dn,
search_filter= '(objectClass=*)', # required
search_scope=ldap3.BASE,
attributes='*'
)

然而,在 ldap3 中没有针对给定 DN 的连接的 LOOKUP 操作的特殊情况似乎很愚蠢。

编辑:@cannatag 提到这是协议(protocol)的限制,所以我决定检查 RFC:(RFC 4511) .显然,ldapsearch 和 Active Directory 通过设置 objectClass 存在过滤器来模拟 x.500 样式的 LIST 或 READ:

Note that an X.500 "list"-like operation can be emulated by theclient requesting a singleLevel Search operation with a filterchecking for the presence of the 'objectClass' attribute, and that anX.500 "read"-like operation can be emulated by a baseObject Searchoperation with the same filter. A server that provides a gateway toX.500 is not required to use the Read or List operations, although itmay choose to do so, and if it does, it must provide the samesemantics as the X.500 Search operation.

关于python - 如何在 ldap3 中读取给定 DN 的属性(如果没有过滤器,如何使用 ldap3 进行搜索),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47665285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com