s4-ldapcmp: fixed exception handling
authorAndrew Tridgell <tridge@samba.org>
Mon, 29 Nov 2010 02:30:46 +0000 (13:30 +1100)
committerAndrew Tridgell <tridge@samba.org>
Mon, 29 Nov 2010 07:04:42 +0000 (18:04 +1100)
This pattern, which is common in our code, is wrong:
            except LdbError, (ERR_NO_SUCH_OBJECT, _):

what it actually does it to change the value of ldb.ERR_NO_SUCH_OBJECT
to be equal to whatever ldb error occurred! This led to some really
bizarre behavior

source4/scripting/devel/ldapcmp

index fdb87e8d285b0d13e49382c90e72500341d06874..8e40877a22277b9489c4213db5e001a1fa89693c 100755 (executable)
@@ -112,19 +112,13 @@ class LDAPBase(object):
     def object_exists(self, object_dn):
         res = None
         try:
-            res = self.ldb.search(base=object_dn, scope=SCOPE_BASE, expression="(objectClass=*)")
-        except LdbError, (ERR_NO_SUCH_OBJECT, _):
-            return False
+            res = self.ldb.search(base=object_dn, scope=SCOPE_BASE)
+        except LdbError, (enum, estr):
+            if enum == ERR_NO_SUCH_OBJECT:
+                return False
+            raise
         return len(res) == 1
 
-    def get_object_sid(self, object_dn):
-        try:
-            res = self.ldb.search(base=object_dn, expression="(objectClass=*)", scope=SCOPE_BASE, attrs=["objectSid"])
-        except LdbError, (ERR_NO_SUCH_OBJECT, _):
-            raise Exception("DN sintax is wrong or object does't exist: " + object_dn)
-        assert len(res) == 1
-        return res[0]["objectSid"][0]
-
     def delete_force(self, object_dn):
         try:
             self.ldb.delete(object_dn)
@@ -669,18 +663,22 @@ class LDAPBundel(object):
             skip = False
             try:
                 object1 = LDAPObject(connection=self.con,
-                        dn=self.dn_list[index],
-                        summary=self.summary)
-            except LdbError, (ERR_NO_SUCH_OBJECT, _):
-                self.log( "\n!!! Object not found: %s" % self.dn_list[index] )
-                skip = True
+                                     dn=self.dn_list[index],
+                                     summary=self.summary)
+            except LdbError, (enum, estr):
+                if enum == ERR_NO_SUCH_OBJECT:
+                    self.log( "\n!!! Object not found: %s" % self.dn_list[index] )
+                    skip = True
+                raise
             try:
                 object2 = LDAPObject(connection=other.con,
                         dn=other.dn_list[index],
                         summary=other.summary)
-            except LdbError, (ERR_NO_SUCH_OBJECT, _):
-                self.log( "\n!!! Object not found: %s" % other.dn_list[index] )
-                skip = True
+            except LdbError, (enum, estr):
+                if enum == ERR_NO_SUCH_OBJECT:
+                    self.log( "\n!!! Object not found: %s" % other.dn_list[index] )
+                    skip = True
+                raise
             if skip:
                 index += 1
                 continue