provision: Put adminpass details in ProvisionResult.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 26 Feb 2012 15:07:21 +0000 (16:07 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 26 Feb 2012 15:27:06 +0000 (16:27 +0100)
source4/scripting/python/samba/provision/__init__.py
source4/scripting/python/samba/tests/provision.py

index f92ee67be518fb431290c3dd7d15f4d28b41a531..2f6a84c70988e1da6e7591b33a97f929638b887e 100644 (file)
@@ -377,9 +377,13 @@ class ProvisionResult(object):
         self.idmap = None
         self.names = None
         self.domainsid = None
+        self.adminpass_generated = None
+        self.adminpass = None
 
     def report_logger(self, logger):
         """Report this provision result to a logger."""
+        if self.adminpass_generated:
+            logger.info("Admin password:        %s", self.adminpass)
         logger.info("Server Role:           %s", self.server_role)
         logger.info("Hostname:              %s", self.names.hostname)
         logger.info("NetBIOS Domain:        %s", self.names.domain)
@@ -388,7 +392,8 @@ class ProvisionResult(object):
 
         if self.paths.phpldapadminconfig is not None:
             logger.info(
-                "A phpLDAPadmin configuration file suitable for administering the Samba 4 LDAP server has been created in %s.",
+                "A phpLDAPadmin configuration file suitable for administering "
+                "the Samba 4 LDAP server has been created in %s.",
                 self.paths.phpldapadminconfig)
 
 
@@ -1790,16 +1795,17 @@ def provision(logger, session_info, credentials, smbconf=None,
             adminpass_generated = False
 
         if samdb_fill == FILL_FULL:
-            provision_fill(samdb, secrets_ldb, logger,
-                           names, paths, schema=schema, targetdir=targetdir,
-                           samdb_fill=samdb_fill, hostip=hostip, hostip6=hostip6, domainsid=domainsid,
-                           next_rid=next_rid, dc_rid=dc_rid, adminpass=adminpass,
-                           krbtgtpass=krbtgtpass, domainguid=domainguid,
-                           policyguid=policyguid, policyguid_dc=policyguid_dc,
-                           invocationid=invocationid, machinepass=machinepass,
-                           ntdsguid=ntdsguid, dns_backend=dns_backend, dnspass=dnspass,
-                           serverrole=serverrole, dom_for_fun_level=dom_for_fun_level,
-                           am_rodc=am_rodc, lp=lp)
+            provision_fill(samdb, secrets_ldb, logger, names, paths,
+                    schema=schema, targetdir=targetdir, samdb_fill=samdb_fill,
+                    hostip=hostip, hostip6=hostip6, domainsid=domainsid,
+                    next_rid=next_rid, dc_rid=dc_rid, adminpass=adminpass,
+                    krbtgtpass=krbtgtpass, domainguid=domainguid,
+                    policyguid=policyguid, policyguid_dc=policyguid_dc,
+                    invocationid=invocationid, machinepass=machinepass,
+                    ntdsguid=ntdsguid, dns_backend=dns_backend,
+                    dnspass=dnspass, serverrole=serverrole,
+                    dom_for_fun_level=dom_for_fun_level, am_rodc=am_rodc,
+                    lp=lp)
 
         create_krb5_conf(paths.krb5conf,
                          dnsdomain=names.dnsdomain, hostname=names.hostname,
@@ -1845,8 +1851,11 @@ def provision(logger, session_info, credentials, smbconf=None,
     result.domainsid = str(domainsid)
 
     if samdb_fill == FILL_FULL:
-        if adminpass_generated:
-            logger.info("Admin password:        %s" % adminpass)
+        result.adminpass_generated = adminpass_generated
+        result.adminpass = adminpass
+    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" %
index 40665c01f4a8031db6eac0f406c64004fb1748a2..8420f9c152af7edc812a95ddad3ff12f0c1e583f 100644 (file)
@@ -152,7 +152,7 @@ class ProvisionResultTests(TestCase):
         result.report_logger(logger)
         return logger.entries
 
-    def test_basic_report_logger(self):
+    def base_result(self):
         result = ProvisionResult()
         result.server_role = "domain controller"
         result.names = ProvisionNames()
@@ -161,6 +161,10 @@ class ProvisionResultTests(TestCase):
         result.names.dnsdomain = "dnsdomein"
         result.domainsid = "S1-1-1"
         result.paths = ProvisionPaths()
+        return result
+
+    def test_basic_report_logger(self):
+        result = self.base_result()
         entries = self.report_logger(result)
         self.assertEquals(entries, [
             ('INFO', 'Server Role:           domain controller'),
@@ -170,15 +174,17 @@ class ProvisionResultTests(TestCase):
             ('INFO', 'DOMAIN SID:            S1-1-1')])
 
     def test_report_logger_phpldapadmin(self):
-        result = ProvisionResult()
-        result.server_role = "domain controller"
-        result.names = ProvisionNames()
-        result.names.hostname = "hostnaam"
-        result.names.domain = "DOMEIN"
-        result.names.dnsdomain = "dnsdomein"
-        result.domainsid = "S1-1-1"
-        result.paths = ProvisionPaths()
+        result = self.base_result()
         result.paths.phpldapadminconfig = "/some/ldapconfig"
         entries = self.report_logger(result)
         self.assertEquals(entries[-1],
             ("INFO", "A phpLDAPadmin configuration file suitable for administering the Samba 4 LDAP server has been created in /some/ldapconfig."))
+
+    def test_report_logger_adminpass(self):
+        result = self.base_result()
+        result.adminpass_generated = True
+        result.adminpass = "geheim"
+        entries = self.report_logger(result)
+        self.assertEquals(entries[0],
+                ("INFO", 'Admin password:        geheim'))
+