From 0166c3728b30446f2ed63204f2e4278275c9ecff Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 1 Jul 2016 16:04:11 -0400 Subject: [PATCH] Stop trying to chmod if SerializerPermissions is null, fixes #71 Signed-off-by: Edward Z. Yang --- configdoc/usage.xml | 2 +- library/HTMLPurifier/ConfigSchema/schema.ser | Bin 15525 -> 15526 bytes .../schema/Cache.SerializerPermissions.txt | 7 ++++- .../DefinitionCache/Serializer.php | 28 ++++++++++++------ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/configdoc/usage.xml b/configdoc/usage.xml index b4d0d863..d59b6b1c 100644 --- a/configdoc/usage.xml +++ b/configdoc/usage.xml @@ -424,7 +424,7 @@ 200 - 218 + 219 diff --git a/library/HTMLPurifier/ConfigSchema/schema.ser b/library/HTMLPurifier/ConfigSchema/schema.ser index 2ec212dadc970e459a562bd7e67f7fb68f32ab6c..9ea0978d43c1d800bd1cf50634cd73efe120f81c 100644 GIT binary patch delta 19 bcmZ2lxvX--bsZ*M)5(l%@|(Zwtm6j&Q!)pk delta 18 acmZ2hxwLY_bsa|2$&76Bn}6u6;|BmuO9ylS diff --git a/library/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt b/library/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt index b2b83d9a..2e0cc810 100644 --- a/library/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt +++ b/library/HTMLPurifier/ConfigSchema/schema/Cache.SerializerPermissions.txt @@ -1,5 +1,5 @@ Cache.SerializerPermissions -TYPE: int +TYPE: int/null VERSION: 4.3.0 DEFAULT: 0755 --DESCRIPTION-- @@ -8,4 +8,9 @@ DEFAULT: 0755 Directory permissions of the files and directories created inside the DefinitionCache/Serializer or other custom serializer path.

+

+ In HTML Purifier 4.8.0, this also supports NULL, + which means that no chmod'ing or directory creation shall + occur. +

--# vim: et sw=4 sts=4 diff --git a/library/HTMLPurifier/DefinitionCache/Serializer.php b/library/HTMLPurifier/DefinitionCache/Serializer.php index 4686fcff..f930c6b9 100644 --- a/library/HTMLPurifier/DefinitionCache/Serializer.php +++ b/library/HTMLPurifier/DefinitionCache/Serializer.php @@ -198,11 +198,12 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac if ($result !== false) { // set permissions of the new file (no execute) $chmod = $config->get('Cache.SerializerPermissions'); - if (!$chmod) { - $chmod = 0644; // invalid config or simpletest + if ($chmod === null) { + // don't do anything + } else { + $chmod = $chmod & 0666; + chmod($file, $chmod); } - $chmod = $chmod & 0666; - chmod($file, $chmod); } return $result; } @@ -216,9 +217,6 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac { $directory = $this->generateDirectoryPath($config); $chmod = $config->get('Cache.SerializerPermissions'); - if (!$chmod) { - $chmod = 0755; // invalid config or simpletest - } if (!is_dir($directory)) { $base = $this->generateBaseDirectoryPath($config); if (!is_dir($base)) { @@ -231,7 +229,19 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac } elseif (!$this->_testPermissions($base, $chmod)) { return false; } - mkdir($directory, $chmod); + if ($chmod === null) { + trigger_error( + 'Base directory ' . $base . ' does not exist, + please create or change using %Cache.SerializerPath', + E_USER_WARNING + ); + return false; + } + if ($chmod !== null) { + mkdir($directory, $chmod); + } else { + mkdir($directory); + } if (!$this->_testPermissions($directory, $chmod)) { trigger_error( 'Base directory ' . $base . ' does not exist, @@ -268,7 +278,7 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac ); return false; } - if (function_exists('posix_getuid')) { + if (function_exists('posix_getuid') && $chmod !== null) { // POSIX system, we can give more specific advice if (fileowner($dir) === posix_getuid()) { // we can chmod it ourselves