7 # userv root checkpasswd-self <<'END'
12 # userv root checkpasswd-other USERNAME <<'END'
17 # STATUS MESSAGE may be
19 # 2 incorrect password
23 # Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
24 # Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
26 # Chancellor Masters and Scholars of the University of Cambridge
27 # Copyright 2010 Tony Finch <fanf@dotat.at>
29 # This is free software; you can redistribute it and/or modify it
30 # under the terms of the GNU General Public License as published by
31 # the Free Software Foundation; either version 3 of the License, or
32 # (at your option) any later version.
34 # This program is distributed in the hope that it will be useful, but
35 # WITHOUT ANY WARRANTY; without even the implied warranty of
36 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 # General Public License for more details.
39 # You should have received a copy of the GNU General Public License
40 # along with userv-utils; if not, see http://www.gnu.org/licenses/.
47 my ($lockpath, $delay, $separator, $username) = @ARGV;
49 die "$0: bad usage\n" unless
52 $delay =~ m/^[0-9.]+$/ ||
56 $username = $ENV{'USERV_USER'} if $username eq 'SELF';
59 print "@_\n" or die $!;
63 my @pwent = getpwnam($username);
64 result 4, "no such user" unless @pwent;
66 my $encrpw= $pwent[1];
67 result 5, "password disabled" unless length $encrpw >= 13;
69 $!=0; my $pw = <STDIN>;
70 chomp $pw or die "reading password: $!\n";
72 my $lockf = new IO::File $lockpath, "w+" or die "open $lockpath: $!\n";
73 flock($lockf, LOCK_EX) or die "lock $lockpath: $!\n";
74 select(undef,undef,undef,0.5);
77 my $crval = crypt($pw,$encrpw);
79 result 2, "incorrect password" unless $crval eq $encrpw;