Having problems using call back to dump a large number of computer accounts from w2k AD. When script is ran I get the following out put:
Ldap opened and starting search
at Call back, vaue passedin = Net::LDAP::Search=HASH(0x1e1626c)
No records found matching filter .
search done. processing
Error code: 83
However when I run the same search without using the NET::LDAP Page control, it returns the machine information upto the limit returned by AD (which is why I'm forced to use the PAGED option in the frist place).
Anyone notice any errors in the code that could be causing this?
use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); #set paged fo
my $userID = 'Domain\\UsrID'; # <- your userid
+ here in the form DOMAIN\USERID;
my $passwd = 'MyPassword';<br> # <- corres
+ponding password here;
$ldap = Net::LDAP->new('Server.lion.ad.haize.com') or die "$@";
my $result = $ldap->bind( dn => $userID, password => $passwd );
print "Ldap opened and starting search\n";
$mesg = $ldap->search(
base => $base,
scope => 'sub',
filter => 'sAMAccountType=805306369',
control => [ $page ],
callback => \&callback,
# At this point the user needs to check the status of the
# ldap search.;
print "search done. processing \n";
if ( $mesg->code )
$errstr = $mesg->code;
print "Error code: $errstr\n";
#$errstr = ldap_error_text($errstr);
print "at Call back, passed= @_ \n";
my ( $mesg, $entry) = @_;
# First you must check to see if something was returned.
# Last execution of callback subroutine will have no
# defined entry and mesg object
if ( !defined($entry) )
print "No records found matching filter $match.\n"
if ($mesg->count == 0) ; # if mesg is not defined nothing will pr
my $dn = $entry->dn; # Obtain DN of this entry
@attrs = $entry->attributes; # Obtain attributes for this entry.
foreach my $var (@attrs)
#get a list of values for a given attribute
$attr = $entry->get_value( $var, asref => 1 );
if ( defined($attr) )
foreach my $value ( @$attr )
print "$var: $value\n"; # Print each value for the attribute.
# For large search requests the following 2 lines of code
# may be very important, they will reduce the amount of memory
# used by the search results.
# If the user is not worried about memory useage then the 2 lines
# of code can be omitted.
# End of callback subroutine
Edit by tye, delete BR tags, add P and CODE tags