[sork] Ldap-Problems

Felipe Scarel fbscarel at gmail.com
Fri Nov 4 17:35:54 UTC 2011


Hey Hanns,

On Fri, Nov 4, 2011 at 15:05, Hanns Mattes <hanns at hannsmattes.de> wrote:

> Hi,
>
> me again,
>
> Am 04.11.2011 15:45, schrieb Hanns Mattes:
>
> > [php, userdn, hooks and me]
>
> okay, got it:
>
> > <?php
> > class Passwd_Hooks
> > {
> >    public function userdn($authid)
> >    {
> >        // Example: Provide LDAP server with a userdn so that you do not
> have
> >        // to perform anonymous binds.
> >        $zwischenschritt = explode("@", $authid);
> >        $hmldapdomain = $zwischenschritt[1];
> >        return 'uid=' . $authid . ',ou=' . $hmldapdomain .
> ',ou=virtualmail' . ',dc=hanns' . ',dc=de';
> >    }
> > }
>
> Looks a bit "hackish", but it's working.
>
> Still got the same issue, Felipe Scarel reported some weeks ago, but
> this is no main problem for me in the moment.
>
> Thanks for the help.
>
> Regards Hanns


Incidentally, I had to make my own hook script as well. I didn't post it on
the original thread, but since it seems it somehow helped you, I'll post it
here for future reference:

class Passwd_Hooks
{
    /**
     * Userdn hook.
     *
     * @param string $authid  The authenticated username.
     *
     * @return string TODO
     */
    public function userdn($authid)
    {
        $ldapServer = 'localhost';
        $ldapPort = '389';
        $searchBase = 'dc=unb,dc=br';

        $ds = @ldap_connect($ldapServer, $ldapPort);
        $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $authid);
        $information = @ldap_get_entries($ds, $searchResult);

        ldap_close($ds);

        if ($information === false || $information['count'] == 0) {
            return '';
        } else {
            return $information[0]['dn'];
        }
    }
}

Cheers,
fbscarel


More information about the sork mailing list