use Net::LDAP; use Net::LDAP::Control::Paged; use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); #set paged for later my $userID = 'Domain\\UsrID'; # <- your userid here in the form DOMAIN\USERID; my $passwd = 'MyPassword';
# <- corresponding 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 "$errstr\n"; }; sub callback { 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 print. return; } 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. # $mesg->pop_entry; } # End of callback subroutine