line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PlugAuth::Plugin::LDAP; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: LDAP back end for PlugAuth |
4
|
|
|
|
|
|
|
our $VERSION = '0.07'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
72950
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
54
|
|
8
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
9
|
2
|
|
|
2
|
|
27
|
use v5.10; |
|
2
|
|
|
|
|
6
|
|
10
|
2
|
|
|
2
|
|
905
|
use Net::LDAP; |
|
2
|
|
|
|
|
294142
|
|
|
2
|
|
|
|
|
44
|
|
11
|
2
|
|
|
2
|
|
1488
|
use Log::Log4perl qw/:easy/; |
|
2
|
|
|
|
|
53485
|
|
|
2
|
|
|
|
|
14
|
|
12
|
2
|
|
|
2
|
|
2257
|
use Role::Tiny::With; |
|
2
|
|
|
|
|
5114
|
|
|
2
|
|
|
|
|
614
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'PlugAuth::Role::Plugin'; |
15
|
|
|
|
|
|
|
with 'PlugAuth::Role::Auth'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub check_credentials { |
19
|
3
|
|
|
3
|
1
|
246652
|
my ($class, $user,$pw) = @_; |
20
|
3
|
|
|
|
|
9
|
$user = lc $user; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
14
|
my $ldap_config = $class->global_config->ldap(default => ''); |
23
|
|
|
|
|
|
|
|
24
|
3
|
50
|
33
|
|
|
70
|
if (!$ldap_config or !$ldap_config->{authoritative}) { |
25
|
|
|
|
|
|
|
# Check files first. |
26
|
0
|
0
|
|
|
|
0
|
return 1 if $class->deligate_check_credentials($user, $pw); |
27
|
|
|
|
|
|
|
} |
28
|
3
|
50
|
|
|
|
12
|
return 0 unless $ldap_config; |
29
|
3
|
50
|
|
|
|
11
|
my $server = $ldap_config->{server} or LOGDIE "Missing ldap server"; |
30
|
3
|
50
|
|
|
|
54
|
my $ldap = Net::LDAP->new($server, timeout => 5) or do { |
31
|
0
|
|
|
|
|
0
|
ERROR "Could not connect to ldap server $server: $@"; |
32
|
0
|
|
|
|
|
0
|
return 0; |
33
|
|
|
|
|
|
|
}; |
34
|
3
|
|
|
|
|
20
|
my $orig = $user; |
35
|
3
|
|
|
|
|
12
|
my $extra = $user =~ tr/a-zA-Z0-9@._-//dc; |
36
|
3
|
50
|
|
|
|
9
|
WARN "Invalid username '$orig', turned into $user" if $extra; |
37
|
3
|
|
|
|
|
14
|
my $dn = sprintf($ldap_config->{dn},$user); |
38
|
3
|
|
|
|
|
14
|
my $mesg = $ldap->bind($dn, password => $pw); |
39
|
3
|
100
|
|
|
|
68
|
$mesg->code or return 1; |
40
|
2
|
|
|
|
|
18
|
INFO "Ldap returned ".$mesg->code." : ".$mesg->error; |
41
|
2
|
|
|
|
|
1349
|
return 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |