LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   using Authen::pam of perl module (https://www.linuxquestions.org/questions/linux-general-1/using-authen-pam-of-perl-module-627222/)

sandiplinux 03-11-2008 08:35 AM

using Authen::pam of perl module
 
Hi,
I have an perl programme that change password but not interactively..
the programme run and ends with this message
"Authentication token manipulation error"



__________________________________________________________________________
#!/usr/bin/perl -w

use Authen::PAM;

$service = "passwd";
$username = "vivek";
$oldpassword = "altctrl";
$newpassword = "redhat";

sub my_conv_func
{
my @res;
while ( @_ )
{
my $code = shift;
my $msg = shift;
my $ans = "";

$ans = $username if ($code == PAM_PROMPT_ECHO_ON() );
if($code == PAM_PROMPT_ECHO_OFF() )
{
$ans = $oldpassword if ($state == 0);
$ans = $newpassword if ($state == 1);
$ans = $newpassword if ($state == 2);
$state++;
}
push @res, (PAM_SUCCESS(),$ans);
}
push @res, PAM_SUCCESS();
return @res;
}
ref($pamh = new Authen::PAM($service, $username, \&my_conv_func)) ||die "Error code $pamh during PAM init!";
$state = 0;
$res = $pamh->pam_chauthtok;
print $pamh->pam_strerror($res),"\n" unless $res == PAM_SUCCESS();

#___________________________________________________________________________



THE BIG QUESTION:
What's going on?
Any help would be greatly appreciated as I'm not really sure what's going on with this!
i am login as root and OS is fedora 7

Thanks much in advance.
Regards,
sandip

chrism01 03-12-2008 07:30 PM

Try these guys: www.perlmonks.org


All times are GMT -5. The time now is 11:03 PM.