Project

General

Profile

Download (3.17 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php-cgi -f
2
<?php
3
/*
4
 * ipsec.auth-user.php
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7
 * Copyright (c) 2008 Shrew Soft Inc
8
 * Copyright (c) 2008-2013 BSD Perimeter
9
 * Copyright (c) 2013-2016 Electric Sheep Fencing
10
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
/*
27
 * ipsec calls this script to authenticate a user
28
 * based on a username and password. We lookup these
29
 * in our config.xml file and check the credentials.
30
 */
31

    
32
require_once("globals.inc");
33
require_once("config.inc");
34
require_once("auth.inc");
35
require_once("interfaces.inc");
36

    
37

    
38
/* setup syslog logging */
39
openlog("charon", LOG_ODELAY, LOG_AUTH);
40

    
41
if (isset($_GET['username'])) {
42
	$authmodes = explode(",", $_GET['authcfg']);
43
	$username = $_GET['username'];
44
	$password = $_GET['password'];
45
	$common_name = $_GET['cn'];
46
} else {
47
	/* read data from environment */
48
	$username = getenv("username");
49
	$password = getenv("password");
50
	$common_name = getenv("common_name");
51
	$authmodes = explode(",", getenv("authcfg"));
52
}
53

    
54
if (!$username) {
55
	syslog(LOG_ERR, "invalid user authentication environment");
56
	if (isset($_GET['username'])) {
57
		echo "FAILED";
58
		closelog();
59
		return;
60
	} else {
61
		closelog();
62
		exit (-1);
63
	}
64
}
65

    
66
$authenticated = false;
67

    
68
if (($strictusercn === true) && ($common_name != $username)) {
69
	syslog(LOG_WARNING, "Username does not match certificate common name ({$username} != {$common_name}), access denied.");
70
	if (isset($_GET['username'])) {
71
		echo "FAILED";
72
		closelog();
73
		return;
74
	} else {
75
		closelog();
76
		exit (1);
77
	}
78
}
79

    
80
$attributes = array("nas_identifier" => "xauthIPsec");
81
foreach ($authmodes as $authmode) {
82
	$authcfg = auth_get_authserver($authmode);
83
	if (!$authcfg && $authmode != "Local Database") {
84
		continue;
85
	}
86

    
87
	$authenticated = authenticate_user($username, $password, $authcfg, $attributes);
88
	if ($authenticated == true) {
89
		if ($authmode == "Local Database") {
90
			$user = getUserEntry($username);
91
			if (!is_array($user) || !userHasPrivilege($user, "user-ipsec-xauth-dialin")) {
92
				$authenticated = false;
93
				syslog(LOG_WARNING, "user '{$username}' cannot authenticate through IPsec since the required privileges are missing.");
94
				continue;
95
			}
96
		}
97
		break;
98
	}
99
}
100

    
101
if ($authenticated == false) {
102
	syslog(LOG_WARNING, "user '{$username}' could not authenticate.");
103
	if (isset($_GET['username'])) {
104
		echo "FAILED";
105
		closelog();
106
		return;
107
	} else {
108
		closelog();
109
		exit (-1);
110
	}
111
}
112

    
113
if (file_exists("/etc/inc/ipsec.attributes.php")) {
114
	include_once("/etc/inc/ipsec.attributes.php");
115
}
116

    
117
syslog(LOG_NOTICE, "user '{$username}' authenticated");
118
closelog();
119

    
120
if (isset($_GET['username'])) {
121
	echo "OK";
122
} else {
123
	exit (0);
124
}
125

    
126
?>
(25-25/60)