Commit | Line | Data |
---|---|---|
655e68e0 | 1 | #!/usr/bin/perl -w |
5e5500ed IJ |
2 | # checkpasswd-service |
3 | # part of userv-utils | |
4 | # | |
5 | # | |
6 | # protocols: | |
7 | # | |
8 | # userv root checkpasswd-self <<'END' | |
9 | # < PASSWORD | |
10 | # < ^D | |
11 | # > STATUS MESSAGE... | |
12 | # | |
13 | # userv root checkpasswd-other USERNAME <<'END' | |
14 | # < PASSWORD | |
15 | # < ^D | |
16 | # > STATUS MESSAGE... | |
17 | # | |
18 | # STATUS MESSAGE may be | |
19 | # 0 ok | |
20 | # 2 incorrect password | |
21 | # 4 no such user | |
22 | # 5 password disabled | |
23 | # | |
24 | # | |
25 | # Copyright (C) 2013 Ian Jackson | |
26 | # | |
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. | |
31 | # | |
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. | |
36 | # | |
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. | |
40 | ||
41 | ||
655e68e0 IJ |
42 | use strict; |
43 | use IO::File; | |
44 | use Fcntl qw(:flock); | |
45 | ||
5e5500ed IJ |
46 | my ($lockpath, $delay, $separator, $username) = @ARGV; |
47 | ||
48 | die "$0: bad usage\n" unless | |
49 | @ARGV == 4 || | |
50 | $lockpath =~ m#^/# || | |
51 | $delay =~ m/^[0-9.]+$/ || | |
52 | $separator eq '--' || | |
53 | $username =~ m/^\w/; | |
54 | ||
655e68e0 IJ |
55 | $username = $ENV{'USERV_USER'} if $username eq 'SELF'; |
56 | ||
57 | sub result { | |
58 | print "@_\n" or die $!; | |
59 | exit 0; | |
60 | } | |
61 | ||
62 | my @pwent = getpwnam($username); | |
63 | result 4, "no such user" unless @pwent; | |
64 | ||
65 | my $encrpw= $pwent[1]; | |
66 | result 5, "password disabled" unless length $encrpw >= 13; | |
67 | ||
68 | $!=0; my $pw = <STDIN>; | |
69 | chomp $pw or die "reading password: $!\n"; | |
70 | ||
655e68e0 IJ |
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); | |
74 | close $lockf; | |
75 | ||
76 | my $crval = crypt($pw,$encrpw); | |
77 | ||
78 | result 2, "incorrect password" unless $crval eq $encrpw; | |
79 | ||
80 | result 0, "ok"; |