samba-tool domain passwordsettings: Avoid except Exception
authorAndrew Bartlett <abartlet@samba.org>
Fri, 10 Aug 2018 01:06:36 +0000 (13:06 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 17 Aug 2018 00:58:27 +0000 (02:58 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/netcmd/pso.py

index c06f55cb62b8ea850ddac2d9d0f4f37527395e6b..e43886eb23bbe9918a4ab7891a1c555244fc30e5 100644 (file)
@@ -109,8 +109,10 @@ def check_pso_valid(samdb, pso_dn, name):
     try:
         res = samdb.search(pso_dn, scope=ldb.SCOPE_BASE,
                            attrs=['msDS-PasswordSettingsPrecedence'])
-    except Exception as e:
-        raise CommandError("Unable to find PSO '%s'" % name)
+    except ldb.LdbError as e:
+        if e.args[0] == ldb.ERR_NO_SUCH_OBJECT:
+            raise CommandError("Unable to find PSO '%s'" % name)
+        raise
 
     # users need admin permission to modify/view a PSO. In this case, the
     # search succeeds, but it doesn't return any attributes
@@ -323,8 +325,11 @@ class cmd_domain_pwdsettings_pso_create(Command):
         pso_dn = "CN=%s,%s" % (psoname, pso_container(samdb))
         try:
             res = samdb.search(pso_dn, scope=ldb.SCOPE_BASE)
-        except Exception as e:
-            pass
+        except ldb.LdbError as e:
+            if e.args[0] == ldb.ERR_NO_SUCH_OBJECT:
+                pass
+            else:
+                raise
         else:
             raise CommandError("PSO '%s' already exists" % psoname)