summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/registry/tests/bindings.py7
-rw-r--r--source4/param/param.i2
-rw-r--r--source4/param/param_wrap.c2
-rw-r--r--source4/scripting/python/samba/__init__.py6
-rw-r--r--source4/scripting/python/samba/provision.py6
-rw-r--r--source4/scripting/python/samba/tests/__init__.py11
-rw-r--r--source4/scripting/python/samba/tests/provision.py10
-rw-r--r--source4/scripting/python/samba/upgrade.py26
-rwxr-xr-xsource4/selftest/samba4_tests.sh6
-rwxr-xr-xsource4/setup/provision.py22
-rwxr-xr-xsource4/setup/upgrade.py19
11 files changed, 68 insertions, 49 deletions
diff --git a/source4/lib/registry/tests/bindings.py b/source4/lib/registry/tests/bindings.py
index 906deed7e9..314cf778a1 100644
--- a/source4/lib/registry/tests/bindings.py
+++ b/source4/lib/registry/tests/bindings.py
@@ -35,7 +35,12 @@ class HelperTests(unittest.TestCase):
class HiveTests(samba.tests.TestCaseInTempDir):
def setUp(self):
super(HiveTests, self).setUp()
- self.hive = registry.open_ldb(os.path.join(self.tempdir, "ldb_new.ldb"))
+ self.hive_path = os.path.join(self.tempdir, "ldb_new.ldb")
+ self.hive = registry.open_ldb(self.hive_path)
+
+ def tearDown(self):
+ del self.hive
+ os.unlink(self.hive_path)
def test_ldb_new(self):
self.assertTrue(self.hive is not None)
diff --git a/source4/param/param.i b/source4/param/param.i
index 375c3d0da4..353fa3ced6 100644
--- a/source4/param/param.i
+++ b/source4/param/param.i
@@ -59,6 +59,8 @@ typedef struct loadparm_context {
bool is_myname(const char *name) { return lp_is_myname($self, name); }
int use(struct param_context *param_ctx) { return param_use($self, param_ctx); }
bool set(const char *parm_name, const char *parm_value) {
+ if (parm_value == NULL)
+ return false;
return lp_set_cmdline($self, parm_name, parm_value);
}
diff --git a/source4/param/param_wrap.c b/source4/param/param_wrap.c
index 5f7ff880ff..ca9fbb77b8 100644
--- a/source4/param/param_wrap.c
+++ b/source4/param/param_wrap.c
@@ -2643,6 +2643,8 @@ SWIGINTERN bool loadparm_context_is_mydomain(loadparm_context *self,char const *
SWIGINTERN bool loadparm_context_is_myname(loadparm_context *self,char const *name){ return lp_is_myname(self, name); }
SWIGINTERN int loadparm_context_use(loadparm_context *self,struct param_context *param_ctx){ return param_use(self, param_ctx); }
SWIGINTERN bool loadparm_context_set(loadparm_context *self,char const *parm_name,char const *parm_value){
+ if (parm_value == NULL)
+ return false;
return lp_set_cmdline(self, parm_name, parm_value);
}
SWIGINTERN PyObject *loadparm_context_get(loadparm_context *self,char const *param_name,char const *service_name){
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index 5b34534133..359457d815 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -164,9 +164,9 @@ class Ldb(ldb.Ldb):
self.add(msg)
def modify_ldif(self, ldif):
- for (changetype, msg) in ldb.parse_ldif(data):
- assert changetype == CHANGETYPE_MODIFY
- ldb.modify(msg)
+ for (changetype, msg) in self.parse_ldif(ldif):
+ assert changetype == ldb.CHANGETYPE_MODIFY
+ self.modify(msg)
def substitute_var(text, values):
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index a4e6c6a214..c4a3bb7fd6 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -95,7 +95,7 @@ def setup_add_ldif(ldb, ldif_path, subst_vars=None):
assert "${" not in data
- ldb.load_ldif_add(data)
+ ldb.add_ldif(data)
def setup_modify_ldif(ldb, ldif_path, substvars=None):
@@ -140,7 +140,7 @@ def setup_file(template, fname, substvars):
open(f, 'w').write(data)
-def provision_default_paths(lp, dnsdomain):
+def provision_paths_from_lp(lp, dnsdomain):
"""Set the default paths for provisioning.
:param lp: Loadparm context.
@@ -605,7 +605,7 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
realm = lp.get("realm")
else:
if lp.get("realm").upper() != realm.upper():
- raise Error("realm '%s' in smb.conf must match chosen realm '%s'\n" %
+ raise Exception("realm '%s' in smb.conf must match chosen realm '%s'\n" %
(lp.get("realm"), realm))
assert realm is not None
diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py
index 5885a3b507..5e1ff87c2b 100644
--- a/source4/scripting/python/samba/tests/__init__.py
+++ b/source4/scripting/python/samba/tests/__init__.py
@@ -67,7 +67,12 @@ class SubstituteVarTestCase(unittest.TestCase):
class LdbExtensionTests(TestCaseInTempDir):
def test_searchone(self):
- l = samba.Ldb(self.tempdir + "/searchone.ldb")
- l.add({"dn": "foo=dc", "bar": "bla"})
- self.assertEquals("bla", l.searchone(ldb.Dn(l, "foo=dc"), "bar"))
+ path = self.tempdir + "/searchone.ldb"
+ l = samba.Ldb(path)
+ try:
+ l.add({"dn": "foo=dc", "bar": "bla"})
+ self.assertEquals("bla", l.searchone(ldb.Dn(l, "foo=dc"), "bar"))
+ finally:
+ del l
+ os.unlink(path)
diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py
index bf7182dbd3..f5a0339c1f 100644
--- a/source4/scripting/python/samba/tests/provision.py
+++ b/source4/scripting/python/samba/tests/provision.py
@@ -29,10 +29,14 @@ def setup_path(file):
class ProvisionTestCase(samba.tests.TestCaseInTempDir):
def test_setup_secretsdb(self):
- ldb = setup_secretsdb(os.path.join(self.tempdir, "secrets.ldb"),
- setup_path, None, None, None)
- self.assertEquals("LSA Secrets",
+ path = os.path.join(self.tempdir, "secrets.ldb")
+ ldb = setup_secretsdb(path, setup_path, None, None, None)
+ try:
+ self.assertEquals("LSA Secrets",
ldb.searchone(Dn(ldb, "CN=LSA Secrets"), "CN"))
+ finally:
+ del ldb
+ os.unlink(path)
class Disabled:
diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py
index c13351bc63..05a63d9326 100644
--- a/source4/scripting/python/samba/upgrade.py
+++ b/source4/scripting/python/samba/upgrade.py
@@ -8,7 +8,6 @@
"""Support code for upgrading from Samba 3 to Samba 4."""
from provision import findnss, provision
-import provision
import grp
import pwd
import uuid
@@ -255,7 +254,7 @@ maxVersion: %llu
return ldif
-def upgrade_provision(samba3, setup_dir, message, credentials, session_info, paths):
+def upgrade_provision(samba3, setup_dir, message, credentials, session_info, lp, paths):
oldconf = samba3.get_conf()
if oldconf.get("domain logons") == "True":
@@ -266,7 +265,11 @@ def upgrade_provision(samba3, setup_dir, message, credentials, session_info, pat
else:
serverrole = "member server"
+ lp.set("server role", serverrole)
domainname = oldconf.get("workgroup")
+ if domainname:
+ domainname = str(domainname)
+ lp.set("workgroup", domainname)
realm = oldconf.get("realm")
netbiosname = oldconf.get("netbios name")
@@ -279,18 +282,19 @@ def upgrade_provision(samba3, setup_dir, message, credentials, session_info, pat
if realm is None:
realm = domainname.lower()
message("No realm specified in smb.conf file, assuming '%s'\n" % realm)
+ lp.set("realm", realm)
domainguid = secrets_db.get_domain_guid(domainname)
- domainsid = secrets_db.get_sid(domainsid)
+ domainsid = secrets_db.get_sid(domainname)
if domainsid is None:
message("Can't find domain secrets for '%s'; using random SID\n" % domainname)
if netbiosname is not None:
machinepass = secrets_db.get_machine_password(netbiosname)
else:
- netbiosname = None
+ machinepass = None
- provision(lp, setup_dir, message, blank=True, paths=path, session_info=session_info,
+ provision(lp=lp, setup_dir=setup_dir, message=message, blank=True, ldapbackend=None, paths=paths, session_info=session_info,
credentials=credentials, realm=realm, domain=domainname,
domainsid=domainsid, domainguid=domainguid, machinepass=machinepass, serverrole=serverrole)
@@ -500,18 +504,6 @@ data: %d
return ret
-def upgrade_verify(subobj, samba3, paths, message):
- message("Verifying account policies")
-
- samldb = Ldb(paths.samdb)
-
- for account in samba3.samaccounts:
- msg = samldb.search("(&(sAMAccountName=" + account.nt_username + ")(objectclass=user))")
- assert(len(msg) >= 1)
-
- # FIXME
-
-
def enable_samba3sam(samdb):
samdb.modify("""
diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh
index 59c7635c19..309b2c067e 100755
--- a/source4/selftest/samba4_tests.sh
+++ b/source4/selftest/samba4_tests.sh
@@ -297,7 +297,11 @@ then
plantest "samba3.python" none PYTHONPATH=bin/python:scripting/python $PYTHON scripting/bin/subunitrun samba.tests.samba3
plantest "samba3sam.python" none PYTHONPATH=bin/python:scripting/python $PYTHON dsdb/samdb/ldb_modules/tests/samba3sam.py `pwd` $DATADIR/samba3/
plantest "ldap.python" dc $PYTHON $samba4srcdir/lib/ldb/tests/python/ldap.py \$SERVER -U\$USERNAME%\$PASSWORD
+ plantest "blackbox.samba3dump" none $PYTHON scripting/bin/samba3dump $samba4srcdir/../testdata/samba3
rm -rf $PREFIX/upgrade
mkdir -p $PREFIX/upgrade
- plantest "blackbox.upgrade" none $PYTHON setup/upgrade.py $CONFIGURATION --verify --targetdir=$PREFIX ../testdata/samba3 ../testdata/samba3/smb.conf
+ plantest "blackbox.upgrade" none $PYTHON setup/upgrade.py $CONFIGURATION --targetdir=$PREFIX ../testdata/samba3 ../testdata/samba3/smb.conf
+ rm -rf $PREFIX/provision
+ mkdir -p $PREFIX/provision
+ plantest "blackbox.provision.py" none $PYTHON ./setup/provision.py $CONFIGURATION --domain=FOO --realm=foo --targetdir=$PREFIX/provision
fi
diff --git a/source4/setup/provision.py b/source4/setup/provision.py
index a16dde718d..f6f032da70 100755
--- a/source4/setup/provision.py
+++ b/source4/setup/provision.py
@@ -21,7 +21,7 @@
import getopt
import optparse
-import sys
+import os, sys
# Add path to the library for in-tree use
sys.path.append("scripting/python")
@@ -32,7 +32,7 @@ from auth import system_session
import samba.getopt as options
import param
from samba.provision import (provision,
- provision_default_paths, provision_ldapbase)
+ provision_paths_from_lp, provision_ldapbase)
parser = optparse.OptionParser("provision [options]")
parser.add_option_group(options.SambaOptions(parser))
@@ -93,6 +93,8 @@ parser.add_option("--server-role", type="choice", metavar="ROLE",
help="Set server role to provision for (default standalone)")
parser.add_option("--partitions-only",
help="Configure Samba's partitions, but do not modify them (ie, join a BDC)", action="store_true")
+parser.add_option("--targetdir", type="string", metavar="DIR",
+ help="Set target directory")
opts = parser.parse_args()[0]
@@ -101,29 +103,29 @@ def message(text):
if not opts.quiet:
print text
-hostname = opts.host_name
-
-if opts.realm is None or opts.domain is None or opts.host_name is None:
+if opts.realm is None or opts.domain is None:
if opts.realm is None:
print >>sys.stderr, "No realm set"
if opts.domain is None:
print >>sys.stderr, "No domain set"
- if opts.host_name is None:
- print >>sys.stderr, "No host name set"
parser.print_usage()
sys.exit(1)
# cope with an initially blank smb.conf
lp = param.LoadParm()
-lp.load(opts.configfile)
+if opts.configfile:
+ lp.load(opts.configfile)
+if opts.targetdir is not None:
+ lp.set("private dir", os.path.abspath(opts.targetdir))
+ lp.set("lock dir", os.path.abspath(opts.targetdir))
lp.set("realm", opts.realm)
lp.set("workgroup", opts.domain)
-lp.set("server role", opts.server_role)
+lp.set("server role", opts.server_role or "domain controller")
if opts.aci is not None:
print "set ACI: %s" % opts.aci
-paths = provision_default_paths(lp, opts.realm.lower())
+paths = provision_paths_from_lp(lp, opts.realm.lower())
paths.smbconf = opts.configfile
if opts.ldap_backend:
diff --git a/source4/setup/upgrade.py b/source4/setup/upgrade.py
index 186ad3772b..c531e28ed5 100755
--- a/source4/setup/upgrade.py
+++ b/source4/setup/upgrade.py
@@ -11,7 +11,7 @@ sys.path.append("scripting/python")
import param
import samba
import samba.getopt as options
-from samba.provision import provision_default_paths
+from auth import system_session
parser = optparse.OptionParser("upgrade [options] <libdir> <smbconf>")
parser.add_option_group(options.SambaOptions(parser))
@@ -22,7 +22,6 @@ parser.add_option("--setupdir", type="string", metavar="DIR",
help="directory with setup files")
parser.add_option("--realm", type="string", metavar="REALM", help="set realm")
parser.add_option("--quiet", help="Be quiet")
-parser.add_option("--verify", help="Verify resulting configuration")
parser.add_option("--blank",
help="do not add users or groups, just the structure")
parser.add_option("--targetdir", type="string", metavar="DIR",
@@ -51,6 +50,7 @@ else:
samba3 = Samba3(libdir, smbconf)
from samba.upgrade import upgrade_provision
+from samba.provision import provision_paths_from_lp
message("Provisioning\n")
@@ -60,9 +60,12 @@ if setup_dir is None:
creds = credopts.get_credentials()
lp = param.LoadParm()
-lp.load(opts.configfile)
-upgrade_provision(samba3, setup_dir, message, credentials=creds, session_info=system_session())
-
-if opts.verify:
- message("Verifying...\n")
- ret = upgrade_verify(subobj, samba3, paths, message)
+if opts.configfile:
+ lp.load(opts.configfile)
+if opts.targetdir is not None:
+ lp.set("private dir", os.path.abspath(opts.targetdir))
+ lp.set("lock dir", os.path.abspath(opts.targetdir))
+paths = provision_paths_from_lp(lp, "")
+paths.smbconf = opts.configfile
+upgrade_provision(samba3, setup_dir, message, credentials=creds, session_info=system_session(),
+ lp=lp, paths=paths)