Commit c3c3454e authored by paulvandenburg's avatar paulvandenburg
Browse files

Fix access bypass for admin pages when using DvG Domains

parent 9ef25daa
Loading
Loading
Loading
Loading
+0 −56
Original line number Diff line number Diff line
@@ -290,66 +290,10 @@ function dvg_domains_admin_menu_cache_cid_alter(&$cid) {
 * Implements hook_menu_alter().
 */
function dvg_domains_menu_alter(&$items) {
  foreach ($items as $path => $item) {
    $whitelisted_paths = drupal_match_path($path, implode("\n", array(
      'admin/content/scheduler',
      'admin/content/scheduler/*',
    )));
    $admin_paths = drupal_match_path($path, implode("\n", array(
      'admin',
      'admin/*',
    )));
    $admin_sub_paths = drupal_match_path($path, implode("\n", array(
      'admin/config',
      'admin/config/*',
      'admin/structure',
      'admin/structure/*',
      'admin/content/*',
    )));
    $views_protected_page = isset($item['access callback']) && $item['access callback'] == 'views_access';

    if (!$whitelisted_paths && $admin_paths && ($views_protected_page || $admin_sub_paths)) {

      // Add defaults.
      $items[$path] += array(
        'access callback' => 'user_access',
        'access arguments' => array('access content'),
      );

      // Copy the access callback into the arguments and replace it with ours.
      array_unshift($items[$path]['access arguments'], $items[$path]['access callback']);
      $items[$path]['access callback'] = 'dvg_domains_admin_access';
    }
  }

  // Fix the node clone menu type.
  $items['node/%node/clone/%clone_token']['type'] = MENU_LOCAL_TASK;
}

/**
 * Custom menu access function that checks the Editor's assigned domains, or the original callback.
 */
function dvg_domains_admin_access() {
  global $user;
  // Check if the editor is at his own domain; deny access if he's not.
  if (user_access('clone node')) {
    $domain = domain_get_domain();
    if (!in_array($domain['domain_id'], domain_get_user_domains($user))) {
      return FALSE;
    }
  }

  // Fallback on original access callback.
  $args = func_get_args();
  $callback = array_shift($args);

  if (is_bool($callback)) {
    return $callback;
  }

  return call_user_func_array($callback, $args);
}

/**
 * Implements hook_module_implements_alter().
 */