mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add core.request_insecure_environment()
This commit is contained in:
parent
05ab9973f9
commit
6c06330daf
5 changed files with 46 additions and 4 deletions
|
@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "filesys.h"
|
||||
#include "settings.h"
|
||||
#include "util/auth.h"
|
||||
#include <algorithm>
|
||||
|
||||
// debug(...)
|
||||
// Writes a line to dstream
|
||||
|
@ -316,7 +317,7 @@ int ModApiUtil::l_compress(lua_State *L)
|
|||
int ModApiUtil::l_decompress(lua_State *L)
|
||||
{
|
||||
size_t size;
|
||||
const char * data = luaL_checklstring(L, 1, &size);
|
||||
const char *data = luaL_checklstring(L, 1, &size);
|
||||
|
||||
std::istringstream is(std::string(data, size));
|
||||
std::ostringstream os;
|
||||
|
@ -339,6 +340,30 @@ int ModApiUtil::l_mkdir(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
int ModApiUtil::l_request_insecure_environment(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
if (!ScriptApiSecurity::isSecure(L)) {
|
||||
lua_getglobal(L, "_G");
|
||||
return 1;
|
||||
}
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, SCRIPT_MOD_NAME_FIELD);
|
||||
if (!lua_isstring(L, -1)) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
const char *mod_name = lua_tostring(L, -1);
|
||||
std::string trusted_mods = g_settings->get("secure.trusted_mods");
|
||||
std::vector<std::string> mod_list = str_split(trusted_mods, ',');
|
||||
if (std::find(mod_list.begin(), mod_list.end(), mod_name) == mod_list.end()) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, "globals_backup");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void ModApiUtil::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(debug);
|
||||
|
@ -366,6 +391,8 @@ void ModApiUtil::Initialize(lua_State *L, int top)
|
|||
API_FCT(decompress);
|
||||
|
||||
API_FCT(mkdir);
|
||||
|
||||
API_FCT(request_insecure_environment);
|
||||
}
|
||||
|
||||
void ModApiUtil::InitializeAsync(AsyncEngine& engine)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue