diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-11-29 13:30:46 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-11-29 18:04:42 +1100 |
commit | f8d73e466b454a63f256021ad2f353e9ad93e8f7 (patch) | |
tree | 929cc112ed8917e121da5a433ec1e144a588a30c | |
parent | 0dd2152b01b93b2a09ea0332ba60e2e0338b1c15 (diff) | |
download | samba-f8d73e466b454a63f256021ad2f353e9ad93e8f7.tar.gz samba-f8d73e466b454a63f256021ad2f353e9ad93e8f7.tar.bz2 samba-f8d73e466b454a63f256021ad2f353e9ad93e8f7.zip |
s4-ldapcmp: fixed exception handling
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
-rwxr-xr-x | source4/scripting/devel/ldapcmp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/source4/scripting/devel/ldapcmp b/source4/scripting/devel/ldapcmp index fdb87e8d28..8e40877a22 100755 --- a/source4/scripting/devel/ldapcmp +++ b/source4/scripting/devel/ldapcmp @@ -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 |