Authen-Simple-DBM-0.2/0040755000076500007650000000000010362477330014271 5ustar chansenchansenAuthen-Simple-DBM-0.2/Build.PL0100644000076500007650000000047410362477330015567 0ustar chansenchansenuse strict; use Module::Build; my $build = Module::Build->new( license => 'perl', module_name => 'Authen::Simple::DBM', requires => { 'Authen::Simple' => 0.3 }, create_makefile_pl => 'traditional', create_readme => 1 ); $build->create_build_script; Authen-Simple-DBM-0.2/Changes0100644000076500007650000000027710362477330015567 0ustar chansenchansenRevision history for Perl extension Authen::Simple::DBM 0.2 2006-01-15 00:00 - Use OO DBM interface instead of tie. - Added support for CDB 0.1 2006-01-15 00:00 - First release Authen-Simple-DBM-0.2/lib/0040755000076500007650000000000010362477330015037 5ustar chansenchansenAuthen-Simple-DBM-0.2/lib/Authen/0040755000076500007650000000000010362477330016263 5ustar chansenchansenAuthen-Simple-DBM-0.2/lib/Authen/Simple/0040755000076500007650000000000010362477330017514 5ustar chansenchansenAuthen-Simple-DBM-0.2/lib/Authen/Simple/DBM.pm0100644000076500007650000001206410362477330020454 0ustar chansenchansenpackage Authen::Simple::DBM; use strict; use warnings; use base 'Authen::Simple::Adapter'; use Carp qw[]; use Fcntl qw[]; use Params::Validate qw[]; our $VERSION = 0.2; __PACKAGE__->options({ path => { type => Params::Validate::SCALAR, optional => 0 }, type => { type => Params::Validate::SCALAR, default => 'SDBM', optional => 1, callbacks => { 'is either DB, GDBM, NDBM or SDBM' => sub { $_[0] =~ qr/^CDB|DB|GDBM|NDBM|SDBM$/; } } } }); sub init { my ( $self, $params ) = @_; my $type = $params->{type}; my $path = $params->{path}; my $class = sprintf( '%s_File', $type ); unless ( -e $path || -e "$path.db" || -e "$path.pag" ) { Carp::croak( qq/Database path '$path' does not exist./ ); } unless ( -f _ ) { Carp::croak( qq/Database path '$path' is not a file./ ); } unless ( -r _ ) { Carp::croak( qq/Database path '$path' is not readable by effective uid '$>'./ ); } unless ( eval "require $class;" ) { Carp::croak( qq/Failed to load class '$class' for DBM type '$type'. Reason: '$@'/ ); } my $dbm = $self->_open_dbm( $type, $path ) or Carp::croak( qq/Failed to open database '$path'. Reason: '$!'/ ); return $self->SUPER::init($params); } sub _open_dbm { my $self = shift; my $type = shift || $self->type; my $path = shift || $self->path; my $flags = $type eq 'GDBM' ? &GDBM_File::GDBM_READER : &Fcntl::O_RDONLY; my $class = sprintf( '%s_File', $type ); my @args = ( $path ); unless ( $type eq 'CDB' ) { push( @args, $flags, 0644 ); } return $class->TIEHASH(@args); } sub check { my ( $self, $username, $password ) = @_; my ( $path, $dbm, $encrypted ) = ( $self->path, undef, undef ); unless ( $dbm = $self->_open_dbm ) { $self->log->error( qq/Failed to open database '$path'. Reason: '$!'/ ) if $self->log; return 0; } unless ( defined( $encrypted = $dbm->FETCH( $username ) ) || defined( $encrypted = $dbm->FETCH( $username . "\0" ) ) ) { $self->log->debug( qq/User '$username' was not found in database '$path'./ ) if $self->log; return 0; } chop($encrypted) if substr( $encrypted, -1 ) eq "\0"; $encrypted = ( split( ':', $encrypted, 3 ) )[0]; unless ( defined $encrypted && 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::DBM - Simple DBM authentication =head1 SYNOPSIS use Authen::Simple::DBM; my $dbm = Authen::Simple::DBM->new( path => '/var/db/www/passwd' ); if ( $dbm->authenticate( $username, $password ) ) { # successfull authentication } # or as a mod_perl Authen handler PerlModule Authen::Simple::Apache PerlModule Authen::Simple::DBM PerlSetVar AuthenSimpleDBM_path "/var/db/www/passwd" PerlAuthenHandler Authen::Simple::DBM AuthType Basic AuthName "Protected Area" Require valid-user =head1 DESCRIPTION DBM authentication. =head1 METHODS =over 4 =item * new This method takes a hash of parameters. The following options are valid: =over 8 =item * path Path to DBM file. Usually specified without trailing C<.db>, C<.pag> or C<.dir> suffix. Required. path => '/var/db/www/passwd' =item * type DBM type. Valid options are: C, C, C and C. Defaults to C. type => 'NDBM' =over 12 =item * CDB Constant Database =item * DB Berkeley DB =item * GDBM GNU Database Mandager =item * NDBM New Database Mandager. C should be specified without a trailing C<.db> suffix. =item * SDBM Substitute Database Mandager. Comes with both with perl and Apache. C should be specified without a trailing C<.pag> or C<.dir> suffix. =back =item * log Any object that supports C, C, C and C. log => Log::Log4perl->get_logger('Authen::Simple::DBM') =back =item * authenticate( $username, $password ) Returns true on success and false on failure. =back =head1 SEE ALSO L. L. L L L - Overview of various DBM's. L - CDB L - Compares different DBM's =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-DBM-0.2/Makefile.PL0100644000076500007650000000061510362477330016242 0ustar chansenchansen# Note: this file was auto-generated by Module::Build::Compat version 0.03 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'Authen::Simple::DBM', 'VERSION_FROM' => 'lib/Authen/Simple/DBM.pm', 'PREREQ_PM' => { 'Authen::Simple' => '0.3' }, 'INSTALLDIRS' => 'site', 'PL_FILES' => {} ) ; Authen-Simple-DBM-0.2/MANIFEST0100644000076500007650000000022610362477330015417 0ustar chansenchansenBuild.PL Changes lib/Authen/Simple/DBM.pm Makefile.PL MANIFEST This list of files README t/01use.t t/02pod.t t/03podcoverage.t t/04basic.t META.yml Authen-Simple-DBM-0.2/META.yml0100644000076500007650000000045410362477330015542 0ustar chansenchansen--- name: Authen-Simple-DBM version: 0.2 author: - 'Christian Hansen C' abstract: Simple DBM authentication license: perl requires: Authen::Simple: 0.3 provides: Authen::Simple::DBM: file: lib/Authen/Simple/DBM.pm version: 0.2 generated_by: Module::Build version 0.2611 Authen-Simple-DBM-0.2/README0100644000076500007650000000453710362477330015157 0ustar chansenchansenNAME Authen::Simple::DBM - Simple DBM authentication SYNOPSIS use Authen::Simple::DBM; my $dbm = Authen::Simple::DBM->new( path => '/var/db/www/passwd' ); if ( $dbm->authenticate( $username, $password ) ) { # successfull authentication } # or as a mod_perl Authen handler PerlModule Authen::Simple::Apache PerlModule Authen::Simple::DBM PerlSetVar AuthenSimpleDBM_path "/var/db/www/passwd" PerlAuthenHandler Authen::Simple::DBM AuthType Basic AuthName "Protected Area" Require valid-user DESCRIPTION DBM authentication. METHODS * new This method takes a hash of parameters. The following options are valid: * path Path to DBM file. Usually specified without trailing ".db", ".pag" or ".dir" suffix. Required. path => '/var/db/www/passwd' * type DBM type. Valid options are: "DB", "GDBM", "NDBM" and "SDBM". Defaults to "SDBM". type => 'NDBM' * CDB Constant Database * DB Berkeley DB * GDBM GNU Database Mandager * NDBM New Database Mandager. "path" should be specified without a trailing ".db" suffix. * SDBM Substitute Database Mandager. Comes with both with perl and Apache. "path" should be specified without a trailing ".pag" or ".dir" suffix. * log Any object that supports "debug", "info", "error" and "warn". log => Log::Log4perl->get_logger('Authen::Simple::DBM') * authenticate( $username, $password ) Returns true on success and false on failure. SEE ALSO Authen::Simple. Authen::Simple::Password. htdbm(1) dbmmanage(1) - Overview of various DBM's. - CDB AnyDBM_File - Compares different DBM's 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-DBM-0.2/t/0040755000076500007650000000000010362477330014534 5ustar chansenchansenAuthen-Simple-DBM-0.2/t/01use.t0100644000076500007650000000007310362477330015653 0ustar chansenchansenuse Test::More tests => 1; use_ok('Authen::Simple::DBM'); Authen-Simple-DBM-0.2/t/02pod.t0100644000076500007650000000027610362477330015647 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-DBM-0.2/t/03podcoverage.t0100644000076500007650000000037210362477330017361 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-DBM-0.2/t/04basic.t0100644000076500007650000000467610362477330016160 0ustar chansenchansen#!perl use strict; use warnings; use Test::More; use Fcntl; unless ( eval "use SDBM_File; 1;" ) { plan skip_all => 'needs SDBM_File for testing'; } plan tests => 14; use_ok('Authen::Simple::DBM'); { my $dbm = SDBM_File->TIEHASH( 'database.db', O_RDWR | O_CREAT | O_TRUNC, 0664 ) or die q/Failed to create database 'database.db'. Reason: $!/; my %create = ( 'plain' => 'plain', 'crypt' => 'lk9Mh5KHGjAaM', 'md5' => '$1$NRe32ijZ$THIS7aDH.e093oDOGD10M/', 'smd5' => '{SMD5}eVWRi45+VqS2Xw4bJPN+SrGfpVg=', 'sha' => '{SHA}2PRZAyDhNDqRW2OUFwZQqPNdaSY=', 'sha-1 base64' => '4zJ0YGPiLDff9wRf61PVIsC5Nms', 'sha-1 hex' => 'fc1e1866232bfebfac8a8db8f0225a5166fa1a99', 'empty' => '', 'empty2' => ':group,group:comment', 'with groups' => "lk9Mh5KHGjAaM:user,admin:comment", "with null\0" => "lk9Mh5KHGjAaM\0" ); while ( my ( $key, $value ) = each(%create) ) { $dbm->STORE( $key => $value ); } } my $dbm = Authen::Simple::DBM->new( path => 'database.db' ); ok( $dbm, 'Got instance' ); ok( $dbm->authenticate( 'crypt', 'crypt' ), 'Successfully authenticated user crypt' ); ok( $dbm->authenticate( 'md5', 'md5' ), 'Successfully authenticated user md5' ); ok( $dbm->authenticate( 'plain', 'plain' ), 'Successfully authenticated user plain' ); ok( $dbm->authenticate( 'sha', 'sha' ), 'Successfully authenticated user sha' ); ok( $dbm->authenticate( 'smd5', 'smd5' ), 'Successfully authenticated user smd5' ); ok( $dbm->authenticate( 'sha-1 hex', 'sha-1 hex' ), 'Successfully authenticated user sha-1 hex' ); ok( $dbm->authenticate( 'sha-1 base64', 'sha-1 base64' ), 'Successfully authenticated user sha-1 base64' ); ok( $dbm->authenticate( 'with null', 'crypt' ), 'Successfully authenticated user with null' ); ok( $dbm->authenticate( 'with groups', 'crypt' ), 'Successfully authenticated user with groups' ); ok( ! $dbm->authenticate( 'bogus', 'bogus' ), 'Failed to authenticate user bogus' ); ok( ! $dbm->authenticate( 'empty', 'empty' ), 'Failed to authenticate user empty' ); ok( ! $dbm->authenticate( 'empty2', 'empty' ), 'Failed to authenticate user empty2' ); END { unlink 'database.db.dir'; unlink 'database.db.pag'; }