From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 46E252E0D4 for ; Sat, 27 Apr 2019 11:30:48 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fEd_XaLSr0lM for ; Sat, 27 Apr 2019 11:30:48 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 9E1DE2E0C9 for ; Sat, 27 Apr 2019 11:30:47 -0400 (EDT) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name() Date: Sat, 27 Apr 2019 18:30:44 +0300 Message-Id: <46e305e6bbce44d3a785963a58135d9efa425bdb.1556377851.git.imeevma@gmail.com> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: korablev@tarantool.org Cc: tarantool-patches@freelists.org This patch replaces schema_find_id() with box_space_id_by_name() in SQL. The box_space_id_by_name() is more specialized. In addition, it checks if the user has sufficient rights, unlike schema_find_id(). Closes #3570 --- https://github.com/tarantool/tarantool/issues/3570 https://github.com/tarantool/tarantool/tree/imeevma/gh-3570-replace-schema_find_id src/box/sql/trigger.c | 7 +++---- test/sql/triggers.result | 36 ++++++++++++++++++++++++++++++++++++ test/sql/triggers.test.lua | 18 ++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c index 14e4198..fe19244 100644 --- a/src/box/sql/trigger.c +++ b/src/box/sql/trigger.c @@ -38,6 +38,7 @@ #include "tarantoolInt.h" #include "vdbeInt.h" #include "box/session.h" +#include "box/box.h" /* See comment in sqlInt.h */ int sqlSubProgramsRemaining; @@ -87,10 +88,8 @@ sql_trigger_begin(struct Parse *parse) goto trigger_cleanup; const char *table_name = alter_def->entity_name->a[0].zName; - uint32_t space_id; - if (schema_find_id(BOX_SPACE_ID, 2, table_name, strlen(table_name), - &space_id) != 0) - goto set_tarantool_error_and_cleanup; + uint32_t space_id = box_space_id_by_name(table_name, + strlen(table_name)); if (space_id == BOX_ID_NIL) { diag_set(ClientError, ER_NO_SUCH_SPACE, table_name); goto set_tarantool_error_and_cleanup; diff --git a/test/sql/triggers.result b/test/sql/triggers.result index 77b88f4..af9085d 100644 --- a/test/sql/triggers.result +++ b/test/sql/triggers.result @@ -512,3 +512,39 @@ box.execute("DROP TABLE t1;") --- - row_count: 1 ... +-- +-- gh-3570: Use box_space_id_by_name() instead of schema_find_id() +-- in SQL +-- +box.schema.user.create('tester') +--- +... +box.schema.user.grant('tester','read,write,create,execute', 'space', '_trigger') +--- +... +box.execute("CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT);") +--- +- row_count: 1 +... +box.session.su('tester') +--- +... +-- +-- Ensure that the CREATE TRIGGER statement cannot be executed if +-- the user does not have enough rights. In this case, the user +-- does not have rights to read from _space. +-- +box.execute([[CREATE TRIGGER r1 AFTER INSERT ON t1 FOR EACH ROW BEGIN SELECT 1; END; ]]) +--- +- error: Space 'T1' does not exist +... +box.session.su('admin') +--- +... +box.schema.user.drop('tester') +--- +... +box.execute("DROP TABLE t1;") +--- +- row_count: 1 +... diff --git a/test/sql/triggers.test.lua b/test/sql/triggers.test.lua index 13497d6..a056e79 100644 --- a/test/sql/triggers.test.lua +++ b/test/sql/triggers.test.lua @@ -173,3 +173,21 @@ box.execute("CREATE TABLE t1(a INT PRIMARY KEY, b INT);") space_id = box.space.T1.id box.execute("CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN ; END;") box.execute("DROP TABLE t1;") + +-- +-- gh-3570: Use box_space_id_by_name() instead of schema_find_id() +-- in SQL +-- +box.schema.user.create('tester') +box.schema.user.grant('tester','read,write,create,execute', 'space', '_trigger') +box.execute("CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT);") +box.session.su('tester') +-- +-- Ensure that the CREATE TRIGGER statement cannot be executed if +-- the user does not have enough rights. In this case, the user +-- does not have rights to read from _space. +-- +box.execute([[CREATE TRIGGER r1 AFTER INSERT ON t1 FOR EACH ROW BEGIN SELECT 1; END; ]]) +box.session.su('admin') +box.schema.user.drop('tester') +box.execute("DROP TABLE t1;") -- 2.7.4