| Authen-Simple-NIS documentation | Contained in the Authen-Simple-NIS distribution. |
Authen::Simple::NIS - Simple NIS authentication
use Authen::Simple::NIS;
my $nis = Authen::Simple::NIS->new;
if ( $nis->authenticate( $username, $password ) ) {
# successfull authentication
}
# or as a mod_perl Authen handler
PerlModule Authen::Simple::Apache
PerlModule Authen::Simple::NIS
PerlSetVar AuthenSimpleNIS_domain "domain"
<Location /protected>
PerlAuthenHandler Authen::Simple::NIS
AuthType Basic
AuthName "Protected Area"
Require valid-user
</Location>
NIS authentication.
This method takes a hash of parameters. The following options are valid:
NIS domain. Required unless it can be obtained from yp_get_default_domain().
domain => 'domain'
NIS map. Defaults to passwd.byname.
map => 'passwd.byname'
Any object that supports debug, info, error and warn.
log => Log::Log4perl->get_logger('Authen::Simple::NIS')
Returns true on success and false on failure.
Christian Hansen ch@ngmedia.com
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
| Authen-Simple-NIS documentation | Contained in the Authen-Simple-NIS distribution. |
package Authen::Simple::NIS; use strict; use warnings; use base 'Authen::Simple::Adapter'; use Net::NIS qw[YPERR_KEY YPERR_SUCCESS]; use Net::NIS::Table qw[]; use Params::Validate qw[]; our $VERSION = 0.3; __PACKAGE__->options({ domain => { type => Params::Validate::SCALAR, optional => 1 }, map => { type => Params::Validate::SCALAR, default => 'passwd.byname', optional => 1 } }); sub check { my ( $self, $username, $password ) = @_; my $domain = $self->domain; unless ( $domain ||= Net::NIS::yp_get_default_domain() ) { $self->log->error( qq/Failed to obtain default NIS domain./ ) if $self->log; return 0; } my $nis = Net::NIS::Table->new( $self->map, $domain ); my $entry = $nis->match($username); unless ( $nis->status == YPERR_SUCCESS ) { my $map = $self->map; if ( $nis->status == YPERR_KEY ) { $self->log->debug( qq/User '$username' was not found in map '$map' from domain '$domain'./ ) if $self->log; } else { my $error = Net::NIS::yperr_string( $nis->status ); $self->log->error( qq/Failed to lookup key '$username' in map '$map' from domain '$domain'. Reason: '$error'/ ) if $self->log; } return 0; } my $encrypted = ( split( /:/, $entry ) )[1]; 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' using domain '$domain'./ ) if $self->log; return 1; } 1; __END__