Apache2-AuthenNIS

 view release on metacpan or  search on metacpan

lib/Apache2/AuthenNIS.pm  view on Meta::CPAN

=over 4

=item PerlSetVar AllowAlternateAuth

This attribute allows you to set an alternative method of authentication
(Basically, this allows you to mix authentication methods, if you don't have
 all users in the NIS database). It does this by returning a DECLINE and checking
 for the next handler, which could be another authentication, such as
Apache-AuthenNTLM or basic authentication.

=back


=head2 Functions

=over 4

=item handler

This is the mod_perl2 handler function.

=cut

sub handler {
    my $r = shift;
    my( $res, $sent_pwd ) = $r->get_basic_auth_pw;
    return $res if $res; #decline if not Basic

    my $name = $r->user;

    my $allowaltauth = $r->dir_config( 'AllowAlternateAuth' ) || "no";

    my $domain = Net::NIS::yp_get_default_domain();
    unless( $domain ) {
        $r->note_basic_auth_failure;
        $r->log_error( __PACKAGE__, " - cannot obtain NIS domain", $r->uri );
        return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
    }

    if ( $name eq q() ) {
        $r->note_basic_auth_failure;
        $r->log_error( __PACKAGE__, " - no username given", $r->uri );
        return Apache2::Const::HTTP_UNAUTHORIZED;
    }

    my( $status, $entry ) = Net::NIS::yp_match( $domain, "passwd.byname", $name );

    if ( $status ) {
        if ( lc( $allowaltauth ) eq "yes" && $status == 5 ) {
            return Apache2::Const::DECLINED;
        }
        else {
            my $error_msg = Net::NIS::yperr_string( $status );
            $r->note_basic_auth_failure;
            $r->log_error( __PACKAGE__, " - user $name: yp_match: status ",
                           "$status, $error_msg", $r->uri );
            return Apache2::Const::HTTP_UNAUTHORIZED;
        }
    }

    my( $user, $hash, $uid, $gid, $gecos, $dir, $shell ) = split( /:/, $entry );

    if ( crypt( $sent_pwd, $hash ) eq $hash ) {
        return Apache2::Const::OK;
    } else {
        if ( lc( $allowaltauth ) eq "yes" ) {
            return Apache2::Const::DECLINED;
        }
        else {
            $r->note_basic_auth_failure;
            $r->log_error( __PACKAGE__, " - user $name: bad password", $r->uri );
            return Apache2::Const::HTTP_UNAUTHORIZED;
        }
    }

    return Apache2::Const::OK;
}

=back


=head1 INSTALLATION

To install this module, run the following commands:

    perl Build.PL
    ./Build
    ./Build test
    ./Build install


=head1 AUTHOR

Demetrios E. Paneras, C<< <dep at media.mit.edu> >>

Ported to mod_perl by Shannon Eric Peevey, C<< <speeves at unt.edu> >>

Ported to mod_perl2 by Nguon Hao Ching, C<< <hao at iteaha.us> >>


=head1 BUGS

Please report any bugs or feature requests to
C<bug-apache2-authennis at rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Apache2-AuthenNIS>.  I will be
notified, and then you'll automatically be notified of progress on your bug as
I make changes.


=head1 SUPPORT & DOCUMENTATION

You can find documentation for this module with the perldoc command.

    perldoc Apache2::AuthenNIS


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker



( run in 1.060 second using v1.01-cache-2.11-cpan-ceb78f64989 )