3 # Works out the full schema
10 # Find right directory when running from source tree
11 sys.path.insert(0, "bin/python")
14 from samba import getopt as options, Ldb
15 from ldb import SCOPE_SUBTREE, SCOPE_BASE
18 parser = optparse.OptionParser("fullschema <URL>")
19 sambaopts = options.SambaOptions(parser)
20 parser.add_option_group(sambaopts)
21 credopts = options.CredentialsOptions(parser)
22 parser.add_option_group(credopts)
23 parser.add_option_group(options.VersionOptions(parser))
24 parser.add_option("--dump-classes", action="store_true")
25 parser.add_option("--dump-attributes", action="store_true")
27 opts, args = parser.parse_args()
32 if opts.dump_attributes:
35 opts.dump_classes = True
36 opts.dump_attributes = True
44 lp_ctx = sambaopts.get_loadparm()
46 creds = credopts.get_credentials(lp_ctx)
47 ldb = Ldb(url, credentials=creds, lp=lp_ctx, options=["modules:paged_searches"])
49 # the attributes we need for objectclasses
50 class_attrs = ["objectClass",
62 "objectClassCategory",
66 "systemPossSuperiors",
69 "systemAuxiliaryClass",
70 "defaultSecurityDescriptor",
73 "defaultObjectCategory",
75 # this attributes are not used by w2k3
78 "msDs-Schema-Extensions",
82 attrib_attrs = ["objectClass",
96 "extendedCharsAllowed",
99 "attributeSecurityGUID",
102 "isMemberOfPartialAttributeSet",
104 # this attributes are not used by w2k3
107 "msDs-Schema-Extensions",
112 class Objectclass(dict):
114 def __init__(self, ldb, name):
115 """create an objectclass object"""
119 class Attribute(dict):
121 def __init__(self, ldb, name):
122 """create an attribute object"""
124 self["cn"] = get_object_cn(ldb, name)
129 """fix a string DN to use ${SCHEMADN}"""
130 return dn.replace(rootDse["schemaNamingContext"][0], "${SCHEMADN}")
133 def write_ldif_one(o, attrs):
134 """dump an object as ldif"""
135 print "dn: CN=%s,${SCHEMADN}" % o["cn"]
139 # special case for oMObjectClass, which is a binary object
149 if a == "oMObjectClass":
150 print "%s:: %s" % (a, base64.b64encode(value))
151 elif a.endswith("GUID"):
152 print "%s: %s" % (a, ldb.schema_format_value(a, value))
154 print "%s: %s" % (a, value)
159 res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["schemaNamingContext"])
162 if opts.dump_attributes:
163 res = ldb.search(expression="objectClass=attributeSchema",
164 base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE,attrs=attrib_attrs,
165 controls=["server_sort:1:0:cn"])
168 o = Objectclass(ldb, msg["ldapDisplayName"])
171 write_ldif_one(o, attrib_attrs)
173 if opts.dump_classes:
174 res = ldb.search(expression="objectClass=classSchema",
175 base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE,attrs=class_attrs,
176 controls=["server_sort:1:0:cn"])
179 o = Objectclass(ldb, msg["ldapDisplayName"])
182 write_ldif_one(o, class_attrs)