From: imeevma@tarantool.org
To: korablev@tarantool.org
Cc: tarantool-patches@freelists.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 [thread overview]
Message-ID: <46e305e6bbce44d3a785963a58135d9efa425bdb.1556377851.git.imeevma@gmail.com> (raw)
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
next reply other threads:[~2019-04-27 15:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-27 15:30 imeevma [this message]
2019-05-07 16:20 ` [tarantool-patches] " n.pettik
2019-05-07 16:41 ` Konstantin Osipov
2019-05-11 12:17 ` n.pettik
2019-05-17 11:43 ` Kirill Yukhin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46e305e6bbce44d3a785963a58135d9efa425bdb.1556377851.git.imeevma@gmail.com \
--to=imeevma@tarantool.org \
--cc=korablev@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name()' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox