Apache-AuthenLDAP
view release on metacpan or search on metacpan
AuthenLDAP.pm view on Meta::CPAN
# Connect to the server
my $ld;
unless ($ld = new Net::LDAP($ldapserver, port => $ldapport)) {
$r->note_basic_auth_failure;
$r->log_reason("user $name: LDAP Connection Failed", $r->uri);
return SERVER_ERROR;
}
# Bind anonymously
my $msg = $ld->bind;
unless ($msg->code == LDAP_SUCCESS) {
$r->note_basic_auth_failure;
$r->log_reason("user $name: LDAP Initial Bind Failed: " . $msg->code .
" " . $msg->error, $r->uri);
return SERVER_ERROR;
}
# Create the filter and search
my $filter = "($uidattrtype=$name)";
$r->log->debug("handler: Using filter: $filter");
AuthenLDAP.pm view on Meta::CPAN
$r->note_basic_auth_failure;
$r->log_reason("user $name: username not found",$r->uri);
return AUTH_REQUIRED;
}
# Only want the first if we've received more than one
my $entry = $msg->first_entry;
my $dn = $entry->dn;
# Bind as the user we're authenticating
$msg = $ld->bind($dn, password => $sent_pwd);
unless ($msg->code == LDAP_SUCCESS) {
$r->note_basic_auth_failure;
$r->log_reason("user $name: password mismatch", $r->uri);
return AUTH_REQUIRED;
}
$ld->unbind;
if ($expire eq 'true') {
# Is the password set to expired in LDAP?
if (($entry->get($exp_attrtype))[0] eq 'true') {
$r->log->debug("handler: password flag expired");
$r->custom_response(FORBIDDEN, "$exp_redirect");
return FORBIDDEN;
}
# Has the password passed the age limit?
( run in 2.355 seconds using v1.01-cache-2.11-cpan-2398b32b56e )