ac7d03
From ca26e32beb77fbd8fcc66e6eea07c6eeeb9261c9 Mon Sep 17 00:00:00 2001
ac7d03
From: Jan Cholasta <jcholast@redhat.com>
ac7d03
Date: Wed, 22 Mar 2017 06:58:25 +0000
ac7d03
Subject: [PATCH] cert: do not limit internal searches in cert-find
ac7d03
ac7d03
Instead, apply the limits on the combined result.
ac7d03
ac7d03
This fixes (absence of) `--sizelimit` leading to strange behavior, such as
ac7d03
`cert-find --users user` returning a non-empty result only with
ac7d03
`--sizelimit 0`.
ac7d03
ac7d03
https://pagure.io/freeipa/issue/6716
ac7d03
ac7d03
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
ac7d03
---
ac7d03
 ipaserver/plugins/cert.py | 28 ++++++++++------------------
ac7d03
 1 file changed, 10 insertions(+), 18 deletions(-)
ac7d03
ac7d03
diff --git a/ipaserver/plugins/cert.py b/ipaserver/plugins/cert.py
ac7d03
index 9f901076075809592ad5ddeec8d71c273d4853c9..1a6d04533cebb2eb00022981dae9ffe5b785ba8b 100644
ac7d03
--- a/ipaserver/plugins/cert.py
ac7d03
+++ b/ipaserver/plugins/cert.py
ac7d03
@@ -1324,7 +1324,7 @@ class cert_find(Search, CertMethod):
ac7d03
 
ac7d03
         return result, False, True
ac7d03
 
ac7d03
-    def _ca_search(self, all, raw, pkey_only, sizelimit, exactly, **options):
ac7d03
+    def _ca_search(self, all, raw, pkey_only, exactly, **options):
ac7d03
         ra_options = {}
ac7d03
         for name in ('revocation_reason',
ac7d03
                      'issuer',
ac7d03
@@ -1343,10 +1343,6 @@ class cert_find(Search, CertMethod):
ac7d03
             elif isinstance(value, DN):
ac7d03
                 value = unicode(value)
ac7d03
             ra_options[name] = value
ac7d03
-        if sizelimit > 0:
ac7d03
-            # Dogtag doesn't tell that the size limit was exceeded
ac7d03
-            # search for one more entry so that we can tell ourselves
ac7d03
-            ra_options['sizelimit'] = sizelimit + 1
ac7d03
         if exactly:
ac7d03
             ra_options['exactly'] = True
ac7d03
 
ac7d03
@@ -1369,11 +1365,6 @@ class cert_find(Search, CertMethod):
ac7d03
 
ac7d03
         ra = self.api.Backend.ra
ac7d03
         for ra_obj in ra.find(ra_options):
ac7d03
-            if sizelimit > 0 and len(result) >= sizelimit:
ac7d03
-                self.add_message(messages.SearchResultTruncated(
ac7d03
-                        reason=errors.SizeLimitExceeded()))
ac7d03
-                break
ac7d03
-
ac7d03
             issuer = DN(ra_obj['issuer'])
ac7d03
             serial_number = ra_obj['serial_number']
ac7d03
 
ac7d03
@@ -1411,8 +1402,7 @@ class cert_find(Search, CertMethod):
ac7d03
 
ac7d03
         return result, False, complete
ac7d03
 
ac7d03
-    def _ldap_search(self, all, raw, pkey_only, no_members, timelimit,
ac7d03
-                     sizelimit, **options):
ac7d03
+    def _ldap_search(self, all, raw, pkey_only, no_members, **options):
ac7d03
         ldap = self.api.Backend.ldap2
ac7d03
 
ac7d03
         filters = []
ac7d03
@@ -1453,8 +1443,8 @@ class cert_find(Search, CertMethod):
ac7d03
                 base_dn=self.api.env.basedn,
ac7d03
                 filter=filter,
ac7d03
                 attrs_list=['usercertificate'],
ac7d03
-                time_limit=timelimit,
ac7d03
-                size_limit=sizelimit,
ac7d03
+                time_limit=0,
ac7d03
+                size_limit=0,
ac7d03
             )
ac7d03
         except errors.EmptyResult:
ac7d03
             entries = []
ac7d03
@@ -1527,13 +1517,9 @@ class cert_find(Search, CertMethod):
ac7d03
                 raw=raw,
ac7d03
                 pkey_only=pkey_only,
ac7d03
                 no_members=no_members,
ac7d03
-                timelimit=timelimit,
ac7d03
-                sizelimit=sizelimit,
ac7d03
                 **options)
ac7d03
 
ac7d03
             if sub_complete:
ac7d03
-                sizelimit = 0
ac7d03
-
ac7d03
                 for key in tuple(result):
ac7d03
                     if key not in sub_result:
ac7d03
                         del result[key]
ac7d03
@@ -1552,6 +1538,12 @@ class cert_find(Search, CertMethod):
ac7d03
             complete = complete or sub_complete
ac7d03
 
ac7d03
         result = list(six.itervalues(result))
ac7d03
+        if sizelimit > 0 and len(result) > sizelimit:
ac7d03
+            if not truncated:
ac7d03
+                self.add_message(messages.SearchResultTruncated(
ac7d03
+                        reason=errors.SizeLimitExceeded()))
ac7d03
+            result = result[:sizelimit]
ac7d03
+            truncated = True
ac7d03
 
ac7d03
         ret = dict(
ac7d03
             result=result
ac7d03
-- 
ac7d03
2.12.1
ac7d03