#include <s_security.h>
|
static bool | isSecure (lua_State *L) |
|
static void | getGlobalsBackup (lua_State *L) |
|
static bool | safeLoadString (lua_State *L, std::string_view code, const char *chunk_name) |
| Loads a string as Lua code safely (doesn't allow bytecode).
|
|
static bool | safeLoadFile (lua_State *L, const char *path, const char *display_name=nullptr) |
| Loads a file as Lua code safely (doesn't allow bytecode).
|
|
static std::string | getCurrentModName (lua_State *L) |
| Returns the currently running mod, only during init time.
|
|
static bool | checkWhitelisted (lua_State *L, const std::string &setting) |
| Check if mod is whitelisted in the given setting.
|
|
static bool | checkPath (lua_State *L, const char *path, bool write_required, bool *write_allowed=nullptr) |
| Checks if mods are allowed to read (and optionally write) to the path.
|
|
static std::string | getCurrentModNameInsecure (lua_State *L) |
| Returns the currently running mod, only during init time.
|
|
|
virtual bool | modNamesAreTrusted () |
| Specify if the mod names during init time(!) can be trusted.
|
|
virtual bool | checkPathInternal (const std::string &abs_path, bool write_required, bool *write_allowed)=0 |
| Should check if the given path may be accessed.
|
|
lua_State * | getStack () |
|
void | realityCheck () |
|
void | scriptError (int result, const char *fxn) |
|
void | stackDump (std::ostream &o) |
|
void | setGameDef (IGameDef *gamedef) |
|
Environment * | getEnv () |
|
void | setEnv (Environment *env) |
|
EmergeThread * | getEmergeThread () |
|
void | setEmergeThread (EmergeThread *emerge) |
|
void | objectrefGetOrCreate (lua_State *L, ServerActiveObject *cobj) |
|
void | pushPlayerHPChangeReason (lua_State *L, const PlayerHPChangeReason &reason) |
|
template<> |
bool | readParam (lua_State *L, int index) |
|
template<> |
s16 | readParam (lua_State *L, int index) |
|
template<> |
int | readParam (lua_State *L, int index) |
|
template<> |
float | readParam (lua_State *L, int index) |
|
template<> |
v2s16 | readParam (lua_State *L, int index) |
|
template<> |
v2f | readParam (lua_State *L, int index) |
|
template<> |
v3f | readParam (lua_State *L, int index) |
|
template<> |
std::string_view | readParam (lua_State *L, int index) |
|
template<> |
std::string | readParam (lua_State *L, int index) |
|
template<> |
std::string_view | readParam (lua_State *L, int index) |
| Read a string from Lua state L at index without copying it.
|
|
|
static bool | checkPathWithGamedef (lua_State *L, const std::string &abs_path, bool write_required, bool *write_allowed) |
|
template<typename T > |
static T | readParam (lua_State *L, int index) |
| Read a value using a template type T from Lua state L at index.
|
|
template<typename T > |
static T | readParam (lua_State *L, int index, const T &default_value) |
| Read a value using a template type T from Lua state L at index.
|
|
◆ checkPath()
bool ScriptApiSecurity::checkPath |
( |
lua_State * | L, |
|
|
const char * | path, |
|
|
bool | write_required, |
|
|
bool * | write_allowed = nullptr ) |
|
static |
◆ checkPathInternal()
virtual bool ScriptApiSecurity::checkPathInternal |
( |
const std::string & | abs_path, |
|
|
bool | write_required, |
|
|
bool * | write_allowed ) |
|
protectedpure virtual |
Should check if the given path may be accessed.
If write_required
is true test for write access, if false test for read access.
- Parameters
-
abs_path | absolute file/directory path, may not exist |
write_required | was write access requested? |
write_allowed | output parameter (nullable): set to true if writing is allowed |
- Returns
- true if access is allowed
Implemented in AsyncWorkerThread, ClientScripting, EmergeScripting, MainMenuScripting, and ServerScripting.
◆ checkPathWithGamedef()
bool ScriptApiSecurity::checkPathWithGamedef |
( |
lua_State * | L, |
|
|
const std::string & | abs_path, |
|
|
bool | write_required, |
|
|
bool * | write_allowed ) |
|
staticprotected |
References fs::AbsolutePath(), BUILTIN_MOD_NAME, checkModNameWhitelisted(), DIR_DELIM, g_settings_path, ScriptApiBase::getCurrentModNameInsecure(), fs::GetFilenameFromPath(), ModApiBase::getGameDef(), log_deprecated(), lowercase(), ModSpec::path, SubgameSpec::path, and fs::PathStartsWith().
Referenced by AsyncWorkerThread::checkPathInternal(), EmergeScripting::checkPathInternal(), and ServerScripting::checkPathInternal().
◆ checkWhitelisted()
bool ScriptApiSecurity::checkWhitelisted |
( |
lua_State * | L, |
|
|
const std::string & | setting ) |
|
static |
◆ createEmptyEnv()
void ScriptApiSecurity::createEmptyEnv |
( |
lua_State * | L | ) |
|
|
private |
◆ getCurrentModName()
std::string ScriptApiSecurity::getCurrentModName |
( |
lua_State * | L | ) |
|
|
static |
◆ getGlobalsBackup()
void ScriptApiSecurity::getGlobalsBackup |
( |
lua_State * | L | ) |
|
|
static |
◆ getThread()
int ScriptApiSecurity::getThread |
( |
lua_State * | L | ) |
|
|
private |
◆ initializeSecurity()
void ScriptApiSecurity::initializeSecurity |
( |
| ) |
|
References copy_safe(), createEmptyEnv(), CUSTOM_RIDX_GLOBALS_BACKUP, ScriptApiBase::getStack(), getThread(), m_secure, remove(), SECURE_API, setLuaEnv(), and shallow_copy_table().
Referenced by AsyncWorkerThread::AsyncWorkerThread(), EmergeScripting::EmergeScripting(), MainMenuScripting::MainMenuScripting(), and ServerScripting::ServerScripting().
◆ initializeSecurityClient()
void ScriptApiSecurity::initializeSecurityClient |
( |
| ) |
|
|
inline |
◆ isSecure()
bool ScriptApiSecurity::isSecure |
( |
lua_State * | L | ) |
|
|
static |
◆ modNamesAreTrusted()
virtual bool ScriptApiSecurity::modNamesAreTrusted |
( |
| ) |
|
|
inlineprotectedvirtual |
Specify if the mod names during init time(!) can be trusted.
It needs to be assured that no tampering happens before any call to loadMod()
.
- Note
- disabling this implies that mod whitelisting never works
- Returns
- boolean value
Reimplemented in ClientScripting, and ServerScripting.
◆ safeLoadFile()
bool ScriptApiSecurity::safeLoadFile |
( |
lua_State * | L, |
|
|
const char * | path, |
|
|
const char * | display_name = nullptr ) |
|
static |
◆ safeLoadString()
bool ScriptApiSecurity::safeLoadString |
( |
lua_State * | L, |
|
|
std::string_view | code, |
|
|
const char * | chunk_name ) |
|
static |
◆ setLuaEnv()
void ScriptApiSecurity::setLuaEnv |
( |
lua_State * | L, |
|
|
int | thread ) |
|
private |
◆ sl_g_dofile()
int ScriptApiSecurity::sl_g_dofile |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_g_load()
int ScriptApiSecurity::sl_g_load |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_g_loadfile()
int ScriptApiSecurity::sl_g_loadfile |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_g_loadstring()
int ScriptApiSecurity::sl_g_loadstring |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_g_require()
int ScriptApiSecurity::sl_g_require |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_io_input()
int ScriptApiSecurity::sl_io_input |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_io_lines()
int ScriptApiSecurity::sl_io_lines |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_io_open()
int ScriptApiSecurity::sl_io_open |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_io_output()
int ScriptApiSecurity::sl_io_output |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_os_remove()
int ScriptApiSecurity::sl_os_remove |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_os_rename()
int ScriptApiSecurity::sl_os_rename |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ sl_os_setlocale()
int ScriptApiSecurity::sl_os_setlocale |
( |
lua_State * | L | ) |
|
|
staticprivate |
◆ m_secure
bool ScriptApiSecurity::m_secure = false |
|
private |
The documentation for this class was generated from the following files: