Index: modules/user/user.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.admin.inc,v
retrieving revision 1.40
diff -u -p -r1.40 user.admin.inc
--- modules/user/user.admin.inc	26 Feb 2009 07:30:28 -0000	1.40
+++ modules/user/user.admin.inc	7 Mar 2009 20:37:48 -0000
@@ -546,8 +546,14 @@ function user_admin_perm($form_state, $r
   // Retrieve role names for columns.
   $role_names = user_roles();
   if (is_numeric($rid)) {
+    // Include js to show custom roles have access to authenticated user permsissions.
+    if ($rid > 2) {  
+      $authenticated_permissions = user_role_permissions(array('2' => $role_names[2]));
+      drupal_add_js(array('user' => array('authPermissions' => $authenticated_permissions)), 'setting');
+    }
     $role_names = array($rid => $role_names[$rid]);
   }
 
@@ -581,14 +587,21 @@ function user_admin_perm($form_state, $r
       }
     }
   }
-
   // Have to build checkboxes here after checkbox arrays are built
   foreach ($role_names as $rid => $name) {
-    $form['checkboxes'][$rid] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => isset($status[$rid]) ? $status[$rid] : array());
+    $form['checkboxes'][$rid] = array(
+      '#type' => 'checkboxes', 
+      '#options' => $options, 
+      '#default_value' => isset($status[$rid]) ? $status[$rid] : array(),
+    );
     $form['role_names'][$rid] = array('#markup' => $name, '#tree' => TRUE);
   }
   $form['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
 
+  // Custom roles inherit checked permissions from authenticated users.
+  drupal_add_js(drupal_get_path('module', 'user') . '/user.js');
+  drupal_add_js(array('user' => array('accessControl' => array())), 'setting');
+  
   return $form;
 }
 
Index: modules/user/user.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.js,v
retrieving revision 1.10
diff -u -p -r1.10 user.js
--- modules/user/user.js	18 Feb 2009 13:46:55 -0000	1.10
+++ modules/user/user.js	7 Mar 2009 20:37:48 -0000
@@ -173,4 +173,63 @@ Drupal.behaviors.userSettings = {
   }
 };
 
+/**
+ * On the admin/user/permissions page, check and disable permissions for 
+ * custom roles when the authenticated user role is given a permission.
+ */
+Drupal.behaviors.permissions = {
+  attach: function(context) {
+    var settings = Drupal.settings.user.accessControl;
+    var authPermissions = Drupal.settings.user.authPermissions;
+    
+    // Store the state of checked permissions for custom roles.
+    $('#permissions input').each(function() {
+      var matches = this.id.match(/^edit-(\d+?)-(.*)$/i);
+      if (matches[1] > 2) { // all custom roles
+        if (!settings[matches[2]]) settings[matches[2]] = {};
+        settings[matches[2]][matches[1]] = this.checked; 
+        $(this).change(Drupal.accessControlUpdate);
+        
+        // If we are on a role-specific permisisons page, 
+        // check and disable permisisons inherited from authenticated role.
+        if (authPermissions) {
+          if (authPermissions[2][this.value]) {
+            this.checked = true;
+            this.disabled = true;
+          }
+        }      
+      }
+    });
+    
+    // Check and disable custom permissions when authenticated permission is checked.
+    $('#permissions input[@id^="edit-2-"]').each(function() {
+      $(this).change(Drupal.accessControlToggle);
+      Drupal.accessControlToggle.apply(this);
+    });
+  }
+}
+
+/**
+ * Callback function that is attached to a change of a checkbox of the "authenticated user" column.
+ * It changes the state of all custom roles to either checked or the previous state.
+ */
+Drupal.accessControlToggle = function() {
+  var matches = this.id.match(/^edit-(\d+?)-(.*)$/i), roles = Drupal.settings.user.accessControl[matches[2]];
+  
+  for (var i in roles) {
+    var checkbox = document.getElementById('edit-' + i + '-' + matches[2]);
+    checkbox.disabled = this.checked;
+    checkbox.checked = this.checked ? true : roles[i];
+  }
+};
+
+/**
+ * Updates the status of a custom role in the array when the user changes the permission checkbox.
+ * This allows the status to persist if the authenticated permission is checked and then unchecked.
+ */
+Drupal.accessControlUpdate = function() {
+  var matches = this.id.match(/^edit-(\d+?)-(.*)$/i);
+  Drupal.settings.user.accessControl[matches[2]][matches[1]] = this.checked;
+}
+
 })(jQuery);
