diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index 494269fb1c9bd73ba604ae311e816555c8d3922e..19d3dbbcecc57b6a8ae79234797f17614625f72f 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -105,7 +105,7 @@ add_library(box STATIC relay.cc journal.c wal.cc - call.cc + call.c ${lua_sources} lua/init.c lua/call.c diff --git a/src/box/call.cc b/src/box/call.c similarity index 94% rename from src/box/call.cc rename to src/box/call.c index ed7c833ab6ed11005d786b96f3c20bb09cbc061f..b47df6a754420f9f309bdd46aae4dd196c679c9d 100644 --- a/src/box/call.cc +++ b/src/box/call.c @@ -35,7 +35,6 @@ #include "session.h" #include "func.h" #include "port.h" -#include "scoped_guard.h" #include "box.h" #include "txn.h" #include "xrow.h" @@ -106,7 +105,6 @@ box_c_call(struct func *func, struct call_request *request, struct obuf *out) /* Create a call context */ struct port port; port_create(&port); - auto port_guard = make_scoped_guard([&](){ port_destroy(&port); }); box_function_ctx_t ctx = { &port }; /* Clear all previous errors */ @@ -136,7 +134,7 @@ box_c_call(struct func *func, struct call_request *request, struct obuf *out) goto error; } iproto_reply_select(out, &svp, request->header->sync, - ::schema_version, port.size); + schema_version, port.size); } else { assert(request->header->type == IPROTO_CALL); char *size_buf = (char *) @@ -149,13 +147,15 @@ box_c_call(struct func *func, struct call_request *request, struct obuf *out) goto error; } iproto_reply_select(out, &svp, request->header->sync, - ::schema_version, 1); + schema_version, 1); } + port_destroy(&port); return 0; error: txn_rollback(); + port_destroy(&port); return -1; } @@ -177,7 +177,7 @@ box_func_reload(const char *name) return -1; } -void +int box_process_call(struct call_request *request, struct obuf *out) { rmean_collect(rmean_box, IPROTO_CALL, 1); @@ -193,8 +193,8 @@ box_process_call(struct call_request *request, struct obuf *out) * Sic: func == NULL means that perhaps the user has a global * "EXECUTE" privilege, so no specific grant to a function. */ - if ((access_check_func(name, name_len, &func)) < 0) - diag_raise(); /* permission denied */ + if (access_check_func(name, name_len, &func) != 0) + return -1; /* permission denied */ /** * Change the current user id if the function is @@ -212,7 +212,9 @@ box_process_call(struct call_request *request, struct obuf *out) * be around to fill it (recovery of * system spaces from a snapshot). */ - struct user *owner = user_find_xc(func->def->uid); + struct user *owner = user_find(func->def->uid); + if (owner == NULL) + return -1; credentials_init(&func->owner_credentials, owner->auth_token, owner->def->uid); @@ -232,7 +234,7 @@ box_process_call(struct call_request *request, struct obuf *out) if (rc != 0) { txn_rollback(); - diag_raise(); + return -1; } if (in_txn()) { @@ -241,17 +243,20 @@ box_process_call(struct call_request *request, struct obuf *out) name_len, name); txn_rollback(); } + + return 0; } -void +int box_process_eval(struct call_request *request, struct obuf *out) { rmean_collect(rmean_box, IPROTO_EVAL, 1); /* Check permissions */ - access_check_universe_xc(PRIV_X); + if (access_check_universe(PRIV_X) != 0) + return -1; if (box_lua_eval(request, out) != 0) { txn_rollback(); - diag_raise(); + return -1; } if (in_txn()) { @@ -263,4 +268,6 @@ box_process_eval(struct call_request *request, struct obuf *out) expr_len, expr); txn_rollback(); } + + return 0; } diff --git a/src/box/call.h b/src/box/call.h index 9e105087a983c46a208fe7d9e23a58f840c3fb8c..b334626ae08ac0e28841b46a671e2a12ba186061 100644 --- a/src/box/call.h +++ b/src/box/call.h @@ -31,28 +31,29 @@ * SUCH DAMAGE. */ -#include <stdint.h> - #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ -int -box_func_reload(const char *name); - -#if defined(__cplusplus) -} /* extern "C" */ -#endif /* defined(__cplusplus) */ struct obuf; +struct port; +struct call_request; struct box_function_ctx { struct port *port; }; -void +int +box_func_reload(const char *name); + +int box_process_call(struct call_request *request, struct obuf *out); -void +int box_process_eval(struct call_request *request, struct obuf *out); +#if defined(__cplusplus) +} /* extern "C" */ +#endif /* defined(__cplusplus) */ + #endif /* INCLUDES_TARANTOOL_MOD_BOX_CALL_H */ diff --git a/src/box/iproto.cc b/src/box/iproto.cc index 0d0ef64be0f2a7b0096f64587678a4502a10cd80..c091e14bad0b4bee85d8dfb39cc2e6e5e6ca962f 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -1191,10 +1191,12 @@ tx_process_misc(struct cmsg *m) switch (msg->header.type) { case IPROTO_CALL: case IPROTO_CALL_16: - box_process_call(&msg->call, out); + if (box_process_call(&msg->call, out) != 0) + diag_raise(); break; case IPROTO_EVAL: - box_process_eval(&msg->call, out); + if (box_process_eval(&msg->call, out) != 0) + diag_raise(); break; case IPROTO_AUTH: box_process_auth(&msg->auth);