示例#1
0
文件: schema2xml.py 项目: GOsa3/gosa
def list_classes(uri):  # pragma: nocover
    subschemasubentry_dn, schema = ldap.schema.urlfetch(uri.encode('ascii'))
    schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())

    ocs = ldap.schema.SCHEMA_CLASS_MAPPING['objectclasses']
    for element_id in schema.listall(ocs):
        obj = schema.get_obj(ocs, element_id)
        print("%s - %s" % (obj.names[0], obj.desc or "no description"))
示例#2
0
def list_classes(uri):
    subschemasubentry_dn, schema = ldap.schema.urlfetch(uri)
    schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())

    ocs = ldap.schema.SCHEMA_CLASS_MAPPING['objectclasses']
    for element_id in schema.listall(ocs):
        obj = schema.get_obj(ocs, element_id)
        print("%s - %s" % (obj.names[0], obj.desc or "no description"))
 def assertSlapdSchema(self, dn, schema):
     self.assertEqual(dn, 'cn=Subschema')
     self.assertIsInstance(schema, ldap.schema.subentry.SubSchema)
     obj = schema.get_obj(ObjectClass, '1.3.6.1.1.3.1')
     self.assertEqual(
         str(obj),
         "( 1.3.6.1.1.3.1 NAME 'uidObject' DESC 'RFC2377: uid object' "
         "SUP top AUXILIARY MUST uid )"
     )
     entries = schema.ldap_entry()
     self.assertIsInstance(entries, dict)
     self.assertEqual(sorted(entries), [
         'attributeTypes', 'ldapSyntaxes', 'matchingRuleUse',
         'matchingRules', 'objectClasses',
     ])
