8 # userv root checkpasswd-self <<'END'
13 # userv root checkpasswd-other USERNAME <<'END'
18 # STATUS MESSAGE may be
20 # 2 incorrect password
25 # Copyright (C) 2013 Ian Jackson
27 # This is free software; you can redistribute it and/or modify it
28 # under the terms of the GNU General Public License as published by
29 # the Free Software Foundation; either version 2 of the License, or
30 # (at your option) any later version.
32 # This program is distributed in the hope that it will be useful, but
33 # WITHOUT ANY WARRANTY; without even the implied warranty of
34 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 # General Public License for more details.
37 # You should have received a copy of the GNU General Public License
38 # along with userv-utils; if not, write to the Free Software
39 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
46 my ($lockpath, $delay, $separator, $username) = @ARGV;
48 die "$0: bad usage\n" unless
51 $delay =~ m/^[0-9.]+$/ ||
55 $username = $ENV{'USERV_USER'} if $username eq 'SELF';
58 print "@_\n" or die $!;
62 my @pwent = getpwnam($username);
63 result 4, "no such user" unless @pwent;
65 my $encrpw= $pwent[1];
66 result 5, "password disabled" unless length $encrpw >= 13;
68 $!=0; my $pw = <STDIN>;
69 chomp $pw or die "reading password: $!\n";
71 my $lockf = new IO::File $lockpath, "w+" or die "open $lockpath: $!\n";
72 flock($lockf, LOCK_EX) or die "lock $lockpath: $!\n";
73 select(undef,undef,undef,0.5);
76 my $crval = crypt($pw,$encrpw);
78 result 2, "incorrect password" unless $crval eq $encrpw;