Add "error_log_mode" setting

This commit is contained in:
Mikhail Galanin 2022-01-06 17:09:40 +00:00 committed by Jakub Zelenka
parent 7db9c2a2c3
commit ffdf25a270
No known key found for this signature in database
GPG key ID: 1C0779DC5C0A9DE4
5 changed files with 54 additions and 2 deletions

1
NEWS
View file

@ -15,6 +15,7 @@ PHP NEWS
http_build_query(), strstr(), Reflection*::__toString(). (Arnaud) http_build_query(), strstr(), Reflection*::__toString(). (Arnaud)
. Fixed bug GH-8995 (WeakMap object reference offset causing TypeError). . Fixed bug GH-8995 (WeakMap object reference offset causing TypeError).
(Tobias Bachert) (Tobias Bachert)
. Added error_log_mode ini setting. (Mikhail Galanin)
- COM: - COM:
. Fixed bug GH-8750 (Can not create VT_ERROR variant type). (cmb) . Fixed bug GH-8750 (Can not create VT_ERROR variant type). (cmb)

View file

@ -76,6 +76,8 @@ PHP 8.2 UPGRADE NOTES
RFC: https://wiki.php.net/rfc/true-type RFC: https://wiki.php.net/rfc/true-type
. Added support for Disjoint Normal Form (DNF) types. . Added support for Disjoint Normal Form (DNF) types.
RFC: https://wiki.php.net/rfc/dnf_types RFC: https://wiki.php.net/rfc/dnf_types
. Added error_log_mode ini setting that allows setting of permissions for
error log file.
- Curl: - Curl:

View file

@ -712,7 +712,8 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals) STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals) STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("output_encoding", NULL, PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, php_core_globals, core_globals) STD_PHP_INI_ENTRY("output_encoding", NULL, PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals) STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("error_log_mode", "0644", PHP_INI_ALL, OnUpdateLong, error_log_mode, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals) STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals) STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals) STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
@ -807,6 +808,8 @@ PHPAPI ZEND_COLD void php_log_err_with_severity(const char *log_message, int sys
/* Try to use the specified logging location. */ /* Try to use the specified logging location. */
if (PG(error_log) != NULL) { if (PG(error_log) != NULL) {
int error_log_mode;
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
if (!strcmp(PG(error_log), "syslog")) { if (!strcmp(PG(error_log), "syslog")) {
php_syslog(syslog_type_int, "%s", log_message); php_syslog(syslog_type_int, "%s", log_message);
@ -814,7 +817,14 @@ PHPAPI ZEND_COLD void php_log_err_with_severity(const char *log_message, int sys
return; return;
} }
#endif #endif
fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
error_log_mode = 0644;
if (PG(error_log_mode) > 0 && PG(error_log_mode) <= 0777) {
error_log_mode = PG(error_log_mode);
}
fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, error_log_mode);
if (fd != -1) { if (fd != -1) {
char *tmp; char *tmp;
size_t len; size_t len;

View file

@ -165,6 +165,7 @@ struct _php_core_globals {
char *syslog_ident; char *syslog_ident;
bool have_called_openlog; bool have_called_openlog;
zend_long syslog_filter; zend_long syslog_filter;
zend_long error_log_mode;
}; };

View file

@ -0,0 +1,38 @@
--TEST--
Check permissions for created errorlog file
--SKIPIF--
<?php
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
die("skip this test on windows");
}
?>
--INI--
error_log=error_permissions_test.log
error_log_mode=0600
--FILE--
<?php
const LOG_FILENAME='error_permissions_test.log';
try {
if (file_exists(LOG_FILENAME)) {
unlink(LOG_FILENAME);
}
$oldMask = umask(0000);
error_log("hello world");
assert(file_exists(LOG_FILENAME));
printf("got permissions=%o\n", fileperms(LOG_FILENAME) & 0777);
printf("errorlog contents\n%s", file_get_contents(LOG_FILENAME));
umask($oldMask);
} finally {
unlink(LOG_FILENAME);
}
?>
--EXPECTF--
got permissions=600
errorlog contents
[%d-%s-%d %d:%d:%d %s] hello world