-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypt_passwd.pl
executable file
·63 lines (55 loc) · 1.37 KB
/
crypt_passwd.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl
# Authentication script to use with MRBS's "ext" authentication
# scheme. config.inc.php should include something like:
#
# $auth["realm"] = "MRBS";
# $auth["type"] = "ext";
# $auth["prog"] = "../crypt_passwd.pl";
# $auth["params"] = "/etc/httpd/mrbs_passwd #USERNAME# #PASSWORD#";
#
# The script takes 3 pararameters:
#
# PASSWDFILE USERNAME PASSWORD
#
# Where:
#
# PASSWDFILE - Filename of password file, which is the form
# <username>:<crypted password>
# [See crypt_passwd.example for an example]
# You should make sure this is readable by the
# user that PHP (most likely the web server)
# runs as.
# USERNAME - Username to check
# PASSWORD - Password to check against crypted password in
# password file
#
# Returns 0 on success, 1 on failure
use strict;
use warnings;
my $passwd_filename = shift || die "No passwd filename supplied\n";
my $username = shift || die "No username supplied\n";
my $password = shift || die "No password supplied\n";
my $retcode = 1;
open PASSWD,'<',$passwd_filename;
while (<PASSWD>)
{
if (m/^([^:]+):(.*)$/)
{
my $user = $1;
my $crypt = $2;
if ($user eq $username)
{
if (crypt($password, $crypt) eq $crypt)
{
$retcode = 0;
last;
}
else
{
last;
}
}
}
}
close PASSWD;
exit $retcode;