Skip to content

Commit

Permalink
schema: add "_vcollation" sysview
Browse files Browse the repository at this point in the history
Needed for #3941
  • Loading branch information
romanhabibov committed Mar 12, 2019
1 parent 6666db8 commit 285dfa3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
Binary file modified src/box/bootstrap.snap
Binary file not shown.
2 changes: 2 additions & 0 deletions src/box/lua/space.cc
Expand Up @@ -546,6 +546,8 @@ box_lua_space_init(struct lua_State *L)
lua_setfield(L, -2, "FUNC_ID");
lua_pushnumber(L, BOX_COLLATION_ID);
lua_setfield(L, -2, "COLLATION_ID");
lua_pushnumber(L, BOX_VCOLLATION_ID);
lua_setfield(L, -2, "VCOLLATION_ID");
lua_pushnumber(L, BOX_VFUNC_ID);
lua_setfield(L, -2, "VFUNC_ID");
lua_pushnumber(L, BOX_PRIV_ID);
Expand Down
14 changes: 13 additions & 1 deletion src/box/lua/upgrade.lua
Expand Up @@ -636,12 +636,24 @@ local function upgrade(options)
return
end

local function create_vcollation_space()
local _collation = box.space._collation
local format = _collation:format()
create_sysview(box.schema.COLLATION_ID, box.schema.VCOLLATION_ID)
box.space._vcollation:format(format)
end

local function upgrade_to_2_1_2()
create_vcollation_space()
end

local handlers = {
{version = mkversion(1, 7, 6), func = upgrade_to_1_7_6, auto = true},
{version = mkversion(1, 7, 7), func = upgrade_to_1_7_7, auto = true},
{version = mkversion(1, 10, 0), func = upgrade_to_1_10_0, auto = true},
{version = mkversion(1, 10, 2), func = upgrade_to_1_10_2, auto = true},
{version = mkversion(2, 1, 0), func = upgrade_to_2_1_0, auto = true}
{version = mkversion(2, 1, 0), func = upgrade_to_2_1_0, auto = true},
{version = mkversion(2, 1, 2), func = upgrade_to_2_1_2, auto = true}
}

for _, handler in ipairs(handlers) do
Expand Down
2 changes: 2 additions & 0 deletions src/box/schema_def.h
Expand Up @@ -72,6 +72,8 @@ enum {
BOX_SCHEMA_ID = 272,
/** Space id of _collation. */
BOX_COLLATION_ID = 276,
/** Space id of _vcollation. */
BOX_VCOLLATION_ID = 277,
/** Space id of _space. */
BOX_SPACE_ID = 280,
/** Space id of _vspace view. */
Expand Down
31 changes: 31 additions & 0 deletions src/box/sysview.c
Expand Up @@ -402,6 +402,33 @@ vsequence_filter(struct space *source, struct tuple *tuple)
((PRIV_WRDA | PRIV_X) & effective);
}

static bool
vcollation_filter(struct space *source, struct tuple *tuple)
{
struct credentials *cr = effective_user();
/*
* Allow access for a user with read, write,
* drop, alter or execute privileges for universe.
*/
if ((PRIV_WRDA | PRIV_X) & cr->universal_access)
return true;
/* Allow access for a user with collations privileges. */
if ((PRIV_WRDA | PRIV_X) &
entity_access_get(SC_COLLATION)[cr->auth_token].effective)
return true;
if (PRIV_R & source->access[cr->auth_token].effective)
return true; /* read access to _sequence space */

uint32_t collation_id;
if (tuple_field_u32(tuple, BOX_COLLATION_FIELD_ID, &collation_id) != 0)
return false;
uint32_t collation_uid;
if (tuple_field_u32(tuple, BOX_COLLATION_FIELD_UID, &collation_uid) != 0)
return false;
/* Allow access for privilege grantor or grantee. */
return collation_id == cr->uid || collation_uid == cr->uid;
}

static struct index *
sysview_space_create_index(struct space *space, struct index_def *def)
{
Expand All @@ -427,6 +454,10 @@ sysview_space_create_index(struct space *space, struct index_def *def)
source_space_id = BOX_INDEX_ID;
source_index_id = def->iid;
filter = vspace_filter;
case BOX_VCOLLATION_ID:
source_space_id = BOX_COLLATION_ID;
source_index_id = def->iid;
filter = vcollation_filter;
break;
case BOX_VUSER_ID:
source_space_id = BOX_USER_ID;
Expand Down

0 comments on commit 285dfa3

Please sign in to comment.