/** * Method to determine if script owns the path. * * @param string $path Path to check ownership. * * @return boolean True if the php script owns the path passed. * * @since 11.1 */ public static function isOwner($path) { jimport('joomla.filesystem.file'); $tmp = md5(JCrypt::genRandomBytes()); $ssp = ini_get('session.save_path'); $jtp = JPATH_SITE . '/tmp'; // Try to find a writable directory $dir = false; foreach (array($jtp, $ssp, '/tmp') as $currentDir) { if (is_writable($currentDir)) { $dir = $currentDir; break; } } if ($dir) { $fileObject = new JFilesystemWrapperFile(); $test = $dir . '/' . $tmp; // Create the test file $blank = ''; $fileObject->write($test, $blank, false); // Test ownership $return = fileowner($test) == fileowner($path); // Delete the test file $fileObject->delete($test); return $return; } return false; }
/** * Method to determine if script owns the path. * * @param string $path Path to check ownership. * * @return boolean True if the php script owns the path passed. * * @since 11.1 */ public static function isOwner($path) { jimport('joomla.filesystem.file'); $tmp = md5(JCrypt::genRandomBytes()); $ssp = ini_get('session.save_path'); $jtp = JPATH_SITE . '/tmp'; // Try to find a writable directory $dir = is_writable('/tmp') ? '/tmp' : false; $dir = !$dir && is_writable($ssp) ? $ssp : false; $dir = !$dir && is_writable($jtp) ? $jtp : false; if ($dir) { $fileObject = new JFilesystemWrapperFile(); $test = $dir . '/' . $tmp; // Create the test file $blank = ''; $fileObject->write($test, $blank, false); // Test ownership $return = fileowner($test) == fileowner($path); // Delete the test file $fileObject->delete($test); return $return; } return false; }