Authen-Simple-Passwd-0.6/ 0040755 0000765 0000765 00000000000 10362440520 015123 5 ustar chansen chansen Authen-Simple-Passwd-0.6/Build.PL 0100644 0000765 0000765 00000000536 10362440520 016420 0 ustar chansen chansen use strict;
use Module::Build;
my $build = Module::Build->new(
license => 'perl',
module_name => 'Authen::Simple::Passwd',
requires => {
'Authen::Simple' => 0.3,
'IO::File' => 0
},
create_makefile_pl => 'traditional',
create_readme => 1
);
$build->create_build_script;
Authen-Simple-Passwd-0.6/Changes 0100644 0000765 0000765 00000001053 10362440520 016412 0 ustar chansen chansen Revision history for Perl extension Authen::Simple::Passwd
0.6 2006-01-15 00:00
- Verify passwd path at construction time.
- Deprecated passwd option in favor for path.
0.5 2006-01-13 00:00
- Removed allow option
- Use Authen::Simple::Password for password verification
0.4 2006-01-12 00:00
- Fixed MANIFEST
0.3 2006-01-12 00:00
- POD fixes. No functional changes.
0.2 2006-01-04 00:00
- Fixed parameters spec.
- Flock defaults to d_flock in Config.pm
- Added basic tests
0.1 2006-01-03 00:00
- First release
Authen-Simple-Passwd-0.6/lib/ 0040755 0000765 0000765 00000000000 10362440520 015671 5 ustar chansen chansen Authen-Simple-Passwd-0.6/lib/Authen/ 0040755 0000765 0000765 00000000000 10362440520 017115 5 ustar chansen chansen Authen-Simple-Passwd-0.6/lib/Authen/Simple/ 0040755 0000765 0000765 00000000000 10362440520 020346 5 ustar chansen chansen Authen-Simple-Passwd-0.6/lib/Authen/Simple/Passwd.pm 0100644 0000765 0000765 00000011713 10362440520 022145 0 ustar chansen chansen package Authen::Simple::Passwd;
use strict;
use warnings;
use bytes;
use base 'Authen::Simple::Adapter';
use Carp qw[];
use Config qw[];
use Fcntl qw[LOCK_SH];
use IO::File qw[O_RDONLY];
use Params::Validate qw[];
our $VERSION = 0.6;
__PACKAGE__->options({
path => {
type => Params::Validate::SCALAR,
optional => 1
},
flock => {
type => Params::Validate::SCALAR,
default => ( $Config::Config{d_flock} ) ? 1 : 0,
optional => 1
},
passwd => { # deprecated
type => Params::Validate::SCALAR,
optional => 1
},
allow => { # deprecated
type => Params::Validate::ARRAYREF,
optional => 1,
}
});
sub init {
my ( $self, $params ) = @_;
my $path = $params->{path} ||= delete $params->{passwd};
unless ( -e $path ) {
Carp::croak( qq/Passwd path '$path' does not exist./ );
}
unless ( -f _ ) {
Carp::croak( qq/Passwd path '$path' is not a file./ );
}
unless ( -r _ ) {
Carp::croak( qq/Passwd path '$path' is not readable by effective uid '$>'./ );
}
return $self->SUPER::init($params);
}
sub check {
my ( $self, $username, $password ) = @_;
if ( $username =~ /^-/ ) {
$self->log->debug( qq/User '$username' begins with a hyphen which is not allowed./ )
if $self->log;
return 0;
}
my ( $path, $fh, $encrypted ) = ( $self->path, undef, undef );
unless ( $fh = IO::File->new( $path, O_RDONLY ) ) {
$self->log->error( qq/Failed to open passwd '$path'. Reason: '$!'/ )
if $self->log;
return 0;
}
unless ( !$self->flock || flock( $fh, LOCK_SH ) ) {
$self->log->error( qq/Failed to obtain a shared lock on passwd '$path'. Reason: '$!'/ )
if $self->log;
return 0;
}
while ( defined( $_ = $fh->getline ) ) {
next if /^#/;
next if /^\s+/;
chop;
my (@credentials) = split( /:/, $_, 3 );
if ( $credentials[0] eq $username ) {
$encrypted = $credentials[1];
$self->log->debug( qq/Found user '$username' in passwd '$path'./ )
if $self->log;
last;
}
}
unless ( $fh->close ) {
$self->log->warn( qq/Failed to close passwd '$path'. Reason: '$!'/ )
if $self->log;
}
unless ( defined $encrypted ) {
$self->log->debug( qq/User '$username' was not found in passwd '$path'./ )
if $self->log;
return 0;
}
unless ( length $encrypted ) {
$self->log->debug( qq/Encrypted password for user '$username' is null./ )
if $self->log;
return 0;
}
unless ( $self->check_password( $password, $encrypted ) ) {
$self->log->debug( qq/Failed to authenticate user '$username'. Reason: 'Invalid credentials'/ )
if $self->log;
return 0;
}
$self->log->debug( qq/Successfully authenticated user '$username'./ )
if $self->log;
return 1;
}
1;
__END__
=head1 NAME
Authen::Simple::Passwd - Simple Passwd authentication
=head1 SYNOPSIS
use Authen::Simple::Passwd;
my $passwd = Authen::Simple::Passwd->new(
path => '/etc/passwd'
);
if ( $passwd->authenticate( $username, $password ) ) {
# successfull authentication
}
# or as a mod_perl Authen handler
PerlModule Authen::Simple::Apache
PerlModule Authen::Simple::Passwd
PerlSetVar AuthenSimplePasswd_path "/etc/passwd"
PerlAuthenHandler Authen::Simple::Passwd
AuthType Basic
AuthName "Protected Area"
Require valid-user
=head1 DESCRIPTION
Authenticate against a passwd file.
=head1 METHODS
=over 4
=item * new
This method takes a hash of parameters. The following options are valid:
=over 8
=item * path
Path to passwd file to authenticate against. Any standard passwd file that
has records seperated with newline and fields seperated by C<:> is supported.
First field is expected to be username and second field, plain or encrypted
password. Required.
path => '/etc/passwd'
path => '/var/www/.htpasswd'
=item * flock
A boolean to enable or disable the usage of C. Defaults to C in L.
flock => 0
=item * log
Any object that supports C, C, C and C.
log => Log::Log4perl->get_logger('Authen::Simple::Passwd')
=back
=item * authenticate( $username, $password )
Returns true on success and false on failure. Authentication attempts with a username that begins with a
hyphen C<-> will always return false.
=back
=head1 SEE ALSO
L.
L.
L.
=head1 AUTHOR
Christian Hansen C
=head1 COPYRIGHT
This program is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
Authen-Simple-Passwd-0.6/Makefile.PL 0100644 0000765 0000765 00000000701 10362440520 017070 0 ustar chansen chansen # Note: this file was auto-generated by Module::Build::Compat version 0.03
use ExtUtils::MakeMaker;
WriteMakefile
(
'NAME' => 'Authen::Simple::Passwd',
'VERSION_FROM' => 'lib/Authen/Simple/Passwd.pm',
'PREREQ_PM' => {
'Authen::Simple' => '0.3',
'IO::File' => '0'
},
'INSTALLDIRS' => 'site',
'PL_FILES' => {}
)
;
Authen-Simple-Passwd-0.6/MANIFEST 0100644 0000765 0000765 00000000246 10362440520 016253 0 ustar chansen chansen Build.PL
Changes
lib/Authen/Simple/Passwd.pm
Makefile.PL
MANIFEST This list of files
README
t/01use.t
t/02pod.t
t/03podcoverage.t
t/04basic.t
t/etc/passwd
META.yml
Authen-Simple-Passwd-0.6/META.yml 0100644 0000765 0000765 00000000506 10362440520 016372 0 ustar chansen chansen ---
name: Authen-Simple-Passwd
version: 0.6
author:
- 'Christian Hansen C'
abstract: Simple Passwd authentication
license: perl
requires:
Authen::Simple: 0.3
IO::File: 0
provides:
Authen::Simple::Passwd:
file: lib/Authen/Simple/Passwd.pm
version: 0.6
generated_by: Module::Build version 0.2611
Authen-Simple-Passwd-0.6/README 0100644 0000765 0000765 00000004113 10362440520 015777 0 ustar chansen chansen NAME
Authen::Simple::Passwd - Simple Passwd authentication
SYNOPSIS
use Authen::Simple::Passwd;
my $passwd = Authen::Simple::Passwd->new(
path => '/etc/passwd'
);
if ( $passwd->authenticate( $username, $password ) ) {
# successfull authentication
}
# or as a mod_perl Authen handler
PerlModule Authen::Simple::Apache
PerlModule Authen::Simple::Passwd
PerlSetVar AuthenSimplePasswd_path "/etc/passwd"
PerlAuthenHandler Authen::Simple::Passwd
AuthType Basic
AuthName "Protected Area"
Require valid-user
DESCRIPTION
Authenticate against a passwd file.
METHODS
* new
This method takes a hash of parameters. The following options are
valid:
* path Path to passwd file to authenticate against. Any standard
passwd file that has records seperated with newline and
fields seperated by ":" is supported. First field is
expected to be username and second field, plain or encrypted
password. Required.
path => '/etc/passwd'
path => '/var/www/.htpasswd'
* flock A boolean to enable or disable the usage of "flock()".
Defaults to "d_flock" in Config.
flock => 0
* log Any object that supports "debug", "info", "error" and
"warn".
log => Log::Log4perl->get_logger('Authen::Simple::Passwd')
* authenticate( $username, $password )
Returns true on success and false on failure. Authentication
attempts with a username that begins with a hyphen "-" will always
return false.
SEE ALSO
Authen::Simple.
Authen::Simple::Password.
passwd(5).
AUTHOR
Christian Hansen "ch@ngmedia.com"
COPYRIGHT
This program is free software, you can redistribute it and/or modify it
under the same terms as Perl itself.
Authen-Simple-Passwd-0.6/t/ 0040755 0000765 0000765 00000000000 10362440520 015366 5 ustar chansen chansen Authen-Simple-Passwd-0.6/t/01use.t 0100644 0000765 0000765 00000000076 10362440520 016510 0 ustar chansen chansen use Test::More tests => 1;
use_ok('Authen::Simple::Passwd');
Authen-Simple-Passwd-0.6/t/02pod.t 0100644 0000765 0000765 00000000276 10362440520 016501 0 ustar chansen chansen use Test::More;
eval "use Test::Pod 1.14";
plan skip_all => 'Test::Pod 1.14 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_files_ok();
Authen-Simple-Passwd-0.6/t/03podcoverage.t 0100644 0000765 0000765 00000000372 10362440520 020213 0 ustar chansen chansen use Test::More;
eval "use Test::Pod::Coverage 1.04";
plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_coverage_ok( { trustme => [ qr/^check|init$/ ] } );
Authen-Simple-Passwd-0.6/t/04basic.t 0100644 0000765 0000765 00000001313 10362440520 016773 0 ustar chansen chansen use Test::More tests => 8;
use_ok('Authen::Simple::Passwd');
ok( my $passwd = Authen::Simple::Passwd->new( path => 't/etc/passwd' ) );
ok( $passwd->authenticate( 'apr1', 'apr1' ), 'Successfully authenticated using $apr1' );
ok( $passwd->authenticate( 'crypt', 'crypt' ), 'Successfully authenticated using crypt() with Traditional DES' );
ok( $passwd->authenticate( 'md5', 'md5' ), 'Successfully authenticated using $1$' );
ok( $passwd->authenticate( 'plain', 'plain' ), 'Successfully authenticated using plain' );
ok( $passwd->authenticate( 'sha', 'sha' ), 'Successfully authenticated using {SHA}' );
ok( ! $passwd->authenticate( '-', '-' ), 'Usernames with hyphens is not allowed' );
Authen-Simple-Passwd-0.6/t/etc/ 0040755 0000765 0000765 00000000000 10362440520 016141 5 ustar chansen chansen Authen-Simple-Passwd-0.6/t/etc/passwd 0100644 0000765 0000765 00000000235 10362440520 017362 0 ustar chansen chansen crypt:lk9Mh5KHGjAaM
apr1:$apr1$0yFRBeLR$an6fzRWvbu9jUAo/iHz4Z/
md5:$1$NRe32ijZ$THIS7aDH.e093oDOGD10M/
sha:{SHA}2PRZAyDhNDqRW2OUFwZQqPNdaSY=
plain:plain
-:-