Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.554
diff -u -F^f -r1.554 common.inc
--- includes/common.inc	10 Aug 2006 15:42:32 -0000	1.554
+++ includes/common.inc	12 Aug 2006 14:05:12 -0000
@@ -1546,6 +1546,8 @@ function drupal_mail($mailkey, $to, $sub
  * Returns TRUE if ran successfully
  */
 function drupal_cron_run() {
+  global $user;
+
   // If not in 'safe mode', increase the maximum execution time:
   if (!ini_get('safe_mode')) {
     set_time_limit(240);
@@ -1559,6 +1561,11 @@ function drupal_cron_run() {
     variable_set('cron_busy', TRUE);
   }
 
+  // If running as an anonymous user, give the user the desired privileges to do the cron work
+  if ($user->uid == 0) {
+    $user->roles = variable_get('cron_user_roles', array(DRUPAL_ANONYMOUS_RID, 'anonymous user'));
+  }
+
   // Iterate through the modules calling their cron handlers (if any):
   module_invoke_all('cron');
 
@@ -1567,6 +1574,11 @@ function drupal_cron_run() {
   variable_set('cron_last', time());
   watchdog('cron', t('Cron run completed.'), WATCHDOG_NOTICE);
 
+  // end this session if anonymous so that we don't have an anonymous user with extra privileges
+  if ($user->uid == 0) {
+    sess_destroy(session_id());
+  }
+
   // Return TRUE so other functions can check if it did run successfully
   return TRUE;
 }
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.341
diff -u -F^f -r1.341 system.module
--- modules/system/system.module	10 Aug 2006 15:42:33 -0000	1.341
+++ modules/system/system.module	12 Aug 2006 14:05:17 -0000
@@ -774,7 +774,19 @@ function system_cron_status($cron = '') 
   }
   $status .= ' '. t('Cron can, if necessary, also be run <a href="%cron">manually</a>.', array('%cron' => url('admin/settings/cron-status/cron')));
 
-  return $status;
+  $form['cron_status'] = array(
+    '#type' => 'markup',
+    '#value' => $status,
+  );
+  $form['cron_user_roles'] = array(
+    '#type' => 'select',
+    '#title' => t('Cron user roles'),
+    '#default_value' => variable_get('cron_user_roles', array(DRUPAL_ANONYMOUS_RID, 'anonymous user')),
+    '#options' => user_roles(),
+    '#multiple' => true,
+    '#description' => t('Choose which user roles the cron user should have when it runs. For most cases <code>anonymous user</code> is adequate. Only change this setting if a particular module has instructed you to do so.'),
+  );
+  return system_settings_form('system_cron_settings', $form);
 }
 
 /**