示例#4
0
文件: schema2xml.py 项目: GOsa3/gosa
def dump_ui(uri,
            oc,
            outfile=None,
            extend=None,
            rdn=None,
            contains=None):  # pragma: nocover
    subschemasubentry_dn, schema = ldap.schema.urlfetch(uri)
    schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())

    oco = schema.get_obj(ldap.schema.ObjectClass, oc)
    if oco is None:
        log.error(
            "unknown objectclass '%s' - please use the --list option to see what's there"
            % oc)
        exit(1)

    # Complete attributes in case of inheritance
    if oco.kind == 0:
        r = resolve_inherited_attrs(schema, oco.sup[0])
        oco.must = list(set(list(oco.must) + r['must']))
        oco.may = list(set(list(oco.may) + r['must']))

    # Tabstop and connection collectors
    ts = []
    cs = []

    # Build resulting json dump
    children_must = generate_children(oco.must, schema)
    children_may = generate_children(oco.may, schema,
                                     len(children_must) // 2, children_must)

    template = {
        'type': 'widget',
        'class': 'qx.ui.container.Composite',
        'layout': 'qx.ui.layout.Grid',
        'extensions': {
            'tabConfig': {
                'title': oc
            }
        },
        'children': children_must + children_may
    }

    return json.dumps(template, indent=2)
示例#5
0
def dump_ui(uri, oc, outfile=None, extend=None, rdn=None, contains=None):  # pragma: nocover
    subschemasubentry_dn, schema = ldap.schema.urlfetch(uri)
    schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())

    oco = schema.get_obj(ldap.schema.ObjectClass, oc)
    if oco is None:
        log.error("unknown objectclass '%s' - please use the --list option to see what's there" % oc)
        exit(1)

    # Complete attributes in case of inheritance
    if oco.kind == 0:
        r = resolve_inherited_attrs(schema, oco.sup[0])
        oco.must = list(set(list(oco.must) + r['must']))
        oco.may = list(set(list(oco.may) + r['must']))

    # Tabstop and connection collectors
    ts = []
    cs = []

    # Build resulting json dump
    children_must = generate_children(oco.must, schema)
    children_may = generate_children(oco.may, schema, len(children_must) // 2, children_must)

    template = {
        'type': 'widget',
        'class': 'qx.ui.container.Composite',
        'layout': 'qx.ui.layout.Grid',
        'extensions': {
            'tabConfig': {
                'title': oc
            }
        },
        'children': children_must + children_may
    }

    return json.dumps(template, indent=2)
示例#6
0
inetOrgPerson = schema.get_obj(ldap.schema.ObjectClass,'inetOrgPerson')
if not inetOrgPerson is None:
  print(inetOrgPerson.must,inetOrgPerson.may)

print('*** person,organizationalPerson,inetOrgPerson ***')
try:
  print(schema.attribute_types()
    ['person','organizationalPerson','inetOrgPerson']
  )
  print(schema.attribute_types()
    ['person','organizationalPerson','inetOrgPerson'],
    attr_type_filter = [
      ('no_user_mod',[0]),
      ('usage',range(2)),
    ]  
  )
except KeyError as e:
  print('***KeyError',str(e))


schema.ldap_entry()

print(str(schema.get_obj(ldap.schema.MatchingRule,'2.5.13.0')))
print(str(schema.get_obj(ldap.schema.MatchingRuleUse,'2.5.13.0')))

print(str(schema.get_obj(ldap.schema.AttributeType,'name')))
print(str(schema.get_inheritedobj(ldap.schema.AttributeType,'cn',['syntax','equality','substr','ordering'])))

must_attr,may_attr = schema.attribute_types(['person','organizationalPerson','inetOrgPerson'],raise_keyerror=0)
示例#7
0
def dump_class(uri, oc, outfile=None, extend=None, rdn=None, contains=None):
    subschemasubentry_dn, schema = ldap.schema.urlfetch(uri)
    schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())

    oco = schema.get_obj(ldap.schema.ObjectClass, oc)
    if oco is None:
        log.error("unknown objectclass '%s' - please use the --list option to see what's there" % oc)
        exit(1)

    # Complete attributes in case of inheritance
    if oco.kind == 0:
        r = resolve_inherited_attrs(schema, oco.sup[0])
        oco.must = list(set(list(oco.must) + r['must']))
        oco.may = list(set(list(oco.may) + r['must']))

    # Build resulting XML dump
    e = ElementMaker(namespace="http://www.gonicus.de/Objects", nsmap={None: "http://www.gonicus.de/Objects"})
    more = []
    if oco.desc:
        more.append(e.Description(oco.desc))
    more.append(e.Backend("LDAP"))
    if oco.kind == 0:
        if not rdn:
            log.error("no RDN provided - please use --rdn <value> to specify one")
            exit(1)
        more.append(e.BackendParameters(e.Backend("LDAP", objectClasses=oc, RDN=rdn)))

    if oco.kind != 0:
        more.append(e.BaseObject("false"))
    else:
        more.append(e.BaseObject("true"))

    # Build attribute set
    attrs = []
    for mua in oco.must:
        attr = resolve_attribute(schema, mua)
        syntax = attr['syntax']

        if skip(syntax):
            continue

	values = gen_values(syntax)
	values += gen_validators(syntax)
	values += gen_index(syntax)

        attrs.append(
           e.Attribute(
               e.Name(attr['name']),
               e.Description(attr['desc']),
               e.Type(attr['type']),
               e.MultiValue("true" if attr['multivalue'] else "false"),
               e.Mandatory("true"),
	       *values))
    for mua in oco.may:
        attr = resolve_attribute(schema, mua)
        syntax = attr['syntax']
        if skip(syntax):
            continue
	values = gen_values(syntax)
	values += gen_validators(syntax)
	values += gen_index(syntax)
        attrs.append(
           e.Attribute(
               e.Name(attr['name']),
               e.Description(attr['desc']),
               e.Type(attr['type']),
               e.MultiValue("true" if attr['multivalue'] else "false"),
               e.Mandatory("false"),
	       *values))

    more.append(e.Attributes(*attrs))

    # Add container
    if contains == None:
        c = []
        for typ in contains.split(","):
            c.append(e.Type(typ))
        more.append(e.Container(*c))

    # Maintain extension
    if extend == None:
        more.append(e.Extends(e.Value(extend)))

    res = '<?xml version="1.0" encoding="UTF-8"?>\n'
    data = e.Objects(e.Object(e.Name(oc), e.DisplayName(oc), *more))
    res += etree.tostring(data, pretty_print=True)

    return res
