| 1 | package Mail::MtPolicyd::Connection::Ldap; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 2 | extends 'Mail::MtPolicyd::Connection'; | |||||||||
| 6 | |||||||||||
| 7 | # ABSTRACT: a LDAP connection plugin for mtpolicyd | ||||||||||
| 8 | 2 | our $VERSION = '2.01'; # VERSION | |||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use Net::LDAP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | 2 | has 'host' => ( is => 'ro', isa => 'Str', default => 'localhost' ); | |||||||||
| 14 | 2 | has 'port' => ( is => 'ro', isa => 'Int', default => 389 ); | |||||||||
| 15 | |||||||||||
| 16 | 2 | has 'keepalive' => ( is => 'ro', isa => 'Bool', default => 1 ); | |||||||||
| 17 | 2 | has 'timeout' => ( is => 'ro', isa => 'Int', default => 120 ); | |||||||||
| 18 | |||||||||||
| 19 | 2 | has 'binddn' => ( is => 'ro', isa => 'Maybe[Str]' ); | |||||||||
| 20 | 2 | has 'password' => ( is => 'ro', isa => 'Maybe[Str]' ); | |||||||||
| 21 | |||||||||||
| 22 | 2 | has 'starttls' => ( is => 'ro', isa => 'Bool', default => 1 ); | |||||||||
| 23 | |||||||||||
| 24 | has 'handle' => ( is => 'rw', isa => 'Net::LDAP', lazy => 1, | ||||||||||
| 25 | default => sub { | ||||||||||
| 26 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 1 | return $self->_connect_ldap; | |||||||||
| 28 | }, | ||||||||||
| 29 | 2 | handles => { | |||||||||
| 30 | 'disconnect' => 'unbind', | ||||||||||
| 31 | }, | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | 2 | has 'connection_class' => ( is => 'ro', isa => 'Maybe[Str]' ); | |||||||||
| 35 | |||||||||||
| 36 | sub _connect_ldap { | ||||||||||
| 37 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_connect_ldap: called CC=6 SCAR=19.2
| |||||||||||
| 38 | 1 | my $ldap_class = 'Net::LDAP'; | |||||||||
| 39 | |||||||||||
| 40 | 1 | ▶ | if( defined $self->connection_class ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 1 | $ldap_class = $self->connection_class; | |||||||||
| 42 | 1 | eval "require $ldap_class;"; ## no critic | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | my $ldap = $ldap_class->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if( $self->starttls ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 1 | eval{ $ldap->start_tls( verify => 'require' ); }; | |||||||||
| 55 | 1 | ▶ | if( $@ ) { die('starttls on ldap connection failed: '.$@); } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 1 | ▶ | if( defined $self->binddn ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 1 | $ldap->bind( $self->binddn, password => $self->password ); | |||||||||
| 60 | } else { | ||||||||||
| 61 | 0 | $ldap->bind; # anonymous bind | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 1 | return $ldap; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | sub reconnect { | ||||||||||
| 68 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
reconnect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 69 | 0 | $self->handle( $self->_connect_ldap ); | |||||||||
| 70 | 0 | return; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | sub shutdown { | ||||||||||
| 74 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
shutdown: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 75 | 0 | $self->handle->unbind; | |||||||||
| 76 | 0 | return; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 2 | 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 | ||||||||||