2 # by Ben Collins <bcollins@debian.org>, butchered by Marco d'Itri <md@linux.it>
3 # to use, add to ~/.muttrc:
4 # set query_command="/usr/lib/mutt/debian-ldap-query %s"
8 my @attrs = qw(sn mn cn ircnick uid);
9 my $base = 'ou=users, dc=debian, dc=org';
10 my $server = 'db.debian.org';
13 die "Usage: $0 <name> [<name>...]\n" if not $ARGV[0];
15 eval 'require Net::LDAP;';
17 $@ =~ s/ in \@INC.*/./;
18 die "Could not load Net::LDAP: $@\n" .
19 "(Warning: this script depends on the libnet-ldap-perl (>=0.22-1) package.)\n"
22 my $ldap = Net::LDAP->new($server, port => $port) or
23 die "Could not contact LDAP server $server:$port";
24 $ldap->bind or die 'Could not bind';
28 foreach my $search (@ARGV) {
29 my $query = join '', map { "($_=*$search*)" } @attrs;
30 my $mesg = $ldap->search(
31 base => $base, filter => "(|$query)", attrs => [ @attrs ]
32 ) or die 'Failed search';
33 foreach my $entry ($mesg->entries) {
34 my $uid = $entry->get_value('uid') || next;
35 my $fname = $entry->get_value('cn') || '';
36 my $mname = $entry->get_value('mn') || '';
37 $mname .= ' ' if $mname;
38 my $lname = $entry->get_value('sn') || '';
39 my $nick = $entry->get_value('ircnick')|| '';
40 push @results, "<$uid\@debian.org>\t$fname $mname$lname\t($nick)\n";
46 print 'Debian Developer query: found ', scalar @results, "\n", @results;
47 exit 1 if not @results;