Find role based on list of permissions Is there any way of finding the role given a list of permissions?

I.E.:

$permissions = array('administer content', 'access content');
$role        = find_related_roles();

// $role = array(4 =&gt; 'client')
Something like this should do it:

  $permissions = array('administer content', 'access content');
  $query = db_select('role', 'r')
    -&gt;fields('r', array('name'));
  $alias = 'rp';
  foreach($permissions as $perm){
    $query-&gt;innerJoin('role_permission', $alias, 'r.rid='.$alias.'.rid');
    $query-&gt;condition($alias.'.permission', $perm);
    $alias = $alias . 'a';
  }
  $result = $query-&gt;execute()-&gt;fetchAllAssoc('name');


It's doing separate inner joins with the role_permission table for each permission, to ensure that the role has all the permissions.