using Net::LDAPs with Net::LDAP::Control::Paged

593 Views Asked by At

I'm trying to use Net::LDAPs with Net::LDAP::CONTROL::PAGED to return many records via a privlidged bind, but so far I have failed, miserably. I've used this Net::LDAPs extensively in the past, but I've never been able to find any documentation suggesting that it is compatible with Net::LDAP:Control::Paged. Everything I find is related to Net::LDAP.

The error message I get is: Undefined subroutine &main::process_entry called at /usr/local/share/perl/5.20.2/Net/LDAP/Search.pm line 55, line 755

Here is my code:

sub Ldap636{
    my ($filter) = $_[0];
    my $USERNAME = 'username';
    my $PASSWORD = 'password';
    my $LDAP_SERVER = 'directory.domain.edu';
    my $LDAP_SSL_PORT = '636';
    my $LDAP_BASE = 'ou=people,dc=domain,dc=edu';
    my $userDN = "uid=$USERNAME,ou=identities,ou=special,dc=domain,dc=edu";

    my $ldap = Net::LDAPS->new($LDAP_SERVER, port => $LDAP_SSL_PORT) or die "Could not create LDAP object because:\n$!";

    my $ldapMsg = $ldap->bind($userDN, password => $PASSWORD);
    die $ldapMsg->error if $ldapMsg->is_error;

    my $page = Net::LDAP::Control::Paged->new( size => 100 );      

    @args = (base => "$LDAP_BASE",
            callback => \&process_entry,
            filter => $filter,
            control  => [ $page ],
    );

    my $cookie;
    while (1) {
            my $result = $ldap->search(@args);
            "LDAP error: server says ",$result->error,"\n" if $result->code;

            foreach my $entry ($result->entries ) {
                    my $cn   = $entry->get_value('cn');
                    my $desc = $entry->get_value('description');
                    print "$cn - $desc\n";
            }

            # Get cookie from paged control
            my($resp)  = $result->control( LDAP_CONTROL_PAGED )  or last;
            $cookie    = $resp->cookie or last;


            $page->cookie($cookie);
    }

    $ldap->unbind;
}
1

There are 1 best solutions below

0
On BEST ANSWER

The error message I get is: Undefined subroutine &main::process_entry called at /usr/local/share/perl/5.20.2/Net/LDAP/Search.pm line 55, line 755

You have written process_entry as a callback but you didn't write that subroutine. That's why you are getting the above error.