diff --git a/core/includes/file.inc b/core/includes/file.inc index f141cc8..cf67045 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -557,7 +557,7 @@ function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS) return FALSE; } // The directory exists, so check to see if it is writable. - $writable = is_writable($directory); + $writable = file_directory_is_writable($directory); if (!$writable && ($options & FILE_MODIFY_PERMISSIONS)) { return drupal_chmod($directory); } @@ -566,6 +566,46 @@ function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS) } /** + * Determines if a directory is writable by the web server. + * + * In order to be able to write files within the directory, the directory + * itself must be writable, and it must also have the executable bit set. This + * helper function checks both at the same time. + * + * @param $uri + * A URI or pathname pointing to the directory that will be checked. + * + * @return + * TRUE if the directory is writable and executable; FALSE otherwise. + */ +function file_directory_is_writable($uri) { + // By converting the URI to a normal path using drupal_realpath(), we can + // correctly handle both stream wrappers and normal paths. + return is_writable(drupal_realpath($uri)) && drupal_is_executable($uri); +} + +/** + * Determines if a file or directory is executable. + * + * PHP's is_executable() does not fully support stream wrappers, so this + * function fills that gap. + * + * @param $uri + * A URI or pathname pointing to the file or directory that will be checked. + * + * @return + * TRUE if the file or directory is executable; FALSE otherwise. + * + * @see is_executable() + * @ingroup php_wrappers + */ +function drupal_is_executable($uri) { + // By converting the URI to a normal path using drupal_realpath(), we can + // correctly handle both stream wrappers and normal paths. + return is_executable(drupal_realpath($uri)); +} + +/** * Creates a .htaccess file in each Drupal files directory if it is missing. */ function file_ensure_htaccess() { @@ -607,7 +647,7 @@ function file_save_htaccess($directory, $private = TRUE, $force_overwrite = FALS $htaccess_lines = file_htaccess_lines($private); // Write the .htaccess file. - if (file_exists($directory) && is_writable($directory) && file_put_contents($htaccess_path, $htaccess_lines)) { + if (file_exists($directory) && file_directory_is_writable($directory) && file_put_contents($htaccess_path, $htaccess_lines)) { return drupal_chmod($htaccess_path, 0444); } else { @@ -1700,7 +1740,7 @@ function file_directory_os_temp() { $directories[] = sys_get_temp_dir(); foreach ($directories as $directory) { - if (is_dir($directory) && is_writable($directory)) { + if (is_dir($directory) && file_directory_is_writable($directory)) { return $directory; } } diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index aa158a2..a59a486 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -2106,7 +2106,7 @@ function install_check_translations($install_state) { // Get values so the requirements errors can be specific. if (drupal_verify_install_file($translations_directory, FILE_EXIST|FILE_WRITABLE, 'dir')) { $readable = is_readable($translations_directory); - $writable = is_writable($translations_directory); + $writable = file_directory_is_writable($translations_directory); $translations_directory_exists = TRUE; } @@ -2276,7 +2276,7 @@ function install_check_requirements($install_state) { // Otherwise, if settings.php does not exist yet, we can try to copy // default.settings.php to create it. elseif (!$exists) { - $copied = drupal_verify_install_file($conf_path, FILE_EXIST|FILE_WRITABLE, 'dir') && @copy($default_settings_file, $settings_file); + $copied = drupal_verify_install_file($conf_path, FILE_EXIST|FILE_WRITABLE|FILE_EXECUTABLE, 'dir') && @copy($default_settings_file, $settings_file); if ($copied) { // If the new settings file has the same owner as default.settings.php, // this means default.settings.php is owned by the webserver user. diff --git a/core/includes/install.inc b/core/includes/install.inc index e7e5206..dd1740f 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -539,7 +539,7 @@ function install_verify_config_directory($type) { // prepared settings.php that defines $config_directories already. try { $config_directory = config_get_config_directory($type); - if (is_dir($config_directory) && is_writable($config_directory)) { + if (is_dir($config_directory) && file_directory_is_writable($config_directory)) { return TRUE; } } @@ -735,12 +735,12 @@ function drupal_verify_install_file($file, $mask = NULL, $type = 'file') { } break; case FILE_WRITABLE: - if (!is_writable($file) && !drupal_install_fix_file($file, $mask)) { + if (!file_directory_is_writable($file) && !drupal_install_fix_file($file, $mask)) { $return = FALSE; } break; case FILE_EXECUTABLE: - if (!is_executable($file) && !drupal_install_fix_file($file, $mask)) { + if (!drupal_is_executable($file) && !drupal_install_fix_file($file, $mask)) { $return = FALSE; } break; @@ -750,12 +750,12 @@ function drupal_verify_install_file($file, $mask = NULL, $type = 'file') { } break; case FILE_NOT_WRITABLE: - if (is_writable($file) && !drupal_install_fix_file($file, $mask)) { + if (file_directory_is_writable($file) && !drupal_install_fix_file($file, $mask)) { $return = FALSE; } break; case FILE_NOT_EXECUTABLE: - if (is_executable($file) && !drupal_install_fix_file($file, $mask)) { + if (drupal_is_executable($file) && !drupal_install_fix_file($file, $mask)) { $return = FALSE; } break; @@ -850,12 +850,12 @@ function drupal_install_fix_file($file, $mask, $message = TRUE) { } break; case FILE_WRITABLE: - if (!is_writable($file)) { + if (!file_directory_is_writable($file)) { $mod |= 0222; } break; case FILE_EXECUTABLE: - if (!is_executable($file)) { + if (!drupal_is_executable($file)) { $mod |= 0111; } break; @@ -865,12 +865,12 @@ function drupal_install_fix_file($file, $mask, $message = TRUE) { } break; case FILE_NOT_WRITABLE: - if (is_writable($file)) { + if (file_directory_is_writable($file)) { $mod &= ~0222; } break; case FILE_NOT_EXECUTABLE: - if (is_executable($file)) { + if (drupal_is_executable($file)) { $mod &= ~0111; } break; diff --git a/core/lib/Drupal/Core/Updater/Updater.php b/core/lib/Drupal/Core/Updater/Updater.php index abd7686..ff1ca50 100644 --- a/core/lib/Drupal/Core/Updater/Updater.php +++ b/core/lib/Drupal/Core/Updater/Updater.php @@ -273,7 +273,7 @@ public function prepareInstallDirectory(&$filetransfer, $directory) { // Make the parent dir writable if need be and create the dir. if (!is_dir($directory)) { $parent_dir = dirname($directory); - if (!is_writable($parent_dir)) { + if (!file_directory_is_writable($parent_dir)) { @chmod($parent_dir, 0755); // It is expected that this will fail if the directory is owned by the // FTP user. If the FTP user == web server, it will succeed. @@ -315,7 +315,7 @@ public function prepareInstallDirectory(&$filetransfer, $directory) { * If the chmod should be applied recursively. */ public function makeWorldReadable(&$filetransfer, $path, $recursive = TRUE) { - if (!is_executable($path)) { + if (!drupal_is_executable($path)) { // Set it to read + execute. $new_perms = substr(sprintf('%o', fileperms($path)), -4, -1) . "5"; $filetransfer->chmod($path, intval($new_perms, 8), $recursive); diff --git a/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php b/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php index 2fb139a..dee8484 100644 --- a/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php +++ b/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php @@ -101,7 +101,7 @@ public function buildForm(array $form, array &$form_state) { ); $directory = 'public://'; - $is_writable = is_dir($directory) && is_writable($directory); + $is_writable = is_dir($directory) && file_directory_is_writable($directory); $disabled = !$is_writable; $disabled_message = ''; if (!$is_writable) { diff --git a/core/modules/system/system.install b/core/modules/system/system.install index ca5d128..31567d0 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -386,7 +386,7 @@ function system_requirements($phase) { if ($phase == 'install') { file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); } - $is_writable = is_writable($directory); + $is_writable = file_directory_is_writable($directory); $is_directory = is_dir($directory); if (!$is_writable || !$is_directory) { $description = ''; diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 7b35fca..1aac8a4 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1109,7 +1109,7 @@ function system_check_directory($form_element) { watchdog('file system', 'The directory %directory does not exist and could not be created.', array('%directory' => $directory), WATCHDOG_ERROR); } - if (is_dir($directory) && !is_writable($directory) && !drupal_chmod($directory)) { + if (is_dir($directory) && !file_directory_is_writable($directory) && !drupal_chmod($directory)) { // If the directory is not writable and cannot be made so. form_set_error($form_element['#parents'][0], $form_state, t('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory))); watchdog('file system', 'The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory), WATCHDOG_ERROR);