1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-02-27 06:54:16 +01:00

Fix issue with $baseParam value.

- introduced recently in these log format changes.

- require_once 'ykval-config.php in logformat()
	did not import, because it takes place in ykval-verify.php.

- hence logformat() did not have $baseParams in scope,
	so we never write the log line.

- refactor and set format outside the class itself.
This commit is contained in:
Jean Paul Galea 2016-04-18 16:38:39 +02:00
parent 0838ecf56f
commit be784b8aaa
2 changed files with 11 additions and 25 deletions

View File

@ -31,6 +31,8 @@ require_once 'ykval-common.php';
class LogVerify class LogVerify
{ {
public $format = NULL;
private $fields = array( private $fields = array(
'time_start' => NULL, 'time_start' => NULL,
'time_end' => NULL, 'time_end' => NULL,
@ -75,14 +77,11 @@ class LogVerify
/** /**
* Write verify request log line to syslog. * Write verify request log line to syslog.
* *
* P.S only writes to syslog if __YKVAL_VERIFY_LOGFORMAT__
* is set correctly in ykval-config.php.
*
* @return bool * @return bool
*/ */
public function write() public function write()
{ {
if (($logformat = $this->logformat()) === FALSE) if ($this->format === NULL)
return false; return false;
$values = array(); $values = array();
@ -91,7 +90,7 @@ class LogVerify
$values['%'.$key.'%'] = $val; $values['%'.$key.'%'] = $val;
} }
$message = strtr($logformat, $values); $message = strtr($this->format, $values);
if (!is_string($message)) if (!is_string($message))
return false; return false;
@ -99,26 +98,6 @@ class LogVerify
return syslog(LOG_INFO, $message); return syslog(LOG_INFO, $message);
} }
/**
* Fetch the logging format as set in the configuration file.
*
* @return string|bool
*/
private function logformat()
{
require_once 'ykval-config.php';
if (!isset($baseParams)
|| !is_array($baseParams)
|| !array_key_exists('__YKVAL_VERIFY_LOGFORMAT__', $baseParams)
|| !is_string($baseParams['__YKVAL_VERIFY_LOGFORMAT__']))
{
return false;
}
return $baseParams['__YKVAL_VERIFY_LOGFORMAT__'];
}
/** /**
* Sanitize untrusted values from clients before writing them to syslog. * Sanitize untrusted values from clients before writing them to syslog.
* *

View File

@ -56,6 +56,13 @@ $myLog = new Log('ykval-verify');
$myLog->addField('ip', $ipaddr); $myLog->addField('ip', $ipaddr);
$myLog->request = new LogVerify(); $myLog->request = new LogVerify();
if (array_key_exists('__YKVAL_VERIFY_LOGFORMAT__', $baseParams)
&& is_string($baseParams['__YKVAL_VERIFY_LOGFORMAT__']))
{
$myLog->request->format = $baseParams['__YKVAL_VERIFY_LOGFORMAT__'];
}
$myLog->request->set('ip', $ipaddr); $myLog->request->set('ip', $ipaddr);
$myLog->request->set('tls', ($https ? 'tls' : '-')); $myLog->request->set('tls', ($https ? 'tls' : '-'));
$myLog->request->set('time_start', $time_start); $myLog->request->set('time_start', $time_start);