line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Handler::PTR; |
2
|
29
|
|
|
29
|
|
16263
|
use 5.20.0; |
|
29
|
|
|
|
|
167
|
|
3
|
29
|
|
|
29
|
|
233
|
use strict; |
|
29
|
|
|
|
|
72
|
|
|
29
|
|
|
|
|
959
|
|
4
|
29
|
|
|
29
|
|
189
|
use warnings; |
|
29
|
|
|
|
|
157
|
|
|
29
|
|
|
|
|
965
|
|
5
|
29
|
|
|
29
|
|
191
|
use Mail::Milter::Authentication::Pragmas; |
|
29
|
|
|
|
|
84
|
|
|
29
|
|
|
|
|
343
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Handler class for PTR checking |
7
|
|
|
|
|
|
|
our $VERSION = '3.20230911'; # VERSION |
8
|
29
|
|
|
29
|
|
7127
|
use base 'Mail::Milter::Authentication::Handler'; |
|
29
|
|
|
|
|
96
|
|
|
29
|
|
|
|
|
17671
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub default_config { |
11
|
0
|
|
|
0
|
0
|
0
|
return {}; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub grafana_rows { |
15
|
0
|
|
|
0
|
0
|
0
|
my ( $self ) = @_; |
16
|
0
|
|
|
|
|
0
|
my @rows; |
17
|
0
|
|
|
|
|
0
|
push @rows, $self->get_json( 'PTR_metrics' ); |
18
|
0
|
|
|
|
|
0
|
return \@rows; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub register_metrics { |
22
|
|
|
|
|
|
|
return { |
23
|
28
|
|
|
28
|
1
|
191
|
'ptr_total' => 'The number of emails processed for PTR', |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub helo_callback { |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# On HELO |
30
|
68
|
|
|
68
|
0
|
350
|
my ( $self, $helo_host ) = @_; |
31
|
68
|
100
|
|
|
|
416
|
return if ( $self->is_local_ip_address() ); |
32
|
60
|
100
|
|
|
|
402
|
return if ( $self->is_trusted_ip_address() ); |
33
|
58
|
50
|
|
|
|
499
|
return if ( $self->is_authenticated() ); |
34
|
|
|
|
|
|
|
|
35
|
58
|
50
|
|
|
|
315
|
if ( ! $self->is_handler_loaded( 'IPRev' ) ) { |
36
|
0
|
|
|
|
|
0
|
$self->log_error( 'PTR Config Error: IPRev is missing '); |
37
|
0
|
|
|
|
|
0
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
58
|
|
|
|
|
296
|
my $iprev_handler = $self->get_handler('IPRev'); |
41
|
|
|
|
|
|
|
my $domains = |
42
|
|
|
|
|
|
|
exists( $iprev_handler->{'verified_ptr'} ) |
43
|
58
|
100
|
|
|
|
368
|
? $iprev_handler->{'verified_ptr'} |
44
|
|
|
|
|
|
|
: q{}; |
45
|
|
|
|
|
|
|
|
46
|
58
|
|
|
|
|
195
|
my $found_match = 0; |
47
|
|
|
|
|
|
|
|
48
|
58
|
|
|
|
|
375
|
foreach my $domain ( split ',', $domains ) { |
49
|
22
|
100
|
|
|
|
132
|
if ( lc $domain eq lc $helo_host ) { |
50
|
20
|
|
|
|
|
80
|
$found_match = 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
58
|
100
|
|
|
|
314
|
my $result = $found_match ? 'pass' : 'fail'; |
55
|
58
|
|
|
|
|
382
|
$self->dbgout( 'PTRMatch', $result, LOG_DEBUG ); |
56
|
58
|
|
|
|
|
413
|
my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-ptr' )->safe_set_value( $result ); |
57
|
58
|
|
|
|
|
4116
|
$header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'smtp.helo' )->safe_set_value( $helo_host ) ); |
58
|
58
|
|
|
|
|
5910
|
$header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'policy.ptr' )->safe_set_value( $domains ) ); |
59
|
58
|
|
|
|
|
5384
|
$self->add_c_auth_header( $header ); |
60
|
58
|
|
|
|
|
642
|
$self->metric_count( 'ptr_total', { 'result' => $result} ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=encoding UTF-8 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Mail::Milter::Authentication::Handler::PTR - Handler class for PTR checking |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 VERSION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
version 3.20230911 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Check DNS PTR Records match. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This handler requires the IPRev handler to be installed and active. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 CONFIGURATION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
No configuration options exist for this handler. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 AUTHOR |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Marc Bradshaw <marc@marcbradshaw.net> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Marc Bradshaw. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
98
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |