]> granicus.if.org Git - php/commitdiff
Add syslog.filter INI for filtering syslog messages
authorPhilip Prindeville <philipp@redfish-solutions.com>
Fri, 11 Aug 2017 18:30:50 +0000 (12:30 -0600)
committerJakub Zelenka <bukka@php.net>
Sun, 22 Jul 2018 14:36:47 +0000 (15:36 +0100)
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
main/main.c
main/php_globals.h
main/php_syslog.c
main/php_syslog.h
php.ini-development
php.ini-production

index 874c00e70ffba1957841e33b61471cd7b1dd68b2..3c7eaf6cebbfa36f59116c5910384a72f1042055 100644 (file)
@@ -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()
 /* }}} */
 
index e01160a12cd41f52297dfe17377b2995307a02fe..5d6b17d13972e92026322af987a190dc59e57543 100644 (file)
@@ -170,6 +170,7 @@ struct _php_core_globals {
        zend_long syslog_facility;
        char *syslog_ident;
        zend_bool have_called_openlog;
+       zend_long syslog_filter;
 };
 
 
index 7fcecef231aeef7ba633823ca2d9a900563f98a0..3bb9ee86ddf1a3d8387c2db93c4688f7229d7cfd 100644 (file)
@@ -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]);
                }
        }
 
index 28cfe171cdaf9b835f74936e56c9ba011ea411fd..d8e45acfc9bd134f836e51b54fcd2b1d0d532950 100644 (file)
 #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);
index 3f45c084985e2050079daa169c188436c835a9a1..d7aac12a16a349f65d9c96d45d17ec95b9314f2a 100644 (file)
@@ -517,6 +517,14 @@ report_memleaks = On
 ; This setting is on by default.
 ;report_zend_debug = 0
 
+; Set this to disable filtering control characters (the default).
+; Some loggers only accept NVT-ASCII, others accept anything that's not
+; control characters.  If your logger accepts everything, then no filtering
+; is needed at all.
+; Values are: ascii (space-tilde), no_ctrl (all characters space and above),
+; and none (all characters)
+;syslog.filter = ascii
+
 ; Store the last error/warning message in $php_errormsg (boolean).
 ; This directive is DEPRECATED.
 ; Default Value: Off
index 793174d88fbcb9ccf503d91edc67bbea09aa30b6..339a632c0428490d1dd7bb986e48eb026dd48d40 100644 (file)
@@ -522,6 +522,14 @@ report_memleaks = On
 ; This setting is on by default.
 ;report_zend_debug = 0
 
+; Set this to disable filtering control characters (the default).
+; Some loggers only accept NVT-ASCII, others accept anything that's not
+; control characters.  If your logger accepts everything, then no filtering
+; is needed at all.
+; Values are: ascii (space-tilde), no_ctrl (all characters space and above),
+; and none (all characters)
+;syslog.filter = ascii
+
 ; Store the last error/warning message in $php_errormsg (boolean). Setting this value
 ; to On can assist in debugging and is appropriate for development servers. It should
 ; however be disabled on production servers.