10#define CHECK_SECURE_PATH_INTERNAL(L, path, write_required, ptr) \
11 if (!ScriptApiSecurity::checkPath(L, path, write_required, ptr)) { \
12 throw LuaError(std::string("Mod security: Blocked attempted ") + \
13 (write_required ? "write to " : "read from ") + path); \
16#define CHECK_SECURE_PATH(L, path, write_required) \
17 if (ScriptApiSecurity::isSecure(L)) { \
18 CHECK_SECURE_PATH_INTERNAL(L, path, write_required, nullptr); \
21#define CHECK_SECURE_PATH_POSSIBLE_WRITE(L, path, ptr) \
22 if (ScriptApiSecurity::isSecure(L)) { \
23 CHECK_SECURE_PATH_INTERNAL(L, path, false, ptr); \
32#if CHECK_CLIENT_BUILD()
44 static bool safeLoadString(lua_State *L, std::string_view code,
const char *chunk_name);
47 static bool safeLoadFile(lua_State *L,
const char *path,
const char *display_name =
nullptr);
63 static bool checkPath(lua_State *L,
const char *path,
bool write_required,
64 bool *write_allowed =
nullptr);
86 bool *write_allowed) = 0;
90 bool write_required,
bool *write_allowed);
Definition s_security.h:28
static int sl_os_remove(lua_State *L)
Definition s_security.cpp:943
static int sl_os_setlocale(lua_State *L)
Definition s_security.cpp:956
void initializeSecurityClient()
Definition s_security.h:35
void initializeSecurity()
Definition s_security.cpp:62
static int sl_g_loadstring(lua_State *L)
Definition s_security.cpp:822
static std::string getCurrentModName(lua_State *L)
Returns the currently running mod, only during init time.
Definition s_security.cpp:513
bool m_secure
Definition s_security.h:99
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).
Definition s_security.cpp:433
int getThread(lua_State *L)
Definition s_security.cpp:383
static int sl_g_require(lua_State *L)
Definition s_security.cpp:845
static int sl_os_rename(lua_State *L)
Definition s_security.cpp:925
static int sl_io_open(lua_State *L)
Definition s_security.cpp:852
static int sl_g_loadfile(lua_State *L)
Definition s_security.cpp:779
virtual bool checkPathInternal(const std::string &abs_path, bool write_required, bool *write_allowed)=0
Should check if the given path may be accessed.
static bool checkPathWithGamedef(lua_State *L, const std::string &abs_path, bool write_required, bool *write_allowed)
Definition s_security.cpp:607
static int sl_io_input(lua_State *L)
Definition s_security.cpp:880
static int sl_io_lines(lua_State *L)
Definition s_security.cpp:908
static int sl_g_dofile(lua_State *L)
Definition s_security.cpp:725
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.
Definition s_security.cpp:563
void createEmptyEnv(lua_State *L)
Definition s_security.cpp:394
static bool isSecure(lua_State *L)
Definition s_security.cpp:414
static void getGlobalsBackup(lua_State *L)
Definition s_security.cpp:422
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).
Definition s_security.cpp:444
static int sl_io_output(lua_State *L)
Definition s_security.cpp:894
static int sl_g_load(lua_State *L)
Definition s_security.cpp:740
virtual bool modNamesAreTrusted()
Specify if the mod names during init time(!) can be trusted.
Definition s_security.h:75
static bool checkWhitelisted(lua_State *L, const std::string &setting)
Check if mod is whitelisted in the given setting.
Definition s_security.cpp:556
void setLuaEnv(lua_State *L, int thread)
Definition s_security.cpp:401