For Programmers: Free Programming Magazines  


Home > Archive > LDAP > February 2008 > Problem with array of hosts in Net:LDAP(S)->new









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem with array of hosts in Net:LDAP(S)->new
Markus Moeller

2008-02-10, 8:43 am

I am new to LDAP.pm and like to query several ldap servers for
redundancy/failover. The documentation says that the host can be an array:

"HOST may also be a reference to an array of hosts, host-port pairs or URIs
to try. Each will be tried in order until a connection is made. Only when
all have failed will the result of undef be returned."

When I use the below perl script with 192.168.1.12 being the good ldap
server and 192.168.1.18 a bad ldap server (e.g. switched off). I get
../ldap_query.pl
IO::Socket::SSL: connect: timeout at ./ldap_query.pl line 4, <DATA> line
228.

an error. But I would expect the same result as with
$ldap = Net::LDAPS->new( '192.168.1.12', timeout => 2, version => 3) or die
"$@";

../ldap_query.pl
MM Result: 500

only delayed by max 2 seconds.

What is wrong in my script as I don't get a syntax error or similar ?

Thank you
Markus


#!/usr/bin/perl
use Net::LDAPS;

$ldap = Net::LDAPS->new( '192.168.1.18 192.168.1.12', timeout => 2, version
=> 3) or die "$@";

$mesg = $ldap->bind('cn=ldap user,cn=users,dc=win2003r2,dc=home', password
=> 'TestPass!') ;

$mesg = $ldap->search( # perform a search
base => "dc=win2003r2,dc=home",
filter => "(samaccountname=mm)",
attrs => ["employeeid"]
);

$mesg->code && die $mesg->error;

foreach $entry ($mesg->entries) {
$ref=$entry->get_value('employeeid');print "MM Result: $ref\n"; }

$mesg = $ldap->unbind; # take down session






Peter Marschall

2008-02-10, 7:33 pm

Hi,

On Sunday, 10. February 2008, Markus Moeller wrote:
> I am new to LDAP.pm and like to query several ldap servers for
> redundancy/failover. The documentation says that the host can be an array:
>
> "HOST may also be a reference to an array of hosts, host-port pairs or URIs
> to try. Each will be tried in order until a connection is made. Only when
> all have failed will the result of undef be returned."
>
> [...]
>
> $ldap = Net::LDAPS->new( '192.168.1.18 192.168.1.12', timeout => 2,
> version => 3) or die "$@";


'192.168.1.18 192.168.1.12' is not an array reference but a string.

Please try it with
[ qw(192.168.1.18 192.168.1.12) ]
or the equivalent
[ '192.168.1.18', '192.168.1.12' ]
as the 1st arg to Net::LDAP->new()

Hope it helps
Peter
--
Peter Marschall
peter@adpm.de
Markus Moeller

2008-02-10, 7:33 pm

That helped. I am only wondering why then '192.168.1.12 192.168.1.18' was
working and didn't give an error.

Thank you
Markus

"Peter Marschall" <peter@adpm.de> wrote in message
news:200802101627.26624.peter@adpm.de...
> Hi,
>
> On Sunday, 10. February 2008, Markus Moeller wrote:
>
> '192.168.1.18 192.168.1.12' is not an array reference but a string.
>
> Please try it with
> [ qw(192.168.1.18 192.168.1.12) ]
> or the equivalent
> [ '192.168.1.18', '192.168.1.12' ]
> as the 1st arg to Net::LDAP->new()
>
> Hope it helps
> Peter
> --
> Peter Marschall
> peter@adpm.de
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com