in reply to LDAP address lookup from Mutt
This is my first comment...
I grabbed this script to give me ldap access to my server, naturally. However my mail attribute is multivalued for a number of entries, so I have made some modifications to the script to handle the multivalued attribute.
Make sure you change all entries as required.
#!/usr/bin/perl use strict; use Net::LDAP; use constant HOST => 'ldap.your.domain'; use constant BASE => 'ou=People, dc=your, dc=domain'; use constant VERSION => 3; use constant SCOPE => 'sub'; my $name; my @attributes = qw( dn givenName sn mail ); my $filter = "(|(sn=$name*)(givenName=$name*))"; { print "Searching directory... "; $name = shift || die "Usage: $0 filter\n"; my $ldap = Net::LDAP->new( HOST, onerror => 'die' ) || die "Cannot connect: $@"; $ldap->bind(version => VERSION) or die "Cannot bind: $@"; my $result = $ldap->search( base => BASE, scope => SCOPE, attrs => \@attributes, filter => $filter ); my @entries = $result->entries; $ldap->unbind(); print scalar @entries, " entries found.\n"; foreach my $entry ( @entries ) { my @emailAddr = $entry->get_value('mail'); foreach my $addr (@emailAddr) { print $addr , "\t"; print $entry->get_value('givenName'), " "; print $entry->get_value('sn'), "\n"; } } }
Make sure you have the Net::LDAP module installed.
Hope someone finds it of use, and thanks to the original author... I just hacked on what was already provided.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: LDAP address lookup from Mutt
by waxhead (Acolyte) on Dec 26, 2002 at 13:33 UTC | |
by Anonymous Monk on Aug 11, 2009 at 22:19 UTC |