Re: LDAP configuration and hooks

"David Wells - Alfavinil S.A." <[email protected]> Mon, 2 Dec 2019 09:46:12 -0300
Newsgroups gmane.comp.horde.user
Message-ID <[email protected]>
Thanks for your answer. This same code which is taken from the
hooks.php.dist as a sample does actually work on a server that has an
openldap server listening on localhost:389, but this is not the case on
this server. Thanks for the code sample, I'll try it and report back.

Thanks again!
Best regards,
David Wells.


El 30/11/2019 a las 10:08, Jens Wahnes escribi=F3:
> David Wells wrote:
>> When I modify the hooks.local.php file so that it reads
>>
>>> <?php
>>> class Horde_Hooks
>>> {
>>> =A0=A0=A0 public function prefs_init($pref, $value, $username, $scope_o=
b)
>>> =A0=A0=A0 {
>>> =A0=A0=A0=A0=A0=A0=A0 switch ($pref) {
>>> =A0=A0=A0=A0=A0=A0=A0 case 'from_addr':
>>>
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (is_null($username)) {
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return $value;
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
>>>
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 $ldap =3D $GLOBALS['injector']->getIn=
stance('Horde_Ldap');
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 try {
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 $result =3D $ldap->search(
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 $GLOBALS['con=
f']['ldap']['user']['basedn'],
>>> Horde_Ldap_Filter::create('userPrincipalName', 'equals', $username),
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 array('attrib=
utes' =3D> array('mail'))
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 );
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if ($result->count()) {
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 $entry =3D $r=
esult->shiftEntry();
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return $entry=
->getValue('mail', 'single');
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 } catch (Horde_Ldap_Exception $e) {
>>> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
>
> I'm not sure if that can actually work.
>
> Here's an excerpt of what we use inside Horde_Hooks that does the job:
>
> =A0=A0=A0 public function prefs_init($pref, $value, $username, $scope_ob)
> =A0=A0=A0 {
> =A0=A0=A0=A0=A0 // [...]
> =A0=A0=A0=A0
> =A0=A0=A0=A0=A0=A0=A0=A0=A0 $factory =3D
> $GLOBALS['injector']->getInstance('Horde_Core_Factory_Ldap');
> =A0=A0=A0=A0=A0=A0=A0=A0=A0 $ldap =3D $factory->create('horde', $factory-=
>getConfig('auth'));
> =A0=A0=A0=A0=A0=A0=A0=A0=A0 try {
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 $userdn =3D $ldap->findUserDN($username=
);
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 $user =3D $ldap->getEntry($userdn, arra=
y('mail','sn'));
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 $email =3D $user->getValue('mail', 'sin=
gle');
> =A0=A0=A0=A0=A0=A0=A0=A0=A0 } catch (Horde_Ldap_Exception $e) {
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Horde::log("prefs_init: user $username:=
 Error looking up
> LDAP information", 'WARN');
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Horde::log($e, 'WARN');
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return $value;
> =A0=A0=A0=A0=A0=A0=A0=A0=A0 } catch (Horde_Exception_NotFound $e) {
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Horde::log("prefs_init: user $username:=
 User not present
> in LDAP", 'WARN');
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Horde::log($e, 'WARN');
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return $value;
> =A0=A0=A0=A0=A0=A0=A0=A0=A0 }
>
> =A0=A0=A0=A0 // [...]
> =A0=A0=A0 }
> =A0=A0=A0=A0
>
>
> For all I know, it doesn't matter if the file is named hooks.php or
> hooks.local.php.
>
>
> Jens

-- =

Horde mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]