⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minschema.py

📁 samba最新软件
💻 PY
📖 第 1 页 / 共 2 页
字号:
            continue        list = msg[aname]        if isinstance(list, str):            list = [msg[aname]]        for name in list:            if not objectclasses.has_key(name):                print "Found new objectclass '%s'\n" % name                objectclasses[name] = Objectclass(ldb, name)def add_objectclass_attributes(ldb, objectclass):    """add the must and may attributes from an objectclass to the full list    of attributes"""    attrs = ["mustContain", "systemMustContain",                   "mayContain", "systemMayContain"]    for aname in attrs:        if not objectclass.has_key(aname):            continue        alist = objectclass[aname]        if isinstance(alist, str):            alist = [alist]        for a in alist:            if not attributes.has_key(a):                attributes[a] = Attribute(ldb, a)def walk_dn(ldb, dn):    """process an individual record, working out what attributes it has"""    # get a list of all possible attributes for this object     attrs = ["allowedAttributes"]    try:        res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, attrs)    except LdbError, e:        print "Unable to fetch allowedAttributes for '%s' - %r\n" % (dn, e)        return    allattrs = res[0]["allowedAttributes"]    try:        res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, allattrs)    except LdbError, e:        print "Unable to fetch all attributes for '%s' - %s\n" % (dn, e)        return    msg = res[0]    for a in msg:        if not attributes.has_key(a):            attributes[a] = Attribute(ldb, a)def walk_naming_context(ldb, namingContext):    """walk a naming context, looking for all records"""    try:        res = ldb.search("objectClass=*", namingContext, ldb.SCOPE_DEFAULT,                          ["objectClass"])    except LdbError, e:        print "Unable to fetch objectClasses for '%s' - %s\n" % (namingContext, e)        return    for msg in res:        msg = res.msgs[r]["objectClass"]        for objectClass in msg:            if not objectclasses.has_key(objectClass):                objectclasses[objectClass] = Objectclass(ldb, objectClass)                objectclasses[objectClass].exampleDN = res.msgs[r]["dn"]        walk_dn(ldb, res.msgs[r].dn)def trim_objectclass_attributes(ldb, objectclass):    """trim the may attributes for an objectClass"""    # trim possibleInferiors,    # include only the classes we extracted    if objectclass.has_key("possibleInferiors"):        possinf = objectclass["possibleInferiors"]        newpossinf = []        if isinstance(possinf, str):            possinf = [possinf]        for x in possinf:            if objectclasses.has_key(x):                newpossinf[n] = x                n+=1        objectclass["possibleInferiors"] = newpossinf    # trim systemMayContain,    # remove duplicates    if objectclass.has_key("systemMayContain"):        sysmay = objectclass["systemMayContain"]        newsysmay = []        if isinstance(sysmay, str):            sysmay = [sysmay]        for x in sysmay:            if not x in newsysmay:                newsysmay.append(x)        objectclass["systemMayContain"] = newsysmay    # trim mayContain,    # remove duplicates    if not objectclass.has_key("mayContain"):        may = objectclass["mayContain"]        newmay = []        if isinstance(may, str):            may = [may]        for x in may:            if not x in newmay:                newmay.append(x)        objectclass["mayContain"] = newmaydef build_objectclass(ldb, name):    """load the basic attributes of an objectClass"""    attrs = ["name"]    try:        res = ldb.search(            expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % name,            basedn=rootDse["schemaNamingContext"], scope=ldb.SCOPE_SUBTREE,             attrs=attrs)    except LdbError, e:        print "unknown class '%s'\n" % name        return None    if len(res) == 0:        print "unknown class '%s'\n" % name        return None    return Objectclass(ldb, name)def attribute_list(objectclass, attr1, attr2):    """form a coalesced attribute list"""    a1 = objectclass[attr1]    a2 = objectclass[attr2]    if isinstance(a1, str):        a1 = [a1]    if isinstance(a2, str):        a2 = [a2]    return a1 + a2def aggregate_list(name, list):    """write out a list in aggregate form"""    if list is None:        return    print "%s ( %s )" % (name, "$ ".join(list))def write_aggregate_objectclass(objectclass):    """write the aggregate record for an objectclass"""    print "objectClasses: ( %s NAME '%s' " % (objectclass.governsID, objectclass.name)    if not objectclass.has_key('subClassOf'):        print "SUP %s " % objectclass['subClassOf']    if objectclass.objectClassCategory == 1:        print "STRUCTURAL "    elif objectclass.objectClassCategory == 2:        print "ABSTRACT "    elif objectclass.objectClassCategory == 3:        print "AUXILIARY "    list = attribute_list(objectclass, "systemMustContain", "mustContain")    aggregate_list("MUST", list)    list = attribute_list(objectclass, "systemMayContain", "mayContain")    aggregate_list("MAY", list)    print ")\n"def write_aggregate_ditcontentrule(objectclass):    """write the aggregate record for an ditcontentrule"""    list = attribute_list(objectclass, "auxiliaryClass", "systemAuxiliaryClass")    if list is None:        return    print "dITContentRules: ( %s NAME '%s' " % (objectclass.governsID, objectclass.name)    aggregate_list("AUX", list)    may_list = None    must_list = None    for c in list:        list2 = attribute_list(objectclasses[c],                        "mayContain", "systemMayContain")        may_list = may_list + list2        list2 = attribute_list(objectclasses[c],                        "mustContain", "systemMustContain")        must_list = must_list + list2    aggregate_list("MUST", must_list)    aggregate_list("MAY", may_list)    print ")\n"def write_aggregate_attribute(attrib):    """write the aggregate record for an attribute"""    print "attributeTypes: ( %s NAME '%s' SYNTAX '%s' " % (           attrib.attributeID, attrib.name,            map_attribute_syntax(attrib.attributeSyntax))    if attrib['isSingleValued'] == "TRUE":        print "SINGLE-VALUE "    if attrib['systemOnly'] == "TRUE":        print "NO-USER-MODIFICATION "    print ")\n"def write_aggregate():    """write the aggregate record"""    print "dn: CN=Aggregate,${SCHEMADN}\n"    print """objectClass: topobjectClass: subSchemaobjectCategory: CN=SubSchema,${SCHEMADN}"""    if not opts.dump_subschema_auto:        return    for objectclass in objectclasses:        write_aggregate_objectclass(objectclass)    for attr in attributes:        write_aggregate_attribute(attr)    for objectclass in objectclasses:        write_aggregate_ditcontentrule(objectclass)def load_list(file):    """load a list from a file"""    return open(file, 'r').splitlines()# get the rootDSEres = ldb.search("", "", ldb.SCOPE_BASE)rootDse = res[0]# load the list of classes we are interested inclasses = load_list(classfile)for classname in classes:    objectclass = build_objectclass(ldb, classname)    if objectclass is not None:        objectclasses[classname] = objectclass##  expand the objectclass list as needed#expanded = 0# so EJS do not have while nor the break statement# cannot find any other way than doing more loops# than necessary to recursively expand all classes#for inf in range(500):    for n in objectclasses:        if not n in objectclasses_expanded:            expand_objectclass(ldb, objectclasses[i])            objectclasses_expanded.add(n)##  find objectclass properties#for objectclass in objectclasses:    find_objectclass_properties(ldb, objectclass)##  form the full list of attributes#for objectclass in objectclasses:    add_objectclass_attributes(ldb, objectclass)# and attribute propertiesfor attr in attributes:    find_attribute_properties(ldb, attr)## trim the 'may' attribute lists to those really needed#for objectclass in objectclasses:    trim_objectclass_attributes(ldb, objectclass)##  dump an ldif form of the attributes and objectclasses#if opts.dump_attributes:    write_ldif(attributes, attrib_attrs)if opts.dump_classes:    write_ldif(objectclasses, class_attrs)if opts.dump_subschema:    write_aggregate()if not opts.verbose:    sys.exit(0)##  dump list of objectclasses#print "objectClasses:\n"for objectclass in objectclasses:    print "\t%s\n" % objectclassprint "attributes:\n"for attr in attributes:    print "\t%s\n" % attrprint "autocreated attributes:\n"for attr in attributes:    if attr.autocreate:        print "\t%s\n" % i

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -