line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Connection::Ldap; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1090
|
use Moose; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
14
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Mail::MtPolicyd::Connection'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: a LDAP connection plugin for mtpolicyd |
8
|
|
|
|
|
|
|
our $VERSION = '2.01'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
9081
|
use Net::LDAP; |
|
2
|
|
|
|
|
184275
|
|
|
2
|
|
|
|
|
11
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'host' => ( is => 'ro', isa => 'Str', default => 'localhost' ); |
14
|
|
|
|
|
|
|
has 'port' => ( is => 'ro', isa => 'Int', default => 389 ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'keepalive' => ( is => 'ro', isa => 'Bool', default => 1 ); |
17
|
|
|
|
|
|
|
has 'timeout' => ( is => 'ro', isa => 'Int', default => 120 ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'binddn' => ( is => 'ro', isa => 'Maybe[Str]' ); |
20
|
|
|
|
|
|
|
has 'password' => ( is => 'ro', isa => 'Maybe[Str]' ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'starttls' => ( is => 'ro', isa => 'Bool', default => 1 ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'handle' => ( is => 'rw', isa => 'Net::LDAP', lazy => 1, |
25
|
|
|
|
|
|
|
default => sub { |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
return $self->_connect_ldap; |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
handles => { |
30
|
|
|
|
|
|
|
'disconnect' => 'unbind', |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'connection_class' => ( is => 'ro', isa => 'Maybe[Str]' ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _connect_ldap { |
37
|
1
|
|
|
1
|
|
1
|
my $self = shift; |
38
|
1
|
|
|
|
|
2
|
my $ldap_class = 'Net::LDAP'; |
39
|
|
|
|
|
|
|
|
40
|
1
|
50
|
|
|
|
42
|
if( defined $self->connection_class ) { |
41
|
1
|
|
|
|
|
40
|
$ldap_class = $self->connection_class; |
42
|
1
|
|
|
|
|
61
|
eval "require $ldap_class;"; ## no critic |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
|
|
4674
|
my $ldap = $ldap_class->new( |
46
|
|
|
|
|
|
|
$self->host, |
47
|
|
|
|
|
|
|
port => $self->port, |
48
|
|
|
|
|
|
|
keepalive => $self->keepalive, |
49
|
|
|
|
|
|
|
timeout => $self->timeout, |
50
|
|
|
|
|
|
|
onerror => 'die', |
51
|
|
|
|
|
|
|
) or die ('cant connect ldap: '.$@); |
52
|
|
|
|
|
|
|
|
53
|
1
|
50
|
|
|
|
16561
|
if( $self->starttls ) { |
54
|
1
|
|
|
|
|
2
|
eval{ $ldap->start_tls( verify => 'require' ); }; |
|
1
|
|
|
|
|
9
|
|
55
|
1
|
50
|
|
|
|
37624
|
if( $@ ) { die('starttls on ldap connection failed: '.$@); } |
|
0
|
|
|
|
|
0
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
1
|
50
|
|
|
|
35
|
if( defined $self->binddn ) { |
59
|
1
|
|
|
|
|
25
|
$ldap->bind( $self->binddn, password => $self->password ); |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
0
|
$ldap->bind; # anonymous bind |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
956
|
return $ldap; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub reconnect { |
68
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
69
|
0
|
|
|
|
|
|
$self->handle( $self->_connect_ldap ); |
70
|
0
|
|
|
|
|
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub shutdown { |
74
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
75
|
0
|
|
|
|
|
|
$self->handle->unbind; |
76
|
0
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=encoding UTF-8 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Mail::MtPolicyd::Connection::Ldap - a LDAP connection plugin for mtpolicyd |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 VERSION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
version 2.01 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SYNOPSIS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
<Connection ldap> |
98
|
|
|
|
|
|
|
module = "Ldap" |
99
|
|
|
|
|
|
|
host = "localhost" |
100
|
|
|
|
|
|
|
</Connection> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 PARAMETERS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item host (default: 'localhost') |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
LDAP server to connect to. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item port (default: 389) |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
LDAP servers port number to connect to. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item keepalive (default: 1) |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Enable connection keepalive for this connection. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item timeout (default: 120) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Timeout in seconds for operations on this connection. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item binddn (default: undef) |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
If set a bind with this binddn is done when connecting. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item password (default: undef) |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item starttls (default: 1) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Enable or disabled the use of starttls. (TLS/SSL encryption) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This is free software, licensed under: |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |