From: Ziya S. <zi...@ri...> - 2003-01-26 19:24:39
|
This one uses LDAPI.pm and LDAPS.pm. Attached a patch file, which includes a couple of test cases as well as the diff below. You will need to apply LDAPI patch separately to test LDAPI URIs as well as LDAPS. Unfortunately (Although URL test written for LDAPS as well) I couldn't run it for LDAPS. Only with LDAP and LDAPI. Cheers, Ziya. --- ldap/lib/Net/LDAP.pm 2003-01-26 16:56:06.730623000 +0000 +++ ldap_patch.d/lib/Net/LDAP.pm 2003-01-26 16:55:52.100623000 +0000 @@ -97,10 +97,30 @@ my $obj = bless {}, $type; foreach my $h (ref($host) ? @$host : ($host)) { + + my $save_port = $arg->{port}; + + # Check for URL + if ($h =~m!^([a-z]+)://([/\w\.\-\@\#\~]+?)(?::(\d+))?/?$!i) { + my $uri = uc($1); + my $new_type = "Net::$uri"; + $h = $2; + $arg->{port} = $3 if $3; + eval "require $new_type" and bless $obj, $new_type and $obj->isa('Net::LDAP') + or require Carp and Carp::croak("Cannot handle $uri URIs"); + + $obj->can('_connect') + or require Carp and Carp::croak("$new_type does not implement Net::LDAP interface"); + } + if ($obj->_connect($h, $arg)) { $obj->{net_ldap_host} = $h; last; } + + # Restore to defaults + $arg->{port} = $save_port; + bless $obj, $type; } return undef unless $obj->{net_ldap_socket}; On 2003-01-16 19:14:46 +0000, Graham Barr wrote: > On Sat, Jan 11, 2003 at 04:48:18PM +0100, Peter Marschall wrote: > > Hi, > > > > On Thursday 09 January 2003 14:43, Ziya Suzen wrote: > > > I was running some tests on my sand-box station and because my OpenLDAP > > > is compiled with TCP wrappers I cannot connect to it. Sure the > > > solution can be adding slapd to hosts.allow but I thought a better > > > solution could be using Unix sockets. And I came up with the following > > > patch to LDAP.pm. What do you think? > > > > > > BTW, I have only tested ldapi:// syntax. I wanted to get your opinions > > > before going any further. > > I think your ldaps:// implementation is wrong. It needs todo what Net::LDAPS > is currently doing. > > I also think the connect dispatch should look something like > > if ($host_or_url =~m!^([a-z]+)://([/\w\.\-\@\#\~]+?)(?::(\d+))?/?$!i) { > my $connect = $obj->can("_connect_$1") or croak("Cannot handle $1 URIs"); > $host = $2; > local $arg->{port} = $3 if $3; > > $obj->$connect($host, $arg); > } > > The foreach to allow the user to pass multiple hosts should be around this and > the old code. > > > there has been a similar patch on the list a few weeks ago. > > It added a Net::LDAPI.pm file for the ldapi:// connection. > > That was going to be my reply too :) > > However after thinking for a bit, I think I like the option to pass a URI to > Net::LDAP and have it DWIM. Being able to specify different protocols when > giving a list of hosts to try to connect to might be useful. > > Graham. |