Authen-Simple-DBM-0.2/ 0040755 0000765 0000765 00000000000 10362477330 014271 5 ustar chansen chansen Authen-Simple-DBM-0.2/Build.PL 0100644 0000765 0000765 00000000474 10362477330 015567 0 ustar chansen chansen use 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/Changes 0100644 0000765 0000765 00000000277 10362477330 015567 0 ustar chansen chansen Revision 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/ 0040755 0000765 0000765 00000000000 10362477330 015037 5 ustar chansen chansen Authen-Simple-DBM-0.2/lib/Authen/ 0040755 0000765 0000765 00000000000 10362477330 016263 5 ustar chansen chansen Authen-Simple-DBM-0.2/lib/Authen/Simple/ 0040755 0000765 0000765 00000000000 10362477330 017514 5 ustar chansen chansen Authen-Simple-DBM-0.2/lib/Authen/Simple/DBM.pm 0100644 0000765 0000765 00000012064 10362477330 020454 0 ustar chansen chansen package 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.PL 0100644 0000765 0000765 00000000615 10362477330 016242 0 ustar chansen chansen # 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/MANIFEST 0100644 0000765 0000765 00000000226 10362477330 015417 0 ustar chansen chansen Build.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.yml 0100644 0000765 0000765 00000000454 10362477330 015542 0 ustar chansen chansen ---
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/README 0100644 0000765 0000765 00000004537 10362477330 015157 0 ustar chansen chansen NAME
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/ 0040755 0000765 0000765 00000000000 10362477330 014534 5 ustar chansen chansen Authen-Simple-DBM-0.2/t/01use.t 0100644 0000765 0000765 00000000073 10362477330 015653 0 ustar chansen chansen use Test::More tests => 1;
use_ok('Authen::Simple::DBM');
Authen-Simple-DBM-0.2/t/02pod.t 0100644 0000765 0000765 00000000276 10362477330 015647 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-DBM-0.2/t/03podcoverage.t 0100644 0000765 0000765 00000000372 10362477330 017361 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-DBM-0.2/t/04basic.t 0100644 0000765 0000765 00000004676 10362477330 016160 0 ustar chansen chansen #!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';
}