From 110d46b79209b74c0081e0baffc90b0cfc9f3ba2 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Wed, 18 Aug 2010 14:04:58 -0400 Subject: Use global time and size limit values when searching. Add test to verify that limit is honored and truncated flag set. ticket #48 --- ipaserver/plugins/ldap2.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'ipaserver') diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py index 81c2aeb53..79d6d9960 100644 --- a/ipaserver/plugins/ldap2.py +++ b/ipaserver/plugins/ldap2.py @@ -466,7 +466,7 @@ class ldap2(CrudBackend, Encoder): @encode_args(1, 2, 3) @decode_retval() def find_entries(self, filter, attrs_list=None, base_dn='', - scope=_ldap.SCOPE_SUBTREE, time_limit=1, size_limit=3000, + scope=_ldap.SCOPE_SUBTREE, time_limit=None, size_limit=None, normalize=True): """ Return a list of entries [(dn, entry_attrs)] matching specified @@ -477,8 +477,8 @@ class ldap2(CrudBackend, Encoder): attrs_list -- list of attributes to return, all if None (default None) base_dn -- dn of the entry at which to start the search (default '') scope -- search scope, see LDAP docs (default ldap2.SCOPE_SUBTREE) - time_limit -- time limit in seconds (default 1) - size_limit -- size (number of entries returned) limit (default 3000) + time_limit -- time limit in seconds (default use IPA config values) + size_limit -- size (number of entries returned) limit (default use IPA config values) normalize -- normalize the DN (default True) """ if normalize: @@ -488,6 +488,17 @@ class ldap2(CrudBackend, Encoder): res = [] truncated = False + if time_limit is None or size_limit is None: + (cdn, config) = self.get_ipa_config() + if time_limit is None: + time_limit = config.get('ipasearchtimelimit')[0] + if size_limit is None: + size_limit = config.get('ipasearchrecordslimit')[0] + if not isinstance(size_limit, int): + size_limit = int(size_limit) + if not isinstance(time_limit, float): + time_limit = float(time_limit) + # pass arguments to python-ldap try: id = self.conn.search_ext( @@ -534,8 +545,9 @@ class ldap2(CrudBackend, Encoder): def get_ipa_config(self): """Returns the IPA configuration entry (dn, entry_attrs).""" - filter = '(cn=ipaConfig)' - return self.find_entries(filter, None, 'cn=etc', self.SCOPE_ONELEVEL)[0][0] + cdn = "%s,%s" % (api.Object.config.get_dn(), api.env.basedn) + return self.find_entries(None, None, cdn, self.SCOPE_BASE, + time_limit=2, size_limit=10)[0][0] def get_schema(self): """Returns a copy of the current LDAP schema.""" -- cgit