summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2007-12-06 16:48:26 -0500
committerRob Crittenden <rcritten@redhat.com>2007-12-06 16:48:26 -0500
commit04cccd44264b2607cc919758146cfdce99d342b5 (patch)
treee8233dc2e17b0053af01b681cbac6be143c30d18
parent2a2d8665522a239aad56954cadfc618f220841d3 (diff)
downloadfreeipa-04cccd44264b2607cc919758146cfdce99d342b5.tar.gz
freeipa-04cccd44264b2607cc919758146cfdce99d342b5.tar.xz
freeipa-04cccd44264b2607cc919758146cfdce99d342b5.zip
Improve the error message when an entry is not found.
We used to return the entire argument string ala: ('dc=freeipa,dc=org', 2, 'uid=foo', ['*']) This adds a regex to try to print anything after = in the filter. Not perfect but better.
-rw-r--r--ipa-server/ipaserver/ipaldap.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/ipa-server/ipaserver/ipaldap.py b/ipa-server/ipaserver/ipaldap.py
index ef8becec..b1a9ea56 100644
--- a/ipa-server/ipaserver/ipaldap.py
+++ b/ipa-server/ipaserver/ipaldap.py
@@ -356,13 +356,13 @@ class IPAdmin(SimpleLDAPObject):
type, obj = self.result(res)
except ldap.NO_SUCH_OBJECT:
raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND,
- "no such entry for " + str(args))
+ notfound(args))
except ldap.LDAPError, e:
raise ipaerror.gen_exception(ipaerror.LDAP_DATABASE_ERROR, None, e)
if not obj:
raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND,
- "no such entry for " + str(args))
+ notfound(args))
elif isinstance(obj,Entry):
return obj
else: # assume list/tuple
@@ -386,7 +386,7 @@ class IPAdmin(SimpleLDAPObject):
if not obj:
raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND,
- "no such entry for " + str(args))
+ notfound(args))
all_users = []
for s in obj:
@@ -424,7 +424,7 @@ class IPAdmin(SimpleLDAPObject):
if not entries:
raise ipaerror.gen_exception(ipaerror.LDAP_NOT_FOUND,
- "no such entry for " + str(args))
+ notfound(args))
if partial == 1:
counter = -1
@@ -717,3 +717,16 @@ class IPAdmin(SimpleLDAPObject):
"""Returns True if the given string is a DN, False otherwise."""
return (dn.find("=") > 0)
is_a_dn = staticmethod(is_a_dn)
+
+
+def notfound(args):
+ """Return a string suitable for displaying as an error when a
+ search returns no results.
+
+ This just returns whatever is after the equals sign"""
+ filter = args[2]
+ try:
+ target = re.match(r'\(.*=(.*)\)', filter).group(1)
+ except:
+ target = filter
+ return "%s not found" % str(target)