示例#1
0
def _get_oid_dependency_order(schema, cls):
    """
    Returns a ordered list of OIDs sets, in order which respects inheritance in LDAP
    OIDs in second set, depend on first set, etc.

    :return [set(1st-tree-level), set(2nd-tree-level), ...]
    """
    top_node = '_'
    ordered_oid_groups = []

    tree = schema.tree(cls)  # tree structure of schema

    # remove top_node from tree, it breaks ordering
    # we don't need this, tree from file is not consistent
    del tree[top_node]
    unordered_oids = set(tree.keys())

    # split into two groups, parents and child nodes, and iterate until
    # child nodes are not empty
    while unordered_oids:
        parent_nodes = set()
        child_nodes = set()

        for node in unordered_oids:
            if node not in child_nodes:
                # if node was child once, must remain as child
                parent_nodes.add(node)

            for child_oid in tree[node]:
                # iterate over all child nodes stored in tree[node] per node
                # child node must be removed from parents
                parent_nodes.discard(child_oid)
                child_nodes.add(child_oid)

        ordered_oid_groups.append(
            parent_nodes)  # parents nodes are not dependent

        assert len(child_nodes) < len(
            unordered_oids)  # while iteration must be finite
        unordered_oids = child_nodes  # extract new parent nodes in next iteration

    return ordered_oid_groups
示例#2
0
def _get_oid_dependency_order(schema, cls):
    """
    Returns a ordered list of OIDs sets, in order which respects inheritance in LDAP
    OIDs in second set, depend on first set, etc.

    :return [set(1st-tree-level), set(2nd-tree-level), ...]
    """
    top_node = '_'
    ordered_oid_groups = []

    tree = schema.tree(cls)  # tree structure of schema

    # remove top_node from tree, it breaks ordering
    # we don't need this, tree from file is not consistent
    del tree[top_node]
    unordered_oids = set(tree.keys())

    # split into two groups, parents and child nodes, and iterate until
    # child nodes are not empty
    while unordered_oids:
        parent_nodes = set()
        child_nodes = set()

        for node in unordered_oids:
            if node not in child_nodes:
                # if node was child once, must remain as child
                parent_nodes.add(node)

            for child_oid in tree[node]:
                # iterate over all child nodes stored in tree[node] per node
                # child node must be removed from parents
                parent_nodes.discard(child_oid)
                child_nodes.add(child_oid)

        ordered_oid_groups.append(parent_nodes)  # parents nodes are not dependent

        assert len(child_nodes) < len(unordered_oids)  # while iteration must be finite
        unordered_oids = child_nodes  # extract new parent nodes in next iteration

    return ordered_oid_groups
示例#3
0
ldap._trace_level = 0

subschemasubentry_dn,schema = ldap.schema.urlfetch(sys.argv[-1],ldap.trace_level)

if subschemasubentry_dn is None:
  print('No sub schema sub entry found!')
  sys.exit(1)

try:
  options,args=getopt.getopt(sys.argv[1:],'',['html'])
except getopt.error:
  print('Error: %s\nUsage: schema_oc_tree.py [--html] [LDAP URL]')

html_output = options and options[0][0]=='--html'

oc_tree = schema.tree(ldap.schema.ObjectClass)
at_tree = schema.tree(ldap.schema.AttributeType)

#for k,v in oc_tree.items():
#  print(k,'->',v)
#for k,v in at_tree.items():
#  print(k,'->',v)

if html_output:

  print("""<html>
<head>
  <title>Object class tree</title>
</head>
<body bgcolor="#ffffff">
<h1>Object class tree</h1>
示例#4
0
ldap._trace_level = 0

subschemasubentry_dn,schema = ldap.schema.urlfetch(sys.argv[-1],ldap.trace_level)

if subschemasubentry_dn is None:
  print ('No sub schema sub entry found!')
  sys.exit(1)

try:
  options,args=getopt.getopt(sys.argv[1:],'',['html'])
except getopt.error(e):
  print ('Error: %s\nUsage: schema_oc_tree.py [--html] [LDAP URL]')

print("----------\n")
html_output = options and options[0][0]=='--html'
oc_tree = schema.tree(ldap.schema.ObjectClass)
at_tree = schema.tree(ldap.schema.AttributeType)

#for k,v in oc_tree.items():
#  print k,'->',v
#for k,v in at_tree.items():
#  print k,'->',v

if html_output:

  print ("""<html>
<head>
  <title>Object class tree</title>
</head>
<body bgcolor="#ffffff">
<h1>Object class tree</h1>