From 48c75bade7fe68f3fcaf075a97bcdb80b448bbb7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 10 Jan 2008 17:47:58 +0100 Subject: configure: Complain when Python is not found. (This used to be commit 6aaccdb0b38366963d5bdff444d24d6dcacc817b) --- source4/scripting/python/config.m4 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/config.m4 b/source4/scripting/python/config.m4 index 326cef8440..348f9197f7 100644 --- a/source4/scripting/python/config.m4 +++ b/source4/scripting/python/config.m4 @@ -65,8 +65,5 @@ then LIBS="$ac_save_LIBS" CFLAGS="$ac_save_CFLAGS" else - SMB_ENABLE(EXT_LIB_PYTHON,NO) - SMB_ENABLE(LIBPYTHONyy,NO) - SMB_ENABLE(smbpython,NO) - AC_MSG_RESULT([no]) + AC_MSG_ERROR([Python not found. Please install Python 2.x and its development headers/libraries.]) fi -- cgit From c61dc3849434347ca8a77f917ca6241bf4ee3174 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Feb 2008 15:42:19 +0100 Subject: Re-enable python support in BECOME-DC test. (This used to be commit ed44fd59bfa289bcef82e0650ccda381efb52268) --- source4/scripting/python/config.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/config.m4 b/source4/scripting/python/config.m4 index e4a34ece1e..3acd7321c7 100644 --- a/source4/scripting/python/config.m4 +++ b/source4/scripting/python/config.m4 @@ -66,7 +66,7 @@ if test $working_python = yes; then SMB_ENABLE(EXT_LIB_PYTHON,YES) SMB_ENABLE(smbpython,YES) SMB_ENABLE(LIBPYTHON,YES) - dnl AC_DEFINE(HAVE_WORKING_PYTHON, 1, [Whether we have working python support]) + AC_DEFINE(HAVE_WORKING_PYTHON, 1, [Whether we have working python support]) AC_MSG_RESULT([yes]) else SMB_ENABLE(EXT_LIB_PYTHON,NO) -- cgit From 2fa4c158580a1e3efea7f8d121305d16eda815cb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Feb 2008 17:37:42 +0100 Subject: Fix syntax of docstrings, set project name when generating Python API documentation. (This used to be commit 68f13d87eb034fdbc712169f2d1b1a0475751ec5) --- source4/scripting/python/config.mk | 2 +- source4/scripting/python/samba/provision.py | 6 ++---- source4/scripting/python/samba/upgrade.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk index 450da0e90a..b15e1fcda7 100644 --- a/source4/scripting/python/config.mk +++ b/source4/scripting/python/config.mk @@ -33,7 +33,7 @@ pythonmods:: $(PYTHON_DSOS) $(PYTHON_PYS) PYDOCTOR_MODULES=bin/python/ldb.py bin/python/auth.py bin/python/credentials.py bin/python/registry.py bin/python/tdb.py bin/python/security.py bin/python/events.py bin/python/net.py pydoctor:: pythonmods - LD_LIBRARY_PATH=bin/shared PYTHONPATH=bin/python pydoctor --make-html --docformat=restructuredtext --add-package scripting/python/samba/ $(addprefix --add-module , $(PYDOCTOR_MODULES)) + LD_LIBRARY_PATH=bin/shared PYTHONPATH=bin/python pydoctor --project-name=Samba --make-html --docformat=restructuredtext --add-package scripting/python/samba/ $(addprefix --add-module , $(PYDOCTOR_MODULES)) installpython:: pythonmods @$(SHELL) $(srcdir)/script/installpython.sh \ diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 7dd564fae1..4f52d36167 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -278,13 +278,12 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, Alternatively, provision() may call this, and then populate the database. :param erase: Remove the existing data present in the database. - :param :note: This will wipe the Sam Database! :note: This function always removes the local SAM LDB file. The erase - parameter controls whether to erase the existing data, which - may not be stored locally but in LDAP. + parameter controls whether to erase the existing data, which + may not be stored locally but in LDAP. """ assert session_info is not None @@ -479,7 +478,6 @@ def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, :param samdb: Sam Database handle :param setup_path: Obtain setup path - ... """ setup_add_ldif(samdb, setup_path("provision_rootdse_add.ldif"), { "SCHEMADN": schemadn, diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py index b332bb89ae..8bf75d776e 100644 --- a/source4/scripting/python/samba/upgrade.py +++ b/source4/scripting/python/samba/upgrade.py @@ -10,6 +10,7 @@ from provision import findnss, provision, FILL_DRS import grp import ldb +import time import pwd import uuid import registry @@ -162,7 +163,6 @@ def import_wins(samba4_winsdb, samba3_winsdb): :param samba3_winsdb: WINS database to import from """ version_id = 0 - import time for (name, (ttl, ips, nb_flags)) in samba3_winsdb.items(): version_id+=1 -- cgit From cf287aa831a538c9f6c95882cee382fa836756d1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Feb 2008 17:42:31 +0100 Subject: Add docstring. (This used to be commit 073ed0dd1cc8fae9eb4a2f7ff6763124917c56e8) --- source4/scripting/python/samba/tests/provision.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py index eb49f7af83..54a7782b3d 100644 --- a/source4/scripting/python/samba/tests/provision.py +++ b/source4/scripting/python/samba/tests/provision.py @@ -33,6 +33,8 @@ def setup_path(file): class ProvisionTestCase(samba.tests.TestCaseInTempDir): + """Some simple tests for individual functions in the provisioning code. + """ def test_setup_secretsdb(self): path = os.path.join(self.tempdir, "secrets.ldb") ldb = setup_secretsdb(path, setup_path, None, None, lp=lp) -- cgit From 1342b265caa91bcd12ce608e3821c4e355ce1577 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Feb 2008 20:09:58 +0100 Subject: Fix typo. (This used to be commit 80dbf04266d15833f7eb18704cfece1f95965e83) --- source4/scripting/python/config.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/config.m4 b/source4/scripting/python/config.m4 index 3acd7321c7..77cabdfcb3 100644 --- a/source4/scripting/python/config.m4 +++ b/source4/scripting/python/config.m4 @@ -70,7 +70,7 @@ if test $working_python = yes; then AC_MSG_RESULT([yes]) else SMB_ENABLE(EXT_LIB_PYTHON,NO) - SMB_ENABLE(LIBPYTHONyy,NO) + SMB_ENABLE(LIBPYTHON,NO) SMB_ENABLE(smbpython,NO) AC_MSG_RESULT([no]) fi -- cgit From 63aa4b902144873243e37eb7d7ce91d30b886abc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Feb 2008 20:47:12 +0100 Subject: Remove unused define. (This used to be commit 64d6d729135e1b3b19c9bdbbe973fcdaca15e8b3) --- source4/scripting/python/config.m4 | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/config.m4 b/source4/scripting/python/config.m4 index 1f03ec8e34..908efd1588 100644 --- a/source4/scripting/python/config.m4 +++ b/source4/scripting/python/config.m4 @@ -66,7 +66,6 @@ if test $working_python = yes; then SMB_ENABLE(EXT_LIB_PYTHON,YES) SMB_ENABLE(smbpython,YES) SMB_ENABLE(LIBPYTHON,YES) - AC_DEFINE(HAVE_WORKING_PYTHON, 1, [Whether we have working python support]) AC_MSG_RESULT([yes]) else AC_MSG_ERROR([Python not found. Please install Python 2.x and its development headers/libraries.]) -- cgit From 2cf29aebff0dc821487e60ce86c18c6bbf1be866 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Feb 2008 22:29:42 +0100 Subject: Add tests for upgrade of WINS database. (This used to be commit 7777611c0f32a693f0fa057c130e4ea491658f6b) --- source4/scripting/python/samba/tests/upgrade.py | 19 +++++++++++++++++-- source4/scripting/python/samba/upgrade.py | 4 +++- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/tests/upgrade.py b/source4/scripting/python/samba/tests/upgrade.py index ddafa00691..4dc86ace8a 100644 --- a/source4/scripting/python/samba/tests/upgrade.py +++ b/source4/scripting/python/samba/tests/upgrade.py @@ -17,6 +17,21 @@ # along with this program. If not, see . # -import samba.upgrade -from unittest import TestCase +from samba import Ldb +from samba.upgrade import import_wins +from samba.tests import LdbTestCase +class WinsUpgradeTests(LdbTestCase): + def test_upgrade(self): + winsdb = { + "FOO#20": (200, ["127.0.0.1", "127.0.0.2"], 0x60) + } + import_wins(self.ldb, winsdb) + + self.assertEquals(['name=FOO,type=0x20'], + [str(m.dn) for m in self.ldb.search(expression="(objectClass=winsRecord)")]) + + def test_version(self): + import_wins(self.ldb, {}) + self.assertEquals("VERSION", + self.ldb.search(expression="(objectClass=winsMaxVersion)")[0]["cn"]) diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py index 8bf75d776e..01b62ff984 100644 --- a/source4/scripting/python/samba/upgrade.py +++ b/source4/scripting/python/samba/upgrade.py @@ -18,6 +18,7 @@ from samba import Ldb from samba.samdb import SamDB def import_sam_policy(samldb, samba3_policy, domaindn): + """Import a Samba 3 policy database.""" samldb.modify_ldif(""" dn: %s changetype: modify @@ -201,7 +202,8 @@ def import_wins(samba4_winsdb, samba3_winsdb): "versionID": str(version_id), "address": ips}) - samba4_winsdb.add({"dn": "CN=VERSION", + samba4_winsdb.add({"dn": "cn=VERSION", + "cn": "VERSION", "objectClass": "winsMaxVersion", "maxVersion": str(version_id)}) -- cgit From f75d6241291eaa079d01e658efd7d00a60584830 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 10 Feb 2008 00:21:41 +0100 Subject: Start working on python conversion of minschema. (This used to be commit 239a1616644321e2d1e64985ea3f3c4971997228) --- source4/scripting/bin/minschema.py | 660 +++++++++++++++++++++++++++++++++++++ 1 file changed, 660 insertions(+) create mode 100755 source4/scripting/bin/minschema.py (limited to 'source4/scripting') diff --git a/source4/scripting/bin/minschema.py b/source4/scripting/bin/minschema.py new file mode 100755 index 0000000000..0a16cc9886 --- /dev/null +++ b/source4/scripting/bin/minschema.py @@ -0,0 +1,660 @@ +#!/usr/bin/python +# +# work out the minimal schema for a set of objectclasses +# + +import getopt +import optparse +import samba + +parser = optparse.OptionParser("minschema ") +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 +if dump_subschema_auto: + opts.dump_all = False + opts.dump_subschema = True +if opts.dump_all: + opts.dump_classes = True + opts.dump_attributes = True + opts.dump_subschema = True + opts.dump_subschema_auto = True + +if len(args) != 2: + parser.print_usage() + sys.exit(1) + +(url, classfile) = args + +creds = credopts.get_credentials() +ldb = Ldb(url, credentials=creds) + +objectclasses = [] +attributes = [] +rootDse = {} + +objectclasses_expanded = [] + +# the attributes we need for objectclasses +class_attrs = ["objectClass", + "subClassOf", + "governsID", + "possSuperiors", + "possibleInferiors", + "mayContain", + "mustContain", + "auxiliaryClass", + "rDNAttID", + "showInAdvancedViewOnly", + "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", + "showInAdvancedViewOnly", + "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 + +# +# print only if verbose is set +# +def dprintf(text): + if verbose is not None: + print text + +def get_object_cn(ldb, name): + attrs = ["cn"] + + res = ldb.search("(ldapDisplayName=%s)" % name, rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) + assert len(res) == 1 + + cn = res[0]["cn"] + +# +# create an objectclass object +# +def obj_objectClass(ldb, name): + var o = new Object() + o.name = name + o.cn = get_object_cn(ldb, name) + return o + +# +# create an attribute object +# +def obj_attribute(ldb, name): + var o = new Object() + o.name = name + o.cn = get_object_cn(ldb, name) + return o + + +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' + +# +# map some attribute syntaxes from some apparently MS specific +# syntaxes to the standard syntaxes +# +def map_attribute_syntax(s): + if syntaxmap.has_key(s): + return syntaxmap[s] + return s + +# +# fix a string DN to use ${SCHEMADN} +# +def fix_dn(dn): + s = strstr(dn, rootDse.schemaNamingContext) + if (s == NULL) { + return dn + } + return substr(dn, 0, strlen(dn) - strlen(s)) + "${SCHEMADN}" + +# +# dump an object as ldif +# +def write_ldif_one(o, attrs): + print "dn: CN=%s,${SCHEMADN}\n" % o["cn"] + for a in attrs: + if not o.has_key(a): + continue + # special case for oMObjectClass, which is a binary object + if a == "oMObjectClass": + print "%s:: %s\n" % (a, o[a]) + continue + v = o[a] + if isinstance(v, str): + v = [v] + for j in v: + print "%s: %s\n" % (a, fix_dn(j)) + print "\n" + +# +# dump an array of objects as ldif +# +def write_ldif(o, attrs): + for i in o: + write_ldif_one(i, attrs) + + +# +# create a testDN based an an example DN +# the idea is to ensure we obey any structural rules +# +def create_testdn(exampleDN): + a = split(",", exampleDN) + a[0] = "CN=TestDN" + return ",".join(a) + +# +# find the properties of an objectclass +# +def find_objectclass_properties(ldb, o): + res = ldb.search( + expression="(ldapDisplayName=%s)" % o.name, + rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, class_attrs) + assert(len(res) == 1) + msg = res[0] + for a in msg: + o[a] = msg[a] + +# +# find the properties of an attribute +# +def find_attribute_properties(ldb, o): + res = ldb.search( + expression="(ldapDisplayName=%s)" % o.name, + rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrib_attrs) + assert(len(res) == 1) + msg = res[0] + for a in msg: + # special case for oMObjectClass, which is a binary object + if a == "oMObjectClass": + o[a] = ldb.encode(msg[a]) + continue + o[a] = msg[a] + +# +# find the auto-created properties of an objectclass. Only works for classes +# that can be created using just a DN and the objectclass +# +def find_objectclass_auto(ldb, o): + if not o.has_key("exampleDN"): + return + testdn = create_testdn(o.exampleDN) + + print "testdn is '%s'\n" % testdn + + ldif = "dn: " + testdn + ldif += "\nobjectClass: " + o.name + try: + ldb.add(ldif) + except LdbError, e: + print "error adding %s: %s\n" % (o.name, e) + print "%s\n" % ldif + return + + res = ldb.search("", testdn, ldb.SCOPE_BASE) + ldb.delete(testdn) + + for a in res.msgs[0]: + attributes[a].autocreate = True + + +# +# look at auxiliary information from a class to intuit the existance of more +# classes needed for a minimal schema +# +def expand_objectclass(ldb, o): + attrs = ["auxiliaryClass", "systemAuxiliaryClass", + "possSuperiors", "systemPossSuperiors", + "subClassOf"] + res = ldb.search( + "(&(objectClass=classSchema)(ldapDisplayName=%s))" % o.name, + rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) + print "Expanding class %s\n" % o.name + assert(len(res) == 1) + msg = res[0] + for a in attrs: + if not msg.has_key(aname): + continue + list = msg[aname] + if isinstance(list, str): + list = [msg[aname]] + for name in list: + if not objectclasses.has_key(name): + print "Found new objectclass '%s'\n" % name + objectclasses[name] = obj_objectClass(ldb, name) + + +# +# add the must and may attributes from an objectclass to the full list +# of attributes +# +def add_objectclass_attributes(ldb, class): + attrs = ["mustContain", "systemMustContain", + "mayContain", "systemMayContain"] + for aname in attrs: + if not class.has_key(aname): + continue + alist = class[aname] + if isinstance(alist, str): + alist = [alist] + for a in alist: + if not attributes.has_key(a): + attributes[a] = obj_attribute(ldb, a) + + +# +# process an individual record, working out what attributes it has +# +def walk_dn(ldb, dn): + # get a list of all possible attributes for this object + attrs = ["allowedAttributes"] + try: + res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, attrs) + except LdbError, e: + print "Unable to fetch allowedAttributes for '%s' - %r\n" % (dn, e) + return + allattrs = res[0]["allowedAttributes"] + try: + res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, allattrs) + except LdbError, e: + print "Unable to fetch all attributes for '%s' - %s\n" % (dn, e) + return + msg = res[0] + for a in msg: + if not attributes.has_key(a): + attributes[a] = obj_attribute(ldb, a) + +# +# walk a naming context, looking for all records +# +def walk_naming_context(ldb, namingContext): + try: + res = ldb.search("objectClass=*", namingContext, ldb.SCOPE_DEFAULT, + ["objectClass"]) + except LdbError, e: + print "Unable to fetch objectClasses for '%s' - %s\n" % (namingContext, e) + return + for msg in res: + msg = res.msgs[r]["objectClass"] + for objectClass in msg: + if not objectclasses.has_key(objectClass): + objectclasses[objectClass] = obj_objectClass(ldb, objectClass) + objectclasses[objectClass].exampleDN = res.msgs[r]["dn"] + walk_dn(ldb, res.msgs[r].dn) + +# +# trim the may attributes for an objectClass +# +def trim_objectclass_attributes(ldb, class): + # trim possibleInferiors, + # include only the classes we extracted + if class.has_key("possibleInferiors"): + possinf = class["possibleInferiors"] + newpossinf = [] + if isinstance(possinf, str): + possinf = [possinf] + for x in possinf: + if objectclasses.has_key(x): + newpossinf[n] = x + n++ + class["possibleInferiors"] = newpossinf + + # trim systemMayContain, + # remove duplicates + if class.has_key("systemMayContain"): + sysmay = class["systemMayContain"] + newsysmay = [] + if isinstance(sysmay, str): + sysmay = [sysmay] + for x in sysmay: + dup = False + if newsysmay[0] == undefined) { + newsysmay[0] = x + else: + for (n = 0; n < newsysmay.length; n++) { + if (newsysmay[n] == x) { + dup = True + if not dup: + newsysmay[n] = x + class["systemMayContain"] = newsysmay + + # trim mayContain, + # remove duplicates + if not class.has_key("mayContain"): + may = class["mayContain"] + newmay = [] + if isinstance(may, str): + may = [may] + for x in may: + dup = False + if (newmay[0] == undefined) { + newmay[0] = x + } else { + for (n = 0; n < newmay.length; n++) { + if (newmay[n] == x) { + dup = True + if not dup: + newmay[n] = x + class["mayContain"] = newmay + +# +# load the basic attributes of an objectClass +# +def build_objectclass(ldb, name): + attrs = ["name"] + try: + res = ldb.search( + expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % name, + rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) + except LdbError, e: + print "unknown class '%s'\n" % name + return None + if len(res) == 0: + print "unknown class '%s'\n" % name + return None + return obj_objectClass(ldb, name) + +# +# append 2 lists +# +def list_append(a1, a2): + if (a1 == undefined) { + return a2 + if (a2 == undefined) + return a1 + for (i=0;i Date: Sun, 10 Feb 2008 00:56:55 +0100 Subject: More syntax fixes, use more standard python functions. (This used to be commit ea07509b4a9335a3b3fe6f6da1124fd1aab33c96) --- source4/scripting/bin/minschema.py | 575 ++++++++++++++++--------------------- 1 file changed, 247 insertions(+), 328 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/bin/minschema.py b/source4/scripting/bin/minschema.py index 0a16cc9886..fb9d7b05aa 100755 --- a/source4/scripting/bin/minschema.py +++ b/source4/scripting/bin/minschema.py @@ -3,9 +3,10 @@ # work out the minimal schema for a set of objectclasses # -import getopt import optparse import samba +from samba import getopt as options +import sys parser = optparse.OptionParser("minschema ") sambaopts = options.SambaOptions(parser) @@ -28,14 +29,14 @@ if opts.dump_attributes: opts.dump_all = False if opts.dump_subschema: opts.dump_all = False -if dump_subschema_auto: - opts.dump_all = False - opts.dump_subschema = True +if opts.dump_subschema_auto: + opts.dump_all = False + opts.dump_subschema = True if opts.dump_all: - opts.dump_classes = True - opts.dump_attributes = True - opts.dump_subschema = True - opts.dump_subschema_auto = True + opts.dump_classes = True + opts.dump_attributes = True + opts.dump_subschema = True + opts.dump_subschema_auto = True if len(args) != 2: parser.print_usage() @@ -48,9 +49,8 @@ ldb = Ldb(url, credentials=creds) objectclasses = [] attributes = [] -rootDse = {} -objectclasses_expanded = [] +objectclasses_expanded = set() # the attributes we need for objectclasses class_attrs = ["objectClass", @@ -130,33 +130,28 @@ attrib_attrs = ["objectClass", # def dprintf(text): if verbose is not None: - print text + print text def get_object_cn(ldb, name): - attrs = ["cn"] + attrs = ["cn"] - res = ldb.search("(ldapDisplayName=%s)" % name, rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) - assert len(res) == 1 + res = ldb.search("(ldapDisplayName=%s)" % name, rootDse["schemaNamingContext"], ldb.SCOPE_SUBTREE, attrs) + assert len(res) == 1 - cn = res[0]["cn"] + return res[0]["cn"] -# -# create an objectclass object -# -def obj_objectClass(ldb, name): - var o = new Object() - o.name = name - o.cn = get_object_cn(ldb, name) - return o +class Objectclass: + def __init__(self, ldb, name): + """create an objectclass object""" + self.name = name + self.cn = get_object_cn(ldb, name) -# -# create an attribute object -# -def obj_attribute(ldb, name): - var o = new Object() - o.name = name - o.cn = get_object_cn(ldb, name) - return o + +class Attribute: + def __init__(self, ldb, name): + """create an attribute object""" + self.name = name + self.cn = get_object_cn(ldb, name) syntaxmap = dict() @@ -179,397 +174,330 @@ 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' -# -# map some attribute syntaxes from some apparently MS specific -# syntaxes to the standard syntaxes -# + def map_attribute_syntax(s): + """map some attribute syntaxes from some apparently MS specific + syntaxes to the standard syntaxes""" if syntaxmap.has_key(s): - return syntaxmap[s] - return s + return syntaxmap[s] + return s + -# -# fix a string DN to use ${SCHEMADN} -# def fix_dn(dn): - s = strstr(dn, rootDse.schemaNamingContext) - if (s == NULL) { - return dn - } - return substr(dn, 0, strlen(dn) - strlen(s)) + "${SCHEMADN}" + """fix a string DN to use ${SCHEMADN}""" + return dn.replace(rootDse["schemaNamingContext"], "${SCHEMADN}") + -# -# dump an object as ldif -# def write_ldif_one(o, attrs): - print "dn: CN=%s,${SCHEMADN}\n" % o["cn"] + """dump an object as ldif""" + print "dn: CN=%s,${SCHEMADN}\n" % o["cn"] for a in attrs: if not o.has_key(a): - continue - # special case for oMObjectClass, which is a binary object + continue + # special case for oMObjectClass, which is a binary object if a == "oMObjectClass": - print "%s:: %s\n" % (a, o[a]) - continue - v = o[a] + print "%s:: %s\n" % (a, o[a]) + continue + v = o[a] if isinstance(v, str): - v = [v] + v = [v] for j in v: - print "%s: %s\n" % (a, fix_dn(j)) - print "\n" + print "%s: %s\n" % (a, fix_dn(j)) + print "\n" -# -# dump an array of objects as ldif -# def write_ldif(o, attrs): + """dump an array of objects as ldif""" for i in o: - write_ldif_one(i, attrs) + write_ldif_one(i, attrs) -# -# create a testDN based an an example DN -# the idea is to ensure we obey any structural rules -# def create_testdn(exampleDN): - a = split(",", exampleDN) - a[0] = "CN=TestDN" - return ",".join(a) + """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) + -# -# find the properties of an objectclass -# def find_objectclass_properties(ldb, o): - res = ldb.search( - expression="(ldapDisplayName=%s)" % o.name, - rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, class_attrs) - assert(len(res) == 1) + """the properties of an objectclass""" + res = ldb.search( + expression="(ldapDisplayName=%s)" % o.name, + basedn=rootDse["schemaNamingContext"], scope=ldb.SCOPE_SUBTREE, attrs=class_attrs) + assert(len(res) == 1) msg = res[0] for a in msg: - o[a] = msg[a] + o[a] = msg[a] -# -# find the properties of an attribute -# def find_attribute_properties(ldb, o): - res = ldb.search( - expression="(ldapDisplayName=%s)" % o.name, - rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrib_attrs) - assert(len(res) == 1) + """find the properties of an attribute""" + res = ldb.search( + expression="(ldapDisplayName=%s)" % o.name, + basedn=rootDse["schemaNamingContext"], scope=ldb.SCOPE_SUBTREE, + attrs=attrib_attrs) + assert(len(res) == 1) msg = res[0] for a in msg: - # special case for oMObjectClass, which is a binary object + # special case for oMObjectClass, which is a binary object if a == "oMObjectClass": - o[a] = ldb.encode(msg[a]) - continue - o[a] = msg[a] + o[a] = ldb.encode(msg[a]) + continue + o[a] = msg[a] + -# -# find the auto-created properties of an objectclass. Only works for classes -# that can be created using just a DN and the objectclass -# def find_objectclass_auto(ldb, o): + """find the auto-created properties of an objectclass. Only works for + classes that can be created using just a DN and the objectclass""" if not o.has_key("exampleDN"): - return - testdn = create_testdn(o.exampleDN) + return + testdn = create_testdn(o.exampleDN) - print "testdn is '%s'\n" % testdn + print "testdn is '%s'\n" % testdn - ldif = "dn: " + testdn - ldif += "\nobjectClass: " + o.name + ldif = "dn: " + testdn + ldif += "\nobjectClass: " + o.name try: ldb.add(ldif) except LdbError, e: print "error adding %s: %s\n" % (o.name, e) - print "%s\n" % ldif + print "%s\n" % ldif return - res = ldb.search("", testdn, ldb.SCOPE_BASE) - ldb.delete(testdn) + res = ldb.search("", testdn, ldb.SCOPE_BASE) + ldb.delete(testdn) for a in res.msgs[0]: - attributes[a].autocreate = True + attributes[a].autocreate = True -# -# look at auxiliary information from a class to intuit the existance of more -# classes needed for a minimal schema -# def expand_objectclass(ldb, o): - attrs = ["auxiliaryClass", "systemAuxiliaryClass", - "possSuperiors", "systemPossSuperiors", - "subClassOf"] - res = ldb.search( - "(&(objectClass=classSchema)(ldapDisplayName=%s))" % o.name, - rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) - print "Expanding class %s\n" % o.name - assert(len(res) == 1) - msg = res[0] + """look at auxiliary information from a class to intuit the existance of + more classes needed for a minimal schema""" + attrs = ["auxiliaryClass", "systemAuxiliaryClass", + "possSuperiors", "systemPossSuperiors", + "subClassOf"] + res = ldb.search( + expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % o.name, + basedn=rootDse["schemaNamingContext"], scope=ldb.SCOPE_SUBTREE, + attrs=attrs) + print "Expanding class %s\n" % o.name + assert(len(res) == 1) + msg = res[0] for a in attrs: if not msg.has_key(aname): - continue - list = msg[aname] + continue + list = msg[aname] if isinstance(list, str): - list = [msg[aname]] + list = [msg[aname]] for name in list: if not objectclasses.has_key(name): - print "Found new objectclass '%s'\n" % name - objectclasses[name] = obj_objectClass(ldb, name) + print "Found new objectclass '%s'\n" % name + objectclasses[name] = Objectclass(ldb, name) -# -# add the must and may attributes from an objectclass to the full list -# of attributes -# -def add_objectclass_attributes(ldb, class): - attrs = ["mustContain", "systemMustContain", - "mayContain", "systemMayContain"] +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"] for aname in attrs: - if not class.has_key(aname): - continue - alist = class[aname] + if not objectclass.has_key(aname): + continue + alist = objectclass[aname] if isinstance(alist, str): - alist = [alist] + alist = [alist] for a in alist: if not attributes.has_key(a): - attributes[a] = obj_attribute(ldb, a) + attributes[a] = Attribute(ldb, a) -# -# process an individual record, working out what attributes it has -# def walk_dn(ldb, dn): - # get a list of all possible attributes for this object - attrs = ["allowedAttributes"] + """process an individual record, working out what attributes it has""" + # get a list of all possible attributes for this object + attrs = ["allowedAttributes"] try: res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, attrs) except LdbError, e: - print "Unable to fetch allowedAttributes for '%s' - %r\n" % (dn, e) - return - allattrs = res[0]["allowedAttributes"] + print "Unable to fetch allowedAttributes for '%s' - %r\n" % (dn, e) + return + allattrs = res[0]["allowedAttributes"] try: res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, allattrs) except LdbError, e: print "Unable to fetch all attributes for '%s' - %s\n" % (dn, e) - return - msg = res[0] + return + msg = res[0] for a in msg: if not attributes.has_key(a): - attributes[a] = obj_attribute(ldb, a) + attributes[a] = Attribute(ldb, a) -# -# walk a naming context, looking for all records -# def walk_naming_context(ldb, namingContext): + """walk a naming context, looking for all records""" try: res = ldb.search("objectClass=*", namingContext, ldb.SCOPE_DEFAULT, ["objectClass"]) except LdbError, e: - print "Unable to fetch objectClasses for '%s' - %s\n" % (namingContext, e) - return + print "Unable to fetch objectClasses for '%s' - %s\n" % (namingContext, e) + return for msg in res: - msg = res.msgs[r]["objectClass"] + msg = res.msgs[r]["objectClass"] for objectClass in msg: if not objectclasses.has_key(objectClass): - objectclasses[objectClass] = obj_objectClass(ldb, objectClass) - objectclasses[objectClass].exampleDN = res.msgs[r]["dn"] - walk_dn(ldb, res.msgs[r].dn) - -# -# trim the may attributes for an objectClass -# -def trim_objectclass_attributes(ldb, class): - # trim possibleInferiors, - # include only the classes we extracted - if class.has_key("possibleInferiors"): - possinf = class["possibleInferiors"] - newpossinf = [] + 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 = [] if isinstance(possinf, str): - possinf = [possinf] + possinf = [possinf] for x in possinf: if objectclasses.has_key(x): - newpossinf[n] = x - n++ - class["possibleInferiors"] = newpossinf - - # trim systemMayContain, - # remove duplicates - if class.has_key("systemMayContain"): - sysmay = class["systemMayContain"] - newsysmay = [] + newpossinf[n] = x + n+=1 + objectclass["possibleInferiors"] = newpossinf + + # trim systemMayContain, + # remove duplicates + if objectclass.has_key("systemMayContain"): + sysmay = objectclass["systemMayContain"] + newsysmay = [] if isinstance(sysmay, str): - sysmay = [sysmay] + sysmay = [sysmay] for x in sysmay: - dup = False - if newsysmay[0] == undefined) { - newsysmay[0] = x - else: - for (n = 0; n < newsysmay.length; n++) { - if (newsysmay[n] == x) { - dup = True - if not dup: - newsysmay[n] = x - class["systemMayContain"] = newsysmay - - # trim mayContain, - # remove duplicates - if not class.has_key("mayContain"): - may = class["mayContain"] - newmay = [] + if not x in newsysmay: + newsysmay.append(x) + objectclass["systemMayContain"] = newsysmay + + # trim mayContain, + # remove duplicates + if not objectclass.has_key("mayContain"): + may = objectclass["mayContain"] + newmay = [] if isinstance(may, str): - may = [may] + may = [may] for x in may: - dup = False - if (newmay[0] == undefined) { - newmay[0] = x - } else { - for (n = 0; n < newmay.length; n++) { - if (newmay[n] == x) { - dup = True - if not dup: - newmay[n] = x - class["mayContain"] = newmay + if not x in newmay: + newmay.append(x) + objectclass["mayContain"] = newmay -# -# load the basic attributes of an objectClass -# def build_objectclass(ldb, name): - attrs = ["name"] + """load the basic attributes of an objectClass""" + attrs = ["name"] try: res = ldb.search( expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % name, - rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) + basedn=rootDse["schemaNamingContext"], scope=ldb.SCOPE_SUBTREE, + attrs=attrs) except LdbError, e: - print "unknown class '%s'\n" % name - return None + print "unknown class '%s'\n" % name + return None if len(res) == 0: - print "unknown class '%s'\n" % name - return None - return obj_objectClass(ldb, name) - -# -# append 2 lists -# -def list_append(a1, a2): - if (a1 == undefined) { - return a2 - if (a2 == undefined) - return a1 - for (i=0;i Date: Mon, 11 Feb 2008 10:37:26 +0100 Subject: provision: Fix new user creation. Spotted by nobody88 in IRC. (This used to be commit 38d4e2407afb942de21379dc886f9e4c5532a2b9) --- source4/scripting/libjs/provision.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js index e71498010c..dc9eae8e72 100644 --- a/source4/scripting/libjs/provision.js +++ b/source4/scripting/libjs/provision.js @@ -1124,7 +1124,7 @@ unixName: %s sambaPassword: %s objectClass: user ", - user_dn, username, dom_users, + user_dn, username, unixname, password); /* add the user to the users group as well @@ -1134,7 +1134,7 @@ dn: %s changetype: modify add: member member: %s -", +", dom_users, user_dn); -- cgit From af007e5837ac472f0527505c8013b837932136bc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 11 Feb 2008 13:20:24 +0100 Subject: Use SMB_CONF_PATH environment variable inside tests rather than hardcoded paths. (This used to be commit eb04de69c0e319e18b148191946808f81e1cc8c4) --- source4/scripting/python/samba/tests/__init__.py | 6 ++++++ source4/scripting/python/samba/tests/dcerpc/registry.py | 4 ++-- source4/scripting/python/samba/tests/dcerpc/rpcecho.py | 5 ++--- source4/scripting/python/samba/tests/dcerpc/sam.py | 3 ++- source4/scripting/python/samba/tests/provision.py | 3 +-- 5 files changed, 13 insertions(+), 8 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py index 9402002674..c8673d3fae 100644 --- a/source4/scripting/python/samba/tests/__init__.py +++ b/source4/scripting/python/samba/tests/__init__.py @@ -84,3 +84,9 @@ class LdbExtensionTests(TestCaseInTempDir): del l os.unlink(path) + +def get_loadparm(): + import param + lp = param.LoadParm() + lp.load(os.getenv("SMB_CONF_PATH")) + return lp diff --git a/source4/scripting/python/samba/tests/dcerpc/registry.py b/source4/scripting/python/samba/tests/dcerpc/registry.py index f3f0b0fb1a..147acc5098 100644 --- a/source4/scripting/python/samba/tests/dcerpc/registry.py +++ b/source4/scripting/python/samba/tests/dcerpc/registry.py @@ -20,11 +20,11 @@ import winreg from param import LoadParm import unittest +from samba.tests import get_loadparm class WinregTests(unittest.TestCase): def setUp(self): - lp_ctx = LoadParm() - lp_ctx.load("st/client/client.conf") + lp_ctx = get_loadparm() self.conn = winreg.winreg("ncalrpc:", lp_ctx) def get_hklm(self): diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py index 52c2bb8c72..8c1a8bec71 100644 --- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py +++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py @@ -18,13 +18,12 @@ # import echo -from param import LoadParm import unittest +from samba.tests import get_loadparm class RpcEchoTests(unittest.TestCase): def setUp(self): - lp_ctx = LoadParm() - lp_ctx.load("st/client/client.conf") + lp_ctx = get_loadparm() self.conn = echo.rpcecho("ncalrpc:", lp_ctx) def test_addone(self): diff --git a/source4/scripting/python/samba/tests/dcerpc/sam.py b/source4/scripting/python/samba/tests/dcerpc/sam.py index 50caaf2348..96348f2f69 100644 --- a/source4/scripting/python/samba/tests/dcerpc/sam.py +++ b/source4/scripting/python/samba/tests/dcerpc/sam.py @@ -19,10 +19,11 @@ import samr import unittest +from samba.tests import get_loadparm class SamrTests(unittest.TestCase): def setUp(self): - self.conn = samr.samr("ncalrpc:", "st/client/client.conf") + self.conn = samr.samr("ncalrpc:", get_loadparm()) def test_connect5(self): (level, info, handle) = self.conn.Connect5(None, 0, 1, samr.ConnectInfo1()) diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py index 54a7782b3d..514582cbe4 100644 --- a/source4/scripting/python/samba/tests/provision.py +++ b/source4/scripting/python/samba/tests/provision.py @@ -24,8 +24,7 @@ from ldb import Dn import param import unittest -lp = param.LoadParm() -lp.load("st/dc/etc/smb.conf") +lp = samba.tests.get_loadparm() setup_dir = "setup" def setup_path(file): -- cgit From 08c8d3b992d419db7b39a91fb42208beb5d273ba Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 11 Feb 2008 13:51:09 +0100 Subject: Remove Samba 3 backwards compatibility code in C. This code is no longer used, and equivalent code already exists in Python (scripting/python/samba/samba3.py) (This used to be commit c16212e8bf5343496ea4b3afc30a8b4d3a0afe2d) --- source4/scripting/ejs/config.mk | 7 - source4/scripting/ejs/smbcalls_samba3.c | 501 -------------------------------- 2 files changed, 508 deletions(-) delete mode 100644 source4/scripting/ejs/smbcalls_samba3.c (limited to 'source4/scripting') diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index 656ecdae16..5de17263b7 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -28,13 +28,6 @@ SUBSYSTEM = smbcalls OUTPUT_TYPE = INTEGRATED INIT_FUNCTION = smb_setup_ejs_nbt -[MODULE::smbcalls_samba3] -OBJ_FILES = smbcalls_samba3.o -SUBSYSTEM = smbcalls -OUTPUT_TYPE = INTEGRATED -INIT_FUNCTION = smb_setup_ejs_samba3 -PRIVATE_DEPENDENCIES = LIBSAMBA3 - [MODULE::smbcalls_rand] OBJ_FILES = smbcalls_rand.o SUBSYSTEM = smbcalls diff --git a/source4/scripting/ejs/smbcalls_samba3.c b/source4/scripting/ejs/smbcalls_samba3.c deleted file mode 100644 index 36ec2a54e4..0000000000 --- a/source4/scripting/ejs/smbcalls_samba3.c +++ /dev/null @@ -1,501 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks into smbd C calls from ejs scripts - - Copyright (C) Jelmer Vernooij 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "lib/samba3/samba3.h" -#include "libcli/security/security.h" -#include "librpc/gen_ndr/ndr_misc.h" -#include "system/network.h" - - -static struct MprVar mprRegistry(struct samba3_regdb *reg) -{ - struct MprVar mpv = mprObject("registry"), ks, vs, k, v; - int i, j; - - ks = mprArray("array"); - - for (i = 0; i < reg->key_count; i++) { - k = mprObject("regkey"); - - mprSetVar(&k, "name", mprString(reg->keys[i].name)); - - vs = mprArray("array"); - - for (j = 0; j < reg->keys[i].value_count; j++) { - v = mprObject("regval"); - - mprSetVar(&v, "name", mprString(reg->keys[i].values[j].name)); - mprSetVar(&v, "type", mprCreateIntegerVar(reg->keys[i].values[j].type)); - mprSetVar(&v, "data", mprDataBlob(reg->keys[i].values[j].data)); - - mprAddArray(&vs, j, v); - } - - mprSetVar(&k, "values", vs); - - mprAddArray(&ks, i, k); - } - - if (i == 0) { - mprSetVar(&ks, "length", mprCreateIntegerVar(i)); - } - - mprSetVar(&mpv, "keys", ks); - - return mpv; -} - -static struct MprVar mprPolicy(struct samba3_policy *pol) -{ - struct MprVar mpv = mprObject("policy"); - - mprSetVar(&mpv, "min_password_length", mprCreateIntegerVar(pol->min_password_length)); - mprSetVar(&mpv, "password_history", mprCreateIntegerVar(pol->password_history)); - mprSetVar(&mpv, "user_must_logon_to_change_password", mprCreateIntegerVar(pol->user_must_logon_to_change_password)); - mprSetVar(&mpv, "maximum_password_age", mprCreateIntegerVar(pol->maximum_password_age)); - mprSetVar(&mpv, "minimum_password_age", mprCreateIntegerVar(pol->minimum_password_age)); - mprSetVar(&mpv, "lockout_duration", mprCreateIntegerVar(pol->lockout_duration)); - mprSetVar(&mpv, "reset_count_minutes", mprCreateIntegerVar(pol->reset_count_minutes)); - mprSetVar(&mpv, "bad_lockout_minutes", mprCreateIntegerVar(pol->bad_lockout_minutes)); - mprSetVar(&mpv, "disconnect_time", mprCreateIntegerVar(pol->disconnect_time)); - mprSetVar(&mpv, "refuse_machine_password_change", mprCreateIntegerVar(pol->refuse_machine_password_change)); - - return mpv; -} - -static struct MprVar mprIdmapDb(struct samba3_idmapdb *db) -{ - struct MprVar mpv = mprObject("idmapdb"), mps, mp; - int i; - - mprSetVar(&mpv, "user_hwm", mprCreateIntegerVar(db->user_hwm)); - mprSetVar(&mpv, "group_hwm", mprCreateIntegerVar(db->group_hwm)); - - mps = mprArray("array"); - - for (i = 0; i < db->mapping_count; i++) { - char *tmp; - mp = mprObject("idmap"); - - mprSetVar(&mp, "IDMAP_GROUP", mprCreateIntegerVar(IDMAP_GROUP)); - mprSetVar(&mp, "IDMAP_USER", mprCreateIntegerVar(IDMAP_USER)); - mprSetVar(&mp, "type", mprCreateIntegerVar(db->mappings[i].type)); - mprSetVar(&mp, "unix_id", mprCreateIntegerVar(db->mappings[i].unix_id)); - - tmp = dom_sid_string(NULL, db->mappings[i].sid); - mprSetVar(&mp, "sid", mprString(tmp)); - talloc_free(tmp); - - mprAddArray(&mps, i, mp); - } - - if (i == 0) { - mprSetVar(&mpv, "length", mprCreateIntegerVar(i)); - } - - - mprSetVar(&mpv, "mappings", mps); - - return mpv; -} - -static struct MprVar mprGroupMappings(struct samba3_groupdb *db) -{ - struct MprVar mpv = mprArray("array"), g; - int i; - - for (i = 0; i < db->groupmap_count; i++) { - char *tmp; - g = mprObject("group"); - - mprSetVar(&g, "gid", mprCreateIntegerVar(db->groupmappings[i].gid)); - - tmp = dom_sid_string(NULL, db->groupmappings[i].sid); - mprSetVar(&g, "sid", mprString(tmp)); - talloc_free(tmp); - - mprSetVar(&g, "sid_name_use", mprCreateIntegerVar(db->groupmappings[i].sid_name_use)); - mprSetVar(&g, "nt_name", mprString(db->groupmappings[i].nt_name)); - mprSetVar(&g, "comment", mprString(db->groupmappings[i].comment)); - - mprAddArray(&mpv, i, g); - } - - if (i == 0) { - mprSetVar(&mpv, "length", mprCreateIntegerVar(i)); - } - - - return mpv; -} - -static struct MprVar mprAliases(struct samba3_groupdb *db) -{ - struct MprVar mpv = mprObject("array"), a, am; - int i, j; - - for (i = 0; i < db->alias_count; i++) { - char *tmp; - a = mprObject("alias"); - - tmp = dom_sid_string(NULL, db->aliases[i].sid); - mprSetVar(&a, "sid", mprString(tmp)); - talloc_free(tmp); - - am = mprArray("array"); - - for (j = 0; j < db->aliases[i].member_count; j++) { - tmp = dom_sid_string(NULL, db->aliases[i].members[j]); - mprAddArray(&am, j, mprString(tmp)); - talloc_free(tmp); - } - - mprSetVar(&a, "members", am); - } - - if (i == 0) { - mprSetVar(&mpv, "length", mprCreateIntegerVar(i)); - } - - return mpv; -} - -static struct MprVar mprDomainSecrets(struct samba3_domainsecrets *ds) -{ - struct MprVar v, e = mprObject("domainsecrets"); - char *tmp; - DATA_BLOB blob; - - mprSetVar(&e, "name", mprString(ds->name)); - - tmp = dom_sid_string(NULL, &ds->sid); - mprSetVar(&e, "sid", mprString(tmp)); - talloc_free(tmp); - - tmp = GUID_string(NULL, &ds->guid); - mprSetVar(&e, "guid", mprString(tmp)); - talloc_free(tmp); - - mprSetVar(&e, "plaintext_pw", mprString(ds->plaintext_pw)); - - mprSetVar(&e, "last_change_time", mprCreateIntegerVar(ds->last_change_time)); - mprSetVar(&e, "sec_channel_type", mprCreateIntegerVar(ds->sec_channel_type)); - - v = mprObject("hash_pw"); - - blob.data = ds->hash_pw.hash; - blob.length = 16; - mprSetVar(&v, "hash", mprDataBlob(blob)); - - mprSetVar(&v, "mod_time", mprCreateIntegerVar(ds->hash_pw.mod_time)); - - mprSetVar(&e, "hash_pw", v); - - return e; -} - -static struct MprVar mprSecrets(struct samba3_secrets *sec) -{ - struct MprVar mpv = mprObject("samba3_secrets"), es, e; - int i; - - es = mprArray("array"); - - for (i = 0; i < sec->ldappw_count; i++) { - e = mprObject("ldappw"); - - mprSetVar(&e, "dn", mprString(sec->ldappws[i].dn)); - mprSetVar(&e, "password", mprString(sec->ldappws[i].password)); - - mprAddArray(&es, i, e); - } - - mprSetVar(&mpv, "ldappws", es); - - es = mprArray("array"); - - for (i = 0; i < sec->domain_count; i++) { - mprAddArray(&es, i, mprDomainSecrets(&sec->domains[i])); - } - - if (i == 0) { - mprSetVar(&es, "length", mprCreateIntegerVar(i)); - } - - mprSetVar(&mpv, "domains", es); - - es = mprArray("trusted_domains"); - - for (i = 0; i < sec->trusted_domain_count; i++) { - struct MprVar ns; - char *tmp; - int j; - e = mprObject("trusted_domain"); - - ns = mprArray("array"); - - for (j = 0; j < sec->trusted_domains[i].uni_name_len; j++) { - mprAddArray(&ns, j, mprString(sec->trusted_domains[i].uni_name[j])); - } - - mprSetVar(&e, "uni_name", ns); - - mprSetVar(&e, "pass", mprString(sec->trusted_domains[i].pass)); - mprSetVar(&e, "mod_time", mprCreateIntegerVar(sec->trusted_domains[i].mod_time)); - - tmp = dom_sid_string(NULL, &sec->trusted_domains[i].domain_sid); - mprSetVar(&e, "domains_sid", mprString(tmp)); - talloc_free(tmp); - - mprAddArray(&es, i, e); - } - - if (i == 0) { - mprSetVar(&es, "length", mprCreateIntegerVar(i)); - } - - mprSetVar(&mpv, "trusted_domains", es); - - es = mprArray("array"); - - for (i = 0; i < sec->afs_keyfile_count; i++) { - struct MprVar ks; - int j; - e = mprObject("afs_keyfile"); - - mprSetVar(&e, "cell", mprString(sec->afs_keyfiles[i].cell)); - - ks = mprArray("array"); - - for (j = 0; j < 8; j++) { - struct MprVar k = mprObject("entry"); - DATA_BLOB blob; - - mprSetVar(&k, "kvno", mprCreateIntegerVar(sec->afs_keyfiles[i].entry[j].kvno)); - blob.data = (uint8_t*)sec->afs_keyfiles[i].entry[j].key; - blob.length = 8; - mprSetVar(&k, "key", mprDataBlob(blob)); - - mprAddArray(&ks, j, k); - } - - mprSetVar(&e, "entry", ks); - - mprSetVar(&e, "nkeys", mprCreateIntegerVar(sec->afs_keyfiles[i].nkeys)); - - mprAddArray(&es, i, e); - } - - if (i == 0) { - mprSetVar(&es, "length", mprCreateIntegerVar(i)); - } - - mprSetVar(&mpv, "afs_keyfiles", es); - - mprSetVar(&mpv, "ipc_cred", mprCredentials(sec->ipc_cred)); - - return mpv; -} - -static struct MprVar mprShares(struct samba3 *samba3) -{ - struct MprVar mpv = mprArray("array"), s; - int i; - - for (i = 0; i < samba3->share_count; i++) { - s = mprObject("share"); - - mprSetVar(&s, "name", mprString(samba3->shares[i].name)); - - /* FIXME: secdesc */ - - mprAddArray(&mpv, i, s); - } - - if (i == 0) { - mprSetVar(&mpv, "length", mprCreateIntegerVar(i)); - } - - return mpv; -} - -static struct MprVar mprSamAccounts(struct samba3 *samba3) -{ - struct MprVar mpv = mprArray("array"), m; - int i; - - for (i = 0; i < samba3->samaccount_count; i++) { - struct samba3_samaccount *a = &samba3->samaccounts[i]; - DATA_BLOB blob; - - m = mprObject("samba3_samaccount"); - - mprSetVar(&m, "logon_time", mprCreateIntegerVar(a->logon_time)); - mprSetVar(&m, "logoff_time", mprCreateIntegerVar(a->logoff_time)); - mprSetVar(&m, "kickoff_time", mprCreateIntegerVar(a->kickoff_time)); - mprSetVar(&m, "bad_password_time", mprCreateIntegerVar(a->bad_password_time)); - mprSetVar(&m, "pass_last_set_time", mprCreateIntegerVar(a->pass_last_set_time)); - mprSetVar(&m, "pass_can_change_time", mprCreateIntegerVar(a->pass_can_change_time)); - mprSetVar(&m, "pass_must_change_time", mprCreateIntegerVar(a->pass_must_change_time)); - mprSetVar(&m, "user_rid", mprCreateIntegerVar(a->user_rid)); - mprSetVar(&m, "group_rid", mprCreateIntegerVar(a->group_rid)); - mprSetVar(&m, "acct_ctrl", mprCreateIntegerVar(a->acct_ctrl)); - mprSetVar(&m, "logon_divs", mprCreateIntegerVar(a->logon_divs)); - mprSetVar(&m, "bad_password_count", mprCreateIntegerVar(a->bad_password_count)); - mprSetVar(&m, "logon_count", mprCreateIntegerVar(a->logon_count)); - mprSetVar(&m, "username", mprString(a->username)); - mprSetVar(&m, "domain", mprString(a->domain)); - mprSetVar(&m, "nt_username", mprString(a->nt_username)); - mprSetVar(&m, "dir_drive", mprString(a->dir_drive)); - mprSetVar(&m, "munged_dial", mprString(a->munged_dial)); - mprSetVar(&m, "fullname", mprString(a->fullname)); - mprSetVar(&m, "homedir", mprString(a->homedir)); - mprSetVar(&m, "logon_script", mprString(a->logon_script)); - mprSetVar(&m, "profile_path", mprString(a->profile_path)); - mprSetVar(&m, "acct_desc", mprString(a->acct_desc)); - mprSetVar(&m, "workstations", mprString(a->workstations)); - blob.length = 16; - blob.data = a->lm_pw.hash; - mprSetVar(&m, "lm_pw", mprDataBlob(blob)); - blob.data = a->nt_pw.hash; - mprSetVar(&m, "nt_pw", mprDataBlob(blob)); - - mprAddArray(&mpv, i, m); - } - - if (i == 0) { - mprSetVar(&mpv, "length", mprCreateIntegerVar(i)); - } - - return mpv; -} - -static struct MprVar mprWinsEntries(struct samba3 *samba3) -{ - struct MprVar mpv = mprArray("array"); - int i, j; - - for (i = 0; i < samba3->winsdb_count; i++) { - struct MprVar w = mprObject("wins_entry"), ips; - - mprSetVar(&w, "name", mprString(samba3->winsdb_entries[i].name)); - mprSetVar(&w, "nb_flags", mprCreateIntegerVar(samba3->winsdb_entries[i].nb_flags)); - mprSetVar(&w, "type", mprCreateIntegerVar(samba3->winsdb_entries[i].type)); - mprSetVar(&w, "ttl", mprCreateIntegerVar(samba3->winsdb_entries[i].ttl)); - - ips = mprObject("array"); - - for (j = 0; j < samba3->winsdb_entries[i].ip_count; j++) { - const char *addr; - addr = inet_ntoa(samba3->winsdb_entries[i].ips[j]); - mprAddArray(&ips, j, mprString(addr)); - } - - mprSetVar(&w, "ips", ips); - - mprAddArray(&mpv, i, w); - } - - if (i == 0) { - mprSetVar(&mpv, "length", mprCreateIntegerVar(i)); - } - - return mpv; -} - -static int ejs_find_domainsecrets(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct samba3 *samba3 = NULL; - struct samba3_domainsecrets *sec; - - if (argc < 1) { - ejsSetErrorMsg(eid, "find_domainsecrets invalid arguments"); - return -1; - } - - samba3 = (struct samba3 *)mprGetThisPtr(eid, "samba3"); - mprAssert(samba3); - sec = samba3_find_domainsecrets(samba3, mprToString(argv[0])); - - if (sec == NULL) { - mpr_Return(eid, mprCreateUndefinedVar()); - } else { - mpr_Return(eid, mprDomainSecrets(sec)); - } - - return 0; -} - -/* - initialise samba3 ejs subsystem - - samba3 = samba3_read(libdir,smbconf) -*/ -static int ejs_samba3_read(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar mpv = mprObject("samba3"); - struct samba3 *samba3; - NTSTATUS status; - - if (argc < 2) { - ejsSetErrorMsg(eid, "samba3_read invalid arguments"); - return -1; - } - - status = samba3_read(mprToString(argv[0]), mprToString(argv[1]), mprMemCtx(), &samba3); - - if (NT_STATUS_IS_ERR(status)) { - ejsSetErrorMsg(eid, "samba3_read: error"); - return -1; - } - - mprAssert(samba3); - - mprSetPtrChild(&mpv, "samba3", samba3); - mprSetVar(&mpv, "winsentries", mprWinsEntries(samba3)); - mprSetVar(&mpv, "samaccounts", mprSamAccounts(samba3)); - mprSetVar(&mpv, "shares", mprShares(samba3)); - mprSetVar(&mpv, "secrets", mprSecrets(&samba3->secrets)); - mprSetVar(&mpv, "groupmappings", mprGroupMappings(&samba3->group)); - mprSetVar(&mpv, "aliases", mprAliases(&samba3->group)); - mprSetVar(&mpv, "idmapdb", mprIdmapDb(&samba3->idmap)); - mprSetVar(&mpv, "policy", mprPolicy(&samba3->policy)); - mprSetVar(&mpv, "registry", mprRegistry(&samba3->registry)); - mprSetVar(&mpv, "configuration", mprParam(samba3->configuration)); - mprSetCFunction(&mpv, "find_domainsecrets", ejs_find_domainsecrets); - - mpr_Return(eid, mpv); - - return 0; -} - - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_samba3(void) -{ - ejsDefineCFunction(-1, "samba3_read", ejs_samba3_read, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} -- cgit From fdd75e135a8cb43f946af99120566f744df2a8e0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 12 Feb 2008 21:59:23 +0100 Subject: Correctly increment counters in Subunit test runner. (This used to be commit c474a2bb83a3e28a0b83f3b8ca1b646742dfca3d) --- source4/scripting/bin/subunitrun | 4 +--- source4/scripting/python/subunit/__init__.py | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index 7142abed85..8dfe2def9c 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -21,6 +21,4 @@ from subunit import SubunitTestRunner import sys from unittest import TestProgram -program = TestProgram(module=None, argv=sys.argv, - testRunner=SubunitTestRunner()) -program.runTests() +TestProgram(module=None, argv=sys.argv, testRunner=SubunitTestRunner()) diff --git a/source4/scripting/python/subunit/__init__.py b/source4/scripting/python/subunit/__init__.py index 4d3434a3ea..7fcb815937 100644 --- a/source4/scripting/python/subunit/__init__.py +++ b/source4/scripting/python/subunit/__init__.py @@ -218,6 +218,7 @@ class TestProtocolClient(unittest.TestResult): for line in self._exc_info_to_string(error, test).splitlines(): self._stream.write("%s\n" % line) self._stream.write("]\n") + super(TestProtocolClient, self).addError(test, error) def addFailure(self, test, error): """Report a failure in test test.""" @@ -225,14 +226,17 @@ class TestProtocolClient(unittest.TestResult): for line in self._exc_info_to_string(error, test).splitlines(): self._stream.write("%s\n" % line) self._stream.write("]\n") + super(TestProtocolClient, self).addFailure(test, error) def addSuccess(self, test): """Report a success in a test.""" self._stream.write("successful: %s\n" % (test.shortDescription() or str(test))) + super(TestProtocolClient, self).addSuccess(test) def startTest(self, test): """Mark a test as starting its test run.""" self._stream.write("test: %s\n" % (test.shortDescription() or str(test))) + super(TestProtocolClient, self).startTest(test) def RemoteError(description=""): @@ -379,6 +383,5 @@ class SubunitTestRunner: def run(self, test): "Run the given test case or test suite." result = TestProtocolClient(self.stream) - test(result) return result -- cgit From 04aef38453ff977bf260546545e968fce3ddd599 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 12 Feb 2008 22:10:25 +0100 Subject: Fix subunit runner exit codes. (This used to be commit 7911308dbc1233838e44c533302f77b03ea41148) --- source4/scripting/bin/subunitrun | 3 ++- source4/scripting/python/subunit/__init__.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index 8dfe2def9c..11ac426589 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -21,4 +21,5 @@ from subunit import SubunitTestRunner import sys from unittest import TestProgram -TestProgram(module=None, argv=sys.argv, testRunner=SubunitTestRunner()) +runner = SubunitTestRunner() +TestProgram(module=None, argv=sys.argv, testRunner=runner) diff --git a/source4/scripting/python/subunit/__init__.py b/source4/scripting/python/subunit/__init__.py index 7fcb815937..3abfbf522e 100644 --- a/source4/scripting/python/subunit/__init__.py +++ b/source4/scripting/python/subunit/__init__.py @@ -209,7 +209,7 @@ class TestProtocolClient(unittest.TestResult): """A class that looks like a TestResult and informs a TestProtocolServer.""" def __init__(self, stream): - unittest.TestResult.__init__(self) + super(TestProtocolClient, self).__init__() self._stream = stream def addError(self, test, error): @@ -383,5 +383,6 @@ class SubunitTestRunner: def run(self, test): "Run the given test case or test suite." result = TestProtocolClient(self.stream) + test(result) return result -- cgit From b4ce9dc3609aafd6df17bd3b57c0da63fdaba4b1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Feb 2008 01:21:06 +0100 Subject: Fix invalid symbol. (This used to be commit bd0ef811c4e6419ba05076fbc151827cea5d1ca1) --- source4/scripting/python/samba/samdb.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py index c11fabf553..3c6bb23c02 100644 --- a/source4/scripting/python/samba/samdb.py +++ b/source4/scripting/python/samba/samdb.py @@ -100,12 +100,14 @@ userAccountControl: %u self.transaction_start() # find the DNs for the domain and the domain users group - res = self.search("", SCOPE_BASE, "defaultNamingContext=*", - ["defaultNamingContext"]) + res = self.search("", scope=ldb.SCOPE_BASE, + expression="(defaultNamingContext=*)", + attrs=["defaultNamingContext"]) assert(len(res) == 1 and res[0].defaultNamingContext is not None) domain_dn = res[0]["defaultNamingContext"][0] assert(domain_dn is not None) - dom_users = self.searchone(basedn=domain_dn, attribute="dn", expression="name=Domain Users") + dom_users = self.searchone(basedn=domain_dn, attribute="dn", + expression="name=Domain Users") assert(dom_users is not None) user_dn = "CN=%s,CN=Users,%s" % (username, domain_dn) -- cgit From 08e3f99f14f178e87f3543261be59a7f97f60b4f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 13 Feb 2008 02:18:45 +0100 Subject: Initial work on a test for samba.tests.samdb (This used to be commit 8b33860954ca03be1ea45fd8d40963dbbd5b162f) --- source4/scripting/python/samba/provision.py | 3 +- source4/scripting/python/samba/tests/samdb.py | 55 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 source4/scripting/python/samba/tests/samdb.py (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 4f52d36167..97021fceb2 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -332,7 +332,6 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, schemadn_ldb = "schema.ldb" if ldap_backend is not None: schema_ldb = ldap_backend - schemadn_ldb = ldap_backend if ldap_backend_type == "fedora-ds": @@ -536,6 +535,8 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, :note: This will wipe the main SAM database file! """ + assert serverrole in ("domain controller", "member server") + # Also wipes the database setup_samdb_partitions(path, setup_path, schemadn=schemadn, configdn=configdn, domaindn=domaindn, message=message, lp=lp, diff --git a/source4/scripting/python/samba/tests/samdb.py b/source4/scripting/python/samba/tests/samdb.py new file mode 100644 index 0000000000..40e56bebb5 --- /dev/null +++ b/source4/scripting/python/samba/tests/samdb.py @@ -0,0 +1,55 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. Tests for SamDB +# Copyright (C) Jelmer Vernooij 2008 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +from auth import system_session +from credentials import Credentials +import os +from samba.provision import setup_samdb +from samba.samdb import SamDB +from samba.tests import get_loadparm, TestCaseInTempDir +import security +from unittest import TestCase +import uuid + +class SamDBTestCase(TestCaseInTempDir): + def setUp(self): + super(SamDBTestCase, self).setUp() + invocationid = uuid.random() + domaindn = "DC=COM,DC=EXAMPLE" + self.domaindn = domaindn + configdn = "CN=Configuration," + domaindn + schemadn = "CN=Schema," + configdn + domainguid = uuid.random() + policyguid = uuid.random() + setup_path = lambda x: os.path.join("setup", x) + creds = Credentials() + domainsid = security.random_sid() + hostguid = uuid.random() + path = os.path.join(self.tempdir, "samdb.ldb") + self.samdb = setup_samdb(path, setup_path, system_session(), creds, + get_loadparm(), schemadn, configdn, + self.domaindn, "example.com", "EXAMPLE.COM", + "FOO", lambda x: None, "foo", domaindn, + False, domainsid, "# no aci", domainguid, + policyguid, "EXAMPLE", True, "secret", + "secret", "secret", hostguid, invocationid, + "secret", "domain controller") + + def test_add_foreign(self): + self.samdb.add_foreign(self.domaindn, "S-1-5-7", "Somedescription") + -- cgit From 85fe22a85fe7e8db7d2f6e2fdd6f02836f116b8e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Feb 2008 15:14:55 +0100 Subject: Use struct for provision parameters since there are so many of them. (This used to be commit 4b9d5bc57ca4ee14c142ea720dce5e4ee97f8c16) --- source4/scripting/python/samba/provision.py | 40 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 97021fceb2..d30eaf3d7f 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -271,7 +271,7 @@ def setup_name_mappings(ldb, sid, domaindn, root, nobody, nogroup, users, def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, credentials, configdn, schemadn, domaindn, hostname, netbiosname, dnsdomain, realm, - rootdn, serverrole, ldap_backend=None, + rootdn, serverrole, sitename, ldap_backend=None, ldap_backend_type=None, erase=False): """Setup the partitions for the SAM database. @@ -378,7 +378,8 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, message("Setting up sam.ldb rootDSE") setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, - dnsdomain, realm, rootdn, configdn, netbiosname) + dnsdomain, realm, rootdn, configdn, netbiosname, + sitename) if erase: message("Erasing data from partitions") @@ -472,7 +473,8 @@ def setup_registry(path, setup_path, session_info, credentials, lp): def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, - dnsdomain, realm, rootdn, configdn, netbiosname): + dnsdomain, realm, rootdn, configdn, netbiosname, + sitename): """Setup the SamDB rootdse. :param samdb: Sam Database handle @@ -482,7 +484,7 @@ def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, "SCHEMADN": schemadn, "NETBIOSNAME": netbiosname, "DNSDOMAIN": dnsdomain, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "REALM": realm, "DNSNAME": "%s.%s" % (hostname, dnsdomain), "DOMAINDN": domaindn, @@ -495,7 +497,7 @@ def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname, def setup_self_join(samdb, configdn, schemadn, domaindn, netbiosname, hostname, dnsdomain, machinepass, dnspass, realm, domainname, domainsid, invocationid, setup_path, - policyguid, hostguid=None): + policyguid, sitename, hostguid=None): """Join a host to its own domain.""" if hostguid is not None: hostguid_add = "objectGUID: %s" % hostguid @@ -508,7 +510,7 @@ def setup_self_join(samdb, configdn, schemadn, domaindn, "DOMAINDN": domaindn, "INVOCATIONID": invocationid, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "DNSNAME": "%s.%s" % (hostname, dnsdomain), "MACHINEPASS_B64": b64encode(machinepass), "DNSPASS_B64": b64encode(dnspass), @@ -529,7 +531,8 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, domainsid, aci, domainguid, policyguid, domainname, fill, adminpass, krbtgtpass, machinepass, hostguid, invocationid, dnspass, - serverrole, ldap_backend=None, ldap_backend_type=None): + serverrole, sitename, ldap_backend=None, + ldap_backend_type=None): """Setup a complete SAM Database. :note: This will wipe the main SAM database file! @@ -544,7 +547,8 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, hostname=hostname, netbiosname=netbiosname, dnsdomain=dnsdomain, realm=realm, rootdn=rootdn, ldap_backend=ldap_backend, serverrole=serverrole, - ldap_backend_type=ldap_backend_type, erase=erase) + ldap_backend_type=ldap_backend_type, erase=erase, + sitename=sitename) samdb = SamDB(path, session_info=session_info, credentials=credentials, lp=lp) @@ -562,7 +566,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, if lp.get("server role") == "domain controller": samdb.set_invocation_id(invocationid) - load_schema(setup_path, samdb, schemadn, netbiosname, configdn) + load_schema(setup_path, samdb, schemadn, netbiosname, configdn, sitename) samdb.transaction_start() @@ -584,7 +588,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, "DOMAINSID": str(domainsid), "SCHEMADN": schemadn, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "CONFIGDN": configdn, "POLICYGUID": policyguid, "DOMAINDN": domaindn, @@ -614,7 +618,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, setup_path("provision_schema_basedn_modify.ldif"), { "SCHEMADN": schemadn, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "CONFIGDN": configdn, }) @@ -629,7 +633,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, setup_add_ldif(samdb, setup_path("provision_configuration.ldif"), { "CONFIGDN": configdn, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "DNSDOMAIN": dnsdomain, "DOMAIN": domainname, "SCHEMADN": schemadn, @@ -656,7 +660,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, setup_add_ldif(samdb, setup_path("provision.ldif"), { "DOMAINDN": domaindn, "NETBIOSNAME": netbiosname, - "DEFAULTSITE": DEFAULTSITE, + "DEFAULTSITE": sitename, "CONFIGDN": configdn, }) @@ -679,7 +683,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, machinepass=machinepass, domainname=domainname, domainsid=domainsid, policyguid=policyguid, hostname=hostname, hostguid=hostguid, - setup_path=setup_path) + setup_path=setup_path, sitename=sitename) #We want to setup the index last, as adds are faster unindexed message("Setting up sam.ldb index") @@ -702,7 +706,7 @@ def provision(lp, setup_dir, message, paths, session_info, policyguid=None, invocationid=None, machinepass=None, dnspass=None, root=None, nobody=None, nogroup=None, users=None, wheel=None, backup=None, aci=None, serverrole=None, erase=False, - ldap_backend=None, ldap_backend_type=None): + ldap_backend=None, ldap_backend_type=None, sitename=DEFAULTSITE): """Provision samba4 :note: caution, this wipes all existing data! @@ -851,7 +855,7 @@ def provision(lp, setup_dir, message, paths, session_info, hostguid=hostguid, invocationid=invocationid, machinepass=machinepass, dnspass=dnspass, serverrole=serverrole, ldap_backend=ldap_backend, - ldap_backend_type=ldap_backend_type) + ldap_backend_type=ldap_backend_type, sitename=sitename) if lp.get("server role") == "domain controller": policy_path = os.path.join(paths.sysvol, dnsdomain, "Policies", @@ -945,7 +949,7 @@ def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn, }) -def load_schema(setup_path, samdb, schemadn, netbiosname, configdn): +def load_schema(setup_path, samdb, schemadn, netbiosname, configdn, sitename): """Load schema for the SamDB. :param samdb: Load a schema into a SamDB. @@ -962,7 +966,7 @@ def load_schema(setup_path, samdb, schemadn, netbiosname, configdn): "SCHEMADN": schemadn, "NETBIOSNAME": netbiosname, "CONFIGDN": configdn, - "DEFAULTSITE": DEFAULTSITE + "DEFAULTSITE":sitename }) samdb.attach_schema_from_ldif(head_data, schema_data) -- cgit From 7c96ca88c4e6fc5bd9b0c585b0700cc04e0f517c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 16 Feb 2008 15:23:26 +0100 Subject: Formatting fixes. (This used to be commit bc0fab89e325ebb6ab870b1c3f4b263c50631b70) --- source4/scripting/python/samba/provision.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index d30eaf3d7f..3e88b68509 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -335,9 +335,9 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, schemadn_ldb = ldap_backend if ldap_backend_type == "fedora-ds": - backend_modules = ["nsuniqueid","paged_searches"] + backend_modules = ["nsuniqueid", "paged_searches"] elif ldap_backend_type == "openldap": - backend_modules = ["normalise","entryuuid","paged_searches"] + backend_modules = ["normalise", "entryuuid", "paged_searches"] elif serverrole == "domain controller": backend_modules = ["repl_meta_data"] else: @@ -695,6 +695,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, samdb.transaction_commit() return samdb + FILL_FULL = "FULL" FILL_NT4SYNC = "NT4SYNC" FILL_DRS = "DRS" -- cgit From 602f4635da0935abffdda2a29ec302a775fdbe62 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 18 Feb 2008 19:06:17 +0100 Subject: Get rid of 'INTEGRATED' build of modules - now replaced by 'MERGED_OBJ' (This used to be commit 269cbf84d8b7dbf3bc88adc04ae283dc908af5ac) --- source4/scripting/ejs/config.mk | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index 5de17263b7..f99f37ecad 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -4,13 +4,13 @@ OBJ_FILES = \ [MODULE::smbcalls_config] OBJ_FILES = smbcalls_config.o -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbcalls INIT_FUNCTION = smb_setup_ejs_config [MODULE::smbcalls_ldb] OBJ_FILES = smbcalls_ldb.o -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbcalls INIT_FUNCTION = smb_setup_ejs_ldb PRIVATE_DEPENDENCIES = LIBLDB SAMDB LIBNDR @@ -18,38 +18,38 @@ PRIVATE_DEPENDENCIES = LIBLDB SAMDB LIBNDR [MODULE::smbcalls_reg] OBJ_FILES = smbcalls_reg.o SUBSYSTEM = smbcalls -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ INIT_FUNCTION = smb_setup_ejs_reg PRIVATE_DEPENDENCIES = registry SAMDB LIBNDR [MODULE::smbcalls_nbt] OBJ_FILES = smbcalls_nbt.o SUBSYSTEM = smbcalls -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ INIT_FUNCTION = smb_setup_ejs_nbt [MODULE::smbcalls_rand] OBJ_FILES = smbcalls_rand.o SUBSYSTEM = smbcalls -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ INIT_FUNCTION = smb_setup_ejs_random [MODULE::smbcalls_nss] OBJ_FILES = smbcalls_nss.o SUBSYSTEM = smbcalls -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ INIT_FUNCTION = smb_setup_ejs_nss PRIVATE_DEPENDENCIES = NSS_WRAPPER [MODULE::smbcalls_data] OBJ_FILES = smbcalls_data.o SUBSYSTEM = smbcalls -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ INIT_FUNCTION = smb_setup_ejs_datablob [MODULE::smbcalls_auth] OBJ_FILES = smbcalls_auth.o -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbcalls INIT_FUNCTION = smb_setup_ejs_auth PRIVATE_DEPENDENCIES = auth @@ -57,13 +57,13 @@ PRIVATE_DEPENDENCIES = auth [MODULE::smbcalls_string] OBJ_FILES = smbcalls_string.o SUBSYSTEM = smbcalls -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ INIT_FUNCTION = smb_setup_ejs_string [MODULE::smbcalls_sys] OBJ_FILES = smbcalls_sys.o SUBSYSTEM = smbcalls -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ INIT_FUNCTION = smb_setup_ejs_system include ejsnet/config.mk -- cgit From ff0315ba859421dff6aba055887e086fa68c2951 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 18 Feb 2008 20:04:18 +0100 Subject: Rename include to mkinclude to emphasize it is different from make's include. (This used to be commit 0e1d0a874ae3d22b8f97a79b81fe0af3ef53a771) --- source4/scripting/ejs/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting') diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index f99f37ecad..c1f07367fb 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -66,7 +66,7 @@ SUBSYSTEM = smbcalls OUTPUT_TYPE = MERGED_OBJ INIT_FUNCTION = smb_setup_ejs_system -include ejsnet/config.mk +mkinclude ejsnet/config.mk [SUBSYSTEM::smbcalls] PRIVATE_PROTO_HEADER = proto.h -- cgit From 0020793515ade04f3ef5754717490e2eb2ca6bb9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 03:40:44 +0100 Subject: Fix static module list generation for ldb. (This used to be commit 92c1c0e9137f0845cac6cc96bf78711b6aaffe21) --- source4/scripting/ejs/smbscript.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index a4f2e1cd43..9ed4aa490f 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -61,8 +61,6 @@ int main(int argc, const char **argv) lp_load(lp_ctx, dyn_CONFIGFILE); } - ldb_global_init(); - gensec_init(lp_ctx); mprSetCtx(mem_ctx); -- cgit From 845664e94b7bc98f6e93be6d7ff2a141d9d9e192 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 11:32:56 +0100 Subject: Avoid python2.2-specific types. (This used to be commit d45c6b5574ea732d25e9180c83f1fa807ebe57ba) --- source4/scripting/python/config.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/config.m4 b/source4/scripting/python/config.m4 index 908efd1588..2142cd9abd 100644 --- a/source4/scripting/python/config.m4 +++ b/source4/scripting/python/config.m4 @@ -54,7 +54,7 @@ fi if test x$PYTHON != x then - DISTUTILS_CFLAGS=`$PYTHON -c "from distutils import sysconfig; print '-I%s -I%s %s' % (sysconfig.get_python_inc(), sysconfig.get_python_inc(plat_specific=True), sysconfig.get_config_var('CFLAGS'))"` + DISTUTILS_CFLAGS=`$PYTHON -c "from distutils import sysconfig; print '-I%s -I%s %s' % (sysconfig.get_python_inc(), sysconfig.get_python_inc(plat_specific=1), sysconfig.get_config_var('CFLAGS'))"` DISTUTILS_LDFLAGS=`$PYTHON -c "from distutils import sysconfig; print '%s %s -lpython%s -L%s' % (sysconfig.get_config_var('LIBS'), sysconfig.get_config_var('SYSLIBS'), sysconfig.get_config_var('VERSION'), sysconfig.get_config_var('LIBPL'))"` TRY_LINK_PYTHON($DISTUTILS_LDFLAGS, $DISTUTILS_CFLAGS) fi -- cgit