12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- use Authen::PAM;
- use POSIX;
- sub my_conv_func {
- my @res;
- while ( @_ ) {
- my $code = shift;
- my $msg = shift;
- my $ans = "";
- $ans = $password if $msg =~ /[Pp]assword/;
- push @res, (PAM_SUCCESS(),$ans);
- }
- push @res, PAM_SUCCESS();
- return @res;
- }
- $service = "login";
- if ($ARG = shift @ARGV) {
- if (!open (UPFILE, "<$ARG")) {
- print "Could not open username/password file: $ARG\n";
- exit 1;
- }
- } else {
- print "No username/password file specified on command line\n";
- exit 1;
- }
- $username = <UPFILE>;
- $password = <UPFILE>;
- if (!$username || !$password) {
- print "Username/password not found in file: $ARG\n";
- exit 1;
- }
- chomp $username;
- chomp $password;
- close (UPFILE);
- if (!ref($pamh = new Authen::PAM($service, $username, \&my_conv_func))) {
- print "Authen::PAM init failed\n";
- exit 1;
- }
- $res = $pamh->pam_authenticate;
- if ($res == PAM_SUCCESS()) {
- exit 0;
- } else {
- print "Auth '$username' failed, PAM said: ", $pamh->pam_strerror($res), "\n";
- exit 1;
- }
|