Skip to content

Commit 5c98414

Browse files
committed
Better handling of openlog weirdness
1 parent 6f7cba0 commit 5c98414

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

docs/authproc_fticks.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ The filter supports the following configuration options:
4444
> * `host` - the hostname of the remote syslog server, defaulting to `localhost`. _[remote]_
4545
> * `port` - the port of the remote syslog server, defaulting to `514`. _[remote]_
4646
47+
Note that if `logdest` is `local` and you set either `processname` or `facility` to a value that's different to what is
48+
in SimpleSAMLphp's global config, you may end up with inconsistent output from SimpleSAMLphp's own logging. This is
49+
because PHP's [openlog](http://php.net/manual/en/function.openlog.php) function does not return a handle.
50+
4751
Examples
4852
--------
4953

lib/Auth/Process/Fticks.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ public function __construct($config, $reserved)
220220
}
221221
}
222222

223+
if (array_key_exists('logdest', $config)) {
224+
if (is_string($config['logdest']) and
225+
in_array($config['logdest'], array('local', 'syslog', 'remote', 'stdout', 'errorlog', 'simplesamlphp'))
226+
) {
227+
$this->logdest = $config['logdest'];
228+
} else {
229+
throw new \SimpleSAML\Error\Exception('F-ticks log destination must be one of [local, remote, stdout, errorlog, simplesamlphp]');
230+
}
231+
}
232+
223233
/* match SSP config or we risk mucking up the openlog call */
224234
$globalConfig = \SimpleSAML_Configuration::getInstance();
225235
$defaultFacility = $globalConfig->getInteger('logging.facility', defined('LOG_LOCAL5') ? constant('LOG_LOCAL5') : LOG_USER);
@@ -234,20 +244,13 @@ public function __construct($config, $reserved)
234244
$this->logconfig['facility'] = $defaultFacility;
235245
$this->logconfig['processname'] = $defaultProcessName;
236246
}
237-
if (array_key_exists('facility', $this->logconfig) and $this->logconfig['facility'] !== $defaultFacility) {
238-
\SimpleSAML\Logger::warning('F-ticks syslog facility differs from global config');
239-
}
240-
if (array_key_exists('processname', $this->logconfig) and $this->logconfig['processname'] !== $defaultProcessName) {
241-
\SimpleSAML\Logger::warning('F-ticks syslog processname differs from global config');
242-
}
243-
244-
if (array_key_exists('logdest', $config)) {
245-
if (is_string($config['logdest']) and
246-
in_array($config['logdest'], array('local', 'remote', 'stdout', 'errorlog', 'simplesamlphp'))
247-
) {
248-
$this->logdest = $config['logdest'];
249-
} else {
250-
throw new \SimpleSAML\Error\Exception('F-ticks log destination must be one of [local, remote, stdout, errorlog, simplesamlphp]');
247+
/* warn if we risk mucking up the openlog call (doesn't matter for remote syslog) */
248+
if (in_array($this->logdest, array('local', 'syslog'))) {
249+
if (array_key_exists('facility', $this->logconfig) and $this->logconfig['facility'] !== $defaultFacility) {
250+
\SimpleSAML\Logger::warning('F-ticks syslog facility differs from global config which may cause SimpleSAMLphp\'s logging to behave inconsistently');
251+
}
252+
if (array_key_exists('processname', $this->logconfig) and $this->logconfig['processname'] !== $defaultProcessName) {
253+
\SimpleSAML\Logger::warning('F-ticks syslog processname differs from global config which may cause SimpleSAMLphp\'s logging to behave inconsistently');
251254
}
252255
}
253256
}

0 commit comments

Comments
 (0)