summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/python/samba/provision/__init__.py40
-rw-r--r--source4/scripting/python/samba/provision/backend.py46
-rw-r--r--source4/scripting/python/samba/tests/provision.py4
3 files changed, 62 insertions, 28 deletions
diff --git a/source4/scripting/python/samba/provision/__init__.py b/source4/scripting/python/samba/provision/__init__.py
index 2f6a84c709..42da903302 100644
--- a/source4/scripting/python/samba/provision/__init__.py
+++ b/source4/scripting/python/samba/provision/__init__.py
@@ -379,9 +379,13 @@ class ProvisionResult(object):
self.domainsid = None
self.adminpass_generated = None
self.adminpass = None
+ self.backend_result = None
def report_logger(self, logger):
"""Report this provision result to a logger."""
+ logger.info(
+ "Once the above files are installed, your Samba4 server will "
+ "be ready to use")
if self.adminpass_generated:
logger.info("Admin password: %s", self.adminpass)
logger.info("Server Role: %s", self.server_role)
@@ -396,6 +400,9 @@ class ProvisionResult(object):
"the Samba 4 LDAP server has been created in %s.",
self.paths.phpldapadminconfig)
+ if self.backend_result:
+ self.backend_result.report_logger(logger)
+
def check_install(lp, session_info, credentials):
"""Check whether the current install seems ok.
@@ -727,7 +734,7 @@ def setup_samdb_partitions(samdb_path, logger, lp, session_info,
lp=lp, options=["modules:"])
ldap_backend_line = "# No LDAP backend"
- if provision_backend.type is not "ldb":
+ if provision_backend.type != "ldb":
ldap_backend_line = "ldapBackend: %s" % provision_backend.ldap_uri
samdb.transaction_start()
@@ -1604,7 +1611,7 @@ def provision(logger, session_info, credentials, smbconf=None,
if ldapadminpass is None:
# Make a new, random password between Samba and it's LDAP server
- ldapadminpass=samba.generate_random_password(128, 255)
+ ldapadminpass = samba.generate_random_password(128, 255)
if backend_type is None:
backend_type = "ldb"
@@ -1740,8 +1747,7 @@ def provision(logger, session_info, credentials, smbconf=None,
# only install a new shares config db if there is none
if not os.path.exists(paths.shareconf):
logger.info("Setting up share.ldb")
- share_ldb = Ldb(paths.shareconf, session_info=session_info,
- lp=lp)
+ share_ldb = Ldb(paths.shareconf, session_info=session_info, lp=lp)
share_ldb.load_ldif_file_add(setup_path("share.ldif"))
logger.info("Setting up secrets.ldb")
@@ -1751,15 +1757,13 @@ def provision(logger, session_info, credentials, smbconf=None,
try:
logger.info("Setting up the registry")
- setup_registry(paths.hklm, session_info,
- lp=lp)
+ setup_registry(paths.hklm, session_info, lp=lp)
logger.info("Setting up the privileges database")
setup_privileges(paths.privilege, session_info, lp=lp)
logger.info("Setting up idmap db")
- idmap = setup_idmapdb(paths.idmapdb,
- session_info=session_info, lp=lp)
+ idmap = setup_idmapdb(paths.idmapdb, session_info=session_info, lp=lp)
setup_name_mappings(idmap, sid=str(domainsid),
root_uid=root_uid, nobody_uid=nobody_uid,
@@ -1816,7 +1820,7 @@ def provision(logger, session_info, credentials, smbconf=None,
if serverrole == "domain controller":
create_dns_update_list(lp, logger, paths)
- provision_backend.post_setup()
+ backend_result = provision_backend.post_setup()
provision_backend.shutdown()
create_phpldapadmin_config(paths.phpldapadminconfig,
@@ -1839,7 +1843,6 @@ def provision(logger, session_info, credentials, smbconf=None,
logger.info("Failed to chown %s to bind gid %u",
dns_keytab_path, paths.bind_gid)
- logger.info("Once the above files are installed, your Samba4 server will be ready to use")
result = ProvisionResult()
result.server_role = serverrole
result.domaindn = domaindn
@@ -1856,21 +1859,8 @@ def provision(logger, session_info, credentials, smbconf=None,
else:
result.adminpass_generated = False
result.adminpass = None
- if provision_backend.type is not "ldb":
- if provision_backend.credentials.get_bind_dn() is not None:
- logger.info("LDAP Backend Admin DN: %s" %
- provision_backend.credentials.get_bind_dn())
- else:
- logger.info("LDAP Admin User: %s" %
- provision_backend.credentials.get_username())
-
- if provision_backend.slapd_command_escaped is not None:
- # now display slapd_command_file.txt to show how slapd must be
- # started next time
- logger.info("Use later the following commandline to start slapd, then Samba:")
- logger.info(provision_backend.slapd_command_escaped)
- logger.info("This slapd-Commandline is also stored under: %s/ldap_backend_startup.sh",
- provision_backend.ldapdir)
+
+ result.backend_result = backend_result
return result
diff --git a/source4/scripting/python/samba/provision/backend.py b/source4/scripting/python/samba/provision/backend.py
index 4ab827b545..1931bc193e 100644
--- a/source4/scripting/python/samba/provision/backend.py
+++ b/source4/scripting/python/samba/provision/backend.py
@@ -51,7 +51,43 @@ class SlapdAlreadyRunning(Exception):
self.ldapi_uri)
+class BackendResult(object):
+
+ def report_logger(self, logger):
+ """Rerport this result to a particular logger.
+
+ """
+ raise NotImplementedError(self.report_logger)
+
+
+class LDAPBackendResult(BackendResult):
+
+ def __init__(self, credentials, slapd_command_escaped, ldapdir):
+ self.credentials = credentials
+ self.slapd_command_escaped = slapd_command_escaped
+ self.ldapdir = ldapdir
+
+ def report_logger(self, logger):
+ if self.credentials.get_bind_dn() is not None:
+ logger.info("LDAP Backend Admin DN: %s" %
+ self.credentials.get_bind_dn())
+ else:
+ logger.info("LDAP Admin User: %s" %
+ self.credentials.get_username())
+
+ if self.slapd_command_escaped is not None:
+ # now display slapd_command_file.txt to show how slapd must be
+ # started next time
+ logger.info(
+ "Use later the following commandline to start slapd, then Samba:")
+ logger.info(self.slapd_command_escaped)
+ logger.info(
+ "This slapd-Commandline is also stored under: %s/ldap_backend_startup.sh",
+ self.ldapdir)
+
+
class ProvisionBackend(object):
+
def __init__(self, backend_type, paths=None, lp=None,
credentials=None, names=None, logger=None):
"""Provision a backend for samba4"""
@@ -79,7 +115,10 @@ class ProvisionBackend(object):
raise NotImplementedError(self.shutdown)
def post_setup(self):
- """Post setup."""
+ """Post setup.
+
+ :return: A BackendResult or None
+ """
raise NotImplementedError(self.post_setup)
@@ -278,7 +317,8 @@ class LDAPBackend(ProvisionBackend):
self.slapd.communicate()
def post_setup(self):
- pass
+ return LDAPBackendResult(self.credentials, self.slapd_command_escaped,
+ self.ldapdir)
class OpenLDAPBackend(LDAPBackend):
@@ -770,3 +810,5 @@ class FDSBackend(LDAPBackend):
self.names.schemadn):
m.dn = ldb.Dn(ldapi_db, dnstring)
ldapi_db.modify(m)
+ return LDAPBackendResult(self.credentials, self.slapd_command_escaped,
+ self.ldapdir)
diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py
index 8420f9c152..0ebe400405 100644
--- a/source4/scripting/python/samba/tests/provision.py
+++ b/source4/scripting/python/samba/tests/provision.py
@@ -167,6 +167,8 @@ class ProvisionResultTests(TestCase):
result = self.base_result()
entries = self.report_logger(result)
self.assertEquals(entries, [
+ ('INFO', 'Once the above files are installed, your Samba4 server '
+ 'will be ready to use'),
('INFO', 'Server Role: domain controller'),
('INFO', 'Hostname: hostnaam'),
('INFO', 'NetBIOS Domain: DOMEIN'),
@@ -185,6 +187,6 @@ class ProvisionResultTests(TestCase):
result.adminpass_generated = True
result.adminpass = "geheim"
entries = self.report_logger(result)
- self.assertEquals(entries[0],
+ self.assertEquals(entries[1],
("INFO", 'Admin password: geheim'))