| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Handler::UserDB; |
|
2
|
1
|
|
|
1
|
|
941
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
19
|
|
|
4
|
1
|
|
|
1
|
|
95
|
use DB_File; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Mail::Milter::Authentication::Handler::UserDB::Hash; |
|
6
|
|
|
|
|
|
|
use Sys::Syslog qw{:standard :macros}; |
|
7
|
|
|
|
|
|
|
use base 'Mail::Milter::Authentication::Handler'; |
|
8
|
|
|
|
|
|
|
use version; our $VERSION = version->declare('v1.1.3'); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $CHECKED_TIME; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub default_config { |
|
13
|
|
|
|
|
|
|
return { |
|
14
|
|
|
|
|
|
|
'add_header' => 1, |
|
15
|
|
|
|
|
|
|
'lookup' => [ 'hash:/etc/postfix/virtusertable' ], |
|
16
|
|
|
|
|
|
|
}; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub grafana_rows { |
|
20
|
|
|
|
|
|
|
my ( $self ) = @_; |
|
21
|
|
|
|
|
|
|
my @rows; |
|
22
|
|
|
|
|
|
|
push @rows, $self->get_json( 'UserDB_metrics' ); |
|
23
|
|
|
|
|
|
|
return \@rows; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub register_metrics { |
|
27
|
|
|
|
|
|
|
return { |
|
28
|
|
|
|
|
|
|
'userdb_total' => 'The number of emails processed for UserDB', |
|
29
|
|
|
|
|
|
|
}; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub setup_callback { |
|
33
|
|
|
|
|
|
|
my ( $self ) = @_; |
|
34
|
|
|
|
|
|
|
delete $self->{'local_user'}; |
|
35
|
|
|
|
|
|
|
return; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub envrcpt_callback { |
|
39
|
|
|
|
|
|
|
my ( $self, $env_to ) = @_; |
|
40
|
|
|
|
|
|
|
my $address = $self->get_address_from( $env_to ); |
|
41
|
|
|
|
|
|
|
my $user = $self->get_user_from_address( $address ); |
|
42
|
|
|
|
|
|
|
$self->{'local_user'} = $user if $user; |
|
43
|
|
|
|
|
|
|
return; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub eoh_callback { |
|
47
|
|
|
|
|
|
|
my ( $self ) = @_; |
|
48
|
|
|
|
|
|
|
my $config = $self->handler_config(); |
|
49
|
|
|
|
|
|
|
if ( $self->{'local_user'} ) { |
|
50
|
|
|
|
|
|
|
$self->metric_count( 'userdb_total', { 'result' => 'pass' } ); |
|
51
|
|
|
|
|
|
|
if ( $config->{'add_header'} ) { |
|
52
|
|
|
|
|
|
|
$self->add_auth_header('x-local-user=pass'); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
else { |
|
56
|
|
|
|
|
|
|
$self->metric_count( 'userdb_total', { 'result' => 'fail' } ); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
return; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub close_callback { |
|
62
|
|
|
|
|
|
|
my ( $self ) = @_; |
|
63
|
|
|
|
|
|
|
delete $self->{'local_user'}; |
|
64
|
|
|
|
|
|
|
return; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
{ |
|
68
|
|
|
|
|
|
|
my $lookers_cache; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub get_lookers { |
|
71
|
|
|
|
|
|
|
my ( $self ) = @_; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
if ( $lookers_cache ) { |
|
74
|
|
|
|
|
|
|
my $reloaded = 0; |
|
75
|
|
|
|
|
|
|
foreach my $looker ( @{$lookers_cache} ) { |
|
76
|
|
|
|
|
|
|
$reloaded = $reloaded + $looker->check_reload(); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
if ( $reloaded ) { |
|
79
|
|
|
|
|
|
|
$self->dbgout( 'UserDb', 'Re-loading User DB', LOG_INFO ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
return $lookers_cache; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$self->dbgout( 'UserDb', 'Loading User DB', LOG_DEBUG ); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my @lookers; |
|
87
|
|
|
|
|
|
|
my $config = $self->handler_config(); |
|
88
|
|
|
|
|
|
|
my $lookups = $config->{'lookup'}; |
|
89
|
|
|
|
|
|
|
foreach my $lookup ( @$lookups ) { |
|
90
|
|
|
|
|
|
|
my ( $type, $data ) = split ':', $lookup, 2; |
|
91
|
|
|
|
|
|
|
if ( $type eq 'hash' ) { |
|
92
|
|
|
|
|
|
|
my $looker = Mail::Milter::Authentication::Handler::UserDB::Hash->new( $data ); |
|
93
|
|
|
|
|
|
|
push @lookers, $looker; |
|
94
|
|
|
|
|
|
|
$looker->preload(); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
else { |
|
97
|
|
|
|
|
|
|
die "Unknown UserDB lookup type $type"; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
$lookers_cache = \@lookers; |
|
101
|
|
|
|
|
|
|
return $lookers_cache; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub get_user_from_address { |
|
107
|
|
|
|
|
|
|
my ( $self, $address ) = @_; |
|
108
|
|
|
|
|
|
|
$self->dbgout( 'UserDb Lookup', $address, LOG_DEBUG ); |
|
109
|
|
|
|
|
|
|
my $lookers = $self->get_lookers(); |
|
110
|
|
|
|
|
|
|
foreach my $looker ( @{$lookers} ) { |
|
111
|
|
|
|
|
|
|
my $user = $looker->get_user_from_address( $address ); |
|
112
|
|
|
|
|
|
|
$self->dbgout( 'UserDb Found', $user, LOG_DEBUG ) if $user; |
|
113
|
|
|
|
|
|
|
return $user if $user; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
return; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 NAME |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Authentication Milter - UserDB Module |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Check if email has a local recipient account. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
"UserDB" : { |
|
133
|
|
|
|
|
|
|
"add_header" : 1, |
|
134
|
|
|
|
|
|
|
"lookup" : [ "hash:/etc/postfix/virtusertable" ] |
|
135
|
|
|
|
|
|
|
}, |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 CONFIG |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Add a block to the handlers section of your config as follows. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
"UserDB" : { |
|
144
|
|
|
|
|
|
|
"add_header" : 1, |
|
145
|
|
|
|
|
|
|
"lookup" : [ "hash:/etc/postfix/virtusertable" ] |
|
146
|
|
|
|
|
|
|
}, |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHORS |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Marc Bradshaw E<lt>marc@marcbradshaw.netE<gt> |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Copyright 2017 |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This library is free software; you may redistribute it and/or |
|
158
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|