[horde] Some questions

Nicolas Fo nicolasfo at ymail.com
Thu Dec 20 08:00:11 UTC 2012


Le 19/12/2012 19:51, Oscar del Rio a écrit :
> On 12/19/12 11:03 AM, Nicolas Fo wrote:
>>
>> I'd like to have the fullname (cn in my AD base) autofilled in relation
>> with the login user (mail in my AD database).
>>
>
> This is the relevant part of my hooks.php which works with our 
> openldap server.
> It searches for uid=$username and gets the full name from "cn"
> I don't know what you would need to change for Active Directory.
>
> case 'fullname':
>             if (is_null($username)) {
>                 return $value;
>             }
>             $name='';
>             $ds = @ldap_connect($ldapServer);
>             if ($ds) {
>                 $searchResult = @ldap_search($ds, $searchBase, 'uid=' 
> . $username);
>                 if (ldap_count_entries($ds,$searchResult) > 0) {
>                     $information = @ldap_get_entries($ds, $searchResult);
>                     if ($information)
>                         $name=$information[0]['cn'][0];
>                 }
>                 ldap_close($ds);
>             }
>             return empty($name) ? $username : $name;
>
>         }
>

It seems to work !

The stuff we have to add to use it with AD, is the "bind" function.

For others, the hooks.php file :

<?php
class Horde_Hooks
{
     public function prefs_init($pref, $value, $username, $scope_ob)
     {
         switch ($pref) {

         case 'fullname':

             if (is_null($username)) {
                 return $value;
             }

         global $conf;
         $ldapServer = 'AD.SERVER.LAN';
         $ldapPort = '389';
         $binddn = 'HORDE_USER_IN_AD';
         $bindpw = 'HORDE_PASSWD_IN_AD';
         $searchBase = 'OU=OU_NAME,DC=DOMAIN,DC=lan';

         $ds = ldap_connect($ldapServer, $ldapPort);
         ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
         ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);

         if (ldap_bind($ds, $binddn, $bindpw)) {

             $searchResult = ldap_search($ds, $searchBase, 'mail=' . 
$username);

                 if (ldap_count_entries($ds,$searchResult) > 0) {
                     $information = @ldap_get_entries($ds, $searchResult);
                     if ($information)
                         $name=$information[0]['cn'][0];
                 }
         }

             ldap_close($ds);

             return empty($name) ? $username : $name;
}
}
}

The login is the mail address of the account (stored in the "mail" 
field), and Horde shows name and username (in one field) stored in "cn".

Thanks you guys ;)

Nicolas


More information about the horde mailing list