| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#********************************************************************* |
|
2
|
|
|
|
|
|
|
#*** ResourcePool::Resource::Net::LDAP |
|
3
|
|
|
|
|
|
|
#*** Copyright (c) 2020 by Markus Winand |
|
4
|
|
|
|
|
|
|
#*** $Id$ |
|
5
|
|
|
|
|
|
|
#********************************************************************* |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package ResourcePool::Resource::Net::LDAP; |
|
8
|
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
23
|
use vars qw($VERSION @ISA); |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
167
|
|
|
10
|
4
|
|
|
4
|
|
19
|
use strict; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
78
|
|
|
11
|
4
|
|
|
4
|
|
19
|
use Net::LDAP qw(LDAP_SUCCESS); |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
23
|
|
|
12
|
4
|
|
|
4
|
|
203
|
use ResourcePool::Resource; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
2346
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = "1.0003"; |
|
15
|
|
|
|
|
|
|
push @ISA, "ResourcePool::Resource"; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new($$$@) { |
|
18
|
2
|
|
|
2
|
0
|
5
|
my $proto = shift; |
|
19
|
2
|
|
33
|
|
|
7
|
my $class = ref($proto) || $proto; |
|
20
|
2
|
|
|
|
|
13
|
my $self = $class->SUPER::new(); |
|
21
|
2
|
|
|
|
|
42
|
$self->{Factory} = shift; |
|
22
|
2
|
|
|
|
|
4
|
my $host = shift; |
|
23
|
2
|
50
|
|
|
|
7
|
$self->{BindOptions} = defined $_[0] ? shift: []; |
|
24
|
2
|
50
|
|
|
|
5
|
my $NewOptions = defined $_[0] ? shift: []; |
|
25
|
2
|
|
|
|
|
6
|
$self->{start_tlsOptions} = shift; |
|
26
|
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
4
|
$self->{ldaph} = Net::LDAP->new($host, @{$NewOptions}); |
|
|
2
|
|
|
|
|
13
|
|
|
28
|
2
|
50
|
|
|
|
108181
|
if (! defined $self->{ldaph}) { |
|
29
|
|
|
|
|
|
|
swarn("ResourcePool::Resource::Net::LDAP: ". |
|
30
|
|
|
|
|
|
|
"Connect to '%s' failed: $@\n", |
|
31
|
2
|
|
|
|
|
27
|
$self->{Factory}->info()); |
|
32
|
2
|
|
|
|
|
14
|
return undef; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
bless($self, $class); |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
0
|
if (! defined $self->start_tls($self->{start_tlsOptions})) { |
|
38
|
0
|
|
|
|
|
0
|
return undef; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
# bind returns $self on success |
|
41
|
0
|
|
|
|
|
0
|
return $self->bind($self->{BindOptions}); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub close($) { |
|
45
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
46
|
|
|
|
|
|
|
#$self->{ldaph}->unbind(); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub fail_close($) { |
|
50
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
51
|
|
|
|
|
|
|
swarn("ResourcePool::Resource::Net::LDAP: ". |
|
52
|
|
|
|
|
|
|
"closing failed connection to '%s'.\n", |
|
53
|
0
|
|
|
|
|
0
|
$self->{Factory}->info()); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_plain_resource($) { |
|
57
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
58
|
0
|
|
|
|
|
0
|
return $self->{ldaph}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub DESTROY($) { |
|
62
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
|
63
|
0
|
|
|
|
|
0
|
$self->close(); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub precheck($) { |
|
67
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
68
|
0
|
|
|
|
|
0
|
return $self->bind($self->{BindOptions}); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub start_tls($$) { |
|
72
|
0
|
|
|
0
|
0
|
0
|
my ($self, $tlsoptions) = @_; |
|
73
|
0
|
0
|
|
|
|
0
|
if (defined $tlsoptions) { |
|
74
|
0
|
|
|
|
|
0
|
my $rc = $self->{ldaph}->start_tls(@{$tlsoptions}); |
|
|
0
|
|
|
|
|
0
|
|
|
75
|
0
|
0
|
|
|
|
0
|
if ($rc->code != LDAP_SUCCESS) { |
|
76
|
|
|
|
|
|
|
swarn("ResourcePool::Resource::Net::LDAP: " |
|
77
|
|
|
|
|
|
|
. "start_tls to '%s' failed: %s\n" |
|
78
|
|
|
|
|
|
|
, $self->{Factory}->info() |
|
79
|
0
|
|
|
|
|
0
|
, $rc->error() |
|
80
|
|
|
|
|
|
|
); |
|
81
|
0
|
|
|
|
|
0
|
delete $self->{ldaph}; |
|
82
|
0
|
|
|
|
|
0
|
return undef; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
0
|
return $self; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub bind($$) { |
|
90
|
0
|
|
|
0
|
0
|
0
|
my ($self, $bindopts) = @_; |
|
91
|
0
|
|
|
|
|
0
|
my @BindOptions = @{$bindopts}; |
|
|
0
|
|
|
|
|
0
|
|
|
92
|
0
|
|
|
|
|
0
|
my $rc; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
$rc = $self->{ldaph}->bind(@BindOptions); |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
0
|
if ($rc->code != LDAP_SUCCESS) { |
|
97
|
|
|
|
|
|
|
swarn("ResourcePool::Resource::Net::LDAP: ". |
|
98
|
|
|
|
|
|
|
"Bind to '%s' failed: %s\n", |
|
99
|
0
|
|
|
|
|
0
|
$self->{Factory}->info(), |
|
100
|
|
|
|
|
|
|
$rc->error()); |
|
101
|
0
|
|
|
|
|
0
|
delete $self->{ldaph}; |
|
102
|
0
|
|
|
|
|
0
|
return undef; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
0
|
return $self; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub swarn($@) { |
|
110
|
2
|
|
|
2
|
0
|
6
|
my $fmt = shift; |
|
111
|
2
|
|
|
|
|
44
|
warn sprintf($fmt, @_); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
1; |