Commit 55890b47 authored by catch's avatar catch

Issue #2110863 by sun, cpj: Support open_basedir.

parent c7edf435
...@@ -1497,6 +1497,9 @@ function drupal_basename($uri, $suffix = NULL) { ...@@ -1497,6 +1497,9 @@ function drupal_basename($uri, $suffix = NULL) {
* @see mkdir() * @see mkdir()
* @see http://drupal.org/node/515192 * @see http://drupal.org/node/515192
* @ingroup php_wrappers * @ingroup php_wrappers
*
* @todo Update with open_basedir compatible recursion logic from
* \Drupal\Component\PhpStorage\FileStorage::ensureDirectory().
*/ */
function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) { function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {
if (!isset($mode)) { if (!isset($mode)) {
......
...@@ -36,12 +36,6 @@ ...@@ -36,12 +36,6 @@
exit; exit;
} }
// Exit early if the PHP option open_basedir is enabled to avoid fatal errors.
if (ini_get('open_basedir')) {
print 'Your PHP installation has open_basedir enabled. Drupal currently requires the open_basedir option to be turned off. See the <a href="http://www.php.net/manual/en/ini.core.php#ini.open-basedir">PHP manual</a> for details of how to do this. This issue is currently <a href="https://drupal.org/node/2110863">under discussion at drupal.org</a>.';
exit;
}
// Start the installer. // Start the installer.
require_once __DIR__ . '/includes/install.core.inc'; require_once __DIR__ . '/includes/install.core.inc';
install_drupal(); install_drupal();
...@@ -58,31 +58,46 @@ public function save($name, $code) { ...@@ -58,31 +58,46 @@ public function save($name, $code) {
} }
/** /**
* Ensures the root directory exists and has the right permissions. * Ensures the requested directory exists and has the right permissions.
*
* For compatibility with open_basedir, the requested directory is created
* using a recursion logic that is based on the relative directory path/tree:
* It works from the end of the path recursively back towards the root
* directory, until an existing parent directory is found. From there, the
* subdirectories are created.
* *
* @param string $directory * @param string $directory
* The directory path. * The directory path.
*
* @param int $mode * @param int $mode
* The mode, permissions, the directory should have. * The mode, permissions, the directory should have.
* @param bool $is_backwards_recursive
* Internal use only.
*
* @return bool
* TRUE if the directory exists or has been created, FALSE otherwise.
*/ */
protected function ensureDirectory($directory, $mode = 0777) { protected function ensureDirectory($directory, $mode = 0777, $is_backwards_recursive = FALSE) {
if (!file_exists($directory)) { // If the directory exists already, there's nothing to do.
// mkdir() obeys umask() so we need to mkdir() and chmod() manually. if (is_dir($directory)) {
$parts = explode('/', $directory); return TRUE;
$path = ''; }
$delimiter = ''; // Otherwise, try to create the directory and ensure to set its permissions,
do { // because mkdir() obeys the umask of the current process.
$part = array_shift($parts); if (is_dir($parent = dirname($directory))) {
$path .= $delimiter . $part; // If the parent directory exists, then the backwards recursion must end,
$delimiter = '/'; // regardless of whether the subdirectory could be created.
// For absolute paths the first part will be empty. if ($status = mkdir($directory)) {
if ($part && !file_exists($path)) { // Only try to chmod() if the subdirectory could be created.
mkdir($path); $status = chmod($directory, $mode);
chmod($path, $mode); }
} return $is_backwards_recursive ? TRUE : $status;
} while ($parts);
} }
// If the parent directory and the requested directory does not exist and
// could not be created above, walk the requested directory path back up
// until an existing directory is hit, and from there, recursively create
// the sub-directories. Only if that recursion succeeds, create the final,
// originally requested subdirectory.
return $this->ensureDirectory($parent, $mode, TRUE) && mkdir($directory) && chmod($directory, $mode);
} }
/** /**
......
...@@ -510,7 +510,7 @@ protected function buildContainer() { ...@@ -510,7 +510,7 @@ protected function buildContainer() {
foreach (array('Core', 'Component') as $parent_directory) { foreach (array('Core', 'Component') as $parent_directory) {
$path = DRUPAL_ROOT . '/core/lib/Drupal/' . $parent_directory; $path = DRUPAL_ROOT . '/core/lib/Drupal/' . $parent_directory;
foreach (new \DirectoryIterator($path) as $component) { foreach (new \DirectoryIterator($path) as $component) {
if (!$component->isDot() && is_dir($component->getPathname() . '/Plugin')) { if (!$component->isDot() && $component->isDir() && is_dir($component->getPathname() . '/Plugin')) {
$namespaces['Drupal\\' . $parent_directory . '\\' . $component->getFilename()] = DRUPAL_ROOT . '/core/lib'; $namespaces['Drupal\\' . $parent_directory . '\\' . $component->getFilename()] = DRUPAL_ROOT . '/core/lib';
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment