Python: Simplify code in a couple of places. Copy Andrew's changes from g53b5166.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 11 Jan 2008 15:13:46 +0000 (16:13 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 11 Jan 2008 15:13:46 +0000 (16:13 +0100)
source/scripting/python/samba/__init__.py
source/scripting/python/samba/provision.py
source/scripting/python/samba/samdb.py

index e0b9e1d4104fc8d8ea047421043048311cf5b1bd..e85818016928de6d947e6049979333a18d962bc8 100644 (file)
@@ -112,15 +112,15 @@ class Ldb(ldb.Ldb):
         for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES", 
                      "@OPTIONS", "@PARTITION", "@KLUDGEACL"]:
             try:
-                self.delete(ldb.Dn(self, attr))
+                self.delete(attr)
             except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _):
                 # Ignore missing dn errors
                 pass
 
-        basedn = ldb.Dn(self, "")
+        basedn = ""
         # and the rest
         for msg in self.search(basedn, ldb.SCOPE_SUBTREE, 
-                "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", 
+                "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))", 
                 ["dn"]):
             try:
                 self.delete(msg.dn)
@@ -128,12 +128,12 @@ class Ldb(ldb.Ldb):
                 # Ignor eno such object errors
                 pass
 
-        res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"])
+        res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(distinguishedName=*))(!(distinguisedName=@BASEINFO)))", ["dn"])
         assert len(res) == 0
 
     def erase_partitions(self):
         """Erase an ldb, removing all records."""
-        res = self.search(ldb.Dn(self, ""), ldb.SCOPE_BASE, "(objectClass=*)", 
+        res = self.search("", ldb.SCOPE_BASE, "(objectClass=*)", 
                          ["namingContexts"])
         assert len(res) == 1
         if not "namingContexts" in res[0]:
@@ -145,7 +145,7 @@ class Ldb(ldb.Ldb):
             k = 0
             while ++k < 10 and (previous_remaining != current_remaining):
                 # and the rest
-                res2 = self.search(ldb.Dn(self, basedn), ldb.SCOPE_SUBTREE, "(|(objectclass=*)(dn=*))", ["dn"])
+                res2 = self.search(basedn, ldb.SCOPE_SUBTREE, "(|(objectclass=*)(distinguishedName=*))", ["distinguishedName"])
                 previous_remaining = current_remaining
                 current_remaining = len(res2)
                 for msg in res2:
index db3749f72115bb8f98537aa55c576dbb7d6c2bb5..1607cb343bf6d3397e3ff5db587d7d98113e7b80 100644 (file)
@@ -20,7 +20,7 @@ import samba
 from samba import Ldb, substitute_var, valid_netbios_name
 from samba.samdb import SamDB
 import security
-from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \
+from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \
         LDB_ERR_NO_SUCH_OBJECT, timestring, CHANGETYPE_MODIFY, CHANGETYPE_NONE
 
 """Functions for setting up a Samba configuration."""
@@ -64,7 +64,7 @@ def install_ok(lp, session_info, credentials):
         return False
     ldb = Ldb(lp.get("sam database"), session_info=session_info, 
             credentials=credentials, lp=lp)
-    if len(ldb.search(ldb.Dn("(cn=Administrator)"))) != 1:
+    if len(ldb.search("(cn=Administrator)")) != 1:
         return False
     return True
 
@@ -766,9 +766,9 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
         samdb = SamDB(paths.samdb, session_info=session_info, 
                       credentials=credentials, lp=lp)
 
-        domainguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID")
+        domainguid = samdb.searchone(domaindn, "objectGUID")
         assert isinstance(domainguid, str)
-        hostguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID",
+        hostguid = samdb.searchone(domaindn, "objectGUID",
                 expression="(&(objectClass=computer)(cn=%s))" % hostname,
                 scope=SCOPE_SUBTREE)
         assert isinstance(hostguid, str)
index 2af56d8d8eb0300cc4cc5ce07a5b0110c3c31041..353eaee198474f17f5beaf6469792195da46039d 100644 (file)
@@ -60,7 +60,7 @@ description: %s
         :param sid: SID of the NT-side of the mapping.
         :param unixname: Unix name to map to.
         """
-        res = self.search(ldb.Dn(self, domaindn), ldb.SCOPE_SUBTREE, 
+        res = self.search(domaindn, ldb.SCOPE_SUBTREE, 
                          "objectSid=%s" % sid, ["dn"])
         assert len(res) == 1, "Failed to find record for objectSid %s" % sid
 
@@ -103,7 +103,7 @@ userAccountControl: %u
         res = self.search("", SCOPE_BASE, "defaultNamingContext=*", 
                          ["defaultNamingContext"])
         assert(len(res) == 1 and res[0].defaultNamingContext is not None)
-        domain_dn = res[0].defaultNamingContext
+        domain_dn = res[0]["defaultNamingContext"][0]
         assert(domain_dn is not None)
         dom_users = self.searchone(domain_dn, "dn", "name=Domain Users")
         assert(dom_users is not None)