summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorPhilip Prindeville <philipp@redfish-solutions.com>2017-08-11 12:30:50 -0600
committerJakub Zelenka <bukka@php.net>2018-07-22 15:36:47 +0100
commit2010c02e5c3c70880a53cb0403ce696708f4d590 (patch)
tree0593b22f3470a7082b5fbd7bbba4228cd2177b4a /main
parent4a528d46f52f9d3bbb3b8f2191689d4aadca82ba (diff)
downloadphp-git-2010c02e5c3c70880a53cb0403ce696708f4d590.tar.gz
Add syslog.filter INI for filtering syslog messages
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Diffstat (limited to 'main')
-rw-r--r--main/main.c24
-rw-r--r--main/php_globals.h1
-rw-r--r--main/php_syslog.c16
-rw-r--r--main/php_syslog.h5
4 files changed, 44 insertions, 2 deletions
diff --git a/main/main.c b/main/main.c
index 874c00e70f..3c7eaf6ceb 100644
--- a/main/main.c
+++ b/main/main.c
@@ -53,6 +53,7 @@
#include "php_ini.h"
#include "php_globals.h"
#include "php_main.h"
+#include "php_syslog.h"
#include "fopen_wrappers.h"
#include "ext/standard/php_standard.h"
#include "ext/standard/php_string.h"
@@ -329,6 +330,28 @@ static PHP_INI_MH(OnChangeMemoryLimit)
}
/* }}} */
+/* {{{ PHP_INI_MH
+ */
+static PHP_INI_MH(OnSetLogFilter)
+{
+ const char *filter = ZSTR_VAL(new_value);
+
+ if (!strcmp(filter, "none")) {
+ PG(syslog_filter) = PHP_SYSLOG_FILTER_NONE;
+ return SUCCESS;
+ }
+ if (!strcmp(filter, "no-ctrl")) {
+ PG(syslog_filter) = PHP_SYSLOG_FILTER_NO_CTRL;
+ return SUCCESS;
+ }
+ if (!strcmp(filter, "ascii")) {
+ PG(syslog_filter) = PHP_SYSLOG_FILTER_ASCII;
+ return SUCCESS;
+ }
+
+ return FAILURE;
+}
+/* }}} */
/* {{{ php_disable_functions
*/
@@ -775,6 +798,7 @@ PHP_INI_BEGIN()
#endif
STD_PHP_INI_ENTRY("syslog.facility", "LOG_USER", PHP_INI_SYSTEM, OnSetFacility, syslog_facility, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("syslog.ident", "php", PHP_INI_SYSTEM, OnUpdateString, syslog_ident, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("syslog.filter", "no-ctrl", PHP_INI_ALL, OnSetLogFilter, syslog_filter, php_core_globals, core_globals)
PHP_INI_END()
/* }}} */
diff --git a/main/php_globals.h b/main/php_globals.h
index e01160a12c..5d6b17d139 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -170,6 +170,7 @@ struct _php_core_globals {
zend_long syslog_facility;
char *syslog_ident;
zend_bool have_called_openlog;
+ zend_long syslog_filter;
};
diff --git a/main/php_syslog.c b/main/php_syslog.c
index 7fcecef231..3bb9ee86dd 100644
--- a/main/php_syslog.c
+++ b/main/php_syslog.c
@@ -86,11 +86,23 @@ PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */
break;
}
- if (c != '\n')
+ /* check for NVT ASCII only unless test disabled */
+ if (((0x20 <= c) && (c <= 0x7e)))
smart_string_appendc(&sbuf, c);
- else {
+ else if ((c >= 0x80) && (PG(syslog_filter) != PHP_SYSLOG_FILTER_ASCII))
+ smart_string_appendc(&sbuf, c);
+ else if (c == '\n') {
syslog(priority, "%.*s", (int)sbuf.len, sbuf.c);
smart_string_reset(&sbuf);
+ } else if ((c < 0x20) && (PG(syslog_filter) == PHP_SYSLOG_FILTER_NONE))
+ smart_string_appendc(&sbuf, c);
+ else {
+ const char xdigits[] = "0123456789abcdef";
+
+ smart_string_appendl(&sbuf, "\\x", 2);
+ smart_string_appendc(&sbuf, xdigits[(c / 0x10)]);
+ c &= 0x0f;
+ smart_string_appendc(&sbuf, xdigits[c]);
}
}
diff --git a/main/php_syslog.h b/main/php_syslog.h
index 28cfe171cd..d8e45acfc9 100644
--- a/main/php_syslog.h
+++ b/main/php_syslog.h
@@ -32,6 +32,11 @@
#endif
#endif
+/* Syslog filters */
+#define PHP_SYSLOG_FILTER_NONE 0
+#define PHP_SYSLOG_FILTER_NO_CTRL 1
+#define PHP_SYSLOG_FILTER_ASCII 2
+
BEGIN_EXTERN_C()
PHPAPI void php_syslog(int, const char *format, ...);
PHPAPI void php_openlog(const char *, int, int);