LDAP configuration and hooks

David Wells <[email protected]> Thu, 28 Nov 2019 18:12:41 -0300
Newsgroups gmane.comp.horde.user
Message-ID <[email protected]>
Hi!


I have configured the LDAP settings in horde as follow

> $conf['ldap']['hostspec'] =3D array('dc1.fliawells.com.ar');
> $conf['ldap']['port'] =3D 3268;
> $conf['ldap']['tls'] =3D true;
> $conf['ldap']['timeout'] =3D 5;
> $conf['ldap']['version'] =3D 3;
> $conf['ldap']['user']['basedn'] =3D 'DC=3Dfliawells,DC=3Dcom,DC=3Dar';
> $conf['ldap']['user']['uid'] =3D 'userPrincipalName';
> $conf['ldap']['user']['objectclass'] =3D array('*');
> $conf['ldap']['user']['filter_type'] =3D 'objectclass';
> $conf['ldap']['bindas'] =3D 'user';
> $conf['ldap']['useldap'] =3D true;

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']->getInst=
ance('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('attribut=
es' =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 $res=
ult->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 }
>
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return $value;
>
>
> =A0=A0=A0=A0=A0=A0=A0 case 'fullname':
> =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']->getInst=
ance('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('attribut=
es' =3D> array('cn', 'cn;lang-es'))
> =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 $res=
ult->shiftEntry();
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return $entry->=
getValue('cn;lang-es', 'single')
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ?: =
$entry->getValue('cn', '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 }
>
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return $username;
> =A0=A0=A0=A0=A0=A0=A0 }
> =A0=A0=A0 }
> }

and enable these hooks by modifying the prefs.local.php file so that it =

reads

> <?php
> $_prefs['from_addr']['hook'] =3D true;
> $_prefs['fullname']['hook'] =3D true;

I get an error that says

>
>       Could not connect to localhost:389
>
When I comment the prefs.local.php file and access horde I run the =

following piece of code in the PHP Shell (under the horde context

> |$ldap| |=3D ||$GLOBALS||[||'injector'||]->getInstance(||'Horde_Ldap'||);|
> |||try| |{|
> |||$result| |=3D ||$ldap||->search(|
> |||$GLOBALS||[||'conf'||][||'ldap'||][||'user'||][||'basedn'||],|
> |||Horde_Ldap_Filter::create(||'userPrincipalName'||, ||'equals'||, =

> ||'[email protected]'||), ||array||(||'attributes'| |=3D> =

> ||array||(||'mail'||)));|
> |||if| |(||$result||->||count||()) {|
> |||$entry| |=3D ||$result||->shiftEntry();|
> |||return| |$entry||->getValue(||'mail'||, ||'single'||);|
> |||}|
> |||} ||catch| |(Horde_Ldap_Exception ||$e||) {|
> |||}|
> |||return| |$value||;|
I get the following result

> exception 'Horde_Ldap_Exception' with message 'Could not connect to local=
host:389' in /usr/lib64/php/Horde/Ldap.php:321
> Stack trace:
> #0 /usr/lib64/php/Horde/Ldap.php(225): Horde_Ldap->_connect()
> #1 /usr/lib64/php/Horde/Ldap.php(137): Horde_Ldap->bind()
> #2 [internal function]: Horde_Ldap->__construct(Array)
> #3 /usr/lib64/php/Horde/Injector/Binder/Implementation.php(88): Reflectio=
nClass->newInstanceArgs(Array)
> #4 /usr/lib64/php/Horde/Injector/Binder/Implementation.php(70): Horde_Inj=
ector_Binder_Implementation->_getInstance(Object(Horde_Injector), Object(Re=
flectionClass))
> #5 /usr/lib64/php/Horde/Injector/Binder/AnnotatedSetters.php(78): Horde_I=
njector_Binder_Implementation->create(Object(Horde_Injector))
> #6 /usr/lib64/php/Horde/Injector.php(238): Horde_Injector_Binder_Annotate=
dSetters->create(Object(Horde_Injector))
> #7 /usr/lib64/php/Horde/Injector.php(272): Horde_Injector->createInstance=
('Horde_Ldap')
> #8 /var/www/horde/admin/phpshell.php(66) : eval()'d code(1): Horde_Inject=
or->getInstance('Horde_Ldap')
> #9 /var/www/horde/admin/phpshell.php(66): eval()
> #10 {main}

 From what I can tell the library is trying to connect lo localhost:389 =

even though the settings state that it should be connecting to =

dc1.fliawells.com.ar:3268. What could I be missing here?


Thank you very much in advance!

Best regards,

David Wells.



-- =

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