3 # work out the minimal schema for a set of objectclasses
11 # Find right directory when running from source tree
12 sys
.path
.insert(0, "bin/python")
15 from samba
import getopt
as options
, Ldb
16 from ldb
import SCOPE_SUBTREE
, SCOPE_BASE
, LdbError
19 parser
= optparse
.OptionParser("fullschema <URL>")
20 sambaopts
= options
.SambaOptions(parser
)
21 parser
.add_option_group(sambaopts
)
22 credopts
= options
.CredentialsOptions(parser
)
23 parser
.add_option_group(credopts
)
24 parser
.add_option_group(options
.VersionOptions(parser
))
25 parser
.add_option("--dump-classes", action
="store_true")
26 parser
.add_option("--dump-attributes", action
="store_true")
28 opts
, args
= parser
.parse_args()
33 if opts
.dump_attributes
:
36 opts
.dump_classes
= True
37 opts
.dump_attributes
= True
45 lp_ctx
= sambaopts
.get_loadparm()
47 creds
= credopts
.get_credentials(lp_ctx
)
48 ldb
= Ldb(url
, credentials
=creds
, lp
=lp_ctx
, options
=["modules:paged_searches"])
50 # the attributes we need for objectclasses
51 class_attrs
= ["objectClass",
63 "objectClassCategory",
67 "systemPossSuperiors",
70 "systemAuxiliaryClass",
71 "defaultSecurityDescriptor",
74 "defaultObjectCategory",
76 # this attributes are not used by w2k3
79 "msDs-Schema-Extensions",
83 attrib_attrs
= ["objectClass",
97 "extendedCharsAllowed",
100 "attributeSecurityGUID",
103 "isMemberOfPartialAttributeSet",
105 # this attributes are not used by w2k3
108 "msDs-Schema-Extensions",
113 class Objectclass(dict):
115 def __init__(self
, ldb
, name
):
116 """create an objectclass object"""
120 class Attribute(dict):
122 def __init__(self
, ldb
, name
):
123 """create an attribute object"""
125 self
["cn"] = get_object_cn(ldb
, name
)
130 """fix a string DN to use ${SCHEMADN}"""
131 return dn
.replace(rootDse
["schemaNamingContext"][0], "${SCHEMADN}")
134 def write_ldif_one(o
, attrs
):
135 """dump an object as ldif"""
136 print "dn: CN=%s,${SCHEMADN}" % o
["cn"]
140 # special case for oMObjectClass, which is a binary object
145 if a
== "oMObjectClass":
146 print "%s:: %s" % (a
, base64
.b64encode(value
))
147 elif a
.endswith("GUID"):
148 print "%s: %s" % (a
, ldb
.schema_format_value(a
, value
))
150 print "%s: %s" % (a
, value
)
155 res
= ldb
.search(base
="", expression
="", scope
=SCOPE_BASE
, attrs
=["schemaNamingContext"])
158 if opts
.dump_attributes
:
159 res
= ldb
.search(expression
="objectClass=attributeSchema",
160 base
=rootDse
["schemaNamingContext"][0], scope
=SCOPE_SUBTREE
,attrs
=attrib_attrs
,
161 controls
=["server_sort:1:0:cn"])
164 o
= Objectclass(ldb
, msg
["ldapDisplayName"])
167 write_ldif_one(o
, attrib_attrs
)
169 if opts
.dump_classes
:
170 res
= ldb
.search(expression
="objectClass=classSchema",
171 base
=rootDse
["schemaNamingContext"][0], scope
=SCOPE_SUBTREE
,attrs
=class_attrs
,
172 controls
=["server_sort:1:0:cn"])
175 o
= Objectclass(ldb
, msg
["ldapDisplayName"])
178 write_ldif_one(o
, class_attrs
)