Increase limit from 1000?

前端 未结 3 1487
孤街浪徒
孤街浪徒 2021-02-11 04:43

When I do a search like so

my $mesg = $ldap->search(
  base   => \"OU=test,DC=example,DC=com\",
  scope  => \'one\',
  filter => \'(objectClass=organ         


        
3条回答
  •  误落风尘
    2021-02-11 05:22

    The solution is to use paged search like so

    use Net::LDAP;
    use Net::LDAP::Control::Paged;
    use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED );
    
    my $page = Net::LDAP::Control::Paged->new(size => 999);
    my $cookie;
    
    while (1) {
        $mesg = $ldap->search(
        base    => "OU=test,DC=example,DC=com",
        scope   => 'one',
        filter  => '(objectClass=organizationalPerson)',
        attrs   => ['distinguishedName', 'displayName', 'sAMAccountName', 'employeeID'],
        control => [$page]
        );
    
        $mesg->code && die "Error on search: $@ : " . $mesg->error;
        while (my $adentry = $mesg->pop_entry()) {
    
        # process $adentry
        }
    
        my ($resp) = $mesg->control(LDAP_CONTROL_PAGED) or last;
        $cookie    = $resp->cookie or last;
        # Paging Control
        $page->cookie($cookie);
    }
    
    if ($cookie) {
        print "abnormal exit\n";
        # Abnormal exit, so let the server know we do not want any more
        $page->cookie($cookie);
        $page->size(0);
        $ldap->search(control => [$page]);
    }
    

提交回复
热议问题