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