[Freeipa-devel] [PATCH] 0001 pwpolicy-add: Added better error handling

Thorsten Scherf tscherf at redhat.com
Tue Aug 26 15:53:09 UTC 2014


pwpolicy-add: Added better error handling
    
    Make error message more meaningful when a password policy is added for a non
    existing group.
    
    https://fedorahosted.org/freeipa/ticket/4334

-------------- next part --------------
>From b0b2ab6d785bb8d655d3e8d84b0b2946085fbc23 Mon Sep 17 00:00:00 2001
From: Thorsten Scherf <tscherf at redhat.com>
Date: Tue, 26 Aug 2014 17:46:36 +0200
Subject: [PATCH] pwpolicy-add: Added better error handling

Make error message more meaningful when a password policy is added for a non
existing group.

https://fedorahosted.org/freeipa/ticket/4334
---
 ipalib/plugins/pwpolicy.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ipalib/plugins/pwpolicy.py b/ipalib/plugins/pwpolicy.py
index 1976675c56000cff14b211e115fda28105107c15..a6e4fa47cd60342a779ce9a880fabc5ba7a88b39 100644
--- a/ipalib/plugins/pwpolicy.py
+++ b/ipalib/plugins/pwpolicy.py
@@ -159,9 +159,14 @@ class cosentry_add(LDAPCreate):
 
     def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
         assert isinstance(dn, DN)
+        
         # check for existence of the group
         group_dn = self.api.Object.group.get_dn(keys[-1])
-        result = ldap.get_entry(group_dn, ['objectclass'])
+        try:
+            result = ldap.get_entry(group_dn, ['objectclass'])
+        except errors.NotFound:
+            raise errors.NotFound(reason=_(u'%s: Group not found') % keys )
+
         oc = map(lambda x:x.lower(),result['objectclass'])
         if 'mepmanagedentry' in oc:
             raise errors.ManagedPolicyError()
-- 
1.9.3



More information about the Freeipa-devel mailing list