From 5f15ee93f79af5af0ee064ffdb5c03f2af14ee3a Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Wed, 18 Apr 2012 22:28:17 +0200 Subject: Unauthenticate binds; LDAP server defaults to ldap://127.0.0.1:389. --- lib/Fripost/Schema.pm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Fripost/Schema.pm b/lib/Fripost/Schema.pm index 14caccd..6a92be7 100755 --- a/lib/Fripost/Schema.pm +++ b/lib/Fripost/Schema.pm @@ -30,16 +30,30 @@ sub new { my $class = shift; my $h = shift; + $h->{server_host} //= 'ldap://127.0.0.1:389'; + $h->{base_dn} //= ''; + my $self = {_options => $h}; bless $self, $class; my $ldap = Net::LDAP->new ( $h->{server_host} ) - or die "Error: Cannot initialize connection to LDAP server.\n"; + or die "Error: Cannot initialize connection to LDAP server at `" + .$h->{server_host}. "'.\n"; my $mesg; if ( (defined $h->{bind_dn}) and $h->{bind_dn} ne '' ) { - $self->_dsay( "Binding to DN `" .$h->{bind_dn}. "'." ); - $mesg = $ldap->bind( $h->{bind_dn}, password => $h->{bind_pw} ); + my %bind; + my $debug = "Binding to DN `" .$h->{bind_dn}. "'"; + if (defined $h->{bind_pw}) { + $debug .= " (authenticated)."; + $bind{password} = $h->{bind_pw}; + } + else { + $debug .= " (unauthenticated)."; + $bind{noauth} = 1; + } + $self->_dsay( $debug ); + $mesg = $ldap->bind( $h->{bind_dn}, %bind ); } else { # Anonymous bind -- cgit v1.2.3