|
楼主 |
发表于 2005-5-20 21:16:50
|
显示全部楼层
继续求教!
我用下面的代码进行测试,以用户zyhua进行运行,总是出现“Authentication token manipulation error ”的错误,有谁知道为什么吗?多谢!
我试过,用些脚本在root用户下是可以改一般用户密码的。
有那位高手看过请指定!多谢!
***********************************
use Authen:AM;
$service = "passwd";
$username = "zyhua";
$oldpassword = "old_pass";
$newpassword = "new_pass";
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:AM($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();
*********************************** |
|