Last active
August 29, 2015 14:19
-
-
Save hegge/70204bead964de3985dc to your computer and use it in GitHub Desktop.
Mutt LDAP DavMail lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Based on http://www.perlmonks.org/?node_id=65152 | |
use strict; | |
use Net::INET6Glue::INET_is_INET6; | |
use Net::LDAP; | |
use constant HOST => 'ip6-localhost:1389'; | |
use constant BASE => 'ou=people'; | |
{ | |
print "Searching database... "; | |
my $name = shift || die "Usage: $0 filter\n"; | |
my $ldap = Net::LDAP->new( HOST, onerror => 'die' ) | |
|| die "Cannot connect: $@"; | |
$ldap->bind('username', password => 'password') or die "Cannot bind: $@"; | |
my $msg = $ldap->search( base => BASE, | |
filter => "(|(sn=*$name*)(givenName=*$name*)(cn=*$name*))"); | |
my @entries = (); | |
foreach my $entry ( $msg->entries() ) { | |
push @entries, | |
{ email => $entry->get_value( 'mail' ), | |
first_name => $entry->get_value( 'cn' ), | |
last_name => $entry->get_value( 'uid' ) }; | |
} | |
$ldap->unbind(); | |
print scalar @entries, " entries found.\n"; | |
foreach my $entry ( @entries ) { | |
print "$entry->{email}\t$entry->{first_name}\t$entry->{last_name}\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment