Re: LDAP configuration and hooks
Jens Wahnes <[email protected]> Sat, 30 Nov 2019 14:08:07 +0100
| Newsgroups | gmane.comp.horde.user |
|---|---|
| Organization | Wahnes World |
| Message-ID | <[email protected]> |
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_ob)
>> =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']->getIns=
tance('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['conf=
']['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('attribu=
tes' =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 $re=
sult->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:
public function prefs_init($pref, $value, $username, $scope_ob)
{
// [...]
=
$factory =3D =
$GLOBALS['injector']->getInstance('Horde_Core_Factory_Ldap');
$ldap =3D $factory->create('horde', $factory->getConfig('auth'));
try {
$userdn =3D $ldap->findUserDN($username);
$user =3D $ldap->getEntry($userdn, array('mail','sn'));
$email =3D $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
-- =
Horde mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]