line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Authen::Simple::DBM; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
6158
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
173
|
|
4
|
2
|
|
|
2
|
|
15
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
76
|
|
5
|
2
|
|
|
2
|
|
22
|
use base 'Authen::Simple::Adapter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2018
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
90046
|
use Carp qw[]; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
36
|
|
8
|
2
|
|
|
2
|
|
15
|
use Fcntl qw[]; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
33
|
|
9
|
2
|
|
|
2
|
|
14
|
use Params::Validate qw[]; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1764
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.2; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->options({ |
14
|
|
|
|
|
|
|
path => { |
15
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
16
|
|
|
|
|
|
|
optional => 0 |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
type => { |
19
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
20
|
|
|
|
|
|
|
default => 'SDBM', |
21
|
|
|
|
|
|
|
optional => 1, |
22
|
|
|
|
|
|
|
callbacks => { |
23
|
|
|
|
|
|
|
'is either DB, GDBM, NDBM or SDBM' => sub { |
24
|
|
|
|
|
|
|
$_[0] =~ qr/^CDB|DB|GDBM|NDBM|SDBM$/; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
}); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub init { |
31
|
1
|
|
|
1
|
1
|
1350
|
my ( $self, $params ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
2
|
my $type = $params->{type}; |
34
|
1
|
|
|
|
|
2
|
my $path = $params->{path}; |
35
|
1
|
|
|
|
|
4
|
my $class = sprintf( '%s_File', $type ); |
36
|
|
|
|
|
|
|
|
37
|
1
|
50
|
33
|
|
|
37
|
unless ( -e $path || -e "$path.db" || -e "$path.pag" ) { |
|
|
|
33
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
Carp::croak( qq/Database path '$path' does not exist./ ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
50
|
|
|
|
3
|
unless ( -f _ ) { |
42
|
0
|
|
|
|
|
0
|
Carp::croak( qq/Database path '$path' is not a file./ ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
|
|
6
|
unless ( -r _ ) { |
46
|
0
|
|
|
|
|
0
|
Carp::croak( qq/Database path '$path' is not readable by effective uid '$>'./ ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
1
|
50
|
|
|
|
58
|
unless ( eval "require $class;" ) { |
50
|
0
|
|
|
|
|
0
|
Carp::croak( qq/Failed to load class '$class' for DBM type '$type'. Reason: '$@'/ ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
50
|
|
|
|
4
|
my $dbm = $self->_open_dbm( $type, $path ) |
54
|
|
|
|
|
|
|
or Carp::croak( qq/Failed to open database '$path'. Reason: '$!'/ ); |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
7
|
return $self->SUPER::init($params); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _open_dbm { |
60
|
13
|
|
|
13
|
|
17
|
my $self = shift; |
61
|
13
|
|
66
|
|
|
52
|
my $type = shift || $self->type; |
62
|
13
|
|
66
|
|
|
94
|
my $path = shift || $self->path; |
63
|
|
|
|
|
|
|
|
64
|
13
|
50
|
|
|
|
85
|
my $flags = $type eq 'GDBM' ? &GDBM_File::GDBM_READER : &Fcntl::O_RDONLY; |
65
|
13
|
|
|
|
|
34
|
my $class = sprintf( '%s_File', $type ); |
66
|
13
|
|
|
|
|
24
|
my @args = ( $path ); |
67
|
|
|
|
|
|
|
|
68
|
13
|
50
|
|
|
|
25
|
unless ( $type eq 'CDB' ) { |
69
|
13
|
|
|
|
|
22
|
push( @args, $flags, 0644 ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
13
|
|
|
|
|
572
|
return $class->TIEHASH(@args); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub check { |
76
|
12
|
|
|
12
|
1
|
5688
|
my ( $self, $username, $password ) = @_; |
77
|
|
|
|
|
|
|
|
78
|
12
|
|
|
|
|
28
|
my ( $path, $dbm, $encrypted ) = ( $self->path, undef, undef ); |
79
|
|
|
|
|
|
|
|
80
|
12
|
50
|
|
|
|
59
|
unless ( $dbm = $self->_open_dbm ) { |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
0
|
$self->log->error( qq/Failed to open database '$path'. Reason: '$!'/ ) |
83
|
|
|
|
|
|
|
if $self->log; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
return 0; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
12
|
100
|
100
|
|
|
159
|
unless ( defined( $encrypted = $dbm->FETCH( $username ) ) |
89
|
|
|
|
|
|
|
|| defined( $encrypted = $dbm->FETCH( $username . "\0" ) ) ) { |
90
|
|
|
|
|
|
|
|
91
|
1
|
50
|
|
|
|
3
|
$self->log->debug( qq/User '$username' was not found in database '$path'./ ) |
92
|
|
|
|
|
|
|
if $self->log; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
41
|
return 0; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
11
|
100
|
|
|
|
34
|
chop($encrypted) if substr( $encrypted, -1 ) eq "\0"; |
98
|
|
|
|
|
|
|
|
99
|
11
|
|
|
|
|
30
|
$encrypted = ( split( ':', $encrypted, 3 ) )[0]; |
100
|
|
|
|
|
|
|
|
101
|
11
|
100
|
100
|
|
|
48
|
unless ( defined $encrypted && length $encrypted ) { |
102
|
|
|
|
|
|
|
|
103
|
2
|
50
|
|
|
|
7
|
$self->log->debug( qq/Encrypted password for user '$username' is null./ ) |
104
|
|
|
|
|
|
|
if $self->log; |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
68
|
return 0; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
9
|
50
|
|
|
|
35
|
unless ( $self->check_password( $password, $encrypted ) ) { |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
0
|
$self->log->debug( qq/Failed to authenticate user '$username'. Reason: 'Invalid credentials'/ ) |
112
|
|
|
|
|
|
|
if $self->log; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
0
|
return 0; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
9
|
50
|
|
|
|
1455
|
$self->log->debug( qq/Successfully authenticated user '$username'./ ) |
118
|
|
|
|
|
|
|
if $self->log; |
119
|
|
|
|
|
|
|
|
120
|
9
|
|
|
|
|
274
|
return 1; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |