From d0ce4c9a1eaf5d92b4d5fe8475071d618d080a7a Mon Sep 17 00:00:00 2001 From: Vladimir Davydov <vdavydov@tarantool.org> Date: Wed, 6 Apr 2022 16:00:18 +0300 Subject: [PATCH] console: add internal on_console_eval trigger The trigger is invoked on console eval. The trigger callback is passed the eval expression string. It will be used for auditing console events in the EE version. NO_TEST=ee NO_DOC=internal NO_CHANGELOG=internal --- src/box/lua/console.c | 15 +++++++++++++++ src/box/lua/console.h | 9 +++++++++ src/box/lua/console.lua | 1 + 3 files changed, 25 insertions(+) diff --git a/src/box/lua/console.c b/src/box/lua/console.c index a66b309f14..d203629d12 100644 --- a/src/box/lua/console.c +++ b/src/box/lua/console.c @@ -51,6 +51,8 @@ #include <stdlib.h> #include <ctype.h> +struct rlist on_console_eval = RLIST_HEAD_INITIALIZER(on_console_eval); + static struct luaL_serializer *serializer_yaml; static struct luaL_serializer *serializer_lua; @@ -472,6 +474,18 @@ lbox_console_format_yaml(struct lua_State *L) return lua_yaml_encode(L, serializer_yaml, NULL, NULL); } +/** + * Runs registered on_console_eval triggers. + * Takes eval expression string, which is passed to trigger callback. + */ +static int +lbox_console_run_on_eval(struct lua_State *L) +{ + const char *expr = lua_tostring(L, 1); + trigger_run(&on_console_eval, (void *)expr); + return 0; +} + int console_session_fd(struct session *session) { @@ -641,6 +655,7 @@ tarantool_lua_console_init(struct lua_State *L) {"completion_handler", lbox_console_completion_handler}, {"format_yaml", lbox_console_format_yaml}, {"format_lua", lbox_console_format_lua}, + {"run_on_eval", lbox_console_run_on_eval}, {NULL, NULL} }; luaL_register_module(L, "console", consolelib); diff --git a/src/box/lua/console.h b/src/box/lua/console.h index 208b314909..29348f5af3 100644 --- a/src/box/lua/console.h +++ b/src/box/lua/console.h @@ -30,10 +30,19 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + +#include "small/rlist.h" + #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ +/** + * Triggers invoked on console eval. + * Passed eval expression string. + */ +extern struct rlist on_console_eval; + struct lua_State; void diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 09c9d11f0a..69d9d99210 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -380,6 +380,7 @@ local function local_eval(storage, line) if not line then return nil end + internal.run_on_eval(line) local command = get_command(line) if command then return preprocess(storage, command) -- GitLab