azmeuk
azmeuk

Reputation: 4506

How to retrieve every objectClass available with python-ldap?

Given a valid python-ldap context, how can I query all the objectClass available in the LDAP server? I suppose the result would be a list of ldap.schema.models.ObjectClass.

Upvotes: 0

Views: 1118

Answers (1)

azmeuk
azmeuk

Reputation: 4506

I finally managed to do it with:

import ldap

l = ldap.initialize(ldap_uri)
l.simple_bind_s(ldap_bind_dn, ldap_bind_pw)
res = l.search_s("cn=subschema", ldap.SCOPE_BASE, "(objectclass=*)", ["*", "+"])
subschema_entry = res[0]
subschema_subentry = ldap.cidict.cidict(subschema_entry[1])
subschema = ldap.schema.SubSchema(subschema_subentry)
object_class_oids = subschema.listall(ldap.schema.models.ObjectClass)
object_classes = [
    subschema.get_obj(ldap.schema.models.ObjectClass, oid) for oid in object_class_oids
]

Upvotes: 1

Related Questions