--- nfo/perl/libs/Data/Storage/Handler/NetLDAP.pm 2003/01/19 02:11:18 1.1 +++ nfo/perl/libs/Data/Storage/Handler/NetLDAP.pm 2003/01/20 16:46:09 1.2 @@ -1,10 +1,25 @@ +## ------------------------------------------------------------------------ +## $Id: NetLDAP.pm,v 1.2 2003/01/20 16:46:09 joko Exp $ +## ------------------------------------------------------------------------ +## $Log: NetLDAP.pm,v $ +## Revision 1.2 2003/01/20 16:46:09 joko +## - doesn't use global '$ldap' as ldap-connection-handle any more - now using '$self->{_COREHANDLE}' +## + sub getCOREHANDLE +## + sub createChildNode +## +## ------------------------------------------------------------------------ + + package Data::Storage::Handler::NetLDAP; use strict; use warnings; -use base ("Data::Storage::Handler"); -use base ("Data::Storage::Handler::Abstract"); +# Data::Storage::Handler +use base qw( + Data::Storage::Handler::Abstract + DesignPattern::Bridge +); use Data::Dumper; @@ -12,16 +27,18 @@ use Net::LDAP::Entry; #use Net::LDAP::Search; +use Data::Identifier::Dn; + # get logger instance my $logger = Log::Dispatch::Config->instance; # the (package) global ldap-connection-handler -my $ldap; +#my $self->{_COREHANDLE}; # TODO: implement this! my $TRACELEVEL = 0; -my $ldap_errors_file = '../log/ldap_errors.log'; +my $logfile_errors = '../log/ldap_errors.log'; sub getMetaInfo { @@ -32,10 +49,20 @@ }; } +sub _init { + my $self = shift; +#print "!!!!!!!!!!! _init", "\n"; + $self->load("Extensions"); +} + sub connect { my $self = shift; +#print "connect!", "\n"; + +#print Dumper($self); + my $dsn = $self->{locator}->{dsn}; $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); @@ -49,7 +76,7 @@ #print Dumper($self); - $ldap = Net::LDAP->new( + $self->{_COREHANDLE} = Net::LDAP->new( $self->{locator}->{connInfo}->{host}, port => $self->{locator}->{connInfo}->{port}, #timeout => 120, @@ -71,13 +98,15 @@ }; #$self->{_COREHANDLE} = - $ldap->bind( + $self->{_COREHANDLE}->bind( $self->{locator}->{connInfo}->{binddn}, password => $self->{locator}->{connInfo}->{pass} ) or die "$@"; $self->{locator}->{status}->{connected} = 1; +#print "ok", "\n"; + return 1; } @@ -97,19 +126,22 @@ sub existsChildNode { my $self = shift; - my $nodename = shift; -#print Dumper($self->{locator}); - - my $dn = "ou=" . $nodename . ", " . $self->{locator}->{basedn}; - - $logger->debug( __PACKAGE__ . "->existsChildNode( dn '$dn' )" ); - +#print "\n", "==== existsChildNode", "\n"; +#exit; + + my $nodeName = shift; + + $logger->debug( __PACKAGE__ . "->existsChildNode( basedn='$self->{locator}->{basedn}', nodeName='$nodeName' )" ); + + my $nodeDn = Data::Identifier::Dn->new(base => $self->{locator}->{basedn}, type => 'ou', name => $nodeName); + my $nodeDn_asString = $nodeDn->asString(); + my $filter = "(objectClass=*)"; #{ - my $mesg = $ldap->search( - base => $dn, + my $mesg = $self->{_COREHANDLE}->search( + base => $nodeDn_asString, filter => $filter, ); #} @@ -133,7 +165,7 @@ sub disconnect { my $self = shift; - #$self->{_COREHANDLE}->unbind; # take down session + $self->{_COREHANDLE}->unbind; # take down session } sub _ldapError { @@ -142,9 +174,22 @@ my $textMessage = "LDAP-ERROR: " . $message->error . " - code: " . $message->code; $textMessage .= " - dn: " . $message->{matchedDN} if $message->{matchedDN}; #print "msg: '$textMessage'", "\n"; - #a2f($ldap_errors_file, $textMessage) if !$TRACELEVEL; + #a2f($logfile_errors, $textMessage) if !$TRACELEVEL; $logger->error($textMessage); return $message; } +sub getCOREHANDLE { + my $self = shift; + return $self->{_COREHANDLE}; +} + +sub createChildNode { + my $self = shift; + my $nodeName = shift; +#print "createChildNode: $nodeName", "\n"; + my $nodeDn = Data::Identifier::Dn->new(base => $self->{locator}->{basedn}, type => 'ou', name => $nodeName); + return $self->createDn($nodeDn); +} + 1;