Apache-AuthenPasswd
view release on metacpan or search on metacpan
AuthenPasswd.pm view on Meta::CPAN
package Apache::AuthenPasswd;
use strict;
use mod_perl;
$Apache::AuthenPasswd::VERSION = '0.12';
# setting the constants to help identify which version of mod_perl
# is installed
use constant MP2 => ($mod_perl::VERSION >= 1.99);
# test for the version of mod_perl, and use the appropriate libraries
BEGIN {
if (MP2) {
require Apache::Const;
require Apache::Access;
require Apache::Connection;
require Apache::Log;
require Apache::RequestRec;
require Apache::RequestUtil;
Apache::Const->import(-compile => 'HTTP_UNAUTHORIZED','OK');
} else {
require Apache::Constants;
Apache::Constants->import('HTTP_UNAUTHORIZED','OK');
}
}
sub handler {
my $r = shift;
my($res, $sent_pwd) = $r->get_basic_auth_pw;
return $res if $res; #decline if not Basic
my $name = MP2 ? $r->user : $r->connection->user;
if ($name eq "") {
$r->note_basic_auth_failure;
MP2 ? $r->log_error("Apache::AuthenPasswd - no username given", $r->uri) : $r->log_reason("Apache::AuthenPasswd - no username given", $r->uri);
return MP2 ? Apache::HTTP_UNAUTHORIZED : Apache::Constants::HTTP_UNAUTHORIZED;
}
my ($user, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwnam $name;
unless ($user) {
$r->note_basic_auth_failure;
MP2 ? $r->log_error("Apache::AuthenPasswd - user $name: unknown", $r->uri) : $r->log_reason("Apache::AuthenPasswd - user $name: unknown", $r->uri);
return MP2 ? Apache::HTTP_UNAUTHORIZED : Apache::Constants::HTTP_UNAUTHORIZED;
}
if(crypt($sent_pwd, $passwd) eq $passwd) {
return MP2 ? Apache::OK : Apache::Constants::OK;
} else {
$r->note_basic_auth_failure;
MP2 ? $r->log_error("Apache::AuthenPasswd - user $name: bad password", $r->uri) : $r->log_reason("Apache::AuthenPasswd - user $name: bad password", $r->uri);
return MP2 ? Apache::HTTP_UNAUTHORIZED : Apache::Constants::HTTP_UNAUTHORIZED;
}
return MP2 ? Apache::OK : Apache::Constants::OK;
}
1;
__END__
=head1 NAME
Apache::AuthenPasswd - mod_perl /etc/passwd Authentication module
=head1 SYNOPSIS
<Directory /foo/bar>
# This is the standard authentication stuff
AuthName "Foo Bar Authentication"
AuthType Basic
PerlAuthenHandler Apache::AuthenPasswd
# Standard require stuff, /etc/passwd users or /etc/group groups, and
# "valid-user" all work OK
require user username1 username2 ...
require group groupname1 groupname2 ... # [Need Apache::AuthzPasswd]
require valid-user
# The following is actually only needed when authorizing
# against /etc/group. This is a separate module.
PerlAuthzHandler Apache::AuthzPasswd
</Directory>
These directives can also be used in the <Location> directive or in
an .htaccess file.
= head1 DESCRIPTION
**************** NOTICE *********************
Please, please, realize that this module will
only work with passwords that are stored in
/etc/passwd. Most systems use shadow
passwords now, and the call that this module
uses to access the password ONLY checks for
the password in the /etc/passwd file. Also,
the call that is needed to access passwords
( run in 1.495 second using v1.01-cache-2.11-cpan-ceb78f64989 )