summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2008-06-19 11:05:20 +1000
committerAndrew Bartlett <abartlet@samba.org>2008-06-19 11:05:20 +1000
commit9ea25cacf1c564a485897432b73beebf2e634f55 (patch)
tree346c3d17e9952855032c48b66be7cb1ba1e29bb7
parent221b69af846c876957ed3f8bab23e2f51574eb87 (diff)
downloadsamba-9ea25cacf1c564a485897432b73beebf2e634f55.tar.gz
samba-9ea25cacf1c564a485897432b73beebf2e634f55.tar.bz2
samba-9ea25cacf1c564a485897432b73beebf2e634f55.zip
Add a blackbox test for the provision-backend script.
This test (as most tests do :-) found a few bugs, also fixed in this commit. Andrew Bartlett (This used to be commit d96a6482dad54d1d27a87107865e833a9c32cf53)
-rw-r--r--source4/scripting/python/samba/provision.py57
-rwxr-xr-xsource4/selftest/samba4_tests.sh1
-rwxr-xr-xsource4/setup/tests/blackbox_provision-backend.sh25
3 files changed, 56 insertions, 27 deletions
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index 93a4c8f502..504044253e 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -1150,15 +1150,18 @@ def provision_backend(setup_dir=None, message=None,
if root is None:
root = findnss(pwd.getpwnam, ["root"])[0]
- if smbconf is None:
- etcdir = os.path.join(targetdir, "etc")
- os.makedirs(etcdir)
- smbconf = os.path.join(etcdir, "smb.conf")
+ if adminpass is None:
+ adminpass = misc.random_password(12)
+
+ if targetdir is not None:
+ if (not os.path.exists(os.path.join(targetdir, "etc"))):
+ os.makedirs(os.path.join(targetdir, "etc"))
+ smbconf = os.path.join(targetdir, "etc", "smb.conf")
# only install a new smb.conf if there isn't one there already
if not os.path.exists(smbconf):
- make_smbconf(smbconf, setup_path, hostname, domain, realm,
- serverrole, targetdir)
+ make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole,
+ targetdir)
lp = param.LoadParm()
lp.load(smbconf)
@@ -1230,11 +1233,11 @@ def provision_backend(setup_dir=None, message=None,
elif ldap_backend_type == "openldap":
attrs = ["linkID", "lDAPDisplayName"]
- res = schemadb.search(expression="(&(&(linkID=*)(!(linkID:1.2.840.113556.1.4.803:=1)))(objectclass=attributeSchema))", base=names.schemadn, scope=SCOPE_SUBTREE, attrs=attrs)
+ res = schemadb.search(expression="(&(&(linkID=*)(!(linkID:1.2.840.113556.1.4.803:=1)))(objectclass=attributeSchema))", base=names.schemadn, scope=SCOPE_SUBTREE, attrs=attrs)
- memberof_config = "# Generated from schema in %s\n" % schemadb_path
- refint_attributes = ""
- for i in range (0, len(res)):
+ memberof_config = "# Generated from schema in %s\n" % schemadb_path
+ refint_attributes = ""
+ for i in range (0, len(res)):
expression = "(&(objectclass=attributeSchema)(linkID=%d))" % (int(res[i]["linkID"][0])+1)
target = schemadb.searchone(basedn=names.schemadn,
expression=expression,
@@ -1252,11 +1255,11 @@ memberof-dangling-error 32
"""
- memberof_config += """
+ memberof_config += """
overlay refint
refint_attributes""" + refint_attributes + "\n"
- setup_file(setup_path("slapd.conf"), paths.slapdconf,
+ setup_file(setup_path("slapd.conf"), paths.slapdconf,
{"DNSDOMAIN": names.dnsdomain,
"LDAPDIR": paths.ldapdir,
"DOMAINDN": names.domaindn,
@@ -1265,27 +1268,27 @@ refint_attributes""" + refint_attributes + "\n"
"LDAPMANAGERDN": names.ldapmanagerdn,
"LDAPMANAGERPASS": adminpass,
"MEMBEROF_CONFIG": memberof_config})
- setup_file(setup_path("modules.conf"), paths.modulesconf,
+ setup_file(setup_path("modules.conf"), paths.modulesconf,
{"REALM": names.realm})
- setup_db_config(setup_path, os.path.join(paths.ldapdir, os.path.join("db", "user")))
- setup_db_config(setup_path, os.path.join(paths.ldapdir, os.path.join("db", "config")))
- setup_db_config(setup_path, os.path.join(paths.ldapdir, os.path.join("db", "schema")))
- mapping = "schema-map-openldap-2.3"
- backend_schema = "backend-schema.schema"
-
- ldapi_uri = "ldapi://" + urllib.quote(os.path.join(paths.private_dir, "ldap", "ldapi"), safe="")
- if ldap_backend_port is not None:
- server_port_string = " -h ldap://0.0.0.0:%d" % ldap_backend_port
- else:
- server_port_string = ""
- slapdcommand="Start slapd with: slapd -f " + paths.ldapdir + "/slapd.conf -h " + ldapi_uri + server_port_string
+ setup_db_config(setup_path, os.path.join(paths.ldapdir, os.path.join("db", "user")))
+ setup_db_config(setup_path, os.path.join(paths.ldapdir, os.path.join("db", "config")))
+ setup_db_config(setup_path, os.path.join(paths.ldapdir, os.path.join("db", "schema")))
+ mapping = "schema-map-openldap-2.3"
+ backend_schema = "backend-schema.schema"
- schema_command = "bin/ad2oLschema --option=convert:target=" + ldap_backend_type + " -I " + setup_path(mapping) + " -H tdb://" + schemadb_path + " -O " + os.path.join(paths.ldapdir, backend_schema)
+ ldapi_uri = "ldapi://" + urllib.quote(os.path.join(paths.private_dir, "ldap", "ldapi"), safe="")
+ if ldap_backend_port is not None:
+ server_port_string = " -h ldap://0.0.0.0:%d" % ldap_backend_port
+ else:
+ server_port_string = ""
+ slapdcommand="Start slapd with: slapd -f " + paths.ldapdir + "/slapd.conf -h " + ldapi_uri + server_port_string
+
+ schema_command = "bin/ad2oLschema --option=convert:target=" + ldap_backend_type + " -I " + setup_path(mapping) + " -H tdb://" + schemadb_path + " -O " + os.path.join(paths.ldapdir, backend_schema)
+
os.system(schema_command)
-
message("Your %s Backend for Samba4 is now configured, and is ready to be started" % ldap_backend_type)
message("Server Role: %s" % serverrole)
message("Hostname: %s" % names.hostname)
diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh
index e9fbede4fb..107e5bd753 100755
--- a/source4/selftest/samba4_tests.sh
+++ b/source4/selftest/samba4_tests.sh
@@ -358,5 +358,6 @@ plantest "blackbox.upgrade" none $PYTHON setup/upgrade $CONFIGURATION --targetdi
rm -rf $PREFIX/provision
mkdir $PREFIX/provision
plantest "blackbox.provision.py" none PYTHON="$PYTHON" $samba4srcdir/setup/tests/blackbox_provision.sh "$PREFIX/provision"
+plantest "blackbox.provision-backend.py" none PYTHON="$PYTHON" $samba4srcdir/setup/tests/blackbox_provision-backend.sh "$PREFIX/provision"
plantest "blackbox.setpassword.py" none PYTHON="$PYTHON" $samba4srcdir/setup/tests/blackbox_setpassword.sh "$PREFIX/provision"
plantest "blackbox.newuser.py" none PYTHON="$PYTHON" $samba4srcdir/setup/tests/blackbox_newuser.sh "$PREFIX/provision"
diff --git a/source4/setup/tests/blackbox_provision-backend.sh b/source4/setup/tests/blackbox_provision-backend.sh
new file mode 100755
index 0000000000..312ca5c70e
--- /dev/null
+++ b/source4/setup/tests/blackbox_provision-backend.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+if [ $# -lt 1 ]; then
+cat <<EOF
+Usage: blackbox_provision.sh PREFIX
+EOF
+exit 1;
+fi
+
+PREFIX="$1"
+shift 1
+
+. `dirname $0`/../../../testprogs/blackbox/subunit.sh
+
+testit "openldap-backend" $PYTHON ./setup/provision-backend --domain=FOO --realm=foo.example.com --host-name=samba --ldap-backend-type=openldap --targetdir=$PREFIX/openldap-backend
+testit "fedora-ds-backend" $PYTHON ./setup/provision-backend --domain=FOO --realm=foo.example.com --host-name=samba --ldap-backend-type=fedora-ds --targetdir=$PREFIX/fedora-ds-backend
+
+reprovision() {
+ $PYTHON ./setup/provision-backend --domain=FOO --realm=foo.example.com --host-name=samba --ldap-backend-type=openldap --targetdir=$PREFIX/openldap-backend-reprovision
+ $PYTHON ./setup/provision-backend --domain=FOO --realm=foo.example.com --host-name=samba --ldap-backend-type=openldap --targetdir=$PREFIX/openldap-backend-reprovision
+}
+
+testit "reprovision-backend" reprovision
+
+exit $failed