Authen-Simple-Passwd-0.6/0040755000076500007650000000000010362440520015123 5ustar chansenchansenAuthen-Simple-Passwd-0.6/Build.PL0100644000076500007650000000053610362440520016420 0ustar chansenchansenuse 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/Changes0100644000076500007650000000105310362440520016412 0ustar chansenchansenRevision 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/0040755000076500007650000000000010362440520015671 5ustar chansenchansenAuthen-Simple-Passwd-0.6/lib/Authen/0040755000076500007650000000000010362440520017115 5ustar chansenchansenAuthen-Simple-Passwd-0.6/lib/Authen/Simple/0040755000076500007650000000000010362440520020346 5ustar chansenchansenAuthen-Simple-Passwd-0.6/lib/Authen/Simple/Passwd.pm0100644000076500007650000001171310362440520022145 0ustar chansenchansenpackage 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.PL0100644000076500007650000000070110362440520017070 0ustar chansenchansen# 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/MANIFEST0100644000076500007650000000024610362440520016253 0ustar chansenchansenBuild.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.yml0100644000076500007650000000050610362440520016372 0ustar chansenchansen--- 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/README0100644000076500007650000000411310362440520015777 0ustar chansenchansenNAME 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/0040755000076500007650000000000010362440520015366 5ustar chansenchansenAuthen-Simple-Passwd-0.6/t/01use.t0100644000076500007650000000007610362440520016510 0ustar chansenchansenuse Test::More tests => 1; use_ok('Authen::Simple::Passwd'); Authen-Simple-Passwd-0.6/t/02pod.t0100644000076500007650000000027610362440520016501 0ustar chansenchansenuse 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.t0100644000076500007650000000037210362440520020213 0ustar chansenchansenuse 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.t0100644000076500007650000000131310362440520016773 0ustar chansenchansenuse 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/0040755000076500007650000000000010362440520016141 5ustar chansenchansenAuthen-Simple-Passwd-0.6/t/etc/passwd0100644000076500007650000000023510362440520017362 0ustar chansenchansencrypt:lk9Mh5KHGjAaM apr1:$apr1$0yFRBeLR$an6fzRWvbu9jUAo/iHz4Z/ md5:$1$NRe32ijZ$THIS7aDH.e093oDOGD10M/ sha:{SHA}2PRZAyDhNDqRW2OUFwZQqPNdaSY= plain:plain -:-