line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Handler::UserDB::Hash; |
2
|
1
|
|
|
1
|
|
1692
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
5
|
use base 'Mail::Milter::Authentication::Handler::UserDB'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
105
|
|
5
|
|
|
|
|
|
|
use version; our $VERSION = version->declare('v1.1.3'); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use DB_File; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
|
|
|
|
|
|
my ( $class, $file ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $self = { |
13
|
|
|
|
|
|
|
'file' => $file . '.db', |
14
|
|
|
|
|
|
|
'checked_time' => 0, |
15
|
|
|
|
|
|
|
'table' => undef, |
16
|
|
|
|
|
|
|
'table_stamp' => 0, |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
bless $self, $class; |
20
|
|
|
|
|
|
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub preload { |
24
|
|
|
|
|
|
|
my ( $self ) = @_; |
25
|
|
|
|
|
|
|
$self->{'checked_time'} = time; |
26
|
|
|
|
|
|
|
my $null = $self->get_table(); |
27
|
|
|
|
|
|
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub check_reload { |
31
|
|
|
|
|
|
|
my ( $self ) = @_; |
32
|
|
|
|
|
|
|
my $now = time; |
33
|
|
|
|
|
|
|
my $check_time = 60*10; # Check no more often than every 10 minutes |
34
|
|
|
|
|
|
|
if ( $now > $self->{'checked_time'} + $check_time ) { |
35
|
|
|
|
|
|
|
$self->{'checked_time'} = $now; |
36
|
|
|
|
|
|
|
return $self->check_table(); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub get_user_from_address { |
42
|
|
|
|
|
|
|
my ( $self, $address ) = @_; |
43
|
|
|
|
|
|
|
$address =~ s/\+.*@/@/; |
44
|
|
|
|
|
|
|
my $table = $self->get_table(); |
45
|
|
|
|
|
|
|
if ( exists $table->{ lc $address } ) { |
46
|
|
|
|
|
|
|
return $table->{ lc $address }; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get_table { |
52
|
|
|
|
|
|
|
my ( $self ) = @_; |
53
|
|
|
|
|
|
|
return $self->{'table'} if $self->{'table'}; |
54
|
|
|
|
|
|
|
my $file = $self->{'file'}; |
55
|
|
|
|
|
|
|
return if not $file; |
56
|
|
|
|
|
|
|
if ( ! -e $file ) { |
57
|
|
|
|
|
|
|
warn "UserDB File $file does not exist"; |
58
|
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
$self->{'table_stamp'} = ( stat( $file ) )[9]; |
61
|
|
|
|
|
|
|
my %h; |
62
|
|
|
|
|
|
|
tie %h, 'DB_File', $file, O_RDONLY, undef, $DB_HASH; |
63
|
|
|
|
|
|
|
my $table = {}; |
64
|
|
|
|
|
|
|
foreach my $k ( keys %h ) { |
65
|
|
|
|
|
|
|
my $user= $h{$k}; |
66
|
|
|
|
|
|
|
if ( !( $user =~ /\@/ )) { |
67
|
|
|
|
|
|
|
$user =~ s/\x00//g; |
68
|
|
|
|
|
|
|
$k =~ s/\x00//g; |
69
|
|
|
|
|
|
|
$table->{ lc $k } = $user; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
$self->{'table'} = $table; |
73
|
|
|
|
|
|
|
return $table; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub check_table { |
77
|
|
|
|
|
|
|
my ( $self ) = @_; |
78
|
|
|
|
|
|
|
my $file = $self->{'file'}; |
79
|
|
|
|
|
|
|
return if not $file; |
80
|
|
|
|
|
|
|
my $new_table_stamp = ( stat( $file ) )[9]; |
81
|
|
|
|
|
|
|
if ( $new_table_stamp != $self->{'table_stamp'} ) { |
82
|
|
|
|
|
|
|
delete $self->{'table'}; |
83
|
|
|
|
|
|
|
my $null = $self->get_table(); |
84
|
|
|
|
|
|
|
return 1; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
return 0; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |