File: debian-ldap-query

package info (click to toggle)
mutt 1.5.9-2sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,484 kB
  • ctags: 17
  • sloc: sh: 315; makefile: 231; perl: 80
file content (46 lines) | stat: -rw-r--r-- 1,346 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl -w
# by Ben Collins <bcollins@debian.org>, butchered by Marco d'Itri <md@linux.it>
# to use, add to ~/.muttrc:
#  set query_command="/usr/lib/mutt/debian-ldap-query %s"

use strict;

my @attrs = qw(sn cn ircnick uid);
my $base = 'ou=users, dc=debian, dc=org';
my $server = 'db.debian.org';
my $port = 389;

die "Usage: $0 <name> [<name>...]\n" if not $ARGV[0];

eval 'require Net::LDAP;';
if ($@) {
	$@ =~ s/ in \@INC.*/./;
	die "Could not load Net::LDAP: $@\n" .
	"(Warning: this script depends on the libnet-ldap-perl (>=0.22-1) package.)\n"
}

my $ldap = Net::LDAP->new($server, port => $port) or
	die "Could not contact LDAP server $server:$port";
$ldap->bind or die 'Could not bind';

my @results;

foreach my $search (@ARGV) {
	my $query = join '', map { "($_=*$search*)" } @attrs;
    my $mesg = $ldap->search(
		base => $base, filter => "(|$query)", attrs => [ @attrs ]
	) or die 'Failed search';
    foreach my $entry ($mesg->entries) {
		my $uid   = $entry->get_value('uid')	|| next;
		my $fname = $entry->get_value('cn')		|| '';
		my $lname = $entry->get_value('sn')		|| '';
		my $nick  = $entry->get_value('ircnick')|| '';
		push @results, "<$uid\@debian.org>\t$fname $lname\t($nick)\n";
    }
}

$ldap->unbind;

print 'Debian Developer query: found ', scalar @results, "\n", @results;
exit 1 if not @results;
exit 0;