pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0017-cert-do-not-limit-internal-searches-in-cert-find.patch

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