ipif: eat_optionalstr: do not crash on end of argument list
[userv-utils] / misc / checkpasswd-service
CommitLineData
655e68e0 1#!/usr/bin/perl -w
5e5500ed
IJ
2# checkpasswd-service
3# part of userv-utils
9028e234 4
5e5500ed
IJ
5# protocols:
6#
7# userv root checkpasswd-self <<'END'
8# < PASSWORD
9# < ^D
10# > STATUS MESSAGE...
11#
12# userv root checkpasswd-other USERNAME <<'END'
13# < PASSWORD
14# < ^D
15# > STATUS MESSAGE...
16#
17# STATUS MESSAGE may be
18# 0 ok
19# 2 incorrect password
20# 4 no such user
21# 5 password disabled
9028e234
IJ
22
23# Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
24# Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
25# Copyright 1999,2003
26# Chancellor Masters and Scholars of the University of Cambridge
27# Copyright 2010 Tony Finch <fanf@dotat.at>
5e5500ed
IJ
28#
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
9028e234 31# the Free Software Foundation; either version 3 of the License, or
5e5500ed
IJ
32# (at your option) any later version.
33#
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.
38#
39# You should have received a copy of the GNU General Public License
9028e234 40# along with userv-utils; if not, see http://www.gnu.org/licenses/.
5e5500ed
IJ
41
42
655e68e0
IJ
43use strict;
44use IO::File;
45use Fcntl qw(:flock);
46
5e5500ed
IJ
47my ($lockpath, $delay, $separator, $username) = @ARGV;
48
49die "$0: bad usage\n" unless
50 @ARGV == 4 ||
51 $lockpath =~ m#^/# ||
52 $delay =~ m/^[0-9.]+$/ ||
53 $separator eq '--' ||
54 $username =~ m/^\w/;
55
655e68e0
IJ
56$username = $ENV{'USERV_USER'} if $username eq 'SELF';
57
58sub result {
59 print "@_\n" or die $!;
60 exit 0;
61}
62
63my @pwent = getpwnam($username);
64result 4, "no such user" unless @pwent;
65
66my $encrpw= $pwent[1];
67result 5, "password disabled" unless length $encrpw >= 13;
68
69$!=0; my $pw = <STDIN>;
70chomp $pw or die "reading password: $!\n";
71
655e68e0
IJ
72my $lockf = new IO::File $lockpath, "w+" or die "open $lockpath: $!\n";
73flock($lockf, LOCK_EX) or die "lock $lockpath: $!\n";
74select(undef,undef,undef,0.5);
75close $lockf;
76
77my $crval = crypt($pw,$encrpw);
78
79result 2, "incorrect password" unless $crval eq $encrpw;
80
81result 0, "ok";