Fixed bug #16134: TYPO3 doesn't always fix permissions for new files
authorTolleiv Nietsch <info@tolleiv.de>
Mon, 20 Dec 2010 19:32:29 +0000 (19:32 +0000)
committerTolleiv Nietsch <info@tolleiv.de>
Mon, 20 Dec 2010 19:32:29 +0000 (19:32 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9861 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/class.t3lib_iconworks.php
t3lib/class.t3lib_lock.php
t3lib/thumbs.php
tests/t3lib/fixtures/clear.gif [new file with mode: 0644]
tests/t3lib/fixtures/clear.png [new file with mode: 0644]
tests/t3lib/t3lib_divTest.php
tests/t3lib/t3lib_iconWorksTest.php
tests/t3lib/t3lib_lockTest.php [new file with mode: 0644]

index c341459..b61e4bb 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-12-20  Tolleiv Nietsch  <typo3@tolleiv.de>
+
+       * Fixed bug #16134: TYPO3 doesn't always fix permissions for new files
+
 2010-12-20  Steffen Kamper  <steffen@typo3.org>
 
        * Fixed bug #16778: Test failures in t3lib_tree_NodeTest if tests are in typo3_src/tests/ instead of tests/ (Thanks to Oliver Klee)
index f71e7af..ac1eda5 100644 (file)
@@ -490,13 +490,18 @@ final class t3lib_div {
                        if (($type == 'IM' || !$type) && $gfxConf['im'] && $gfxConf['im_path_lzw']) { // IM
                                $cmd = self::imageMagickCommand('convert', '"' . $theFile . '" "' . $theFile . '"', $gfxConf['im_path_lzw']);
                                exec($cmd);
-
                                $returnCode = 'IM';
+                               if (@is_file($theFile)) {
+                                       self::fixPermissions($theFile);
+                               }
                        } elseif (($type == 'GD' || !$type) && $gfxConf['gdlib'] && !$gfxConf['gdlib_png']) { // GD
                                $tempImage = imageCreateFromGif($theFile);
                                imageGif($tempImage, $theFile);
                                imageDestroy($tempImage);
                                $returnCode = 'GD';
+                               if (@is_file($theFile)) {
+                                       self::fixPermissions($theFile);
+                               }
                        }
                }
                return $returnCode;
@@ -520,6 +525,9 @@ final class t3lib_div {
                        $cmd = self::imageMagickCommand('convert', '"' . $theFile . '" "' . $newFile . '"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']);
                        exec($cmd);
                        $theFile = $newFile;
+                       if (@is_file($newFile)) {
+                               self::fixPermissions($newFile);
+                       }
                                // unlink old file?? May be bad idea bacause TYPO3 would then recreate the file every time as TYPO3 thinks the file is not generated because it's missing!! So do not unlink $theFile here!!
                }
                return $theFile;
@@ -547,6 +555,7 @@ final class t3lib_div {
                                $cmd = self::imageMagickCommand('convert', '"' . $theFile . '" "' . $newFile . '"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']);
                                exec($cmd);
                                if (@is_file($newFile)) {
+                                       self::fixPermissions($newFile);
                                        return $newFile;
                                }
                        }
@@ -5996,6 +6005,7 @@ final class t3lib_div {
                                        fwrite($file, date($dateFormat . ' ' . $timeFormat) . $msgLine . LF);
                                        flock($file, LOCK_UN); // release the lock
                                        fclose($file);
+                                       self::fixPermissions($destination);
                                }
                        }
                                // send message per mail
@@ -6075,6 +6085,7 @@ final class t3lib_div {
                                @fwrite($file, $date . $msg . LF);
                                flock($file, LOCK_UN); // release the lock
                                @fclose($file);
+                               self::fixPermissions($destination);
                        }
                }
 
index f38b4ff..9c9333f 100644 (file)
@@ -600,6 +600,9 @@ final class t3lib_iconWorks {
                } else {
                        @ImageGif($im, $path);
                }
+               if (@is_file($path)) {
+                       t3lib_div::fixPermissions($path);
+               }
        }
 
 
