Pergunta

I am using python3-ldap which connects to an LDAP just fine. However, I'm not sure and can't find any documentation to list all the root DNs.

Is there a command on the Server or Connection or anywhere that will let me list the DNs?

Foi útil?

Solução

You must perform a search using an empty value for the base and then specifying in the filter the class of objects you want get back (or * if you want all). You should use a single level scope to get only the first-level object in the ldap tree.

For example:

from ldap3 import Server, Connection, SEARCH_SCOPE_SINGLE_LEVEL

    s = Server('your_server')
    c = connection(s, user='your_user_dn', password='your_password', auto_bind=True)
    c.search('', '(objectClass=*)', search_scope=SEARCH_SCOPE_SINGLE_LEVEL)
    print(c.response)

you should get all the objects in the first level of the tree, if you want you can specify a filter with the object classes you need:

    c.search('', '(!(objectClass=organization)(objectClass=organizationalUnit))', search_scope=SEARCH_SCOPE_SINGLE_LEVEL)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top