develooper Front page | perl.ldap | Postings from May 2008

Strange unpredictable problem

Thread Next
From:
MickB
Date:
May 4, 2008 00:40
Subject:
Strange unpredictable problem
Message ID:
481D6863.5090002@free.fr
Hello everybody,

I encounter a little problem with a script using the Net-LDAP module. I 
post here because I believe Net-LDAP is the root of this annoyance, 
although I could be wrong of course. I've probably made a mistake so 
your help may be very useful ;).
Here's more details :

    - script's goal : connection to a list of AD's servers to extract 
the 'lastLogon' attribute of all users
    - problem : script is sometime hanging so I must kill it, frequency 
and server are unpredictables.
    - context : the following script is running under Windows with 
ActivePerl 5.8.8.822, using Net-LDAP 0.34 provided by ActivePerl itself. 
This is mandatory, no possibility to test or use under a Linux distribution.
    - others usefuls informations : problem occurs under Windows 2000 
SP4 and Server 2003. However, I noticed problem appears a lot more under 
Windows 2000 than under Server 2003

    What I've tried and noticed :
       - tried Net-LDAP 0.35 : no change
       - perl's CPU usage when problem occurs : 0%. It seems to wait for 
something...
       - 'netstat' command always shows connection to AD's server is 
established when it's hanging.
       - 'netstat' has allowed me to see it's not a particular server 
which is causing this trouble.

   
   Here's my source sample :

eval {

        my ($page,$flag,$ldap);

        $page = Net::LDAP::Control::Paged->new( size => 1000 );
        $flag = 1;

       # 1- connection
       $ldap = Net::LDAP->new( $serveur,
                                                    scheme => 'ldap',
                                                    timeout => 5,
                                                    onerror => 'die',
                                                    version => 3,
                                                    port => 389,
                                                    debug => 0 );

       if ( ! defined($ldap) ) { die("connection to server failed\n"); }

       $ldap->bind( user@adouest.edf.fr,
                            password => XXXX
                              );


       # 2- treatment
        while( $flag ) {

            my ($request,$cookie,$resp);

            $request = $ldap->search( base => 'DC=ADOUEST,DC=EDF,DC=FR'
                                                scope => 'sub',
                                                deref => 'never',
                                                sizelimit => 0,
                                                timelimit => 300,
                                                typesonly => 0,
                                                filter => '(& 
(objectclass=top)(objectclass=person)(objectclass=organizationalPerson)(objectclass=user)(! 
(objectclass=computer) ))',
                                                attrs => [ 'lastLogon' ],
                                                control  => [ $page ]
                                            );

            foreach my $entry ( \($request->entries()) ) {

                my $dn;

                # DN
                $dn = $$entry->dn();
               
                if ( defined($user{$dn}) && $$entry->exists('lastLogon') ) {

                    my $date = 
&ConvertTime($$entry->get_value('lastLogon', alloptions => 0, asref => 
0));                 
                    if ( defined($user{$dn}{'lastLogon'}) ) {

                        if ( $user{$dn}{'lastLogon'} < $date ) { 
$user{$dn}{'lastLogon'} = $date; }

                    } else {

                        $user{$dn}{'lastLogon'} = $date;

                    }
                   
                }

            }
           
            ($resp) = $request->control(LDAP_CONTROL_PAGED);
            $cookie = $resp->cookie() or $flag = 0;         
            $page->cookie($cookie);

        }
       
       # 3- end
        die('success');

    };
    if ( $@ ) {     

       print 'status : ' . $@ . "\n";

        # deconnection
        if ( defined($ldap) ) {

            eval {

                $ldap->unbind();
                $ldap->disconnect();

            };

        }

    }
   
}

Las note : i remarked this on Net::LDAP::Paged doc page :  

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

was added just after the loop. I judged this unnecessary because I'm using the 'die' method on error. But I may be wrong...

Anyway, any help would be greatly appreciated.

Thanks.

Mickaƫl




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About