Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name()
@ 2019-04-27 15:30 imeevma
  2019-05-07 16:20 ` [tarantool-patches] " n.pettik
  2019-05-17 11:43 ` Kirill Yukhin
  0 siblings, 2 replies; 5+ messages in thread
From: imeevma @ 2019-04-27 15:30 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name()
  2019-04-27 15:30 [tarantool-patches] [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name() imeevma
@ 2019-05-07 16:20 ` n.pettik
  2019-05-07 16:41   ` Konstantin Osipov
  2019-05-17 11:43 ` Kirill Yukhin
  1 sibling, 1 reply; 5+ messages in thread
From: n.pettik @ 2019-05-07 16:20 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Imeev Mergen


> +-- 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

Such error looks a bit confusing IMHO. Could we tell the absence
of space from lack of rights?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name()
  2019-05-07 16:20 ` [tarantool-patches] " n.pettik
@ 2019-05-07 16:41   ` Konstantin Osipov
  2019-05-11 12:17     ` n.pettik
  0 siblings, 1 reply; 5+ messages in thread
From: Konstantin Osipov @ 2019-05-07 16:41 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Imeev Mergen

* n.pettik <korablev@tarantool.org> [19/05/07 19:21]:
> 
> > +-- 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
> 
> Such error looks a bit confusing IMHO. Could we tell the absence
> of space from lack of rights?

It's OK to produce a confusing error message for a user which has
no access to a space. This message is just fine. We should just be
consistent and not reveal that the space exists through the error
message.

-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name()
  2019-05-07 16:41   ` Konstantin Osipov
@ 2019-05-11 12:17     ` n.pettik
  0 siblings, 0 replies; 5+ messages in thread
From: n.pettik @ 2019-05-11 12:17 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Konstantin Osipov, Imeev Mergen



> On 7 May 2019, at 19:41, Konstantin Osipov <kostja@tarantool.org> wrote:
> 
> * n.pettik <korablev@tarantool.org> [19/05/07 19:21]:
>> 
>>> +-- 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
>> 
>> Such error looks a bit confusing IMHO. Could we tell the absence
>> of space from lack of rights?
> 
> It's OK to produce a confusing error message for a user which has
> no access to a space. This message is just fine. We should just be
> consistent and not reveal that the space exists through the error
> message.

Ok, I don’t have any other objections, so patch LGTM.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name()
  2019-04-27 15:30 [tarantool-patches] [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name() imeevma
  2019-05-07 16:20 ` [tarantool-patches] " n.pettik
@ 2019-05-17 11:43 ` Kirill Yukhin
  1 sibling, 0 replies; 5+ messages in thread
From: Kirill Yukhin @ 2019-05-17 11:43 UTC (permalink / raw)
  To: tarantool-patches; +Cc: korablev

Hello,

On 27 Apr 18:30, imeevma@tarantool.org wrote:
> 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

I've checked your patch into master.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-05-17 11:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-27 15:30 [tarantool-patches] [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name() imeevma
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox