2010-03-24 08:50:50 +03:00
#!/usr/bin/env python
2009-03-20 08:07:49 +03:00
#
2009-09-18 22:15:12 +04:00
# Works out the full schema
2009-03-20 08:07:49 +03:00
#
import base64
import optparse
import sys
# Find right directory when running from source tree
sys.path.insert(0, "bin/python")
import samba
from samba import getopt as options, Ldb
2010-06-20 15:15:09 +04:00
from ldb import SCOPE_SUBTREE, SCOPE_BASE
2009-03-20 08:07:49 +03:00
import sys
parser = optparse.OptionParser("fullschema <URL>")
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("--dump-classes", action="store_true")
parser.add_option("--dump-attributes", 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_all:
opts.dump_classes = True
opts.dump_attributes = True
if len(args) != 1:
parser.print_usage()
sys.exit(1)
url = args[0]
lp_ctx = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp_ctx)
ldb = Ldb(url, credentials=creds, lp=lp_ctx, options=["modules:paged_searches"])
# the attributes we need for objectclasses
class_attrs = ["objectClass",
"cn",
"subClassOf",
"governsID",
"possSuperiors",
"possibleInferiors",
"mayContain",
"mustContain",
"auxiliaryClass",
"rDNAttID",
"adminDisplayName",
"adminDescription",
"objectClassCategory",
"lDAPDisplayName",
"schemaIDGUID",
"systemOnly",
"systemPossSuperiors",
"systemMayContain",
"systemMustContain",
"systemAuxiliaryClass",
"defaultSecurityDescriptor",
"systemFlags",
"defaultHidingValue",
"defaultObjectCategory",
# this attributes are not used by w2k3
"schemaFlagsEx",
"msDs-IntId",
"msDs-Schema-Extensions",
"classDisplayName",
"isDefunct"]
attrib_attrs = ["objectClass",
"cn",
"attributeID",
"attributeSyntax",
"isSingleValued",
"rangeLower",
"rangeUpper",
"mAPIID",
"linkID",
"adminDisplayName",
"oMObjectClass",
"adminDescription",
"oMSyntax",
"searchFlags",
"extendedCharsAllowed",
"lDAPDisplayName",
"schemaIDGUID",
"attributeSecurityGUID",
"systemOnly",
"systemFlags",
"isMemberOfPartialAttributeSet",
# this attributes are not used by w2k3
"schemaFlagsEx",
"msDs-IntId",
"msDs-Schema-Extensions",
"classDisplayName",
"isEphemeral",
"isDefunct"]
class Objectclass(dict):
def __init__(self, ldb, name):
"""create an objectclass object"""
self.name = name
class Attribute(dict):
def __init__(self, ldb, name):
"""create an attribute object"""
self.name = name
self["cn"] = get_object_cn(ldb, name)
def fix_dn(dn):
"""fix a string DN to use ${SCHEMADN}"""
return dn.replace(rootDse["schemaNamingContext"][0], "${SCHEMADN}")
def write_ldif_one(o, attrs):
"""dump an object as ldif"""
print "dn: CN=%s,${SCHEMADN}" % o["cn"]
for a in attrs:
if not o.has_key(a):
continue
# special case for oMObjectClass, which is a binary object
v = o[a]
2009-07-02 10:19:37 +04:00
list = []
2009-03-20 08:07:49 +03:00
for j in v:
2009-07-02 10:19:37 +04:00
value = fix_dn(j)
list.append(value)
list.sort()
for j in list:
2009-03-20 08:07:49 +03:00
value = fix_dn(j)
if a != "cn":
if a == "oMObjectClass":
print "%s:: %s" % (a, base64.b64encode(value))
elif a.endswith("GUID"):
print "%s: %s" % (a, ldb.schema_format_value(a, value))
else:
print "%s: %s" % (a, value)
print ""
# get the rootDSE
res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["schemaNamingContext"])
rootDse = res[0]
if opts.dump_attributes:
res = ldb.search(expression="objectClass=attributeSchema",
2009-03-20 08:47:34 +03:00
base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE,attrs=attrib_attrs,
controls=["server_sort:1:0:cn"])
2009-03-20 08:07:49 +03:00
for msg in res:
o = Objectclass(ldb, msg["ldapDisplayName"])
for a in msg:
o[a] = msg[a]
write_ldif_one(o, attrib_attrs)
if opts.dump_classes:
res = ldb.search(expression="objectClass=classSchema",
2009-03-20 08:47:34 +03:00
base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE,attrs=class_attrs,
controls=["server_sort:1:0:cn"])
2009-03-20 08:07:49 +03:00
for msg in res:
o = Objectclass(ldb, msg["ldapDisplayName"])
for a in msg:
o[a] = msg[a]
write_ldif_one(o, class_attrs)