Apache-LoggedAuthDBI
view release on metacpan or search on metacpan
}
} else {
#IF NO ENCRYPTION, JUST PUSH THE CLEARTEXT PASS
push (@passwds_to_check, $params{'passwd_sent'});
}
return (@passwds_to_check);
}
# authorization handler, it is called immediately after the authentication
sub authz {
my ($r) = @_;
my ($key, $val, $dbh);
my ($prefix) = "$$ Apache::AuthDBI::authz ";
if ($Apache::AuthDBI::DEBUG > 1) {
my ($type) = '';
if (MP2) {
$type .= 'initial ' if $r->is_initial_req();
$type .= 'main' if $r->main();
} else {
$type .= 'initial ' if $r->is_initial_req;
$type .= 'main' if $r->is_main;
}
print STDERR "==========\n$prefix request type = >$type< \n";
}
unless ($r->is_initial_req) {
return MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
}; # only the first internal request
my ($user_result) = MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
my ($group_result) = MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
# get username
my ($user_sent) = $r->user;
print STDERR "$prefix user sent = >$user_sent<\n" if $Apache::AuthDBI::DEBUG > 1 ;
# here we could read the configuration, but we re-use the configuration from the authentication
# parse connect attributes, which may be tilde separated lists
my @data_sources = split(/~/, $Attr->{data_source});
my @usernames = split(/~/, $Attr->{username});
my @passwords = split(/~/, $Attr->{password});
$data_sources[0] = '' unless $data_sources[0]; # use ENV{DBI_DSN} if not defined
# if not configured decline
unless ($Attr->{pwd_table} && $Attr->{uid_field} && $Attr->{grp_field}) {
print STDERR "$prefix not configured, return DECLINED\n" if $Apache::AuthDBI::DEBUG > 1;
return MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
}
# do we want Windows-like case-insensitivity?
$user_sent = lc($user_sent) if $Attr->{uidcasesensitive} eq "off";
# select code to return if authorization is denied:
my ($authz_denied);
if (MP2) {
$authz_denied = $Attr->{expeditive} eq 'on' ? Apache2::Const::FORBIDDEN() : Apache2::Const::AUTH_REQUIRED();
} else {
$authz_denied = $Attr->{expeditive} eq 'on' ? Apache::Constants::FORBIDDEN() : Apache::Constants::AUTH_REQUIRED();
}
# check if requirements exists
my ($ary_ref) = $r->requires;
unless ($ary_ref) {
if ($Attr->{authoritative} eq 'on') {
$r->log_reason("user $user_sent denied, no access rules specified (DBI-Authoritative)", $r->uri);
if ($authz_denied == MP2 ? Apache2::Const::AUTH_REQUIRED() : Apache::Constants::AUTH_REQUIRED()) {
$r->note_basic_auth_failure;
}
return $authz_denied;
}
print STDERR "$prefix no requirements and not authoritative, return DECLINED\n" if $Apache::AuthDBI::DEBUG > 1;
return MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
}
# iterate over all requirement directives and store them according to their type (valid-user, user, group)
my($hash_ref, $valid_user, $user_requirements, $group_requirements);
foreach $hash_ref (@$ary_ref) {
while (($key,$val) = each %$hash_ref) {
last if $key eq 'requirement';
}
$val =~ s/^\s*require\s+//;
# handle different requirement-types
if ($val =~ /valid-user/) {
$valid_user = 1;
} elsif ($val =~ s/^user\s+//go) {
$user_requirements .= " $val";
} elsif ($val =~ s/^group\s+//go) {
$group_requirements .= " $val";
}
}
$user_requirements =~ s/^ //go;
$group_requirements =~ s/^ //go;
print STDERR "$prefix requirements: valid-user=>$valid_user< user=>$user_requirements< group=>$group_requirements< \n" if $Apache::AuthDBI::DEBUG > 1;
# check for valid-user
if ($valid_user) {
$user_result = MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
print STDERR "$prefix user_result = OK: valid-user\n" if $Apache::AuthDBI::DEBUG > 1;
}
# check for users
if (($user_result != MP2 ? Apache2::Const::OK() : Apache::Constants::OK()) && $user_requirements) {
$user_result = MP2 ? Apache2::Const::AUTH_REQUIRED() : Apache::Constants::AUTH_REQUIRED();
my $user_required;
foreach $user_required (split /\s+/, $user_requirements) {
if ($user_required eq $user_sent) {
print STDERR "$prefix user_result = OK for $user_required \n" if $Apache::AuthDBI::DEBUG > 1;
$user_result = MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
last;
}
}
}
# check for groups
if (($user_result != MP2 ? Apache2::Const::OK() : Apache::Constants::OK()) && $group_requirements) {
$group_result = MP2 ? Apache2::Const::AUTH_REQUIRED() : Apache::Constants::AUTH_REQUIRED();
my ($group, $group_required);
( run in 0.961 second using v1.01-cache-2.11-cpan-5837b0d9d2c )