index b5e0eb3..cfb0b3d 100644 (file)
@@ -159,6 +159,8 @@ class t3lib_lock {
                                if (!$isAcquired) {
                                        throw new Exception('Lock file could not be created');
                                }
+
+                               t3lib_div::fixPermissions($this->resource);
                        break;
                        case 'flock':
                                if (($this->filepointer = fopen($this->resource, 'w+')) == FALSE) {
index 9234ba0..852d08a 100644 (file)
@@ -243,6 +243,8 @@ class SC_t3lib_thumbs {
                                        exec($cmd);
                                        if (!file_exists($this->output))        {
                                                $this->errorGif('No thumb','generated!',basename($this->input));
+                                       } else {
+                                               t3lib_div::fixPermissions($this->output);
                                        }
                                }
                                        // The thumbnail is read and output to the browser
diff --git a/tests/t3lib/fixtures/clear.gif b/tests/t3lib/fixtures/clear.gif
new file mode 100644 (file)
index 0000000..b9fe5fc
Binary files /dev/null and b/tests/t3lib/fixtures/clear.gif differ
diff --git a/tests/t3lib/fixtures/clear.png b/tests/t3lib/fixtures/clear.png
new file mode 100644 (file)
index 0000000..7fbfc77
Binary files /dev/null and b/tests/t3lib/fixtures/clear.png differ
index e65a6c0..32fa165 100644 (file)
@@ -54,6 +54,131 @@ class t3lib_divTest extends tx_phpunit_testcase {
 
 
        ///////////////////////////////
+       // Tests concerning gif_compress
+       ///////////////////////////////
+
+       /**
+        * @test
+        */
+       public function gifCompressFixesPermissionOfConvertedFileIfUsingImagemagick() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('gifCompressFixesPermissionOfConvertedFileIfUsingImagemagick() test not available on Windows.');
+               }
+
+               if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] || !$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']) {
+                       $this->markTestSkipped('gifCompressFixesPermissionOfConvertedFileIfUsingImagemagick() test not available without imagemagick setup.');
+               }
+
+               $fixtureGifFile = dirname(__FILE__) . '/fixtures/clear.gif';
+
+               $GLOBALS['TYPO3_CONF_VARS']['GFX']['gif_compress'] = TRUE;
+
+                       // Copy file to unique filename in typo3temp, set target permissions and run method
+               $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif';
+               @copy($fixtureGifFile, $testFilename);
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
+               t3lib_div::gif_compress($testFilename, 'IM');
+
+                       // Get actual permissions and clean up
+               clearstatcache();
+               $resultFilePermissions = substr(decoct(fileperms($testFilename)), 2);
+               t3lib_div::unlink_tempfile($testFilename);
+
+               $this->assertEquals($resultFilePermissions, '0777');
+       }
+
+       /**
+        * @test
+        */
+       public function gifCompressFixesPermissionOfConvertedFileIfUsingGd() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('gifCompressFixesPermissionOfConvertedFileIfUsingImagemagick() test not available on Windows.');
+               }
+
+               $fixtureGifFile = dirname(__FILE__) . '/fixtures/clear.gif';
+
+               $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] = TRUE;
+               $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] = FALSE;
+
+                       // Copy file to unique filename in typo3temp, set target permissions and run method
+               $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif';
+               @copy($fixtureGifFile, $testFilename);
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
+               t3lib_div::gif_compress($testFilename, 'GD');
+
+                       // Get actual permissions and clean up
+               clearstatcache();
+               $resultFilePermissions = substr(decoct(fileperms($testFilename)), 2);
+               t3lib_div::unlink_tempfile($testFilename);
+
+               $this->assertEquals($resultFilePermissions, '0777');
+       }
+
+       ///////////////////////////////
+       // Tests concerning png_to_gif_by_imagemagick
+       ///////////////////////////////
+
+       /**
+        * @test
+        */
+       public function pngToGifByImagemagickFixesPermissionsOfConvertedFile() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('pngToGifByImagemagickFixesPermissionsOfConvertedFile() test not available on Windows.');
+               }
+
+               if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] || !$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']) {
+                       $this->markTestSkipped('pngToGifByImagemagickFixesPermissionsOfConvertedFile() test not available without imagemagick setup.');
+               }
+
+               $fixturePngFile = dirname(__FILE__) . '/fixtures/clear.png';
+
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['png_to_gif'] = TRUE;
+
+                       // Copy file to unique filename in typo3temp, set target permissions and run method
+               $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.png';
+               @copy($fixturePngFile, $testFilename);
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
+               $newGifFile = t3lib_div::png_to_gif_by_imagemagick($testFilename);
+
+                       // Get actual permissions and clean up
+               clearstatcache();
+               $resultFilePermissions = substr(decoct(fileperms($newGifFile)), 2);
+               t3lib_div::unlink_tempfile($newGifFile);
+
+               $this->assertEquals($resultFilePermissions, '0777');
+       }
+
+       ///////////////////////////////
+       // Tests concerning read_png_gif
+       ///////////////////////////////
+
+       /**
+        * @test
+        */
+       public function readPngGifFixesPermissionsOfConvertedFile() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('readPngGifFixesPermissionsOfConvertedFile() test not available on Windows.');
+               }
+
+               if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
+                       $this->markTestSkipped('readPngGifFixesPermissionsOfConvertedFile() test not available without imagemagick setup.');
+               }
+
+               $testGifFile = dirname(__FILE__) . '/fixtures/clear.gif';
+
+                       // Set target permissions and run method
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
+               $newPngFile = t3lib_div::read_png_gif($testGifFile, TRUE);
+
+                       // Get actual permissions and clean up
+               clearstatcache();
+               $resultFilePermissions = substr(decoct(fileperms($newPngFile)), 2);
+               t3lib_div::unlink_tempfile($newPngFile);
+
+               $this->assertEquals($resultFilePermissions, '0777');
+       }
+
+       ///////////////////////////////
        // Tests concerning validIP
        ///////////////////////////////
 