示例#8
0
def dump_ui(uri, oc, outfile=None, extend=None, rdn=None, contains=None):
    subschemasubentry_dn, schema = ldap.schema.urlfetch(uri)
    schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())

    oco = schema.get_obj(ldap.schema.ObjectClass, oc)
    if oco is None:
        log.error("unknown objectclass '%s' - please use the --list option to see what's there" % oc)
        exit(1)

    # Complete attributes in case of inheritance
    if oco.kind == 0:
        r = resolve_inherited_attrs(schema, oco.sup[0])
        oco.must = list(set(list(oco.must) + r['must']))
        oco.may = list(set(list(oco.may) + r['must']))

    # Tabstop and connection collectors
    ts = []
    cs = []

    # Build resulting XML dump
    e = ElementMaker()

    n = 0
    attrs = []
    for mua in oco.must:
        attr = resolve_attribute(schema, mua)
        syntax = attr['syntax']

        if skip(syntax):
            continue

        if not 'widget' in TYPE_MAP[syntax]:
            continue

        widget = TYPE_MAP[syntax]['widget']

        attrs.append(
           e.item(
               e.widget(
                   e.property(e.string(mua), name="text"),
                   CLASS("QLabel"), name="%sLabel*" % mua), row=str(n), column="0"))
        attrs.append(e.item(e.widget(CLASS(widget), name="%sEdit*" % mua), row=str(n), column="1"))

        ts.append(e.tabstop(mua))
        cs.append(e.connection(
          e.sender("%sEdit" % mua),
          e.signal("textChanged(QString)"),
          e.receiver(oc),
          e.slot("property_%s()" % mua)))

        n += 1

    for mua in oco.may:
        if mua in oco.must:
            continue

        attr = resolve_attribute(schema, mua)
        syntax = attr['syntax']

        if skip(syntax):
            continue

        if not 'widget' in TYPE_MAP[syntax]:
            continue

        widget = TYPE_MAP[syntax]['widget']

        attrs.append(
           e.item(
               e.widget(
                   e.property(e.string(mua), name="text"),
                   CLASS("QLabel"), name="%sLabel" % mua), row=str(n), column="0"))
        attrs.append(e.item(e.widget(CLASS(widget), name="%sEdit" % mua), row=str(n), column="1"))

        ts.append(e.tabstop(mua))
        cs.append(e.connection(
          e.sender("%sEdit" % mua),
          e.signal("textChanged(QString)"),
          e.receiver(oc),
          e.slot("property_%s()" % mua)))

        n += 1

    res = '<?xml version="1.0" encoding="UTF-8"?>\n'
    data = e.ui(
        e("class", oc),
        e.widget(
            e.property(e.rect(e.x("0"), e.y("0"), e.width("400"), e.height("300")), name="geometry"),
            e.property(e.string(oc), name="windowTitle"),
            e.layout(
                e.item(
                    e.layout(CLASS("QFormLayout"), *attrs, name="formLayout"), row="0", column="0"),
                CLASS("QGridLayout"), name="gridLayout"),
            CLASS("QWidget"), name=oc),
            e.tabstops(*ts),
            e.connections(*cs),
        version="4.0")
    res += etree.tostring(data, pretty_print=True)

    return res
示例#9
0
inetOrgPerson = schema.get_obj(ldap.schema.ObjectClass, 'inetOrgPerson')
if not inetOrgPerson is None:
    print(inetOrgPerson.must, inetOrgPerson.may)

print('*** person,organizationalPerson,inetOrgPerson ***')
try:
    print(schema.attribute_types()['person', 'organizationalPerson',
                                   'inetOrgPerson'])
    print(schema.attribute_types()['person', 'organizationalPerson',
                                   'inetOrgPerson'],
          attr_type_filter=[
              ('no_user_mod', [0]),
              ('usage', range(2)),
          ])
except KeyError as e:
    print('***KeyError', str(e))

schema.ldap_entry()

print(str(schema.get_obj(ldap.schema.MatchingRule, '2.5.13.0')))
print(str(schema.get_obj(ldap.schema.MatchingRuleUse, '2.5.13.0')))

print(str(schema.get_obj(ldap.schema.AttributeType, 'name')))
print(
    str(
        schema.get_inheritedobj(ldap.schema.AttributeType, 'cn',
                                ['syntax', 'equality', 'substr', 'ordering'])))

must_attr, may_attr = schema.attribute_types(
    ['person', 'organizationalPerson', 'inetOrgPerson'], raise_keyerror=0)
示例#10
0
文件: schema.py 项目: shobull/hue
import sys, ldap, ldap.schema

schema_attrs = ldap.schema.SCHEMA_ATTRS

ldap.set_option(ldap.OPT_DEBUG_LEVEL, 0)

ldap._trace_level = 0

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

schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())

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

print "*** Schema from", repr(subschemasubentry_dn)

# Display schema
for attr_type, schema_class in ldap.schema.SCHEMA_CLASS_MAPPING.items():
    print "*" * 20, attr_type, "*" * 20
    for element_id in schema.listall(schema_class):
        se_orig = schema.get_obj(schema_class, element_id)
        se_reverse = schema_reverse.get_obj(schema_class, element_id)
        #    assert str(se_orig)==str(se_reverse)
        print attr_type, str(se_orig)
