I have written a Perl/Tk program for Windows/UNIX clients that queries a
Microsoft Active Directory (AD) domain controller running LDAP. I am
interested in using the 'async' parameter. When a long LDAP search query
is posted and in progress the program has the look of hanging and this
can occur for several minutes if the user searched for an unreasonable
number of records, i.e. all userids that begin with the letter 'a'. 

I am looking at attempting to provide the ability to cancel a query once
it is posted to the LDAP server. I have been able to cancel a query when
processing is running within the callback subroutine. However, when a
query is posted and when waiting for a reply from the LDAP server, in
what looks like a hung state, the program Cancel button will not respond
until the LDAP server has responded back and has jumped into the
callback subroutine where I can trap for a cancel button pressed there.

How can I use the async parameter to continue to allow the callback
subroutine to post data to the Tk main window and also allow processing
of a cancel request? Am I out of line for what want the async parameter
to do? Does anyone have an example? I have attached some basic code
snippets to show what the program is doing.

Thanks,

Joe Primanti



Example: 

use Net::LDAP;
$base = "dc=aaa, dc=bbb, dc=com";
$userid = "*userid";

if ($ldap = Net::LDAP->new("aaa.bbb.com", port => 3268, timeout => 10))
{
        $qry = "(&(sAMAccountName\=$userid))";
        $mesg = $ldap->search(
                base => $base,
                attrs => [
                        attr => 'mail',
                ],
                filter => $qry,
                timelimit => 30,
                callback => \&do_callback
        );
}

 
sub do_callback {
        print "Running do_callback\n";
        my ($mesg, $entry) = @_;
        my $count = $mesg->count;

        #Abort if timelimit exceeded
        if ($mesg->code) {
                my $error = $mesg->error;
                my $code = $mesg->code;
                if ($error eq "Timelimit exceeded") {
                        if ($count eq 1) {
                                print "Query Error: $error Code:
$code\n";
                        }
                        $ldap->unbind;
                        return;
                }
        }
        
        #If the user presses the Cancel button, abandon the search
        if ($qb eq "Query LDAP") {
                #Unable to properly abondon search when Cancel button is

                #pressed during a query. Unbinding the LDAP server does
the job.
                #$ldap->abandon($mesg); #This doesn't work
                $ldap->unbind;
                return;
        }

        if (defined($entry)) {
                $dn = $entry->dn;
                if ($get = $entry->get_value("mail", asref => 1)) {
                        @r = @$get;
                        print "EMAIL Address: $r[0]\n"; 
                }
        }
        $mesg->pop_entry;
}

Reply via email to