Insure that cron always runs as the anonymous user.

From: Damien Tournoud <damien@tournoud.net>


---

 includes/common.inc |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)


diff --git includes/common.inc includes/common.inc
index 8c53f93..3b3cdb8 100644
--- includes/common.inc
+++ includes/common.inc
@@ -3618,6 +3618,14 @@ function drupal_cron_run() {
   // Allow execution to continue even if the request gets canceled.
   @ignore_user_abort(TRUE);
 
+  // Prevent session information from being saved while the cron is running.
+  drupal_save_session(FALSE);
+
+  // Force the current user to anonymous to ensure consistent permissions on
+  // cron runs.
+  $original_user = $GLOBALS['user'];
+  $GLOBALS['user'] = drupal_anonymous_user();
+
   // Try to allocate enough time to run all the hook_cron implementations.
   drupal_set_time_limit(240);
 
@@ -3658,6 +3666,12 @@ function drupal_cron_run() {
     // Return TRUE so other functions can check if it did run successfully
     return TRUE;
   }
+
+  // Restore the user.
+  $GLOBALS['user'] = $original_user;
+  drupal_save_session(TRUE);
+
+  return $success;
 }
 
 /**
