ldb: use base searches for @ special DNs
authorAndrew Tridgell <tridge@samba.org>
Wed, 13 Jul 2011 03:05:19 +0000 (13:05 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 13 Jul 2011 10:51:05 +0000 (12:51 +0200)
subtree searches on these DNs don't work any more

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/scripting/bin/upgradeprovision
source4/scripting/python/samba/provision/__init__.py
source4/scripting/python/samba/tests/upgradeprovision.py
source4/scripting/python/samba/upgradehelpers.py

index d2a645a637375b9bb6d862b5616aedead8f618a4..54f3cf1507efedd156678869549ef7961a2520c8 100755 (executable)
@@ -1349,7 +1349,7 @@ def rebuild_sd(samdb, names):
 def removeProvisionUSN(samdb):
         attrs = [samba.provision.LAST_PROVISION_USN_ATTRIBUTE, "dn"]
         entry = samdb.search(expression="dn=@PROVISION", base = "",
 def removeProvisionUSN(samdb):
         attrs = [samba.provision.LAST_PROVISION_USN_ATTRIBUTE, "dn"]
         entry = samdb.search(expression="dn=@PROVISION", base = "",
-                                scope=SCOPE_SUBTREE,
+                                scope=SCOPE_BASE,
                                 attrs=attrs)
         empty = Message()
         empty.dn = entry[0].dn
                                 attrs=attrs)
         empty = Message()
         empty.dn = entry[0].dn
index 97cf7bff1797f5d3ae6cac7456f79b24f6f75962..4fa282321483ca079e0aeb87138c19b6d0f2ee84 100644 (file)
@@ -331,10 +331,9 @@ def update_provision_usn(samdb, low, high, id, replace=False):
 
     tab = []
     if not replace:
 
     tab = []
     if not replace:
-        entry = samdb.search(expression="(&(dn=@PROVISION)(%s=*))" %
-                                LAST_PROVISION_USN_ATTRIBUTE, base="",
-                                scope=ldb.SCOPE_SUBTREE,
-                                attrs=[LAST_PROVISION_USN_ATTRIBUTE, "dn"])
+        entry = samdb.search(base="@PROVISION",
+                             scope=ldb.SCOPE_BASE,
+                             attrs=[LAST_PROVISION_USN_ATTRIBUTE, "dn"])
         for e in entry[0][LAST_PROVISION_USN_ATTRIBUTE]:
             if not re.search(';', e):
                 e = "%s;%s" % (e, id)
         for e in entry[0][LAST_PROVISION_USN_ATTRIBUTE]:
             if not re.search(';', e):
                 e = "%s;%s" % (e, id)
@@ -345,9 +344,9 @@ def update_provision_usn(samdb, low, high, id, replace=False):
     delta.dn = ldb.Dn(samdb, "@PROVISION")
     delta[LAST_PROVISION_USN_ATTRIBUTE] = ldb.MessageElement(tab,
         ldb.FLAG_MOD_REPLACE, LAST_PROVISION_USN_ATTRIBUTE)
     delta.dn = ldb.Dn(samdb, "@PROVISION")
     delta[LAST_PROVISION_USN_ATTRIBUTE] = ldb.MessageElement(tab,
         ldb.FLAG_MOD_REPLACE, LAST_PROVISION_USN_ATTRIBUTE)
-    entry = samdb.search(expression="(&(dn=@PROVISION)(provisionnerID=*))",
-                            base="", scope=ldb.SCOPE_SUBTREE,
-                            attrs=["provisionnerID"])
+    entry = samdb.search(expression='provisionnerID=*',
+                         base="@PROVISION", scope=ldb.SCOPE_BASE,
+                         attrs=["provisionnerID"])
     if len(entry) == 0 or len(entry[0]) == 0:
         delta["provisionnerID"] = ldb.MessageElement(id, ldb.FLAG_MOD_ADD, "provisionnerID")
     samdb.modify(delta)
     if len(entry) == 0 or len(entry[0]) == 0:
         delta["provisionnerID"] = ldb.MessageElement(id, ldb.FLAG_MOD_ADD, "provisionnerID")
     samdb.modify(delta)
@@ -398,10 +397,14 @@ def get_last_provision_usn(sam):
     :return: a dictionnary which keys are invocation id and values are an array
              of integer representing the different ranges
     """
     :return: a dictionnary which keys are invocation id and values are an array
              of integer representing the different ranges
     """
-    entry = sam.search(expression="(&(dn=@PROVISION)(%s=*))" %
-                        LAST_PROVISION_USN_ATTRIBUTE,
-                        base="", scope=ldb.SCOPE_SUBTREE,
-                        attrs=[LAST_PROVISION_USN_ATTRIBUTE, "provisionnerID"])
+    try:
+        entry = sam.search(expression="%s=*" % LAST_PROVISION_USN_ATTRIBUTE,
+                           base="@PROVISION", scope=ldb.SCOPE_BASE,
+                           attrs=[LAST_PROVISION_USN_ATTRIBUTE, "provisionnerID"])
+    except ldb.LdbError, (ecode, emsg):
+        if ecode == ldb.ERR_NO_SUCH_OBJECT:
+            return None
+        raise
     if len(entry):
         myids = []
         range = {}
     if len(entry):
         myids = []
         range = {}
index b81ee8a8ab56aa20e1a1de4fb4e7e4f99ebc98c2..62ab1790bcf90821e33a1bf9b2288d0c939941d1 100644 (file)
@@ -27,7 +27,7 @@ from samba.upgradehelpers import  (usn_in_range, dn_sort,
 from samba.tests.provision import create_dummy_secretsdb
 from samba.tests import TestCaseInTempDir
 from samba import Ldb
 from samba.tests.provision import create_dummy_secretsdb
 from samba.tests import TestCaseInTempDir
 from samba import Ldb
-from ldb import SCOPE_SUBTREE
+from ldb import SCOPE_BASE
 import samba.tests
 
 def dummymessage(a=None, b=None):
 import samba.tests
 
 def dummymessage(a=None, b=None):
@@ -123,10 +123,8 @@ class UpdateSecretsTests(samba.tests.TestCaseInTempDir):
     def test_update_modules(self):
         empty_db = self._getEmptyDb()
         update_secrets(self.referencedb, empty_db, dummymessage)
     def test_update_modules(self):
         empty_db = self._getEmptyDb()
         update_secrets(self.referencedb, empty_db, dummymessage)
-        newmodules = empty_db.search(
-            expression="dn=@MODULES", base="", scope=SCOPE_SUBTREE)
-        refmodules = self.referencedb.search(
-            expression="dn=@MODULES", base="", scope=SCOPE_SUBTREE)
+        newmodules = empty_db.search(base="@MODULES", scope=SCOPE_BASE)
+        refmodules = self.referencedb.search(base="@MODULES", scope=SCOPE_BASE)
         self.assertEquals(newmodules.msgs, refmodules.msgs)
 
     def tearDown(self):
         self.assertEquals(newmodules.msgs, refmodules.msgs)
 
     def tearDown(self):
index e15523033fb82c1fc43f37331d0e2e43cc81eec3..1ee1c044e7cfdd1be07d9543e4ac786917761941 100755 (executable)
@@ -441,10 +441,8 @@ def update_secrets(newsecrets_ldb, secrets_ldb, messagefunc):
     """
 
     messagefunc(SIMPLE, "Update of secrets.ldb")
     """
 
     messagefunc(SIMPLE, "Update of secrets.ldb")
-    reference = newsecrets_ldb.search(expression="dn=@MODULES", base="",
-                                        scope=SCOPE_SUBTREE)
-    current = secrets_ldb.search(expression="dn=@MODULES", base="",
-                                        scope=SCOPE_SUBTREE)
+    reference = newsecrets_ldb.search(base="@MODULES", scope=SCOPE_BASE)
+    current = secrets_ldb.search(base="@MODULES", scope=SCOPE_BASE)
     assert reference, "Reference modules list can not be empty"
     if len(current) == 0:
         # No modules present
     assert reference, "Reference modules list can not be empty"
     if len(current) == 0:
         # No modules present