line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- |
2
|
|
|
|
|
|
|
# vim:ts=8:sw=2:et:sta:sts=2 |
3
|
|
|
|
|
|
|
######### |
4
|
|
|
|
|
|
|
# Author: rmp |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package ClearPress::authenticator::ldap; |
7
|
1
|
|
|
1
|
|
1038
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
9
|
1
|
|
|
1
|
|
8
|
use base qw(ClearPress::authenticator); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
491
|
|
10
|
1
|
|
|
1
|
|
515
|
use Readonly; |
|
1
|
|
|
|
|
5072
|
|
|
1
|
|
|
|
|
100
|
|
11
|
1
|
|
|
1
|
|
15
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
80
|
|
12
|
1
|
|
|
1
|
|
461
|
use Net::LDAP; |
|
1
|
|
|
|
|
456
|
|
|
1
|
|
|
|
|
515
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = q[477.1.4]; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly::Scalar our $DEFAULT_SERVER => 'ldaps://ldap.local:636'; |
17
|
|
|
|
|
|
|
Readonly::Scalar our $DEFAULT_AD_DOMAIN => 'WORKGROUP'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub server { |
20
|
8
|
|
|
8
|
1
|
38
|
my ($self, $srv) = @_; |
21
|
8
|
100
|
|
|
|
25
|
if($srv) { |
22
|
1
|
|
|
|
|
16
|
$self->{server} = $srv; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
8
|
100
|
|
|
|
32
|
if($self->{server}) { |
26
|
2
|
|
|
|
|
31
|
return $self->{server}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
6
|
|
|
|
|
247
|
return $DEFAULT_SERVER; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub ad_domain { |
33
|
5
|
|
|
5
|
1
|
30
|
my ($self, $domain) = @_; |
34
|
5
|
100
|
|
|
|
19
|
if($domain) { |
35
|
1
|
|
|
|
|
5
|
$self->{ad_domain} = $domain; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
5
|
100
|
|
|
|
19
|
if($self->{ad_domain}) { |
39
|
2
|
|
|
|
|
12
|
return $self->{ad_domain}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
13
|
return $DEFAULT_AD_DOMAIN; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _ldap { |
46
|
5
|
|
|
5
|
|
855
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
5
|
100
|
|
|
|
17
|
if(!$self->{_ldap}) { |
49
|
4
|
|
|
|
|
15
|
$self->{_ldap} = Net::LDAP->new($self->server); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
|
|
66
|
return $self->{_ldap}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub authen_credentials { |
56
|
6
|
|
|
6
|
1
|
277
|
my ($self, $ref) = @_; |
57
|
|
|
|
|
|
|
|
58
|
6
|
100
|
100
|
|
|
46
|
if(!$ref || |
|
|
|
100
|
|
|
|
|
59
|
|
|
|
|
|
|
!$ref->{username} || |
60
|
|
|
|
|
|
|
!$ref->{password} ) { |
61
|
3
|
|
|
|
|
18
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
3
|
|
|
|
|
10
|
my $ldap = $self->_ldap; |
65
|
3
|
100
|
|
|
|
11
|
if(!$ldap) { |
66
|
1
|
|
|
|
|
4
|
croak qq[Failed to connect to @{[$self->server()]}. Is it available?]; |
|
1
|
|
|
|
|
4
|
|
67
|
|
|
|
|
|
|
} |
68
|
2
|
|
|
|
|
9
|
my $ad_domain = $self->ad_domain; |
69
|
2
|
|
|
|
|
12
|
my $fq_username = sprintf q[%s\%s], $ad_domain, $ref->{username}; |
70
|
|
|
|
|
|
|
my $auth_msg = $ldap->bind( |
71
|
|
|
|
|
|
|
$fq_username, |
72
|
|
|
|
|
|
|
'password' => $ref->{password}, |
73
|
2
|
|
|
|
|
10
|
); |
74
|
2
|
100
|
|
|
|
64
|
if($auth_msg->code) { |
75
|
1
|
|
|
|
|
7
|
carp $auth_msg->error; |
76
|
1
|
|
|
|
|
245
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
16
|
return $ref; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |