r26545: Sync output with ejs.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 20 Dec 2007 14:53:56 +0000 (15:53 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2007 05:28:46 +0000 (06:28 +0100)
(This used to be commit 48ceaa964327ed7094275780cc3c0767636bcb18)

source4/scripting/python/samba/__init__.py
source4/scripting/python/samba/provision.py
source4/scripting/python/samba/samdb.py

index 2c46f7288387be30ab7dd52bfc64e35e8abc64a9..c7353613530f30f2e53b802d37b710454ba1f6f6 100644 (file)
@@ -72,6 +72,8 @@ class Ldb(ldb.Ldb):
         if session_info is not None:
             self.set_session_info(self, session_info)
 
+        assert misc.ldb_register_samba_handlers(self) == 0
+
         if lp is not None:
             self.set_loadparm(self, lp)
 
index 90f7cd0697729e443fbd8d2080b833c895abdea2..a4a9e7ac46cc68f6f94c3e0964561bee0ab050b9 100644 (file)
@@ -219,20 +219,19 @@ def provision_become_dc(setup_dir, message, paths, lp, session_info,
     os.path.unlink(paths.samdb)
 
     message("Setting up templates db")
-    setup_templatesdb(paths.templates, setup_path, session_info, 
-                      credentialslp)
+    setup_templatesdb(paths.templates, setup_path, session_info=session_info
+                      credentials=credentials, lp=lp)
 
     # Also wipes the database
     message("Setting up sam.ldb")
-    samdb = SamDB(paths.samdb, credentials=credentials
-                  session_info=session_info, lp=lp)
+    samdb = SamDB(paths.samdb, session_info=session_info
+                  credentials=credentials, lp=lp)
 
     message("Setting up sam.ldb partitions")
-    setup_samdb_partitions(samdb, setup_path, schemadn, 
-                       configdn, domaindn)
+    setup_samdb_partitions(samdb, setup_path, schemadn, configdn, domaindn)
 
-    samdb = SamDB(paths.samdb, credentials=credentials
-                  session_info=session_info, lp=lp)
+    samdb = SamDB(paths.samdb, session_info=session_info
+                  credentials=credentials, lp=lp)
 
     ldb.transaction_start()
     try:
@@ -257,12 +256,15 @@ def provision_become_dc(setup_dir, message, paths, lp, session_info,
     samdb.transaction_commit()
 
     message("Setting up %s" % paths.secrets)
-    secrets_ldb = setup_secretsdb(paths.secrets, setup_path, session_info, credentials, lp)
+    secrets_ldb = setup_secretsdb(paths.secrets, setup_path, session_info, 
+                                  credentials, lp)
     setup_ldb(secrets_ldb, setup_path("secrets_dc.ldif"), 
               { "MACHINEPASS_B64": b64encode(machinepass) })
 
 
 def setup_secretsdb(path, setup_path, session_info, credentials, lp):
+    if os.path.exists(path):
+        os.unlink(path)
     secrets_ldb = Ldb(path, session_info=session_info, credentials=credentials, lp=lp)
     secrets_ldb.erase()
     secrets_ldb.load_ldif_file_add(setup_path("secrets_init.ldif"))
@@ -474,8 +476,9 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
         share_ldb.load_ldif_file_add(setup_path("share.ldif"))
 
     message("Setting up secrets.ldb")
-    secrets_ldb = setup_secretsdb(paths.secrets, setup_path, session_info=session_info, 
-                    credentials=credentials, lp=lp)
+    secrets_ldb = setup_secretsdb(paths.secrets, setup_path, 
+                                  session_info=session_info, 
+                                  credentials=credentials, lp=lp)
 
     message("Setting up the registry")
     # FIXME: Still fails for some reason
@@ -486,6 +489,8 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
     setup_templatesdb(paths.templates, setup_path, session_info=session_info, 
                       credentials=credentials, lp=lp)
 
+    # Also wipes the database
+    message("Setting up sam.ldb")
     samdb = SamDB(paths.samdb, session_info=session_info, 
                   credentials=credentials, lp=lp)
 
@@ -619,20 +624,6 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
             })
 
         if not blank:
-
-    #    message("Activate schema module")
-    #    setup_modify_ldif("schema_activation.ldif", info, samdb, False)
-    #
-    #    // (hack) Reload, now we have the schema loaded.  
-    #    commit_ok = samdb.transaction_commit()
-    #    if (!commit_ok) {
-    #        message("samdb commit failed: " + samdb.errstring() + "\n")
-    #        assert(commit_ok)
-    #    }
-    #    samdb.close()
-    #
-    #    samdb = open_ldb(info, paths.samdb, False)
-    #
             message("Setting up sam.ldb users and groups")
             setup_add_ldif(samdb, setup_path("provision_users.ldif"), {
                 "DOMAINDN": domaindn,
@@ -696,7 +687,7 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
         message("Setting up sam.ldb index")
         samdb.load_ldif_file_add(setup_path("provision_index.ldif"))
 
-        message("Setting up sam.ldb rootDSE marking as syncronized")
+        message("Setting up sam.ldb rootDSE marking as synchronized")
         setup_modify_ldif(samdb, setup_path("provision_rootdse_modify.ldif"))
     except:
         samdb.transaction_cancel()
@@ -709,10 +700,21 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
 
     message("Please install the phpLDAPadmin configuration located at %s into /etc/phpldapadmin/config.php" % paths.phpldapadminconfig)
 
+    samdb = SamDB(paths.samdb, session_info=session_info, 
+                  credentials=credentials, lp=lp)
+
+    domainguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID")
+    assert isinstance(domainguid, str)
+    hostguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID",
+            expression="(&(objectClass=computer)(cn=%s))" % hostname,
+            scope=SCOPE_SUBTREE)
+    assert isinstance(hostguid, str)
+
     message("Setting up DNS zone: %s" % dnsdomain)
     create_zone_file(paths.dns, setup_path, samdb, 
                   hostname=hostname, hostip=hostip, dnsdomain=dnsdomain,
-                  domaindn=domaindn, dnspass=dnspass, realm=realm)
+                  domaindn=domaindn, dnspass=dnspass, realm=realm, 
+                  domainguid=domainguid, hostguid=hostguid)
     message("Please install the zone located in %s into your DNS server" % paths.dns)
 
 def create_phplpapdadmin_config(path, setup_path, s4_ldapi_path):
@@ -721,16 +723,9 @@ def create_phplpapdadmin_config(path, setup_path, s4_ldapi_path):
 
 
 def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn, 
-                  hostip, hostname, dnspass, realm):
+                  hostip, hostname, dnspass, realm, domainguid, hostguid):
     """Write out a DNS zone file, from the info in the current database."""
 
-    # connect to the sam
-    # These values may have changed, due to an incoming SamSync,
-    # or may not have been specified, so fetch them from the database
-    domainguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID")
-    hostguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID" ,
-                     expression="(&(objectClass=computer)(cn=%s))" % hostname)
-
     setup_file(setup_path("provision.zone"), path, {
             "DNSPASS_B64": b64encode(dnspass),
             "HOSTNAME": hostname,
index 84b604dbc46403a37a7d681b3aca7f0762583d13..46707f060f5090b561661935f2e44dcb847407a0 100644 (file)
@@ -30,7 +30,6 @@ class SamDB(samba.Ldb):
         super(SamDB, self).__init__(session_info=session_info, credentials=credentials,
                                     modules_dir=modules_dir, lp=lp)
         assert misc.dsdb_set_global_schema(self) == 0
-        assert misc.ldb_register_samba_handlers(self) == 0
         if url:
             self.connect(url)