1 |
3c11bd3c
|
Matthew Grooms
|
#!/usr/local/bin/php -f
|
2 |
|
|
<?php
|
3 |
|
|
/* $Id$ */
|
4 |
|
|
/*
|
5 |
|
|
openvpn.auth-user.php
|
6 |
|
|
|
7 |
|
|
Copyright (C) 2008 Shrew Soft Inc
|
8 |
|
|
All rights reserved.
|
9 |
|
|
|
10 |
|
|
Redistribution and use in source and binary forms, with or without
|
11 |
|
|
modification, are permitted provided that the following conditions are met:
|
12 |
|
|
|
13 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
this list of conditions and the following disclaimer.
|
15 |
|
|
|
16 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
notice, this list of conditions and the following disclaimer in the
|
18 |
|
|
documentation and/or other materials provided with the distribution.
|
19 |
|
|
|
20 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
30 |
1f5309a3
|
Matthew Grooms
|
|
31 |
|
|
DISABLE_PHP_LINT_CHECKING
|
32 |
3c11bd3c
|
Matthew Grooms
|
*/
|
33 |
|
|
|
34 |
|
|
/*
|
35 |
|
|
* OpenVPN calls this script to authenticate a user
|
36 |
|
|
* based on a username and password. We lookup these
|
37 |
|
|
* in our config.xml file and check the credentials.
|
38 |
|
|
*/
|
39 |
|
|
|
40 |
|
|
require_once("config.inc");
|
41 |
|
|
|
42 |
|
|
function & lookup_user($name) {
|
43 |
|
|
global $config;
|
44 |
|
|
|
45 |
|
|
foreach($config['system']['user'] as & $userent)
|
46 |
|
|
if ($userent['name'] == $name)
|
47 |
|
|
return $userent;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
/* setup syslog logging */
|
51 |
|
|
openlog("openvpn", LOG_ODELAY, LOG_AUTH);
|
52 |
|
|
|
53 |
|
|
/* read data from environment */
|
54 |
|
|
$username = getenv("username");
|
55 |
|
|
$password = getenv("password");
|
56 |
|
|
|
57 |
|
|
if (!$username || !$password) {
|
58 |
1f5309a3
|
Matthew Grooms
|
syslog(LOG_ERR, "invalid user authentication environment");
|
59 |
3c11bd3c
|
Matthew Grooms
|
exit(-1);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
/* lookup user object by name */
|
63 |
|
|
$user =& lookup_user($username);
|
64 |
|
|
|
65 |
|
|
if (!$user) {
|
66 |
|
|
syslog(LOG_WARNING, "user {$username} is unknown");
|
67 |
|
|
exit(-2);
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
/* authenticate the user */
|
71 |
|
|
$password = crypt($password, $user['password']);
|
72 |
|
|
|
73 |
|
|
if ($password != $user['password']) {
|
74 |
|
|
syslog(LOG_WARNING, "user {$username} supplied an invalid password\n");
|
75 |
|
|
exit(-3);
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
syslog(LOG_WARNING, "user {$username} authenticated\n");
|
79 |
|
|
exit(0);
|
80 |
|
|
|
81 |
|
|
?>
|