Project

General

Profile

Download (3.1 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -f
2 52c9f9fa Ermal
<?php
3
/*
4 ac24dc24 Renato Botelho
 * ipsec.auth-user.php
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7 c5d81585 Renato Botelho
 * Copyright (c) 2008 Shrew Soft Inc
8 0b4c14a4 Steve Beaver
 * Copyright (c) 2008-2019 Rubicon Communications, LLC (Netgate)
9 ac24dc24 Renato Botelho
 * All rights reserved.
10
 *
11 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14 ac24dc24 Renato Botelho
 *
15 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
16 ac24dc24 Renato Botelho
 *
17 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22 ac24dc24 Renato Botelho
 */
23 09221bc3 Renato Botelho
24 52c9f9fa Ermal
/*
25 4881e5a9 Ermal
 * ipsec calls this script to authenticate a user
26 52c9f9fa Ermal
 * based on a username and password. We lookup these
27
 * in our config.xml file and check the credentials.
28
 */
29
30
require_once("globals.inc");
31
require_once("config.inc");
32
require_once("auth.inc");
33
require_once("interfaces.inc");
34
35
36
/* setup syslog logging */
37 9eb4257f Ermal
openlog("charon", LOG_ODELAY, LOG_AUTH);
38 52c9f9fa Ermal
39 9e74f980 Ermal
if (isset($_GET['username'])) {
40 85d0e959 Ermal
	$authmodes = explode(",", $_GET['authcfg']);
41
	$username = $_GET['username'];
42
	$password = $_GET['password'];
43
	$common_name = $_GET['cn'];
44
} else {
45
	/* read data from environment */
46
	$username = getenv("username");
47
	$password = getenv("password");
48
	$common_name = getenv("common_name");
49 2a3e3057 Ermal
	$authmodes = explode(",", getenv("authcfg"));
50 85d0e959 Ermal
}
51 52c9f9fa Ermal
52
if (!$username || !$password) {
53
	syslog(LOG_ERR, "invalid user authentication environment");
54 fe06990e Ermal
	if (isset($_GET['username'])) {
55 85d0e959 Ermal
		echo "FAILED";
56
		closelog();
57
		return;
58
	} else {
59
		closelog();
60 9a92e2ef Renato Botelho
		exit (-1);
61 85d0e959 Ermal
	}
62 52c9f9fa Ermal
}
63
64
$authenticated = false;
65
66
if (($strictusercn === true) && ($common_name != $username)) {
67
	syslog(LOG_WARNING, "Username does not match certificate common name ({$username} != {$common_name}), access denied.\n");
68 eadda967 Ermal
	if (isset($_GET['username'])) {
69 85d0e959 Ermal
		echo "FAILED";
70
		closelog();
71
		return;
72
	} else {
73
		closelog();
74 9a92e2ef Renato Botelho
		exit (1);
75 85d0e959 Ermal
	}
76 52c9f9fa Ermal
}
77
78 f15fdef3 Augustin FL
$attributes = array("nas_identifier" => "xauthIPsec");
79 52c9f9fa Ermal
foreach ($authmodes as $authmode) {
80
	$authcfg = auth_get_authserver($authmode);
81 821a4351 Renato Botelho
	if (!$authcfg && $authmode != "Local Database") {
82 52c9f9fa Ermal
		continue;
83 b37a2e8c Phil Davis
	}
84 52c9f9fa Ermal
85
	$authenticated = authenticate_user($username, $password, $authcfg, $attributes);
86 936fc874 Ermal
	if ($authenticated == true) {
87 821a4351 Renato Botelho
		if ($authmode == "Local Database") {
88 b37a2e8c Phil Davis
			$user = getUserEntry($username);
89 a9157b6b Ermal
			if (!is_array($user) || !userHasPrivilege($user, "user-ipsec-xauth-dialin")) {
90
				$authenticated = false;
91 3c4fc30b Chris Buechler
				syslog(LOG_WARNING, "user '{$username}' cannot authenticate through IPsec since the required privileges are missing.\n");
92 a9157b6b Ermal
				continue;
93
			}
94 936fc874 Ermal
		}
95 52c9f9fa Ermal
		break;
96 936fc874 Ermal
	}
97 52c9f9fa Ermal
}
98
99
if ($authenticated == false) {
100 3260b82f Ermal
	syslog(LOG_WARNING, "user '{$username}' could not authenticate.\n");
101 eadda967 Ermal
	if (isset($_GET['username'])) {
102 85d0e959 Ermal
		echo "FAILED";
103
		closelog();
104
		return;
105
	} else {
106
		closelog();
107 9a92e2ef Renato Botelho
		exit (-1);
108 85d0e959 Ermal
	}
109 52c9f9fa Ermal
}
110
111 b37a2e8c Phil Davis
if (file_exists("/etc/inc/ipsec.attributes.php")) {
112
	include_once("/etc/inc/ipsec.attributes.php");
113
}
114
115 3260b82f Ermal
syslog(LOG_NOTICE, "user '{$username}' authenticated\n");
116 85d0e959 Ermal
closelog();
117 52c9f9fa Ermal
118 b37a2e8c Phil Davis
if (isset($_GET['username'])) {
119 85d0e959 Ermal
	echo "OK";
120 b37a2e8c Phil Davis
} else {
121 9a92e2ef Renato Botelho
	exit (0);
122 b37a2e8c Phil Davis
}
123 52c9f9fa Ermal
124
?>