Hi,
On Friday 19 January 2007 13:42, Graham Barr wrote:
> Begin forwarded message:
> > From: <[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...
Here is a code made largely by reading the man pages for Net::LDAP :-) Some of
it is just cut'n'paste directly from the man pages.
Comments on what could have been done in a better way are appreciated.
#!/usr/bin/perl -w
use strict;
use Net::LDAP;
use Net::LDAP::Control::Paged;
use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED );
my $ldapserver = 'adldap.example.com';
my $base = 'dc=example,dc=com';
my $word ='secretPassword';
my $user = 'cn=ldapsearchinguser,dc=example,dc=com';
my $filter = 'cn=*';
my $page = Net::LDAP::Control::Paged->new( size => 400 );
$ldap = Net::LDAP->new($ldapserver) or die $@;
my $mesg = $ldap -> bind($user,
password => $word);
$mesg -> code && die $mesg -> error;
while(1){
$mesg = $ldap -> search(base => $base,
filter => $filter,
scope => 'sub',
attrs => ['cn'],
control => [ $page ]);
foreach my $entry ($mesg -> all_entries) {
print $entry->get_value('cn') . "\n";
}
$mesg->code and last;
my($resp) = $mesg->control( LDAP_CONTROL_PAGED ) or last;
$cookie = $resp->cookie or last;
$page->cookie($cookie);
$mesg -> code && die $mesg -> error;
}
$ldap->disconnect;
exit 0;
Regards
j
--
Jonas Helgi Palsson
"Microsoft is not the answer. Microsoft is the question. NO is the answer."