summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/bin/fullschema179
-rwxr-xr-xsource4/scripting/bin/minschema49
-rw-r--r--source4/scripting/python/samba/__init__.py6
-rw-r--r--source4/scripting/python/samba/provision.py2
4 files changed, 206 insertions, 30 deletions
diff --git a/source4/scripting/bin/fullschema b/source4/scripting/bin/fullschema
new file mode 100644
index 0000000000..41c45f30c8
--- /dev/null
+++ b/source4/scripting/bin/fullschema
@@ -0,0 +1,179 @@
+#!/usr/bin/python
+#
+# work out the minimal schema for a set of objectclasses
+#
+
+import base64
+import optparse
+import os
+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
+from ldb import SCOPE_SUBTREE, SCOPE_BASE, LdbError
+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]
+ for j in v:
+ 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",
+ base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE,attrs=attrib_attrs,
+ controls=["server_sort:1:0:cn"])
+
+ 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",
+ base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE,attrs=class_attrs,
+ controls=["server_sort:1:0:cn"])
+
+ for msg in res:
+ o = Objectclass(ldb, msg["ldapDisplayName"])
+ for a in msg:
+ o[a] = msg[a]
+ write_ldif_one(o, class_attrs)
+
diff --git a/source4/scripting/bin/minschema b/source4/scripting/bin/minschema
index f2dfdcb564..c860495e96 100755
--- a/source4/scripting/bin/minschema
+++ b/source4/scripting/bin/minschema
@@ -72,7 +72,6 @@ class_attrs = ["objectClass",
"mustContain",
"auxiliaryClass",
"rDNAttID",
- "showInAdvancedViewOnly",
"adminDisplayName",
"adminDescription",
"objectClassCategory",
@@ -104,7 +103,6 @@ attrib_attrs = ["objectClass",
"rangeUpper",
"mAPIID",
"linkID",
- "showInAdvancedViewOnly",
"adminDisplayName",
"oMObjectClass",
"adminDescription",
@@ -405,40 +403,40 @@ def attribute_list(objectclass, attr1, attr2):
def aggregate_list(name, list):
"""write out a list in aggregate form"""
- if list is None:
- return
- print "%s ( %s )" % (name, "$ ".join(list))
+ if list == []:
+ return ""
+ return " %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),
+ line = "objectClasses: ( %s NAME '%s' " % (objectclass["governsID"], objectclass.name)
if not objectclass.has_key('subClassOf'):
- print "SUP %s " % objectclass['subClassOf'],
+ line += "SUP %s" % objectclass['subClassOf']
if objectclass["objectClassCategory"] == 1:
- print "STRUCTURAL ",
+ line += "STRUCTURAL"
elif objectclass["objectClassCategory"] == 2:
- print "ABSTRACT ",
+ line += "ABSTRACT"
elif objectclass["objectClassCategory"] == 3:
- print "AUXILIARY ",
+ line += "AUXILIARY"
list = attribute_list(objectclass, "systemMustContain", "mustContain")
- aggregate_list("MUST", list)
+ line += aggregate_list("MUST", list)
list = attribute_list(objectclass, "systemMayContain", "mayContain")
- aggregate_list("MAY", list)
+ line += aggregate_list("MAY", list)
- print ")"
+ print line + " )"
def write_aggregate_ditcontentrule(objectclass):
"""write the aggregate record for an ditcontentrule"""
list = attribute_list(objectclass, "auxiliaryClass", "systemAuxiliaryClass")
- if list is None:
+ if list == []:
return
- print "dITContentRules: ( %s NAME '%s' " % (objectclass["governsID"], objectclass.name)
+ line = "dITContentRules: ( %s NAME '%s'" % (objectclass["governsID"], objectclass.name)
- aggregate_list("AUX", list)
+ line += aggregate_list("AUX", list)
may_list = []
must_list = []
@@ -451,31 +449,30 @@ def write_aggregate_ditcontentrule(objectclass):
"mustContain", "systemMustContain")
must_list = must_list + list2
- aggregate_list("MUST", must_list)
- aggregate_list("MAY", may_list)
+ line += aggregate_list("MUST", must_list)
+ line += aggregate_list("MAY", may_list)
- print ")\n"
+ print line + " )"
def write_aggregate_attribute(attrib):
"""write the aggregate record for an attribute"""
- print "attributeTypes: ( %s NAME '%s' SYNTAX '%s' " % (
+ line = "attributeTypes: ( %s NAME '%s' SYNTAX '%s' " % (
attrib["attributeID"], attrib.name,
map_attribute_syntax(attrib["attributeSyntax"]))
if attrib.get('isSingleValued') == "TRUE":
- print "SINGLE-VALUE "
+ line += "SINGLE-VALUE "
if attrib.get('systemOnly') == "TRUE":
- print "NO-USER-MODIFICATION "
+ line += "NO-USER-MODIFICATION "
- print ")\n"
+ print line + ")"
def write_aggregate():
"""write the aggregate record"""
- print "dn: CN=Aggregate,${SCHEMADN}\n"
+ print "dn: CN=Aggregate,${SCHEMADN}"
print """objectClass: top
objectClass: subSchema
-objectCategory: CN=SubSchema,${SCHEMADN}
-"""
+objectCategory: CN=SubSchema,${SCHEMADN}"""
if not opts.dump_subschema_auto:
return
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index a49e6e1ead..c5827b96e0 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -54,7 +54,7 @@ class Ldb(ldb.Ldb):
functions see samdb.py.
"""
def __init__(self, url=None, session_info=None, credentials=None,
- modules_dir=None, lp=None):
+ modules_dir=None, lp=None, options=None):
"""Open a Samba Ldb file.
:param url: Optional LDB URL to open
@@ -67,7 +67,7 @@ class Ldb(ldb.Ldb):
modules-dir is used by default and that credentials and session_info
can be passed through (required by some modules).
"""
- super(Ldb, self).__init__()
+ super(Ldb, self).__init__(options=options)
if modules_dir is not None:
self.set_modules_dir(modules_dir)
@@ -90,7 +90,7 @@ class Ldb(ldb.Ldb):
#self.set_debug(msg)
if url is not None:
- self.connect(url)
+ self.connect(url, options=options)
def set_credentials(self, credentials):
glue.ldb_set_credentials(self, credentials)
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index 1e34b11d0a..64908ccb4d 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -1051,7 +1051,7 @@ def provision(setup_dir, message, session_info,
serverrole=serverrole, ldap_backend=ldap_backend,
ldap_backend_type=ldap_backend_type)
- if lp.get("server role") == "domain controller":
+ if serverrole == "domain controller":
if paths.netlogon is None:
message("Existing smb.conf does not have a [netlogon] share, but you are configuring a DC.")
message("Please either remove %s or see the template at %s" %