I have written a Perl/Tk program for Windows/UNIX clients that queries a
Microsoft Active Directory (AD) domain controller running LDAP. Typical
"ends with" type query filters, i.e. sAMAccountName\=*userid, can take
several minutes to produce a result. Also, a user may attempt an
unreasonable and lengthy search, querying all users in the company that
begin with the letter 'a' (producing thousands of results) for example.
The Tk program then looks like it is hung for several minutes. So, I am
attempting to provide a configurable timeout that can be set on the
Perl/Tk main window that is used in the search query. I have found that
the timeout parameter does not function. Here is an example that takes
several minutes to perform the query. The timeout parameter does not
abort the query. Can anyone guide me on how to get the timeout parameter
to work?
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,
timeout => 10,
callback => \&do_callback
);
}
sub do_callback {
print "Running do_callback\n";
my ($mesg, $entry) = @_;
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;
}