On 09/15/2010 11:31 AM, Adam Young wrote:
On 09/15/2010 09:42 AM, Rob Crittenden wrote:
Adam Young wrote:
On 09/14/2010 05:57 PM, Rob Crittenden wrote:
Adam Young wrote:
admiyo-freeipa-0024-user-whoami.patch broke the user-find, due to a
missing return statement. It has been reverted. Here is the corrected
one.

NACK.

I think you want to use false for options.get:
if options.get('whoami', False):

Otherwise it will always return the whoami version.

Doesn't seem to be working that way.

If I kinit as kfrog:

ipa user-find pdawn
--------------
1 user matched
--------------
User login: pdawn
First name: Prairie
Last name: Dawn
Home directory: /home/pdawn
Login shell: /bin/sh
Groups: ipausers, muppets
----------------------------
Number of entries returned 1

[ayo...@ipa ~]$ ipa user-find
---------------
7 users matched
---------------
...


You're relying on the fact that the CLI always includes whoami in the options list. If whoami isn't sent it will default to True and return the wrong thing.
Setting it to false does not work:

[r...@ipa ~]# ipa user-find --whoami
---------------
0 users matched
---------------
----------------------------
Number of entries returned 0
----------------------------



I'm not sure which is most efficient when building a string but it is
easier to read the filter this way IMHO:

return "(&(objectclass=posixaccount)(krbprincipalname=%s))"%\
util.get_current_principal()

If you still NACK after the previous comment, I'll do the printf style.



rob


rob

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

Fixed.  Problem was a typo in the filter.

>From e298eedc4706df21abbe4c3e103eadd22c935356 Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Tue, 14 Sep 2010 16:50:00 -0400
Subject: [PATCH] user-find whoami

Now no longer breaks user-find with a filter
Uses the corrected Params for getting option
printf style strings
---
 ipalib/plugins/user.py |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py
index 5841d7a..1cd28c9 100644
--- a/ipalib/plugins/user.py
+++ b/ipalib/plugins/user.py
@@ -51,6 +51,7 @@ from ipalib import api, errors
 from ipalib import Flag, Int, Password, Str
 from ipalib.plugins.baseldap import *
 from ipalib import _, ngettext
+from ipalib import util
 
 
 class user(LDAPObject):
@@ -241,6 +242,18 @@ class user_find(LDAPSearch):
     Search for users.
     """
 
+    takes_options = (
+        Flag('whoami',
+            label=_('Self'),
+            doc=_('Display user record for current Kerberos principal'),
+        ),
+    )
+    def pre_callback(self, ldap, filter, entry_attrs, attrs_list, *keys, **options):
+        if options.get('whoami'):
+            return "(&(objectclass=posixaccount)(krbprincipalname=%s))"%\
+                util.get_current_principal()
+        return filter
+
     msg_summary = ngettext(
         '%(count)d user matched', '%(count)d users matched', 0
     )
-- 
1.7.1

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

Reply via email to