line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Apache::AuthenMSAD; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30192
|
use mod_perl; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Apache::Access::Headers; |
5
|
|
|
|
|
|
|
use Apache::Log ; |
6
|
|
|
|
|
|
|
use Apache::Request; |
7
|
|
|
|
|
|
|
use Apache::Constants qw(HTTP_UNAUTHORIZED HTTP_INTERNAL_SERVER_ERROR DECLINED HTTP_FORBIDDEN OK) ; |
8
|
|
|
|
|
|
|
use Net::LDAP; |
9
|
|
|
|
|
|
|
use strict; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$Apache::AuthenMSAD::VERSION = '0.02'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# $Id: AuthenMSAD.pm,v 1.7 2005/11/29 13:46:04 reggers Exp $ |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub handler |
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
my $r = shift; |
18
|
|
|
|
|
|
|
# Continue only if the first request. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# return OK unless $r->is_initial_req; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Grab the password, or return in HTTP_UNAUTHORIZED |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my ($res, $pass) = $r->get_basic_auth_pw; |
25
|
|
|
|
|
|
|
return $res if $res; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $user = $r->user; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $domain = $r->dir_config('MSADDomain') || "no-domain"; |
30
|
|
|
|
|
|
|
my $server = $r->dir_config('MSADServer') || $domain; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if ($pass eq "") { |
33
|
|
|
|
|
|
|
$r->note_basic_auth_failure; |
34
|
|
|
|
|
|
|
$r->log_reason("user - no password supplied",$r->uri); |
35
|
|
|
|
|
|
|
return Apache::Constants::HTTP_UNAUTHORIZED; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ($user eq "") { |
39
|
|
|
|
|
|
|
$r->note_basic_auth_failure; |
40
|
|
|
|
|
|
|
$r->log_reason("user - no userid supplied",$r->uri); |
41
|
|
|
|
|
|
|
return Apache::Constants::HTTP_UNAUTHORIZED; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $ldap = Net::LDAP->new($server, version=>3); |
45
|
|
|
|
|
|
|
unless ($ldap) { |
46
|
|
|
|
|
|
|
$r->note_basic_auth_failure; |
47
|
|
|
|
|
|
|
$r->log_reason("user - MSAD LDAP Connect Failed",$r->uri); |
48
|
|
|
|
|
|
|
return Apache::Constants::HTTP_UNAUTHORIZED; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $result= $ldap->bind (dn => "$user\@$domain", password => $pass); |
52
|
|
|
|
|
|
|
if (!$result || ($result && $result->code)) { |
53
|
|
|
|
|
|
|
$r->note_basic_auth_failure; |
54
|
|
|
|
|
|
|
$r->log_reason("user - Active Directory Authen Failed",$r->uri); |
55
|
|
|
|
|
|
|
return Apache::Constants::HTTP_UNAUTHORIZED; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return Apache::Constants::OK; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |