From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Subject: [PATCH 1/5] session: forbid creation from Lua binary and applier sessions Date: Mon, 19 Mar 2018 16:34:48 +0300 [thread overview] Message-ID: <d54f0c011f80a39721dd19b69aef80ff487fb2d8.1521466428.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1521466428.git.v.shpilevoy@tarantool.org> In-Reply-To: <cover.1521466428.git.v.shpilevoy@tarantool.org> Lua has no access to applier or binary sockets, and these session types must be forbidden. And after #2667 applier, binary, console and background session owners will be incapsulated inside corresponding modules. Signed-off-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> --- src/box/lua/session.c | 10 ++++++++-- test/box-tap/session.test.lua | 12 ++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/box/lua/session.c b/src/box/lua/session.c index ad1c6cc25..d8e91bf1f 100644 --- a/src/box/lua/session.c +++ b/src/box/lua/session.c @@ -48,6 +48,13 @@ static const char *sessionlib_name = "box.session"; static int lbox_session_create(struct lua_State *L) { + enum session_type type = + STR2ENUM(session_type, luaL_optstring(L, 2, "console")); + if (type != SESSION_TYPE_CONSOLE && type != SESSION_TYPE_REPL && + type != SESSION_TYPE_BACKGROUND) { + return luaL_error(L, "Can not start non-console or non-REPL "\ + "session from Lua"); + } struct session *session = fiber_get_session(fiber()); if (session == NULL) { int fd = luaL_optinteger(L, 1, -1); @@ -56,8 +63,7 @@ lbox_session_create(struct lua_State *L) return luaT_error(L); } /* If a session already exists, simply reset its type */ - session->type = STR2ENUM(session_type, luaL_optstring(L, 2, "console")); - + session->type = type; lua_pushnumber(L, session->id); return 1; } diff --git a/test/box-tap/session.test.lua b/test/box-tap/session.test.lua index 6fddced3c..ff952fd45 100755 --- a/test/box-tap/session.test.lua +++ b/test/box-tap/session.test.lua @@ -15,14 +15,22 @@ session = box.session space = box.schema.space.create('tweedledum') index = space:create_index('primary', { type = 'hash' }) -test:plan(53) +test:plan(55) + +-- +-- Check that can start from Lua only either console or REPL. +-- +local ok, err = pcall(box.internal.session.create, 100, "binary") +test:is(err, "Can not start non-console or non-REPL session from Lua", "bad session type") +ok, err = pcall(box.internal.session.create, 100, "applier") +test:is(err, "Can not start non-console or non-REPL session from Lua", "bad session type") --- --- Check that Tarantool creates ADMIN session for #! script --- test:ok(session.exists(session.id()), "session is created") test:isnil(session.peer(session.id()), "session.peer") -local ok, err = pcall(session.exists) +ok, err = pcall(session.exists) test:is(err, "session.exists(sid): bad arguments", "exists bad args #1") ok, err = pcall(session.exists, 1, 2, 3) test:is(err, "session.exists(sid): bad arguments", "exists bad args #2") -- 2.14.3 (Apple Git-98)
next prev parent reply other threads:[~2018-03-19 13:34 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-03-19 13:34 [PATCH 0/5] session: introduce box.session.push Vladislav Shpilevoy 2018-03-19 13:34 ` Vladislav Shpilevoy [this message] 2018-03-20 13:20 ` [PATCH 1/5] session: forbid creation from Lua binary and applier sessions Vladimir Davydov 2018-03-20 13:46 ` v.shpilevoy 2018-03-19 13:34 ` [PATCH 2/5] lua: port console yaml formatting to C Vladislav Shpilevoy 2018-03-20 17:51 ` Vladimir Davydov 2018-03-20 18:04 ` v.shpilevoy 2018-03-21 9:14 ` Vladimir Davydov 2018-03-21 9:30 ` v.shpilevoy 2018-03-19 13:34 ` [PATCH 3/5] Remove empty function declaration Vladislav Shpilevoy 2018-03-20 17:55 ` Vladimir Davydov 2018-03-20 17:57 ` [tarantool-patches] " v.shpilevoy 2018-03-21 9:16 ` Vladimir Davydov 2018-03-19 13:34 ` [PATCH 4/5] session: introduce session_owner Vladislav Shpilevoy 2018-03-20 18:29 ` Vladimir Davydov 2018-03-19 13:34 ` [PATCH 5/5] session: introduce box.session.push Vladislav Shpilevoy 2018-03-21 9:10 ` Vladimir Davydov 2018-03-21 9:30 ` [tarantool-patches] " v.shpilevoy 2018-03-21 12:25 ` Vladimir Davydov 2018-03-19 13:41 ` [tarantool-patches] [PATCH 0/5] " v.shpilevoy
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=d54f0c011f80a39721dd19b69aef80ff487fb2d8.1521466428.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH 1/5] session: forbid creation from Lua binary and applier sessions' \ /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