schema.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import sys,ldap,ldap.schema
  2. schema_attrs = ldap.schema.SCHEMA_ATTRS
  3. ldap.set_option(ldap.OPT_DEBUG_LEVEL,0)
  4. ldap._trace_level = 0
  5. subschemasubentry_dn,schema = ldap.schema.urlfetch(sys.argv[-1])
  6. if subschemasubentry_dn is None:
  7. print 'No sub schema sub entry found!'
  8. sys.exit(1)
  9. if schema.non_unique_oids:
  10. print '*** Schema errors ***'
  11. print 'non-unique OIDs:\n','\r\n'.join(schema.non_unique_oids)
  12. print '*** Schema from',repr(subschemasubentry_dn)
  13. # Display schema
  14. for attr_type,schema_class in ldap.schema.SCHEMA_CLASS_MAPPING.items():
  15. print '*'*20,attr_type,'*'*20
  16. for element_id in schema.listall(schema_class):
  17. se_orig = schema.get_obj(schema_class,element_id)
  18. print attr_type,str(se_orig)
  19. print '*** Testing object class inetOrgPerson ***'
  20. drink = schema.get_obj(ldap.schema.AttributeType,'favouriteDrink')
  21. if not drink is None:
  22. print '*** drink ***'
  23. print 'drink.names',repr(drink.names)
  24. print 'drink.collective',repr(drink.collective)
  25. inetOrgPerson = schema.get_obj(ldap.schema.ObjectClass,'inetOrgPerson')
  26. if not inetOrgPerson is None:
  27. print inetOrgPerson.must,inetOrgPerson.may
  28. print '*** person,organizationalPerson,inetOrgPerson ***'
  29. try:
  30. print schema.attribute_types(
  31. ['person','organizationalPerson','inetOrgPerson']
  32. )
  33. print schema.attribute_types(
  34. ['person','organizationalPerson','inetOrgPerson'],
  35. attr_type_filter = [
  36. ('no_user_mod',[0]),
  37. ('usage',range(2)),
  38. ]
  39. )
  40. except KeyError,e:
  41. print '***KeyError',str(e)
  42. schema.ldap_entry()
  43. print str(schema.get_obj(ldap.schema.MatchingRule,'2.5.13.0'))
  44. print str(schema.get_obj(ldap.schema.MatchingRuleUse,'2.5.13.0'))
  45. print str(schema.get_obj(ldap.schema.AttributeType,'name'))
  46. print str(schema.get_inheritedobj(ldap.schema.AttributeType,'cn',['syntax','equality','substr','ordering']))
  47. must_attr,may_attr = schema.attribute_types(['person','organizationalPerson','inetOrgPerson'],raise_keyerror=0)