Authen::PAM login doesn't work after Vintela flush

120 Views Asked by At

I have a perl script that gets the username and password from an external process and then does user authentication using Vintela. Everything works perfectly until someone forces Vintela to flush it's cache. After the cache is flushed, the Authen::PAM module returns code 10, which means that it couldn't find the username.

If I run the "id $username" command in the shell and then run the script then everything returns to normal for that user. Or if the user SSH's into the system then Authen::PAM works perfectly.

On the production server user's don't SSH into the server and hence after Vintela flush, user's can't login anymore. I don't want to run the "id" command for every user before I authenticate them. Is there a way I can force the script or PAM module to look for user and then authenticate them ?

Script --

BEGIN {
    unshift(@INC, "..", "/usr/local/staf/bin", "/usr/local/staf/lib", "C:/STAF/Bin");
}

use strict;
use PLSTAF;
require Authen::PAM;

my $GlobalUserName = <STDIN>;
my $GlobalPasswd = <STDIN>;
my $result = -1;


$GlobalPasswd = STAF::RemovePrivacyDelimiters($GlobalPasswd);

my $pamHandle = Authen::PAM->new("login", $GlobalUserName, \&conversionFunction);
$result = $pamHandle->pam_authenticate();

# force the destructor execution for PAM
$pamHandle = 0;

# When $result is 0 then user has been authenticated
if ($result == 0) {
    print $result;
    exit $result;
}
else {
    exit $result;
}


sub conversionFunction {

    my @response = ();

    # PAM constants
    my $pamEchoOn = Authen::PAM->PAM_PROMPT_ECHO_ON();
    my $pamEchoOff = Authen::PAM->PAM_PROMPT_ECHO_OFF();
    my $pamSuccess = Authen::PAM->PAM_SUCCESS();

    while ( @_ ) {
        my $code = shift;
        my $msg = shift;
        my $answer = "";

        if ($code == $pamEchoOn) {
            $answer = $GlobalUserName;
        }
        if ($code == $pamEchoOff) {
            $answer = $GlobalPasswd;
        }

        # response is always in pairs, response code and the actual answer
        push(@response, $pamSuccess, $answer);
    }
    push(@response, $pamSuccess);

    return @response;
}
0

There are 0 best solutions below