print "*** Testing object class inetOrgPerson ***"

inetOrgPerson = schema.get_obj(ldap.schema.ObjectClass, "inetOrgPerson")
if not inetOrgPerson is None:
    print inetOrgPerson.must, inetOrgPerson.may
示例#11
0
文件: schema2xml.py 项目: GOsa3/gosa
def dump_class(uri, oc, outfile=None, extend=None, rdn=None, contains=None):
    subschemasubentry_dn, schema = ldap.schema.urlfetch(uri)
    schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())

    oco = schema.get_obj(ldap.schema.ObjectClass, oc)
    if oco is None:
        log.error(
            "unknown objectclass '%s' - please use the --list option to see what's there"
            % oc)
        exit(1)

    # Complete attributes in case of inheritance
    if oco.kind == 0:
        r = resolve_inherited_attrs(schema, oco.sup[0])
        oco.must = list(set(list(oco.must) + r['must']))
        oco.may = list(set(list(oco.may) + r['must']))

    # Build resulting XML dump
    e = ElementMaker(namespace="http://www.gonicus.de/Objects",
                     nsmap={None: "http://www.gonicus.de/Objects"})
    more = []
    if oco.desc:
        more.append(e.Description(oco.desc))
    more.append(e.Backend("LDAP"))
    if oco.kind == 0:
        if not rdn:
            log.error(
                "no RDN provided - please use --rdn <value> to specify one")
            exit(1)
        more.append(
            e.BackendParameters(e.Backend("LDAP", objectClasses=oc, RDN=rdn)))

    if oco.kind != 0:
        more.append(e.BaseObject("false"))
    else:
        more.append(e.BaseObject("true"))

    # Build attribute set
    attrs = []
    syntax = None
    for mua in oco.must:
        attr = resolve_attribute(schema, mua)
        syntax = attr['syntax']

        if skip(syntax):
            continue

        values = gen_values(syntax)
        values += gen_validators(syntax)
        values += gen_index(syntax)

        attrs.append(
            e.Attribute(
                e.Name(attr['name']), e.Description(attr['desc']),
                e.Type(attr['type']),
                e.MultiValue("true" if attr['multivalue'] else "false"),
                e.Mandatory("true"), *values))

    for mua in oco.may:
        attr = resolve_attribute(schema, mua)
        syntax = attr['syntax']
        if skip(syntax):
            continue

        values = gen_values(syntax)
        values += gen_validators(syntax)
        values += gen_index(syntax)
        attrs.append(
            e.Attribute(
                e.Name(attr['name']), e.Description(attr['desc']),
                e.Type(attr['type']),
                e.MultiValue("true" if attr['multivalue'] else "false"),
                e.Mandatory("false"), *values))

    more.append(e.Attributes(*attrs))

    # Add container
    if contains == None:
        c = []
        for typ in contains.split(","):
            c.append(e.Type(typ))
        more.append(e.Container(*c))

    # Maintain extension
    if extend == None:
        more.append(e.Extends(e.Value(extend)))

    res = '<?xml version="1.0" encoding="UTF-8"?>\n'
    data = e.Objects(e.Object(e.Name(oc), e.DisplayName(oc), *more))
    res += etree.tostring(data, pretty_print=True).decode('utf-8')

    return res
示例#12
0
import sys,ldap,ldap.schema

schema_attrs = ldap.schema.SCHEMA_ATTRS

ldap.set_option(ldap.OPT_DEBUG_LEVEL,0)

ldap._trace_level = 0

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

schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())

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

print '*** Schema from',repr(subschemasubentry_dn)

# Display schema
for attr_type,schema_class in ldap.schema.SCHEMA_CLASS_MAPPING.items():
  print '*'*20,attr_type,'*'*20
  for element_id in schema.listall(schema_class):
    se_orig = schema.get_obj(schema_class,element_id)
    se_reverse = schema_reverse.get_obj(schema_class,element_id)
#    assert str(se_orig)==str(se_reverse)
    print attr_type,str(se_orig)
print '*** Testing object class inetOrgPerson ***'

inetOrgPerson = schema.get_obj(ldap.schema.ObjectClass,'inetOrgPerson')
if not inetOrgPerson is None:
  print inetOrgPerson.must,inetOrgPerson.may