From 5060fdfade63f299bf3ad15c16a1aff06135b80f Mon Sep 17 00:00:00 2001 From: Pavel Zuna Date: Tue, 23 Nov 2010 09:02:54 -0500 Subject: Change signature of LDAPSearch.pre_callback. Add the opportunity to change base DN and scope in the callback. --- ipalib/plugins/baseldap.py | 19 ++++++++++--------- ipalib/plugins/group.py | 4 ++-- ipalib/plugins/host.py | 4 ++-- ipalib/plugins/misc.py | 10 ++++++++++ ipalib/plugins/service.py | 7 ++++--- ipalib/plugins/user.py | 4 ++-- 6 files changed, 30 insertions(+), 18 deletions(-) (limited to 'ipalib') diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py index 315deb09d..e0dcad44f 100644 --- a/ipalib/plugins/baseldap.py +++ b/ipalib/plugins/baseldap.py @@ -1149,19 +1149,20 @@ class LDAPSearch(CallbackInterface, crud.Search): (term_filter, attr_filter), rules=ldap.MATCH_ALL ) + scope = ldap.SCOPE_ONELEVEL for callback in self.PRE_CALLBACKS: if hasattr(callback, 'im_self'): - filter = callback( - ldap, filter, attrs_list, base_dn, *args, **options - ) + (filter, base_dn, scope) = callback( + ldap, filter, attrs_list, base_dn, scope, *args, **options + ) else: - filter = callback( - self, ldap, filter, attrs_list, base_dn, *args, **options + (filter, base_dn, scope) = callback( + self, ldap, filter, attrs_list, base_dn, scope, *args, **options ) try: (entries, truncated) = ldap.find_entries( - filter, attrs_list, base_dn, scope=ldap.SCOPE_ONELEVEL, + filter, attrs_list, base_dn, scope, time_limit=options.get('timelimit', None), size_limit=options.get('sizelimit', None) ) @@ -1169,7 +1170,7 @@ class LDAPSearch(CallbackInterface, crud.Search): try: (entries, truncated) = self._call_exc_callbacks( args, options, e, ldap.find_entries, filter, attrs_list, - base_dn, scoope=ldap.SCOPE_ONELEVEL, + base_dn, scope=ldap.SCOPE_ONELEVEL, normalize=self.obj.normalize_dn ) except errors.NotFound: @@ -1195,8 +1196,8 @@ class LDAPSearch(CallbackInterface, crud.Search): truncated=truncated, ) - def pre_callback(self, ldap, filter, attrs_list, base_dn, *args, **options): - return filter + def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **options): + return (filter, base_dn, scope) def post_callback(self, ldap, entries, truncated, *args, **options): pass diff --git a/ipalib/plugins/group.py b/ipalib/plugins/group.py index 5ecc72ae8..5db3c67ec 100644 --- a/ipalib/plugins/group.py +++ b/ipalib/plugins/group.py @@ -223,7 +223,7 @@ class group_find(LDAPSearch): ), ) - def pre_callback(self, ldap, filter, attrs_list, base_dn, *args, **options): + def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **options): # if looking for private groups, we need to create a new search filter, # because private groups have different object classes if options['private']: @@ -243,7 +243,7 @@ class group_find(LDAPSearch): cflt = ldap.make_filter(search_kw, exact=False) filter = ldap.combine_filters((oflt, cflt), rules=ldap.MATCH_ALL) - return filter + return (filter, base_dn, scope) api.register(group_find) diff --git a/ipalib/plugins/host.py b/ipalib/plugins/host.py index 9d3a2a9a9..b3caf1851 100644 --- a/ipalib/plugins/host.py +++ b/ipalib/plugins/host.py @@ -556,11 +556,11 @@ class host_find(LDAPSearch): ) member_attributes = ['managedby'] - def pre_callback(self, ldap, filter, attrs_list, base_dn, *args, **options): + def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **options): if 'locality' in attrs_list: attrs_list.remove('locality') attrs_list.append('l') - return filter.replace('locality', 'l') + return (filter.replace('locality', 'l'), base_dn, scope) def post_callback(self, ldap, entries, truncated, *args, **options): for entry in entries: diff --git a/ipalib/plugins/misc.py b/ipalib/plugins/misc.py index d66e6964e..d7529ca05 100644 --- a/ipalib/plugins/misc.py +++ b/ipalib/plugins/misc.py @@ -109,6 +109,16 @@ class plugins(LocalOrRemote): '%(count)d plugin loaded', '%(count)d plugins loaded' ) + takes_options = LocalOrRemote.takes_options + ( + Flag('all', + cli_name='all', + doc=_('retrieve and print all attributes from the server. Affects command output.'), + exclude='webui', + flags=['no_output'], + default=True, + ), + ) + has_output = ( Output('result', dict, 'Dictionary mapping plugin names to bases'), Output('count', diff --git a/ipalib/plugins/service.py b/ipalib/plugins/service.py index c65a7a4ac..6cdba9b32 100644 --- a/ipalib/plugins/service.py +++ b/ipalib/plugins/service.py @@ -377,7 +377,7 @@ class service_find(LDAPSearch): member_attributes = ['managedby'] takes_options = LDAPSearch.takes_options has_output_params = LDAPSearch.has_output_params + output_params - def pre_callback(self, ldap, filter, attrs_list, base_dn, *args, **options): + def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **options): # lisp style! custom_filter = '(&(objectclass=ipaService)' \ '(!(objectClass=posixAccount))' \ @@ -386,8 +386,9 @@ class service_find(LDAPSearch): '(krbprincipalname=krbtgt/*))' \ ')' \ ')' - return ldap.combine_filters( - (custom_filter, filter), rules=ldap.MATCH_ALL + return ( + ldap.combine_filters((custom_filter, filter), rules=ldap.MATCH_ALL), + base_dn, scope ) def post_callback(self, ldap, entries, truncated, *args, **options): diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py index b34ba99f9..5b6e03b66 100644 --- a/ipalib/plugins/user.py +++ b/ipalib/plugins/user.py @@ -251,11 +251,11 @@ class user_find(LDAPSearch): doc=_('Display user record for current Kerberos principal'), ), ) - def pre_callback(self, ldap, filter, entry_attrs, attrs_list, *keys, **options): + def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *keys, **options): if options.get('whoami'): return "(&(objectclass=posixaccount)(krbprincipalname=%s))"%\ getattr(context, 'principal') - return filter + return (filter, base_dn, scope) def post_callback(self, ldap, entries, truncated, *args, **options): for entry in entries: -- cgit