How to search an object in LDAP based on its dn, in python-ldap?

I am trying to use, for example. search_s to search for an object based on its full distinguished name, but I don't find it convenient. For instance,

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

How to simply get a single object based on its full LDAP name?

+4
source share
1 answer

Use SCOPE_BASE and a wildcard filter to return only the dn specified by the first argument (the filter should still match this object!) For example,

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

Source: https://habr.com/ru/post/1336059/


All Articles