Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View all-table-privileges.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
<?php
$permissions = array(
"owner_read" => 256,
"owner_write" => 128,
"owner_delete" => 64,
"group_read" => 32,
"group_write" => 16,
"group_delete" => 8,
"other_read" => 4,
"other_write" => 2,
"other_delete" => 1
);
$groups = array(
"root" => 1,
"officer" => 2,
"user" => 4,
"wheel" => 8
);
$tbl = 't_event';
$user_id = 2;
$user_groups = 4;
$query = "
select ac.c_title
from
t_action as ac
-- Privileges that apply to the table and grant the given action
-- Not an inner join because the action may be granted even if there is no
-- privilege granting it. For example, root users can take all actions.
left outer join t_privilege as pr
on pr.c_related_table = '$tbl'
and pr.c_action = ac.c_title
and pr.c_type = 'table'
where
-- The action must apply to tables (NOT apply to objects)
(ac.c_apply_object = 0) and (
-- Members of the 'root' group are always allowed to do everything
($user_groups & $groups[root] <> 0)
-- user privileges
or (pr.c_role = 'user' and pr.c_who = $user_id)
-- group privileges
or (pr.c_role = 'group' and (pr.c_who & $user_groups <> 0)))
";
echo $query;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.