From: Chris R. <chr...@me...> - 2000-08-07 16:49:32
|
"Howard, Michael J" <Mic...@pn...> wrote: > Hello, I'm new to LDAP. I am trying to use it for authentication. How > do I retrieve the dn using a uid? Here is the code I'm using. I can > successfully bind anonymously and perform a search on the LDAP, however, > I am not sure how to retrieve the DN. Could someone point me in the > right direction? The object returned by search doesn't contain the search results itself - you have to ask it for the entries one by one (using ->entry(index)) or all of them at once (using ->entries()) > $ldap = Net::LDAP->new('[LDAP SERVER]') or die "$@"; > > $mesg = $ldap->bind; > > $base = "o=[my company], c=[country]"; > > my $result = $ldap->search( > base => "$base", > scope => "sub", > filter => "uid = $user", > ); > > my $dn = $result->dn(); die "No unique match" if $result->count() != 1; my $dn = $result->entry(0)->dn(); As you probably ought to check count before selecting an entry to read. Cheers, Chris |