perl - 从 1000 增加限制?

标签 perl active-directory ldap

当我这样搜索时

my $mesg = $ldap->search(
  base   => "OU=test,DC=example,DC=com",
  scope  => 'one',
  filter => '(objectClass=organizationalPerson)',
  attrs  => ['distinguishedName', 'displayName', 'sAMAccountName', 'employeeID'],
);

我只得到 1000 个条目,我预计会有 ~20000 个条目。

是否可以在我的 Perl 脚本中增加此限制,还是必须在服务器上进行更改?

最佳答案

解决方案是像这样使用分页搜索

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]);
}

关于perl - 从 1000 增加限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5830860/

相关文章:

perl - 获取主机名的所有 IP 地址

perl - 比较两个字符串并在Perl中突出显示不匹配的字符

java - Runtime.getRuntime().exec() java 1.7 中的 perl 脚本

python - 在 100 GB 的文件中搜索字符串

c# - 通过 C# .NET 获取没有父级的 AD 组

python - 无法通过 ldap3 模块修改 'cn' 属性,Python 3.x

c# - 用户需要什么权限才能在 Active Directory 中验证凭据?

active-directory - Adobe AIR 应用程序能否实现针对 Active Directory 的 SSO 身份验证?

java - 用于获取 dn 和所有 cn 数据的 LDAP 查询

c# - [C#、.NET] : Validating users via LDAP through IdentityServer3