pythonldappython-ldap

How to get the list of possible operational attributes for an objectClass with python-ldap?


With this python snippet, I can get the list of all the available objectClasses in a LDAP server:

import ldap

conn = ldap.initialize("ldap://127.0.0.1:389")
conn.simple_bind_s("cn=admin,dc=mydomain,dc=tld", "mypassword")
res = conn.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]

From this point this is easy to get all the required and optional attributes with object_class.may and object_class.must, but how can I get the list of the operational attributes applicable on a given objectClass? For instance the memberof attribute brought by the memberof OpenLDAP overlay, or the pwdAccountLockedTime attribute brought by the ppolicy overlay.


Solution

  • Operational attributes are maintained by the LDAP server. They are not "applicable on a given objectClass". Thus they must not be set by user applications and they are not referenced in object class descriptions.

    You can look at the instance attribute AttributeType.usage which contains an Integer indicating its usage.

    See also: