On Wednesday 09 November 2005 15:55, John Parks, SEI Webmaster wrote: > I am trying to use perl-ldap to search an Active Directory. I am able to > connect and bind, but when I attempt to search I am not getting any usable > results back. I am hoping someone can spot what I am doing wrong and help > me out a bit. I have removed some content from the script replacing it with > notes about what the content was surrounded by []. So the [] are not really > part of the script just place holds for the content.
Here's a small script that does a 'ugly' search agains ldap (tried in Linux against AD) that takes one argument and uses that in 'cn=*ARG*' filter :-) #!/usr/bin/perl use strict; use Net::LDAP; my $ldapserver = 'ldap.example.com'; my $base = 'dc=example,dc=com'; my $string = $ARGV[0]; my $word; my $dn; #getting password system "stty -echo"; print STDERR "Password for admin: "; chomp($word = <STDIN>); print "\n"; system "stty echo"; my $ldap = Net::LDAP->new($ldapserver) or die $@; my $mesg = $ldap -> bind("cn=admin,dc=example,dc=com", password => "$word"); $mesg -> code && die $mesg -> error; $mesg = $ldap -> search(base => $base, filter => 'cn=*' . $string . '*', scope => 'subtree'); if($mesg -> code){ $ldap -> unbind; die $mesg -> error; } foreach my $entry ($mesg -> all_entries) { #uncomment the one under to get a dump # $entry -> dump; print $entry->dn . "\n"; } $ldap -> unbind; The Net::LDAP module is just so neat :-) Regards Jonas -- Jonas Helgi Palsson "Microsoft is not the answer. Microsoft is the question. NO is the answer." -Erik Naggum