1 |
|
## ------------------------------------------------------------------------ |
2 |
|
## $Id$ |
3 |
|
## ------------------------------------------------------------------------ |
4 |
|
## $Log$ |
5 |
|
## Revision 1.2 2003/01/20 16:46:09 joko |
6 |
|
## - doesn't use global '$ldap' as ldap-connection-handle any more - now using '$self->{_COREHANDLE}' |
7 |
|
## + sub getCOREHANDLE |
8 |
|
## + sub createChildNode |
9 |
|
## |
10 |
|
## ------------------------------------------------------------------------ |
11 |
|
|
12 |
|
|
13 |
package Data::Storage::Handler::NetLDAP; |
package Data::Storage::Handler::NetLDAP; |
14 |
|
|
15 |
use strict; |
use strict; |
16 |
use warnings; |
use warnings; |
17 |
|
|
18 |
use base ("Data::Storage::Handler"); |
# Data::Storage::Handler |
19 |
use base ("Data::Storage::Handler::Abstract"); |
use base qw( |
20 |
|
Data::Storage::Handler::Abstract |
21 |
|
DesignPattern::Bridge |
22 |
|
); |
23 |
|
|
24 |
|
|
25 |
use Data::Dumper; |
use Data::Dumper; |
27 |
use Net::LDAP::Entry; |
use Net::LDAP::Entry; |
28 |
#use Net::LDAP::Search; |
#use Net::LDAP::Search; |
29 |
|
|
30 |
|
use Data::Identifier::Dn; |
31 |
|
|
32 |
# get logger instance |
# get logger instance |
33 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
34 |
|
|
35 |
|
|
36 |
# the (package) global ldap-connection-handler |
# the (package) global ldap-connection-handler |
37 |
my $ldap; |
#my $self->{_COREHANDLE}; |
38 |
|
|
39 |
# TODO: implement this! |
# TODO: implement this! |
40 |
my $TRACELEVEL = 0; |
my $TRACELEVEL = 0; |
41 |
my $ldap_errors_file = '../log/ldap_errors.log'; |
my $logfile_errors = '../log/ldap_errors.log'; |
42 |
|
|
43 |
|
|
44 |
sub getMetaInfo { |
sub getMetaInfo { |
49 |
}; |
}; |
50 |
} |
} |
51 |
|
|
52 |
|
sub _init { |
53 |
|
my $self = shift; |
54 |
|
#print "!!!!!!!!!!! _init", "\n"; |
55 |
|
$self->load("Extensions"); |
56 |
|
} |
57 |
|
|
58 |
sub connect { |
sub connect { |
59 |
|
|
60 |
my $self = shift; |
my $self = shift; |
61 |
|
|
62 |
|
#print "connect!", "\n"; |
63 |
|
|
64 |
|
#print Dumper($self); |
65 |
|
|
66 |
my $dsn = $self->{locator}->{dsn}; |
my $dsn = $self->{locator}->{dsn}; |
67 |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
68 |
|
|
76 |
|
|
77 |
#print Dumper($self); |
#print Dumper($self); |
78 |
|
|
79 |
$ldap = Net::LDAP->new( |
$self->{_COREHANDLE} = Net::LDAP->new( |
80 |
$self->{locator}->{connInfo}->{host}, |
$self->{locator}->{connInfo}->{host}, |
81 |
port => $self->{locator}->{connInfo}->{port}, |
port => $self->{locator}->{connInfo}->{port}, |
82 |
#timeout => 120, |
#timeout => 120, |
98 |
}; |
}; |
99 |
|
|
100 |
#$self->{_COREHANDLE} = |
#$self->{_COREHANDLE} = |
101 |
$ldap->bind( |
$self->{_COREHANDLE}->bind( |
102 |
$self->{locator}->{connInfo}->{binddn}, |
$self->{locator}->{connInfo}->{binddn}, |
103 |
password => $self->{locator}->{connInfo}->{pass} |
password => $self->{locator}->{connInfo}->{pass} |
104 |
) or die "$@"; |
) or die "$@"; |
105 |
|
|
106 |
$self->{locator}->{status}->{connected} = 1; |
$self->{locator}->{status}->{connected} = 1; |
107 |
|
|
108 |
|
#print "ok", "\n"; |
109 |
|
|
110 |
return 1; |
return 1; |
111 |
|
|
112 |
} |
} |
126 |
|
|
127 |
sub existsChildNode { |
sub existsChildNode { |
128 |
my $self = shift; |
my $self = shift; |
|
my $nodename = shift; |
|
129 |
|
|
130 |
#print Dumper($self->{locator}); |
#print "\n", "==== existsChildNode", "\n"; |
131 |
|
#exit; |
132 |
my $dn = "ou=" . $nodename . ", " . $self->{locator}->{basedn}; |
|
133 |
|
my $nodeName = shift; |
134 |
$logger->debug( __PACKAGE__ . "->existsChildNode( dn '$dn' )" ); |
|
135 |
|
$logger->debug( __PACKAGE__ . "->existsChildNode( basedn='$self->{locator}->{basedn}', nodeName='$nodeName' )" ); |
136 |
|
|
137 |
|
my $nodeDn = Data::Identifier::Dn->new(base => $self->{locator}->{basedn}, type => 'ou', name => $nodeName); |
138 |
|
my $nodeDn_asString = $nodeDn->asString(); |
139 |
|
|
140 |
my $filter = "(objectClass=*)"; |
my $filter = "(objectClass=*)"; |
141 |
|
|
142 |
#{ |
#{ |
143 |
my $mesg = $ldap->search( |
my $mesg = $self->{_COREHANDLE}->search( |
144 |
base => $dn, |
base => $nodeDn_asString, |
145 |
filter => $filter, |
filter => $filter, |
146 |
); |
); |
147 |
#} |
#} |
165 |
|
|
166 |
sub disconnect { |
sub disconnect { |
167 |
my $self = shift; |
my $self = shift; |
168 |
#$self->{_COREHANDLE}->unbind; # take down session |
$self->{_COREHANDLE}->unbind; # take down session |
169 |
} |
} |
170 |
|
|
171 |
sub _ldapError { |
sub _ldapError { |
174 |
my $textMessage = "LDAP-ERROR: " . $message->error . " - code: " . $message->code; |
my $textMessage = "LDAP-ERROR: " . $message->error . " - code: " . $message->code; |
175 |
$textMessage .= " - dn: " . $message->{matchedDN} if $message->{matchedDN}; |
$textMessage .= " - dn: " . $message->{matchedDN} if $message->{matchedDN}; |
176 |
#print "msg: '$textMessage'", "\n"; |
#print "msg: '$textMessage'", "\n"; |
177 |
#a2f($ldap_errors_file, $textMessage) if !$TRACELEVEL; |
#a2f($logfile_errors, $textMessage) if !$TRACELEVEL; |
178 |
$logger->error($textMessage); |
$logger->error($textMessage); |
179 |
return $message; |
return $message; |
180 |
} |
} |
181 |
|
|
182 |
|
sub getCOREHANDLE { |
183 |
|
my $self = shift; |
184 |
|
return $self->{_COREHANDLE}; |
185 |
|
} |
186 |
|
|
187 |
|
sub createChildNode { |
188 |
|
my $self = shift; |
189 |
|
my $nodeName = shift; |
190 |
|
#print "createChildNode: $nodeName", "\n"; |
191 |
|
my $nodeDn = Data::Identifier::Dn->new(base => $self->{locator}->{basedn}, type => 'ou', name => $nodeName); |
192 |
|
return $self->createDn($nodeDn); |
193 |
|
} |
194 |
|
|
195 |
1; |
1; |