[horde] LDAP configuration and hooks

Jens Wahnes wahnes at uni-koeln.de
Sat Nov 30 13:08:07 UTC 2019


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