@@ -2103,5 +2228,59 @@ class t3lib_divTest extends tx_phpunit_testcase {
        public function verifyFilenameAgainstDenyPatternDetectsNullCharacter() {
                $this->assertFalse(t3lib_div::verifyFilenameAgainstDenyPattern("image\x00.gif"));
        }
+
+
+       /////////////////////////////////////////////////////////////////////////////////////
+       // Tests concerning sysLog
+       /////////////////////////////////////////////////////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function syslogFixesPermissionsOnFileIfUsingFileLogging() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('syslogFixesPermissionsOnFileIfUsingFileLogging() test not available on Windows.');
+               }
+
+                       // Fake all required settings
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'] = 0;
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogInit'] = TRUE;
+               unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog']);
+               $testLogFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.txt';
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLog'] = 'file,' . $testLogFilename . ',0';
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
+
+                       // Call method, get actual permissions and clean up
+               t3lib_div::syslog('testLog', 'test', 1);
+               clearstatcache();
+               $resultFilePermissions = substr(decoct(fileperms($testLogFilename)), 2);
+               t3lib_div::unlink_tempfile($testLogFilename);
+
+               $this->assertEquals($resultFilePermissions, '0777');
+       }
+
+       /**
+        * @test
+        */
+       public function deprecationLogFixesPermissionsOnLogFile() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('deprecationLogFixesPermissionsOnLogFile() test not available on Windows.');
+               }
+
+                       // Fake all required settings and get an unique logfilename
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = uniqid('test_');
+               $deprecationLogFilename = t3lib_div::getDeprecationLogFileName();
+               print_r($deprecationLogFilename);
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog'] = TRUE;
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
+
+                       // Call method, get actual permissions and clean up
+               t3lib_div::deprecationLog('foo');
+               clearstatcache();
+               $resultFilePermissions = substr(decoct(fileperms($deprecationLogFilename)), 2);
+               @unlink($deprecationLogFilename);
+
+               $this->assertEquals($resultFilePermissions, '0777');
+       }
 }
 ?>
