SRS/DB.pm

filter: Statementstmt 56.0% 28 / 50 Branchbran 16.6% 2 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 100% 3 / 3 totaltotal 54.6% 41 / 75 CC 7 SCAR 23.6
CC
7
Cov
48%
parse
30.0
new
3.4
compile
2.0
CRAP 10.6
« SRS/Daemon.pm ↑ Summary SRS.pm »
1 package Mail::SRS::DB;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use MLDBM qw(DB_File Storable);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Mail::SRS qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 @ISA = qw(Mail::SRS);
12  
13 =head1 NAME
14  
15 Mail::SRS::DB - A MLDBM based Sender Rewriting Scheme
16  
17 =head1 SYNOPSIS
18  
19 use Mail::SRS::DB;
20 my $srs = new Mail::SRS::DB(
21 Database => '/var/run/srs.db',
22 ...
23 );
24  
25 =head1 DESCRIPTION
26  
27 See Mail::SRS for details of the standard SRS subclass interface.
28 This module provides the methods compile() and parse().
29  
30 This module requires one extra parameter to the constructor, a filename
31 for a Berkeley DB_File database.
32  
33 =head1 BUGS
34  
35 This code relies on not getting collisions in the cryptographic
36 hash. This can and should be fixed.
37  
38 The database is not garbage collected.
39  
40 =head1 SEE ALSO
41  
42 L<Mail::SRS>
43  
44 =cut
45  
46 1 ▶sub new {
Subroutine new: called CC=3 SCAR=12.3
Pod documented
47 1 my $class = shift;
48 1 my $self = $class->SUPER::new(@_);
49 die "No database specified for Mail::SRS::DB"
50 1 ▶ unless $self->{Database};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Database"} 0 1 1
51 1 my %data;
52 my $dbm = tie %data, 'MLDBM',
53 1 ▶ $self->{Database}, O_CREAT|O_RDWR, 0640
Branch: 1 branch
BranchTrueFalseTotal
my $dbm = tie(%data, "MLDBM", $self->{"Database"}, 66, 416) or die qq[Cannot open $self->{"Database"}: $!] 0 1 1
54 or die "Cannot open $self->{Database}: $!";
55 0 $self->{Data} = \%data;
56 0 return $self;
57 }
58  
59 0 ▶sub compile {
Subroutine compile: not called CC=1 SCAR=6.9
Pod documented
60 0 my ($self, $sendhost, $senduser) = @_;
61  
62 0 my $time = time();
63  
64 0 my $data = {
65 Time => $time,
66 SendHost => $sendhost,
67 SendUser => $senduser,
68 };
69  
70 # We rely on not getting collisions in this hash.
71 0 my $hash = $self->hash_create($sendhost, $senduser);
72  
73 0 $self->{Data}->{$hash} = $data;
74  
75 # Note that there are 4 fields here and that sendhost may
76 # not contain a + sign. Therefore, we do not need to escape
77 # + signs anywhere in order to reverse this transformation.
78 0 return $SRS0TAG . $self->separator . $hash;
79 }
80  
81 0 ▶sub parse {
Subroutine parse: not called CC=5 SCAR=34.0
Pod documented
82 0 my ($self, $user) = @_;
83  
84 0 ▶ unless ($user =~ s/$SRS0RE//oi) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user =~ s/$Mail::SRS::DB::SRS0RE//io) 0 0 0
85 0 die "Reverse address does not match $SRS0RE.";
86 }
87  
88 0 my $hash = $user;
89 0 my $data;
90  
91 0 ▶ unless ($data = $self->{Data}->{$hash}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data = $self->{"Data"}{$hash}) 0 0 0
92 0 die "No data found";
93 }
94  
95 0 my $sendhost = $data->{SendHost};
96 0 my $senduser = $data->{SendUser};
97  
98 0 ▶ unless ($self->hash_verify($hash, $sendhost, $senduser)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->hash_verify($hash, $sendhost, $senduser)) 0 0 0
99 0 die "Invalid hash";
100 }
101  
102 0 ▶ unless ($self->time_check($data->{Time})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->time_check($data->{"Time"})) 0 0 0
103 0 die "Invalid timestamp";
104 }
105  
106 0 return ($sendhost, $senduser);
107 }
108  
109 2 1;
« SRS/Daemon.pm ↑ Summary SRS.pm »