From 7df3f37295ed548fbded2896f8e4b5bf80b4778c Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Fri, 9 Oct 2009 07:48:07 +0000 Subject: #67234 by Ralf, Dave Reid, David_Rothstein, Rob Loach, dww, et al: Added a permission to update.php. --- update.php | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'update.php') diff --git a/update.php b/update.php index a5af15854..18612a50a 100644 --- a/update.php +++ b/update.php @@ -13,10 +13,11 @@ define('DRUPAL_ROOT', getcwd()); * Point your browser to "http://www.example.com/update.php" and follow the * instructions. * - * If you are not logged in using the site maintenance account, you will need - * to modify the access check statement inside your settings.php file. After - * finishing the upgrade, be sure to open settings.php again, and change it back - * to its original state! + * If you are not logged in using either the site maintenance account or an + * account with the "Administer software updates" permission, you will need to + * modify the access check statement inside your settings.php file. After + * finishing the upgrade, be sure to open settings.php again, and change it + * back to its original state! */ /** @@ -99,7 +100,6 @@ function update_script_selection_form() { return $form; } - function update_helpful_links() { // NOTE: we can't use l() here because the URL would point to 'update.php?q=admin'. $links[] = 'Front page'; @@ -201,16 +201,42 @@ function update_info_page() { } function update_access_denied_page() { + drupal_add_http_header('403 Forbidden'); + watchdog('access denied', 'update.php', NULL, WATCHDOG_WARNING); drupal_set_title('Access denied'); - return '

Access denied. You are not authorized to access this page. Please log in using the site maintenance account (the account you created during installation). If you cannot log in, you will have to edit settings.php to bypass this access check. To do this:

+ return '

Access denied. You are not authorized to access this page. Please log in using either an account with the administer software updates permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to edit settings.php to bypass this access check. To do this:

  1. With a text editor find the settings.php file on your system. From the main Drupal directory that you installed all the files into, go to sites/your_site_name if such directory exists, or else to sites/default which applies otherwise.
  2. There is a line inside your settings.php file that says $update_free_access = FALSE;. Change it to $update_free_access = TRUE;.
  3. As soon as the update.php script is done, you must change the settings.php file back to its original form with $update_free_access = FALSE;.
  4. -
  5. To avoid having this problem in the future, remember to log in to your website using the site maintenance account (the account you created during installation) before you backup your database at the beginning of the update process.
  6. +
  7. To avoid having this problem in the future, remember to log in to your website using either an account with the administer software updates permission or the site maintenance account (the account you created during installation) before you backup your database at the beginning of the update process.
'; } +/** + * Determines if the current user is allowed to run update.php. + * + * @return + * TRUE if the current user should be granted access, or FALSE otherwise. + */ +function update_access_allowed() { + global $update_free_access, $user; + + // Allow the global variable in settings.php to override the access check. + if (!empty($update_free_access)) { + return TRUE; + } + // Calls to user_access() might fail during the Drupal 6 to 7 update process, + // so we fall back on requiring that the user be logged in as user #1. + try { + require_once drupal_get_path('module', 'user') . '/user.module'; + return user_access('administer software updates'); + } + catch (Exception $e) { + return ($user->uid == 1); + } +} + /** * Add the update task list to the current page. */ @@ -273,13 +299,12 @@ update_prepare_d7_bootstrap(); // Determine if the current user has access to run update.php. drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); -$update_access_allowed = !empty($update_free_access) || $user->uid == 1; // Only allow the requirements check to proceed if the current user has access // to run updates (since it may expose sensitive information about the site's // configuration). $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : ''; -if (empty($op) && $update_access_allowed) { +if (empty($op) && update_access_allowed()) { require_once DRUPAL_ROOT . '/includes/install.inc'; require_once DRUPAL_ROOT . '/includes/file.inc'; require_once DRUPAL_ROOT . '/modules/system/system.install'; @@ -317,7 +342,7 @@ drupal_maintenance_theme(); ini_set('display_errors', TRUE); // Only proceed with updates if the user is allowed to run them. -if ($update_access_allowed) { +if (update_access_allowed()) { include_once DRUPAL_ROOT . '/includes/install.inc'; include_once DRUPAL_ROOT . '/includes/batch.inc'; -- cgit v1.2.3