Commit 3f8a9f08 authored by Ad Schellevis's avatar Ad Schellevis

further cleanup of php-fpm code, related to https://github.com/opnsense/core/issues/42

parent 67601e0d
...@@ -75,10 +75,10 @@ function getNasIP() ...@@ -75,10 +75,10 @@ function getNasIP()
/* setup syslog logging */ /* setup syslog logging */
openlog("openvpn", LOG_ODELAY, LOG_AUTH); openlog("openvpn", LOG_ODELAY, LOG_AUTH);
if (count($argv) > 6) { if (count($argv) >= 6) {
$authmodes = explode(',', $argv[5]); $authmodes = explode(',', $argv[5]);
$username = $argv[1]; $username = base64_decode(str_replace('%3D', '=', $argv[1]));
$password = urldecode($argv[2]); $password = base64_decode(str_replace('%3D', '=', $argv[2]));
$common_name = $argv[3]; $common_name = $argv[3];
$modeid = $argv[6]; $modeid = $argv[6];
$strictusercn = $argv[4] == 'false' ? false : true; $strictusercn = $argv[4] == 'false' ? false : true;
...@@ -91,14 +91,8 @@ if (count($argv) > 6) { ...@@ -91,14 +91,8 @@ if (count($argv) > 6) {
if (!$username || !$password) { if (!$username || !$password) {
syslog(LOG_ERR, "invalid user authentication environment"); syslog(LOG_ERR, "invalid user authentication environment");
if (isset($_GET)) { closelog();
echo "FAILED"; exit(-1);
closelog();
return;
} else {
closelog();
exit(-1);
}
} }
/* Replaced by a sed with propper variables used below(ldap parameters). */ /* Replaced by a sed with propper variables used below(ldap parameters). */
...@@ -113,26 +107,14 @@ $authenticated = false; ...@@ -113,26 +107,14 @@ $authenticated = false;
if (($strictusercn === true) && ($common_name != $username)) { if (($strictusercn === true) && ($common_name != $username)) {
syslog(LOG_WARNING, "Username does not match certificate common name ({$username} != {$common_name}), access denied.\n"); syslog(LOG_WARNING, "Username does not match certificate common name ({$username} != {$common_name}), access denied.\n");
if (isset($_GET)) { closelog();
echo "FAILED"; exit(1);
closelog();
return;
} else {
closelog();
exit(1);
}
} }
if (!is_array($authmodes)) { if (!is_array($authmodes)) {
syslog(LOG_WARNING, "No authentication server has been selected to authenticate against. Denying authentication for user {$username}"); syslog(LOG_WARNING, "No authentication server has been selected to authenticate against. Denying authentication for user {$username}");
if (isset($_GET)) { closelog();
echo "FAILED"; exit(1);
closelog();
return;
} else {
closelog();
exit(1);
}
} }
$attributes = array(); $attributes = array();
...@@ -148,14 +130,8 @@ foreach ($authmodes as $authmode) { ...@@ -148,14 +130,8 @@ foreach ($authmodes as $authmode) {
if ($authenticated == false) { if ($authenticated == false) {
syslog(LOG_WARNING, "user '{$username}' could not authenticate.\n"); syslog(LOG_WARNING, "user '{$username}' could not authenticate.\n");
if (isset($_GET)) { closelog();
echo "FAILED"; exit(-1);
closelog();
return;
} else {
closelog();
exit(-1);
}
} }
@include_once('openvpn.attributes.php'); @include_once('openvpn.attributes.php');
...@@ -190,7 +166,4 @@ if (!empty($content)) ...@@ -190,7 +166,4 @@ if (!empty($content))
syslog(LOG_NOTICE, "user '{$username}' authenticated\n"); syslog(LOG_NOTICE, "user '{$username}' authenticated\n");
closelog(); closelog();
if (isset($_GET)) exit(0);
echo "OK";
else
exit(0);
...@@ -59,23 +59,14 @@ foreach ($subj at $s) { ...@@ -59,23 +59,14 @@ foreach ($subj at $s) {
if (isset($allowed_depth) && ($cert_depth > $allowed_depth)) { if (isset($allowed_depth) && ($cert_depth > $allowed_depth)) {
syslog(LOG_WARNING, "Certificate depth {$cert_depth} exceeded max allowed depth of {$allowed_depth}.\n"); syslog(LOG_WARNING, "Certificate depth {$cert_depth} exceeded max allowed depth of {$allowed_depth}.\n");
if (isset($_GET)) { closelog();
echo "FAILED"; exit(1);
closelog();
return;
} else {
closelog();
exit(1);
}
} }
// Debug // Debug
//syslog(LOG_WARNING, "Found certificate {$argv[2]} with depth {$cert_depth}\n"); //syslog(LOG_WARNING, "Found certificate {$argv[2]} with depth {$cert_depth}\n");
closelog(); closelog();
if (isset($_GET)) exit(0);
echo "OK";
else
exit(0);
?> ?>
#!/bin/sh #!/bin/sh
if [ "$1" = "tls" ]; then if [ "$1" = "tls" ]; then
RESULT=$(/usr/local/bin/php /usr/local/etc/inc/openvpn.tls-verify.php -d $2 $3) (/usr/local/bin/php /usr/local/etc/inc/openvpn.tls-verify.php -d "$2" "$3")
exit $?
else else
# Single quoting $password breaks getting the value from the variable. # Single quoting $password breaks getting the value from the variable.
password=$(echo -n "${password}" | openssl enc -base64 | sed -e 's/=/%3D/g') password=$(echo -n "${password}" | openssl enc -base64 | sed -e 's/=/%3D/g')
username=$(echo -n "${username}" | openssl enc -base64 | sed -e 's/=/%3D/g') username=$(echo -n "${username}" | openssl enc -base64 | sed -e 's/=/%3D/g')
RESULT=$(/usr/local/bin/php /etc/inc/openvpn.auth-user.php $username $password $common_name $3 $2 $4) (/usr/local/bin/php /usr/local/etc/inc/openvpn.auth-user.php "$username" "$password" "$common_name" "$3" "$2" "$4")
fi exit $?
if [ "${RESULT}" = "OK" ]; then
exit 0
fi fi
exit 1 exit 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment