=== modified file 'includes/menu.inc'
--- includes/menu.inc	2007-12-22 23:24:24 +0000
+++ includes/menu.inc	2007-12-23 01:59:14 +0000
@@ -333,8 +333,12 @@ function menu_get_item($path = NULL, $ro
  * Execute the page callback associated with the current path
  */
 function menu_execute_active_handler($path = NULL) {
-  if (_menu_site_is_offline()) {
-    return MENU_SITE_OFFLINE;
+  if ($return = _menu_site_is_offline()) {
+    if ($return === TRUE) {
+      return MENU_SITE_OFFLINE;
+    }
+    // The function might return 'logout', let's use that.
+    $path = $return;
   }
   if ($router_item = menu_get_item($path)) {
     if ($router_item['access']) {
@@ -2228,19 +2232,19 @@ function menu_path_is_external($path) {
 }
 
 /**
- * Returns TRUE if the site is off-line for maintenance.
+ * Checks whether the site is off-line for maintenance.
+ *
+ * @return
+ *   FALSE if the site is not off-line or its the login page or the user has
+ *     'administer site configuration' permission.
+ *   'logout' if an unprivileged user is logged in,
+ *   TRUE for anonymous users if the site is off-line.
  */
 function _menu_site_is_offline() {
   // Check if site is set to off-line mode.
   if (variable_get('site_offline', 0)) {
     // Check if the user has administration privileges.
-    if (!user_access('administer site configuration')) {
-      // Check if this is an attempt to login.
-      if (drupal_get_normal_path($_GET['q']) != 'user') {
-        return TRUE;
-      }
-    }
-    else {
+    if (user_access('administer site configuration')) {
       $offline_message = t('Operating in off-line mode.');
       $messages = drupal_set_message();
       // Ensure that the off-line message is displayed only once [allowing for
@@ -2249,6 +2253,11 @@ function _menu_site_is_offline() {
         drupal_set_message($offline_message);
       }
     }
+    else {
+      // Anonymous users get a FALSE at the login prompt, TRUE otherwise.
+      // Logged in users are unprivileged here, so they are logged out.
+      return user_is_anonymous() ? ($_GET['q'] != 'user' && $_GET['q'] != 'user/login') : 'logout';
+    }
   }
   return FALSE;
 }

