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 47 48 49 50 51 52 53 54 55
|
unless ($#ARGV == 2) {
die "Usage $ARGV[-1] <host> <suffix> <filter>";
}
($directory, $suffix, $filter) = ($ARGV[0], $ARGV[1], $ARGV[2]);
printf "host : $directory\nsuffix : $suffix\nfilter: $filter\n";
use Net::LDAP;
$ldap=Net::LDAP->new($directory) or print "connect impossible\n";
$ldap->bind or print "bind impossible \n";
#$mesg = $ldap->search ( base => "$suffix", filter => "(cn=$nom)" )
$mesg = $ldap->search ( base => "$suffix", filter => "$filter" )
or print "Search impossible \n";
# $mesg->code or print "code chjie\n";
#foreach $entry ($mesg->all_entries) {
# $entry->dump;
# printf "-- %s \n", $entry->get('mail');
#}
$res = $mesg->as_struct ;
#foreach my $k (keys %$res) {
# printf "\t%s => %s\n", $k, $res->{$k};
#}
foreach $dn (keys %$res) {
my $hash = $res->{$dn};
print "#";
foreach my $k (keys %$hash) {
my $array = $hash->{$k};
if ((ref($array) eq 'ARRAY') and ($k ne 'jpegphoto')) {
printf "\t%s => %s\n", $k, join(',', @$array);
}else {
printf "\t%s => %s\n", $k, $array;
}
}
$cpt++;
}
print "Total : $cpt\n";
$ldap->unbind or print "unbind impo \n";
|