Fixed bug #16134: TYPO3 doesn't always fix permissions for new files
authorTolleiv Nietsch <info@tolleiv.de>
Mon, 20 Dec 2010 19:39:08 +0000 (19:39 +0000)
committerTolleiv Nietsch <info@tolleiv.de>
Mon, 20 Dec 2010 19:39:08 +0000 (19:39 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-4@9862 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 a2941b5..a35e0d8 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-19  Steffen Gebert  <steffen@steffen-gebert.de>
 
        * Fixed bug #16777: Test failure in t3lib_extmgmTest if tests are located in typo3_src/tests/ instead of tests/ (Thanks to Oliver Klee)
index e8a5594..751e957 100644 (file)
@@ -466,11 +466,17 @@ final class t3lib_div {
                                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;
@@ -494,6 +500,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;
@@ -520,7 +529,10 @@ final class t3lib_div {
                                $newFile = PATH_site.'typo3temp/readPG_'.md5($theFile.'|'.filemtime($theFile)).($output_png?'.png':'.gif');
                                $cmd = self::imageMagickCommand('convert', '"'.$theFile.'" "'.$newFile.'"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']);
                                exec($cmd);
-                               if (@is_file($newFile)) return $newFile;
+                               if (@is_file($newFile)) {
+                                       self::fixPermissions($newFile);
+                                       return $newFile;
+                               }
                        }
                }
        }
@@ -5738,6 +5750,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
@@ -5817,6 +5830,7 @@ final class t3lib_div {
                                @fwrite($file, $date . $msg . LF);
                                flock($file, LOCK_UN);    // release the lock
                                @fclose($file);
+                               self::fixPermissions($destination);
                        }
                }
 
index beea02d..0280948 100644 (file)
@@ -597,6 +597,9 @@ final class t3lib_iconWorks {
                } else {
                        @ImageGif($im, $path);
                }
+               if (@is_file($path)) {
+                       t3lib_div::fixPermissions($path);
+               }
        }
 
 
index ad7abb1..1e69a30 100644 (file)
@@ -169,6 +169,8 @@ class t3lib_lock {
                                if (($this->filepointer = touch($this->resource)) == FALSE) {
                                        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 628e180..4304f41 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 aeac59a..c93a833 100644 (file)
@@ -40,6 +40,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
        ///////////////////////////////
 
@@ -1803,5 +1928,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');
+       }
 }
 ?>
\ No newline at end of file
index a16306c..2e610c5 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