Add the opportunity to change base DN and scope in the callback.

This makes the callback a lot more powerful, because it enables the plugin author to broaden or completely change the search location.

Pavel
>From 22d9cc1184d410d89e5e51956a65b6fc0c862468 Mon Sep 17 00:00:00 2001
From: Pavel Zuna <pz...@redhat.com>
Date: Tue, 23 Nov 2010 09:02:54 -0500
Subject: [PATCH 1/3] 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(-)

diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 5dd8c9b..d38131a 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -1153,19 +1153,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)
             )
@@ -1173,7 +1174,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:
@@ -1199,8 +1200,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 5ecc72a..5db3c67 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 2e77dd5..61ababe 100644
--- a/ipalib/plugins/host.py
+++ b/ipalib/plugins/host.py
@@ -437,11 +437,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 d66e696..d7529ca 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 c65a7a4..6cdba9b 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 b34ba99..5b6e03b 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:
-- 
1.7.1.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to