2010-03-24 08:50:50 +03:00
#!/usr/bin/env python
2008-02-10 02:21:41 +03:00
#
2009-09-18 22:15:12 +04:00
# Works out the minimal schema for a set of objectclasses
2008-02-10 02:21:41 +03:00
#
2009-03-20 03:29:31 +03:00
import base64
2008-02-10 02:21:41 +03:00
import optparse
2009-03-20 03:29:31 +03:00
import sys
2008-05-23 04:44:42 +04:00
2008-05-11 07:45:49 +04:00
# Find right directory when running from source tree
sys.path.insert(0, "bin/python")
2008-02-10 02:21:41 +03:00
import samba
2008-10-07 03:23:34 +04:00
from samba import getopt as options, Ldb
from ldb import SCOPE_SUBTREE, SCOPE_BASE, LdbError
2008-02-10 02:56:55 +03:00
import sys
2008-02-10 02:21:41 +03:00
parser = optparse.OptionParser("minschema <URL> <classfile>")
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
credopts = options.CredentialsOptions(parser)
parser.add_option_group(credopts)
parser.add_option_group(options.VersionOptions(parser))
parser.add_option("--verbose", help="Be verbose", action="store_true")
parser.add_option("--dump-classes", action="store_true")
parser.add_option("--dump-attributes", action="store_true")
parser.add_option("--dump-subschema", action="store_true")
parser.add_option("--dump-subschema-auto", action="store_true")
opts, args = parser.parse_args()
opts.dump_all = True
if opts.dump_classes:
opts.dump_all = False
if opts.dump_attributes:
opts.dump_all = False
if opts.dump_subschema:
opts.dump_all = False
2008-02-10 02:56:55 +03:00
if opts.dump_subschema_auto:
opts.dump_all = False
opts.dump_subschema = True
2008-02-10 02:21:41 +03:00
if opts.dump_all:
2008-02-10 02:56:55 +03:00
opts.dump_classes = True
opts.dump_attributes = True
opts.dump_subschema = True
opts.dump_subschema_auto = True
2008-02-10 02:21:41 +03:00
if len(args) != 2:
parser.print_usage()
sys.exit(1)
(url, classfile) = args
2008-10-07 03:23:34 +04:00
lp_ctx = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp_ctx)
2009-03-20 03:29:31 +03:00
ldb = Ldb(url, credentials=creds, lp=lp_ctx)
2008-02-10 02:21:41 +03:00
2009-03-20 03:29:31 +03:00
objectclasses = {}
attributes = {}
2008-02-10 02:21:41 +03:00
2008-02-10 02:56:55 +03:00
objectclasses_expanded = set()
2008-02-10 02:21:41 +03:00
# the attributes we need for objectclasses
class_attrs = ["objectClass",
"subClassOf",
"governsID",
"possSuperiors",
"possibleInferiors",
"mayContain",
"mustContain",
"auxiliaryClass",
"rDNAttID",
"adminDisplayName",
"adminDescription",
"objectClassCategory",
"lDAPDisplayName",
"schemaIDGUID",
"systemOnly",
"systemPossSuperiors",
"systemMayContain",
"systemMustContain",
"systemAuxiliaryClass",
"defaultSecurityDescriptor",
"systemFlags",
"defaultHidingValue",
"objectCategory",
"defaultObjectCategory",
# this attributes are not used by w2k3
"schemaFlagsEx",
"msDs-IntId",
"msDs-Schema-Extensions",
"classDisplayName",
"isDefunct"]
attrib_attrs = ["objectClass",
"attributeID",
"attributeSyntax",
"isSingleValued",
"rangeLower",
"rangeUpper",
"mAPIID",
"linkID",
"adminDisplayName",
"oMObjectClass",
"adminDescription",
"oMSyntax",
"searchFlags",
"extendedCharsAllowed",
"lDAPDisplayName",
"schemaIDGUID",
"attributeSecurityGUID",
"systemOnly",
"systemFlags",
"isMemberOfPartialAttributeSet",
"objectCategory",
# this attributes are not used by w2k3
"schemaFlagsEx",
"msDs-IntId",
"msDs-Schema-Extensions",
"classDisplayName",
"isEphemeral",
"isDefunct"]
#
# notes:
#
# objectClassCategory
# 1: structural
# 2: abstract
# 3: auxiliary
def get_object_cn(ldb, name):
2008-02-10 02:56:55 +03:00
attrs = ["cn"]
2009-03-20 03:29:31 +03:00
res = ldb.search(expression="(ldapDisplayName=%s)" % name, base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE, attrs=attrs)
2008-02-10 02:56:55 +03:00
assert len(res) == 1
return res[0]["cn"]
2008-02-10 02:21:41 +03:00
2009-03-20 03:29:31 +03:00
class Objectclass(dict):
2008-02-10 02:56:55 +03:00
def __init__(self, ldb, name):
"""create an objectclass object"""
self.name = name
2009-03-20 03:29:31 +03:00
self["cn"] = get_object_cn(ldb, name)
2008-02-10 02:21:41 +03:00
2009-03-20 03:29:31 +03:00
class Attribute(dict):
2008-02-10 02:56:55 +03:00
def __init__(self, ldb, name):
"""create an attribute object"""
self.name = name
2009-03-20 03:29:31 +03:00
self["cn"] = get_object_cn(ldb, name)
2008-02-10 02:21:41 +03:00
syntaxmap = dict()
syntaxmap['2.5.5.1'] = '1.3.6.1.4.1.1466.115.121.1.12'
syntaxmap['2.5.5.2'] = '1.3.6.1.4.1.1466.115.121.1.38'
syntaxmap['2.5.5.3'] = '1.2.840.113556.1.4.1362'
syntaxmap['2.5.5.4'] = '1.2.840.113556.1.4.905'
syntaxmap['2.5.5.5'] = '1.3.6.1.4.1.1466.115.121.1.26'
syntaxmap['2.5.5.6'] = '1.3.6.1.4.1.1466.115.121.1.36'
syntaxmap['2.5.5.7'] = '1.2.840.113556.1.4.903'
syntaxmap['2.5.5.8'] = '1.3.6.1.4.1.1466.115.121.1.7'
syntaxmap['2.5.5.9'] = '1.3.6.1.4.1.1466.115.121.1.27'
syntaxmap['2.5.5.10'] = '1.3.6.1.4.1.1466.115.121.1.40'
syntaxmap['2.5.5.11'] = '1.3.6.1.4.1.1466.115.121.1.24'
syntaxmap['2.5.5.12'] = '1.3.6.1.4.1.1466.115.121.1.15'
syntaxmap['2.5.5.13'] = '1.3.6.1.4.1.1466.115.121.1.43'
syntaxmap['2.5.5.14'] = '1.2.840.113556.1.4.904'
syntaxmap['2.5.5.15'] = '1.2.840.113556.1.4.907'
syntaxmap['2.5.5.16'] = '1.2.840.113556.1.4.906'
syntaxmap['2.5.5.17'] = '1.3.6.1.4.1.1466.115.121.1.40'
2008-02-10 02:56:55 +03:00
2008-02-10 02:21:41 +03:00
def map_attribute_syntax(s):
2008-02-10 02:56:55 +03:00
"""map some attribute syntaxes from some apparently MS specific
syntaxes to the standard syntaxes"""
2009-03-20 03:29:31 +03:00
if s in list(syntaxmap):
2008-02-10 02:56:55 +03:00
return syntaxmap[s]
return s
2008-02-10 02:21:41 +03:00
def fix_dn(dn):
2008-02-10 02:56:55 +03:00
"""fix a string DN to use ${SCHEMADN}"""
2009-03-20 03:29:31 +03:00
return dn.replace(rootDse["schemaNamingContext"][0], "${SCHEMADN}")
2008-02-10 02:56:55 +03:00
2008-02-10 02:21:41 +03:00
def write_ldif_one(o, attrs):
2008-02-10 02:56:55 +03:00
"""dump an object as ldif"""
2018-10-28 01:12:48 +03:00
print("dn: CN=%s,${SCHEMADN}" % o["cn"])
2008-02-10 02:21:41 +03:00
for a in attrs:
if not o.has_key(a):
2008-02-10 02:56:55 +03:00
continue
# special case for oMObjectClass, which is a binary object
v = o[a]
2008-02-10 02:21:41 +03:00
for j in v:
2018-10-28 01:16:21 +03:00
value = fix_dn(j)
if a == "oMObjectClass":
print("%s:: %s" % (a, base64.b64encode(value).decode('utf8')))
elif a.endswith("GUID"):
print("%s: %s" % (a, ldb.schema_format_value(a, value)))
else:
print("%s: %s" % (a, value))
print()
2009-03-20 03:29:31 +03:00
2008-02-10 02:21:41 +03:00
def write_ldif(o, attrs):
2008-02-10 02:56:55 +03:00
"""dump an array of objects as ldif"""
2009-03-20 03:29:31 +03:00
for n, i in o.items():
2008-02-10 02:56:55 +03:00
write_ldif_one(i, attrs)
2008-02-10 02:21:41 +03:00
def create_testdn(exampleDN):
2008-02-10 02:56:55 +03:00
"""create a testDN based an an example DN
the idea is to ensure we obey any structural rules"""
a = exampleDN.split(",")
a[0] = "CN=TestDN"
return ",".join(a)
2008-02-10 02:21:41 +03:00
def find_objectclass_properties(ldb, o):
2008-02-10 02:56:55 +03:00
"""the properties of an objectclass"""
res = ldb.search(
expression="(ldapDisplayName=%s)" % o.name,
2009-03-20 03:29:31 +03:00
base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE, attrs=class_attrs)
2008-02-10 02:56:55 +03:00
assert(len(res) == 1)
2008-02-10 02:21:41 +03:00
msg = res[0]
for a in msg:
2008-02-10 02:56:55 +03:00
o[a] = msg[a]
2008-02-10 02:21:41 +03:00
def find_attribute_properties(ldb, o):
2008-02-10 02:56:55 +03:00
"""find the properties of an attribute"""
res = ldb.search(
expression="(ldapDisplayName=%s)" % o.name,
2009-03-20 03:29:31 +03:00
base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE,
2008-02-10 02:56:55 +03:00
attrs=attrib_attrs)
assert(len(res) == 1)
2008-02-10 02:21:41 +03:00
msg = res[0]
for a in msg:
2008-02-10 02:56:55 +03:00
o[a] = msg[a]
2008-02-10 02:21:41 +03:00
def find_objectclass_auto(ldb, o):
2008-02-10 02:56:55 +03:00
"""find the auto-created properties of an objectclass. Only works for
classes that can be created using just a DN and the objectclass"""
2008-02-10 02:21:41 +03:00
if not o.has_key("exampleDN"):
2008-02-10 02:56:55 +03:00
return
testdn = create_testdn(o.exampleDN)
2008-02-10 02:21:41 +03:00
2009-03-20 03:29:31 +03:00
print "testdn is '%s'" % testdn
2008-02-10 02:21:41 +03:00
2008-02-10 02:56:55 +03:00
ldif = "dn: " + testdn
ldif += "\nobjectClass: " + o.name
2008-02-10 02:21:41 +03:00
try:
ldb.add(ldif)
2018-02-14 00:33:06 +03:00
except LdbError as e:
2009-03-20 03:29:31 +03:00
print "error adding %s: %s" % (o.name, e)
print "%s" % ldif
2008-02-10 02:21:41 +03:00
return
2008-10-07 03:23:34 +04:00
res = ldb.search(base=testdn, scope=ldb.SCOPE_BASE)
2008-02-10 02:56:55 +03:00
ldb.delete(testdn)
2008-02-10 02:21:41 +03:00
for a in res.msgs[0]:
2008-02-10 02:56:55 +03:00
attributes[a].autocreate = True
2008-02-10 02:21:41 +03:00
def expand_objectclass(ldb, o):
2017-02-17 22:56:18 +03:00
"""look at auxiliary information from a class to intuit the existence of
2008-02-10 02:56:55 +03:00
more classes needed for a minimal schema"""
attrs = ["auxiliaryClass", "systemAuxiliaryClass",
"possSuperiors", "systemPossSuperiors",
"subClassOf"]
res = ldb.search(
expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % o.name,
2009-03-20 03:29:31 +03:00
base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE,
2008-02-10 02:56:55 +03:00
attrs=attrs)
2009-03-20 03:29:31 +03:00
print >>sys.stderr, "Expanding class %s" % o.name
2008-02-10 02:56:55 +03:00
assert(len(res) == 1)
msg = res[0]
2009-03-20 03:29:31 +03:00
for aname in attrs:
if not aname in msg:
2008-02-10 02:56:55 +03:00
continue
list = msg[aname]
2008-02-10 02:21:41 +03:00
if isinstance(list, str):
2008-02-10 02:56:55 +03:00
list = [msg[aname]]
2008-02-10 02:21:41 +03:00
for name in list:
if not objectclasses.has_key(name):
2009-03-20 03:29:31 +03:00
print >>sys.stderr, "Found new objectclass '%s'" % name
2008-02-10 02:56:55 +03:00
objectclasses[name] = Objectclass(ldb, name)
2008-02-10 02:21:41 +03:00
2008-02-10 02:56:55 +03:00
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"]
2008-02-10 02:21:41 +03:00
for aname in attrs:
2008-02-10 02:56:55 +03:00
if not objectclass.has_key(aname):
continue
alist = objectclass[aname]
2008-02-10 02:21:41 +03:00
if isinstance(alist, str):
2008-02-10 02:56:55 +03:00
alist = [alist]
2008-02-10 02:21:41 +03:00
for a in alist:
if not attributes.has_key(a):
2008-02-10 02:56:55 +03:00
attributes[a] = Attribute(ldb, a)
2008-02-10 02:21:41 +03:00
def walk_dn(ldb, dn):
2008-02-10 02:56:55 +03:00
"""process an individual record, working out what attributes it has"""
# get a list of all possible attributes for this object
attrs = ["allowedAttributes"]
2008-02-10 02:21:41 +03:00
try:
2008-10-07 03:23:34 +04:00
res = ldb.search("objectClass=*", dn, SCOPE_BASE, attrs)
2018-02-14 00:33:06 +03:00
except LdbError as e:
2009-03-20 03:29:31 +03:00
print >>sys.stderr, "Unable to fetch allowedAttributes for '%s' - %r" % (dn, e)
2008-02-10 02:56:55 +03:00
return
allattrs = res[0]["allowedAttributes"]
2008-02-10 02:21:41 +03:00
try:
2008-10-07 03:23:34 +04:00
res = ldb.search("objectClass=*", dn, SCOPE_BASE, allattrs)
2018-02-14 00:33:06 +03:00
except LdbError as e:
2009-03-20 03:29:31 +03:00
print >>sys.stderr, "Unable to fetch all attributes for '%s' - %s" % (dn, e)
2008-02-10 02:56:55 +03:00
return
msg = res[0]
2008-02-10 02:21:41 +03:00
for a in msg:
if not attributes.has_key(a):
2008-02-10 02:56:55 +03:00
attributes[a] = Attribute(ldb, a)
2008-02-10 02:21:41 +03:00
def walk_naming_context(ldb, namingContext):
2008-02-10 02:56:55 +03:00
"""walk a naming context, looking for all records"""
2008-02-10 02:21:41 +03:00
try:
2008-10-07 03:23:34 +04:00
res = ldb.search("objectClass=*", namingContext, SCOPE_DEFAULT,
2008-02-10 02:21:41 +03:00
["objectClass"])
2018-02-14 00:33:06 +03:00
except LdbError as e:
2009-03-20 03:29:31 +03:00
print >>sys.stderr, "Unable to fetch objectClasses for '%s' - %s" % (namingContext, e)
2008-02-10 02:56:55 +03:00
return
2008-02-10 02:21:41 +03:00
for msg in res:
2008-02-10 02:56:55 +03:00
msg = res.msgs[r]["objectClass"]
2008-02-10 02:21:41 +03:00
for objectClass in msg:
if not objectclasses.has_key(objectClass):
2008-02-10 02:56:55 +03:00
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 = []
2008-02-10 02:21:41 +03:00
for x in possinf:
if objectclasses.has_key(x):
2009-03-20 03:29:31 +03:00
newpossinf.append(x)
2008-02-10 02:56:55 +03:00
objectclass["possibleInferiors"] = newpossinf
# trim systemMayContain,
# remove duplicates
if objectclass.has_key("systemMayContain"):
sysmay = objectclass["systemMayContain"]
newsysmay = []
2008-02-10 02:21:41 +03:00
for x in sysmay:
2008-02-10 02:56:55 +03:00
if not x in newsysmay:
newsysmay.append(x)
objectclass["systemMayContain"] = newsysmay
# trim mayContain,
# remove duplicates
2009-03-20 03:29:31 +03:00
if objectclass.has_key("mayContain"):
2008-02-10 02:56:55 +03:00
may = objectclass["mayContain"]
newmay = []
2008-02-10 02:21:41 +03:00
if isinstance(may, str):
2008-02-10 02:56:55 +03:00
may = [may]
2008-02-10 02:21:41 +03:00
for x in may:
2008-02-10 02:56:55 +03:00
if not x in newmay:
newmay.append(x)
objectclass["mayContain"] = newmay
2008-02-10 02:21:41 +03:00
2009-03-20 03:29:31 +03:00
2008-02-10 02:21:41 +03:00
def build_objectclass(ldb, name):
2008-02-10 02:56:55 +03:00
"""load the basic attributes of an objectClass"""
attrs = ["name"]
2009-03-20 03:29:31 +03:00
res = ldb.search(
expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % name,
base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE,
attrs=attrs)
2008-02-10 02:21:41 +03:00
if len(res) == 0:
2009-03-20 03:29:31 +03:00
print >>sys.stderr, "unknown class '%s'" % name
2008-02-10 02:56:55 +03:00
return None
return Objectclass(ldb, name)
2009-03-20 03:29:31 +03:00
2008-02-10 02:56:55 +03:00
def attribute_list(objectclass, attr1, attr2):
"""form a coalesced attribute list"""
2009-03-20 03:29:31 +03:00
a1 = list(objectclass.get(attr1, []))
a2 = list(objectclass.get(attr2, []))
2008-02-10 02:56:55 +03:00
return a1 + a2
2008-02-10 02:21:41 +03:00
def aggregate_list(name, list):
2008-02-10 02:56:55 +03:00
"""write out a list in aggregate form"""
2009-03-20 05:55:43 +03:00
if list == []:
return ""
return " %s ( %s )" % (name, " $ ".join(list))
2008-02-10 02:21:41 +03:00
2008-02-10 02:56:55 +03:00
def write_aggregate_objectclass(objectclass):
"""write the aggregate record for an objectclass"""
2009-03-20 05:55:43 +03:00
line = "objectClasses: ( %s NAME '%s' " % (objectclass["governsID"], objectclass.name)
2008-02-10 02:56:55 +03:00
if not objectclass.has_key('subClassOf'):
2009-03-20 05:55:43 +03:00
line += "SUP %s" % objectclass['subClassOf']
2009-03-20 03:29:31 +03:00
if objectclass["objectClassCategory"] == 1:
2009-03-20 05:55:43 +03:00
line += "STRUCTURAL"
2009-03-20 03:29:31 +03:00
elif objectclass["objectClassCategory"] == 2:
2009-03-20 05:55:43 +03:00
line += "ABSTRACT"
2009-03-20 03:29:31 +03:00
elif objectclass["objectClassCategory"] == 3:
2009-03-20 05:55:43 +03:00
line += "AUXILIARY"
2008-02-10 02:21:41 +03:00
2008-02-10 02:56:55 +03:00
list = attribute_list(objectclass, "systemMustContain", "mustContain")
2009-03-20 05:55:43 +03:00
line += aggregate_list("MUST", list)
2008-02-10 02:21:41 +03:00
2008-02-10 02:56:55 +03:00
list = attribute_list(objectclass, "systemMayContain", "mayContain")
2009-03-20 05:55:43 +03:00
line += aggregate_list("MAY", list)
2008-02-10 02:21:41 +03:00
2009-03-20 05:55:43 +03:00
print line + " )"
2008-02-10 02:21:41 +03:00
2008-02-10 02:56:55 +03:00
def write_aggregate_ditcontentrule(objectclass):
"""write the aggregate record for an ditcontentrule"""
list = attribute_list(objectclass, "auxiliaryClass", "systemAuxiliaryClass")
2009-03-20 05:55:43 +03:00
if list == []:
2008-02-10 02:56:55 +03:00
return
2008-02-10 02:21:41 +03:00
2009-03-20 05:55:43 +03:00
line = "dITContentRules: ( %s NAME '%s'" % (objectclass["governsID"], objectclass.name)
2008-02-10 02:21:41 +03:00
2009-03-20 05:55:43 +03:00
line += aggregate_list("AUX", list)
2008-02-10 02:21:41 +03:00
2009-03-20 03:29:31 +03:00
may_list = []
must_list = []
2008-02-10 02:21:41 +03:00
for c in list:
2008-02-10 02:56:55 +03:00
list2 = attribute_list(objectclasses[c],
"mayContain", "systemMayContain")
may_list = may_list + list2
list2 = attribute_list(objectclasses[c],
"mustContain", "systemMustContain")
must_list = must_list + list2
2008-02-10 02:21:41 +03:00
2009-03-20 05:55:43 +03:00
line += aggregate_list("MUST", must_list)
line += aggregate_list("MAY", may_list)
2008-02-10 02:21:41 +03:00
2009-03-20 05:55:43 +03:00
print line + " )"
2008-02-10 02:21:41 +03:00
def write_aggregate_attribute(attrib):
2008-02-10 02:56:55 +03:00
"""write the aggregate record for an attribute"""
2009-03-20 05:55:43 +03:00
line = "attributeTypes: ( %s NAME '%s' SYNTAX '%s' " % (
2009-03-20 03:29:31 +03:00
attrib["attributeID"], attrib.name,
map_attribute_syntax(attrib["attributeSyntax"]))
if attrib.get('isSingleValued') == "TRUE":
2009-03-20 05:55:43 +03:00
line += "SINGLE-VALUE "
2009-03-20 03:29:31 +03:00
if attrib.get('systemOnly') == "TRUE":
2009-03-20 05:55:43 +03:00
line += "NO-USER-MODIFICATION "
2008-02-10 02:21:41 +03:00
2009-03-20 05:55:43 +03:00
print line + ")"
2008-02-10 02:21:41 +03:00
def write_aggregate():
2008-02-10 02:56:55 +03:00
"""write the aggregate record"""
2009-03-20 05:55:43 +03:00
print "dn: CN=Aggregate,${SCHEMADN}"
2008-02-10 02:56:55 +03:00
print """objectClass: top
2008-02-10 02:21:41 +03:00
objectClass: subSchema
2009-03-20 05:55:43 +03:00
objectCategory: CN=SubSchema,${SCHEMADN}"""
2008-02-10 02:21:41 +03:00
if not opts.dump_subschema_auto:
2008-02-10 02:56:55 +03:00
return
2008-02-10 02:21:41 +03:00
2009-03-20 03:29:31 +03:00
for objectclass in objectclasses.values():
2008-02-10 02:56:55 +03:00
write_aggregate_objectclass(objectclass)
2009-03-20 03:29:31 +03:00
for attr in attributes.values():
2008-02-10 02:56:55 +03:00
write_aggregate_attribute(attr)
2009-03-20 03:29:31 +03:00
for objectclass in objectclasses.values():
2008-02-10 02:56:55 +03:00
write_aggregate_ditcontentrule(objectclass)
2008-02-10 02:21:41 +03:00
def load_list(file):
2008-02-10 02:56:55 +03:00
"""load a list from a file"""
2009-03-20 03:29:31 +03:00
return [l.strip("\n") for l in open(file, 'r').readlines()]
2008-02-10 02:21:41 +03:00
# get the rootDSE
2008-10-07 03:23:34 +04:00
res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["schemaNamingContext"])
2008-02-10 02:21:41 +03:00
rootDse = res[0]
# load the list of classes we are interested in
classes = load_list(classfile)
2008-02-10 02:56:55 +03:00
for classname in classes:
objectclass = build_objectclass(ldb, classname)
if objectclass is not None:
objectclasses[classname] = objectclass
2008-02-10 02:21:41 +03:00
#
# 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):
2009-03-20 03:29:31 +03:00
for n, o in objectclasses.items():
2008-02-10 02:56:55 +03:00
if not n in objectclasses_expanded:
2009-03-20 03:29:31 +03:00
expand_objectclass(ldb, o)
2008-02-10 02:56:55 +03:00
objectclasses_expanded.add(n)
2008-02-10 02:21:41 +03:00
#
# find objectclass properties
#
2009-03-20 03:29:31 +03:00
for name, objectclass in objectclasses.items():
2008-02-10 02:56:55 +03:00
find_objectclass_properties(ldb, objectclass)
2008-02-10 02:21:41 +03:00
#
# form the full list of attributes
#
2009-03-20 03:29:31 +03:00
for name, objectclass in objectclasses.items():
2008-02-10 02:56:55 +03:00
add_objectclass_attributes(ldb, objectclass)
2008-02-10 02:21:41 +03:00
# and attribute properties
2009-03-20 03:29:31 +03:00
for name, attr in attributes.items():
2008-02-10 02:56:55 +03:00
find_attribute_properties(ldb, attr)
2008-02-10 02:21:41 +03:00
#
# trim the 'may' attribute lists to those really needed
#
2009-03-20 03:29:31 +03:00
for name, objectclass in objectclasses.items():
2008-02-10 02:56:55 +03:00
trim_objectclass_attributes(ldb, objectclass)
2008-02-10 02:21:41 +03:00
#
# dump an ldif form of the attributes and objectclasses
#
if opts.dump_attributes:
2008-02-10 02:56:55 +03:00
write_ldif(attributes, attrib_attrs)
2008-02-10 02:21:41 +03:00
if opts.dump_classes:
2008-02-10 02:56:55 +03:00
write_ldif(objectclasses, class_attrs)
2008-02-10 02:21:41 +03:00
if opts.dump_subschema:
2008-02-10 02:56:55 +03:00
write_aggregate()
2008-02-10 02:21:41 +03:00
if not opts.verbose:
2008-02-10 02:56:55 +03:00
sys.exit(0)
2008-02-10 02:21:41 +03:00
#
# dump list of objectclasses
#
print "objectClasses:\n"
for objectclass in objectclasses:
2008-02-10 02:56:55 +03:00
print "\t%s\n" % objectclass
2008-02-10 02:21:41 +03:00
print "attributes:\n"
for attr in attributes:
2008-02-10 02:56:55 +03:00
print "\t%s\n" % attr
2008-02-10 02:21:41 +03:00
print "autocreated attributes:\n"
2008-02-10 02:56:55 +03:00
for attr in attributes:
if attr.autocreate:
print "\t%s\n" % i