How do I search for an object in LDAP based on its dn, in python-ldap?

淺唱寂寞╮ 提交于 2020-01-23 01:27:29

问题


I am trying to use e.g. the search_s function to search for an object based on its full distinguished name, but am not finding this to be convenient. For example,

search_s('DC=example, DC=com', ldap.SCOPE_SUBTREE,
    '(CN=Somebody, OU=Department, DC=example, DC=com)')

How do I just retrieve one object based on its full LDAP distinguished name?


回答1:


Use SCOPE_BASE and a wildcard filter to return only the dn given by the first argument (the filter still has to match that object!) For example,

import ldap
...
ldap_connection.search_s('CN=Somebody, OU=Department, DC=example, DC=com',
    ldap.SCOPE_BASE,
    '(objectClass=*)')


来源:https://stackoverflow.com/questions/4729539/how-do-i-search-for-an-object-in-ldap-based-on-its-dn-in-python-ldap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!