Here is how I do it, this is just a piecemeal representation of a script
that I currently use but hopefully lyou get the idea.
use Net::LDAPS;
use Net::LDAP::Control::Paged;
use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED );
my $ldap = Net::LDAPS->new($addr) or die "LDAP server could not be
contacted. Error:$@";
my $page = Net::LDAP::Control::Paged->new( size => 100 );
### binds to DC using above credentials
my $login = $ldap->bind($user, password=> $pass);
my $iserr = $login->is_error;
if ($iserr) { # success returns 0
print "Authentication failed\n";
exit;
}
my @srcargs1 = ( base => $path,
scope => "sub",
filter => "(objectClass=group)",
control => [ $page ],
);
### Main program loop
while (1) {
$search = $ldap->search(@srcargs1);
if ($search->code) { # successful search returns
0
exit print "LDAP Search Failed $?\n";
}
foreach $entry ($search->entries) {
my $grpname = $entry->get_value("name");
print "Group name is: $grpname\n";
}
### After foreach loops ends, client checks LDAP server reponse of
how many search results total.
### This is a control to end the infinite while loop if there are no
search results to go through
### If there are search results, this control will always return the
total number of results. It is
### never decremented
my ($resp) = $search->control( LDAP_CONTROL_PAGED ) or last;
### Obtaining the cookie from the search result. When no more
results, cookie will be NULL
### and infinite while loop will terminate.
$cookie = $resp->cookie or last;
### Sets cookie so server knows the next search result to send
$page->cookie($cookie);
}
### This is a control to check for abnormal exit of the while loop. If this
occurs
### we need to tell the LDAP server that remaining search results are no
longer needed
### by sending a search request with a page size of 0
if ($cookie) {
$page->cookie($cookie);
$page->size(0);
$ldap->search(@srcargs1);
}
On 1/19/07, Graham Barr <[EMAIL PROTECTED]> wrote:
Begin forwarded message:
> From: <[EMAIL PROTECTED]>
> Date: January 18, 2007 2:27:35 PM CST
> To: <[EMAIL PROTECTED]>
> Subject: Net::LDAP - AD paging
> Message-Id:
> <[EMAIL PROTECTED]>
>
> Graham,
>
> I need to do an LDAP search, via Net::LDAP, on a AD server.
> Since I receive back only 1000 objects, I would like to use the
> "paging" feature to receive all responses from my server.
>
> Do you have any example on how to do paging search via your
> Net::LDAP module? I search over the web and I found no example...
>
> Thanks a lot for any help!
>
> Bye!
>
> ----
> Dominic Dupuis
> Services Techniques
> Direction Bureautique
> Maintenance serveurs
> Tél: 514-840-3000 x6241
> [EMAIL PROTECTED]
> <blocked::blocked::mailto:[EMAIL PROTECTED]>