[horde] LDAP configuration and hooks

David Wells - Alfavinil S.A. dwells at alfavinil.com
Mon Dec 2 12:46:12 UTC 2019


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ó:
> David Wells wrote:
>> When I modify the hooks.local.php file so that it reads
>>
>>> <?php
>>> class Horde_Hooks
>>> {
>>>     public function prefs_init($pref, $value, $username, $scope_ob)
>>>     {
>>>         switch ($pref) {
>>>         case 'from_addr':
>>>
>>>             if (is_null($username)) {
>>>                 return $value;
>>>             }
>>>
>>>             $ldap = $GLOBALS['injector']->getInstance('Horde_Ldap');
>>>             try {
>>>                 $result = $ldap->search(
>>>                     $GLOBALS['conf']['ldap']['user']['basedn'],
>>> Horde_Ldap_Filter::create('userPrincipalName', 'equals', $username),
>>>                     array('attributes' => array('mail'))
>>>                 );
>>>                 if ($result->count()) {
>>>                     $entry = $result->shiftEntry();
>>>                     return $entry->getValue('mail', 'single');
>>>                 }
>>>             } catch (Horde_Ldap_Exception $e) {
>>>             }
>
> I'm not sure if that can actually work.
>
> Here's an excerpt of what we use inside Horde_Hooks that does the job:
>
>     public function prefs_init($pref, $value, $username, $scope_ob)
>     {
>       // [...]
>     
>           $factory =
> $GLOBALS['injector']->getInstance('Horde_Core_Factory_Ldap');
>           $ldap = $factory->create('horde', $factory->getConfig('auth'));
>           try {
>             $userdn = $ldap->findUserDN($username);
>             $user = $ldap->getEntry($userdn, array('mail','sn'));
>             $email = $user->getValue('mail', 'single');
>           } catch (Horde_Ldap_Exception $e) {
>             Horde::log("prefs_init: user $username: Error looking up
> LDAP information", 'WARN');
>             Horde::log($e, 'WARN');
>             return $value;
>           } catch (Horde_Exception_NotFound $e) {
>             Horde::log("prefs_init: user $username: User not present
> in LDAP", 'WARN');
>             Horde::log($e, 'WARN');
>             return $value;
>           }
>
>      // [...]
>     }
>     
>
>
> For all I know, it doesn't matter if the file is named hooks.php or
> hooks.local.php.
>
>
> Jens



More information about the horde mailing list