Michael,

In creating test code to send to the perl-ldap mailing list, I fixed the problem! The fix involved creating the page control within the perform_one_query subroutine. Here is the message that I would have sent which contains a complete description of the problem.

David

Fellow programmers,

I am using perl-ldap version 0.28 under Windows 2000 with perl 5.6.1 (ActivePerl Build 633).

I have written a program that binds to an LDAP server and performs one or more paged queries. The program reads the query filters from a file.

If I put several simple filters into the file, everything works fine. For example, here is a list of simple queries:

uid=12345
uid=54321
uid=67890
uid=13579

Each of the above queries returns one entry which is written to standard output.

If I put a filter into the file that returns a lot of output, it works. Here is an example:

businessunit=001410

If I put two filters into the file that each should return a lot of output, the first works and the second returns nothing. For example, running the program with the following filters returns all the entries with business unit 001410 and no entries for business unit 001510.

businessunit=001410
businessunit=001510

If I reverse the order of the filters in the file, like this,

businessunit=001510
businessunit=001410

then the output contains all the entries with business unit 001510 and no entries for business unit 001410. The second query does not fail with an error -- I check for errors. I just get zero entries returned.

Here is some of the relevant source code:

use English;
use strict;

<snipped>

use Net::LDAP;
use Net::LDAP::Control::Paged;
use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED LDAP_SUCCESS );
use Net::LDAP::Bind;
use Net::LDAP::Search;

my $conn;
my $page;

bind_to_server();

<snipped>

if (open(FILTERS, $filters_file_name))
    {
    my $count_queries = 0;
    while (my $line = <FILTERS>)
        {
        if ($line =~ /^\s*#/) {next;}    # skip comments
        if ($line =~ /^\s*$/) {next;}    # skip blank lines
        chomp $line;
        if ($verbose)
            {print STDERR "$line\n";}
        perform_one_query($line);
        $count_queries++;
        } # while
    close FILTERS;
    print STDERR "Performed $count_queries queries.\n";
    } # if
    else {print STDERR "Can't open filters file '$filters_file_name': $OS_ERROR\n";}

<snipped>

sub perform_one_query
{
    my ($filter) = @_;

    # I had problems performing multiple queries with one bind. Therefore,
    # I'm trying to bind and unbind with each query.
    ## bind_to_server();

    my @search_args =
    (
        base     => $search_base,
        scope    => "subtree",
        filter   => $filter,
        control  => [ $page ],
        attrs    => [ @attributes ]
    );

    $count_entries = 0;
    my $cookie;
    while (1)
        {
        my $results = $conn->search(@search_args);
        if ($results->code != LDAP_SUCCESS)
            {die $results->error;}

        foreach my $entry ($results->all_entries)
            {
<snipped>
            $count_entries++;
            } # foreach $entry

        my ($resp) = $results->control(LDAP_CONTROL_PAGED);
        if (not $resp)
            {last;}
        $cookie = $resp->cookie;
        if (not $cookie)
            {last;}
        $page->cookie($cookie);
        } # while

    if ($cookie)
        {
        # We had an abnormal exit, so let the server know we do not want any more
        $page->cookie($cookie);
        $page->size(0);
        $conn->search(@search_args);
        } # if

    ## $conn->unbind;
    return;
} # sub perform_one_query

<snipped>

sub bind_to_server
{
    $conn = Net::LDAP->new("$host_name:$port_number");
    if (not $conn)
        {
        my $error_message = $@;
        die $error_message;
        } # if

    $page = Net::LDAP::Control::Paged->new( size => 500 );
    $conn->bind($bind_dn, password => $password);
    return;
} # sub bind_to_server

The only work-around I have found so far is to bind and unbind for each query. That works, but it's ugly and inefficient.

Can anyone tell me if I'm doing something wrong, if you've had a similar experience, or what I should be doing differently?

Thanks in advance.

David Levner, consultant

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to