Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi, and excuse the English.
I have a perl script that manege ldap users, I tested it with one ldap server, and now I tried to add the second server, the ldap servers are in multi-master configuration.
When I try to do a modification, I call a sub which searches if the user account exists. When using a single ldap server, all was working smoothly, after adding the second ldap server I got this exception :
Uncaught exception from user code: Expected 'PeerHost' at /usr/local/share/perl5/Net/LDAP.pm line + 164. IO::Socket::IP::_io_socket_ip__configure('IO::Socket::IP=GLOB( +0x1b83bb0)', 'HASH(0x2a69050)') called at /usr/local/share/perl5/IO/S +ocket/IP.pm line 402 IO::Socket::IP::configure('IO::Socket::IP=GLOB(0x1b83bb0)', 'H +ASH(0x2a69050)') called at /usr/lib64/perl5/IO/Socket.pm line 49 IO::Socket::new('IO::Socket::IP', 'Proto', 'tcp', 'PeerAddr', +undef, 'MultiHomed', undef, 'PeerPort', 389, ...) called at /usr/loca +l/share/perl5/IO/Socket/IP.pm line 369 IO::Socket::IP::new('IO::Socket::IP', 'PeerAddr', undef, 'Peer +Port', 389, 'LocalAddr', undef, 'Proto', 'tcp', ...) called at /usr/l +ocal/share/perl5/Net/LDAP.pm line 164 Net::LDAP::connect_ldap('Net::LDAP=HASH(0x1b7ba58)', undef, 'H +ASH(0x2a69218)') called at /usr/local/share/perl5/Net/LDAP.pm line 12 +2 Net::LDAP::new('Net::LDAP', 'ldap1.example.com', 'ldap2.exampl +e.com', 'port', 389, 'timeout', 3) called at /opt/scripts/dev/adminco +nsoleV5-Dev.pl line 1112 main::bind_ldap_new('ARRAY(0x289a820)', 389, 'uid=admin,ou=peo +ple,dc=example,dc=com', '/opt/scripts/ssl/cert.pem', '******') called + at /opt/scripts/dev/adminconsoleV5-Dev.pl line 2227 main::call_find_zimbra_user('test.user', 'uid') called at /opt +/scripts/dev/adminconsoleV5-Dev.pl line 2109 main::call_modify_account() called at /opt/scripts/dev/adminco +nsoleV5-Dev.pl line 2447 main::main_menu() called at /opt/scripts/dev/adminconsoleV5-De +v.pl line 2389 main::main() called at /opt/scripts/dev/adminconsoleV5-Dev.pl +line 2392
Here is a snippet of my code :
sub call_find_user { my($attribute, $search) = @_; if(length($search)){ my $ldap = bind_ldap_new(\@LDAP_SERVERS,$LDAP_PORT,$LD +AP_BIND_DN,$CA_FILE,$LDAP_BIND_PASS); my $mesg = search_ldap($ldap, $BASE_DNUSERS_SEARCH, "( +$search=$attribute)", $SCOPE); my $entry = $mesg->entry(0); if(defined($entry)) { my $localdn = $entry->dn(); display_msg("dn: $localdn\n", "other"); unbind_ldap($ldap); return 1; } unbind_ldap($ldap); } } ----- sub bind_ldap_new { my ($ldap_servers,$ldap_port,$ldap_bind_dn,$ldap_ca_file,$ldap +_password) = @_; my @LOCAL_LDAP_SERVERS = @{$ldap_servers}; my $ldap = Net::LDAP->new( @LOCAL_LDAP_SERVERS, port => $ldap_port, timeout => 3); $ldap-> start_tls( verify => 'optional', cafile => $ldap_ca_file) or die "ERROR: Can't connect to ldap servers($@ +)\n"; my $mesg = ldapassert($ldap->bind($ldap_bind_dn, password=>$ld +ap_password),"Binding to ldap server"); return $ldap; } .... my @LDAP_SERVERS=('ldap1.example.com','ldap2.example.com'); if($changeOnUser && call_find_user("test.user","uid")) { modify_zimbra_account(\%hashValues); }
Regards.
2018-12-21 Athanasius added code tags around exception message
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem using NET::LDAP with multiple ldap servers
by poj (Abbot) on Dec 20, 2018 at 07:35 UTC |