[horde] Re: Some user hooks questions
Craig White
craigwhite at azapple.com
Sat Apr 23 22:46:15 PDT 2005
On Sat, 2005-04-23 at 23:19 -0400, Kevin Myer wrote:
> Quoting Kevin Myer <kevin_myer at iu13.org>:
>
> >
> > I found that when using Administration -> Users to view the users in
> > the system,
> > if I would click on a user, their Full Name and email address would be
> > populated with my information. So it would seem that the admin module is
> > passing my userid to the hook function and not the userid that I'm viewing.
> > After looking at the code from the Wiki, it would seem that the Auth::getAuth
> > and Auth:getBareAuth calls are what is actually doing this -
> > regardless of the
> > value of $user passed to the hook, it will always return the info for the
> > currently logged in user. So my question would be - is there an equivalent
> > Auth::getAuth function (or maybe not an Auth function but a utility function)
> > to lookup values for arbitrary users?
>
> Alright, I was thinking a little bit too hard for this. The hook in
> the Wiki is
> actually a little bit buggy. If $user is passed to the fullname or from_addr
> functions and is a value that is not the current user, then Auth::getAuth
> shouldn't be used, because that will always return the currently logged in
> user. I just removed all the Auth:getAuth and Auth::getBareAuth calls, threw
> in a Auth::removeHook call (needed for our environment) and problem
> solved. It
> almost appears that the functions in the Wiki to do this weren't written to
> handle anyone but the currently logged in user, because the search is done for
> $uid and $uid is always Auth::getBareAuth, regardless of what $user is. And
> unless I'm mistaken, $user will always be some value, so the is_null check is
> bogus.
>
> Here's what I ended up using:
>
> if (!function_exists('_prefs_hook_fullname')) {
>
> function _prefs_hook_fullname($uid = null)
> {
> global $conf;
> $ldapServer = 'yourdirectoryserver';
> $ldapPort = '389';
> $searchBase = 'yoursearchbase';
> $ds = @ldap_connect($ldapServer, $ldapPort);
>
> if (@ldap_bind($ds)) {
> $searchResult = @ldap_list($ds, $searchBase,
> $conf['auth']['params']['uid'] . '=' . $uid);
> }
>
> $information = @ldap_get_entries($ds, $searchResult);
>
> // derive the email address if possible
> if ($information[0]['cn'][0] != '') {
> $name = $information[0]['cn'][0];
> } else {
> $name = $information[0]['gecos'][0];
> }
>
> ldap_close($ds);
>
> return $name;
> }
> }
----
that Wiki entry must be mine - of course I was unconcerned for virtual
domains. You might wish to put your info into the Wiki for others that
have a similar use.
Craig
More information about the horde
mailing list