From: "Tyler, Grayling" <[EMAIL PROTECTED]>
Date: 5 December 2003 13:24:40 GMT
To: [EMAIL PROTECTED]
Subject: LDAP_CONTROL_PAGED question
Message-Id: <[EMAIL PROTECTED]>

Hi, I know your busy and may not ever reply to this, but since I've beat my head against the brick wall and asked on all the groups I could find I thought I'd take a shot.

I'm trying to use NET::LDAP to pull all of the computer names/OSVers from our active directory.  I've gotten the non-paged call to work with no problem. Unfortunately our Domain is large so the standard call fails to retrieve all the entries and I need to use the PAGED call to get them all. 

When I run the script below I get the following:
"Undefined subroutine &main::process_entry called at D:/Perl/site/lib/Net/LDAP/Search.pm line 51, <DATA> line 456."
Since I'm fairly new to perl I'm assuming I am doing something wrong in the code.  If you have the time to take a quick look at the attached script and point me in the right direction, I'd sure appreciate it.  If not...thanks anyway and have a great day.


Grayling




#Script
use Net::LDAP;
use Net::LDAP::Control::Paged;
use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED );        #set paged for later


# Info for domain where computers live
my $dc = "Xlinf01";                                            # <- your domain controller here
my $base = "dc=lion,dc=ad,dc=del,dc=com";      # <- your LDAP search base here (ie dc=acme, dc=com)


# Working global variables #(successfully used the same entries on the non paged call (minus the control and callback values)

my $userID = 'Domain\\UsrAccountID';             # <- your userid here in the form DOMAIN\USERID
my $passwd = 'password';                              # <- corresponding password here


my $ldap = Net::LDAP->new($dc) or die "open LDAP: $@";
my $page = Net::LDAP::Control::Paged->new( size => 1000 );
my $result = $ldap->bind( dn => $userID, password => $passwd );
die "LDAP bind failed" . $result->error if $result->code;

# my @args = (
#  base   => $base,
#  scope => 'sub',
#  filter => 'sAMAccountType=805306369',
#  #filter => 'sAMAccountName=tec5$',
#  control => [ $page ],
#  callback => \&process_entry
# );



 my $cookie;
    while(1) {
 # perform search
 $mesg = $ldap->search (
 base   => $base,
 scope => 'sub',
 filter => 'sAMAccountType=805306369',
 control => [ $page ],
 callback => \&process_entry);

 $mesg->code and last;
 foreach my $entry ($mesg->all_entries) {
 print $entry->get_value('sAMAccountName'), "\t";
 print $entry->get_value('operatingSystemVersion');
 }
 # Get cookie from paged control
 my ($resp)  = $mesg->control( LDAP_CONTROL_PAGED ) or last;
 $cookie    = $resp->cookie or last;
 # Set cookie in paged control
 $page->cookie($cookie);



 if ($cookie) {
  # We had an abnormal exit, so let the server know we do not want any more
  $page->cookie($cookie);
  $page->size(0);
  $ldap->search(
        base   => $base,
        scope => 'sub',
        filter => 'sAMAccountType=805306369',
        control => [ $page ],
        callback => \&process_entry);
 }




This electronic message may contain confidential or privileged information
and is intended for the individual or entity named above.  If you are
not the intended recipient, be aware that any disclosure, copying,
distribution or use of the contents of this information is prohibited.
If you have received this electronic transmission in error, please notify
the sender immediately by using the e-mail address or by telephone (704-633-8250).


Reply via email to