OpenPlugin::Authenticate::PAM - PAM driver for the OpenPlugin::Authenticate


OpenPlugin documentation Contained in the OpenPlugin distribution.

Index


Code Index:

NAME

Top

OpenPlugin::Authenticate::PAM - PAM driver for the OpenPlugin::Authenticate plugin

PARAMETERS

Top

No parameters can be passed in to OpenPlugin's new() method for this driver. The following parameters are accepted via the authenticate() method:

* username

The username to authenticate.

* password

The password to verify.

* service

The name of the PAM service to use for the authentication. If none is provided, it defaults to "passwd".

CONFIG OPTIONS

Top

* driver

PAM

TO DO

Top

Nothing known.

BUGS

Top

None known.

COPYRIGHT

Top

AUTHORS

Top

Eric Andreychek <eric@openthought.net>


OpenPlugin documentation Contained in the OpenPlugin distribution.

package OpenPlugin::Authenticate::PAM;

# $Id: PAM.pm,v 1.14 2003/04/03 01:51:24 andreychek Exp $

use strict;
use OpenPlugin::Authenticate();
use base          qw( OpenPlugin::Authenticate );
use Authen::PAM;

$OpenPlugin::Authenticate::PAM::VERSION = sprintf("%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/);


sub authenticate {
    my ($self, $args) = @_;

    $args->{service} ||= "passwd";

    my $pamh;
    my $ret=0;

    # This function is not mod_perl safe, we need to do something about the
    # nested sub
    sub checkpwd_conv_func {
       my @res;
       while ( @_ ) {
          my $code = shift;
          my $msg = shift;
          my $ans = "";

          $ans = $args->{username} if ($code == PAM_PROMPT_ECHO_ON() );
          $ans = $args->{password} if ($code == PAM_PROMPT_ECHO_OFF() );

          push @res, PAM_SUCCESS();
       }
       push @res, PAM_SUCCESS();
       return @res;
    }

    $self->OP->log->info( "Authenticating $args->{username}");
    if ( ref($pamh = new Authen::PAM($args->{service}, $args->{username},
                                    \&checkpwd_conv_func)) ) {
       if ($pamh->pam_authenticate()==0) {
          $ret=1;
       }
    }
    $pamh = 0;  # force Destructor (per docs) (invokes pam_close())

    $self->OP->log->info( "Authenticate returned ($ret)");

    return($ret);
}


1;

__END__