index d1dbdc6..d30e9ee 100644 (file)
  * @subpackage t3lib
  */
 class t3lib_iconWorksTest extends tx_phpunit_testcase {
+
+       /**
+        * Enable backup of global and system variables
+        *
+        * @var boolean
+        */
+       protected $backupGlobals = TRUE;
+       
+       /**
+        * Exclude TYPO3_DB from backup/restore of $GLOBALS
+        * because resource types cannot be handled during serializing
+        *
+        * @var array
+        */
+       protected $backupGlobalsBlacklist = array('TYPO3_DB');
+
        /**
         * @var array
         */
@@ -65,6 +81,33 @@ class t3lib_iconWorksTest extends tx_phpunit_testcase {
 
 
        //////////////////////////////////////////
+       // Tests concerning imagemake
+       //////////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function imagemakeFixesPermissionsOnNewFiles() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('imagemakeFixesPermissionsOnNewFiles() test not available on Windows.');
+               }
+
+               $fixtureGifFile = dirname(__FILE__) . '/fixtures/clear.gif';
+
+                       // Create image ressource, determine target filename, fake target permission, run method and clean up
+               $fixtureGifRessource = imagecreatefromgif($fixtureGifFile);
+               $targetFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif';
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';
+               t3lib_iconWorks::imagemake($fixtureGifRessource, $targetFilename);
+               clearstatcache();
+               $resultFilePermissions = substr(decoct(fileperms($targetFilename)), 2);
+               t3lib_div::unlink_tempfile($targetFilename);
+
+               $this->assertEquals($resultFilePermissions, '0777');
+       }
+
+
+       //////////////////////////////////////////
        // Tests concerning getSpriteIconClasses
        //////////////////////////////////////////
 
diff --git a/tests/t3lib/t3lib_lockTest.php b/tests/t3lib/t3lib_lockTest.php
new file mode 100644 (file)
index 0000000..daaddd7
--- /dev/null
@@ -0,0 +1,77 @@
+<?php\r
+/***************************************************************\r
+ *  Copyright notice\r
+ *\r
+ *  (c) 2010 Christian Kuhn <lolli@schwarzbu.ch>\r
+ *  All rights reserved\r
+ *\r
+ *  This script is part of the TYPO3 project. The TYPO3 project is\r
+ *  free software; you can redistribute it and/or modify\r
+ *  it under the terms of the GNU General Public License as published by\r
+ *  the Free Software Foundation; either version 2 of the License, or\r
+ *  (at your option) any later version.\r
+ *\r
+ *  The GNU General Public License can be found at\r
+ *  http://www.gnu.org/copyleft/gpl.html.\r
+ *\r
+ *  This script is distributed in the hope that it will be useful,\r
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *  GNU General Public License for more details.\r
+ *\r
+ *  This copyright notice MUST APPEAR in all copies of the script!\r
+ ***************************************************************/\r
+\r
+/**\r
+ * Testcase for t3lib_lock\r
+ *\r
+ * @author Christian Kuhn <lolli@schwarzbu.ch>\r
+ *\r
+ * @package TYPO3\r
+ * @subpackage t3lib\r
+ */\r
+\r
+class t3lib_lockTest extends tx_phpunit_testcase {\r
+\r
+       /**\r
+        * Enable backup of global and system variables\r
+        *\r
+        * @var boolean\r
+        */\r
+       protected $backupGlobals = TRUE;\r
+       \r
+       /**\r
+        * Exclude TYPO3_DB from backup/ restore of $GLOBALS\r
+        * because resource types cannot be handled during serializing\r
+        *\r
+        * @var array\r
+        */\r
+       protected $backupGlobalsBlacklist = array('TYPO3_DB');\r
+\r
+       ///////////////////////////////\r
+       // tests concerning acquire\r
+       ///////////////////////////////a\r
+\r
+       /**\r
+        * @test\r
+        */\r
+       public function acquireFixesPermissionsOnLockFileIfUsingSimpleLogging() {\r
+               if (TYPO3_OS == 'WIN') {\r
+                       $this->markTestSkipped('acquireFixesPermissionsOnLockFileIfUsingSimpleLogging() test not available on Windows.');\r
+               }\r
+\r
+                       // Use a very high id to be unique\r
+               $instance = new t3lib_lock(999999999, 'simple');\r
+               $pathOfLockFile = $instance->getResource();\r
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777';\r
+\r
+                       // Acquire lock, get actual file permissions and clean up\r
+               $instance->acquire();\r
+               clearstatcache();\r
+               $resultFilePermissions = substr(decoct(fileperms($pathOfLockFile)), 2);\r
+               $instance->__destruct();\r
+\r
+               $this->assertEquals($resultFilePermissions, '0777');\r
+       }\r
+}\r
+?>\r