line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Authen::Simple::NIS; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
836
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
37
|
|
5
|
1
|
|
|
1
|
|
16
|
use base 'Authen::Simple::Adapter'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
988
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
42511
|
use Net::NIS qw[YPERR_KEY YPERR_SUCCESS]; |
|
1
|
|
|
|
|
7639
|
|
|
1
|
|
|
|
|
106
|
|
8
|
1
|
|
|
1
|
|
1216
|
use Net::NIS::Table qw[]; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
21
|
|
9
|
1
|
|
|
1
|
|
6
|
use Params::Validate qw[]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
422
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.3; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->options({ |
14
|
|
|
|
|
|
|
domain => { |
15
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
16
|
|
|
|
|
|
|
optional => 1 |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
map => { |
19
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
20
|
|
|
|
|
|
|
default => 'passwd.byname', |
21
|
|
|
|
|
|
|
optional => 1 |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
}); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub check { |
26
|
0
|
|
|
0
|
1
|
|
my ( $self, $username, $password ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $domain = $self->domain; |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
0
|
|
|
|
unless ( $domain ||= Net::NIS::yp_get_default_domain() ) { |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
$self->log->error( qq/Failed to obtain default NIS domain./ ) |
33
|
|
|
|
|
|
|
if $self->log; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return 0; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $nis = Net::NIS::Table->new( $self->map, $domain ); |
39
|
0
|
|
|
|
|
|
my $entry = $nis->match($username); |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
unless ( $nis->status == YPERR_SUCCESS ) { |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $map = $self->map; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ( $nis->status == YPERR_KEY ) { |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
$self->log->debug( qq/User '$username' was not found in map '$map' from domain '$domain'./ ) |
48
|
|
|
|
|
|
|
if $self->log; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $error = Net::NIS::yperr_string( $nis->status ); |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
$self->log->error( qq/Failed to lookup key '$username' in map '$map' from domain '$domain'. Reason: '$error'/ ) |
55
|
|
|
|
|
|
|
if $self->log; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return 0; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $encrypted = ( split( /:/, $entry ) )[1]; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
unless ( $self->check_password( $password, $encrypted ) ) { |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
$self->log->debug( qq/Failed to authenticate user '$username'. Reason: 'Invalid credentials'/ ) |
66
|
|
|
|
|
|
|
if $self->log; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return 0; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
$self->log->debug( qq/Successfully authenticated user '$username' using domain '$domain'./ ) |
72
|
|
|
|
|
|
|
if $self->log; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |