How to read a large number of LDAP entries in perl?

前端 未结 1 428
忘了有多久
忘了有多久 2021-01-23 16:03

I already have an LDAP script in order to read LDAP user information one by one. My problem is that I am returning all users found in Active Directory. This will not work becaus

相关标签:
1条回答
  • 2021-01-23 16:32

    If you can get the executable ldapsearch to work in your environment (and it does work in *nix and Windows, although the syntax is often different), you can try something like this:

    my $LDAP_SEARCH = "ldapsearch -h $LDAP_SERVER -p $LDAP_PORT -b $BASE -D uid=$LDAP_USERNAME -w $LDAP_PASSWORD -LLL";
    my @LDAP_FIELDS = qw(uid mail Manager telephoneNumber CostCenter NTLogin displayName);
    open (LDAP, "-|:utf8", "$LDAP_SEARCH \"$FILTER\" " . join(" ", @LDAP_FIELDS));
    while (<LDAP>) {
      # process each LDAP response
    }
    

    I use that to read nearly 100K LDAP entries without memory problems (although it still takes 30 minutes or more). You'll need to define $FILTER (or leave it blank) and of course all the LDAP server/username/password pieces.

    If you want/need to do a more pure-Perl version, I've had better luck with Net::LDAP instead of Net::LDAP::Express, especially for large queries.

    0 讨论(0)
提交回复
热议问题