#!/usr/bin/perl
# check_passwd - HS3-linux tool script
# supports: TOOLS->System->Linux Tools, TOOLS->System->Change System Password
# login password validation
# usage: check_passwd username password
# returns 0 if valid username/password provided; 1 otherwise

use strict;
use warnings;
use English;

die "$0: must be superuser!\n" if $UID;

my $username = shift;
my $passwd = shift;

my (undef, $crypt) = getpwnam($username) if $username;
my $rc = (defined ($passwd) and defined($crypt) and crypt($passwd, $crypt) eq $crypt) ? 0 : 1;
exit $rc;
