diff --git a/loslib.c b/loslib.c index b7a2b0d1..eaf52a6e 100644 --- a/loslib.c +++ b/loslib.c @@ -92,6 +92,10 @@ /* }================================================================== */ +#if !defined(__OpenBSD__) /* WARNIGN: Developent only */ +#define pledge(promises, execpromises) ((void)promises, (void)execpromises, 0) +#define unveil(path, permissions) ((void)path, (void)permissions, 0) +#endif /* ** {================================================================== @@ -405,6 +409,42 @@ static int os_exit (lua_State *L) { return 0; } +static int lua_plunveil_result(lua_State *L, const int retcode, + const int errno_code) { + if (0 != retcode) { + lua_pushnil(L); + lua_pushstring(L, strerror(errno_code)); + lua_pushinteger(L, errno_code); + return 3; + } + + lua_pushinteger(L, retcode); + return 1; +} + +static int os_pledge(lua_State *L) { + const char *promises = luaL_checkstring(L, 1); + const char *execpromises = luaL_checkstring(L, 2); + const int ret = pledge(promises, execpromises); + + return lua_plunveil_result(L, ret, errno); +} + +static int os_unveil(lua_State *L) { + const char *p1 = luaL_optstring(L, 1, NULL); + const char *p2 = luaL_optstring(L, 2, NULL); + + if (p1 == p2 && p1 == NULL) { + const int ret = unveil(NULL, NULL); + lua_plunveil_result(L, ret, errno); + } + + const char *path = luaL_checkstring(L, 1); + const char *permissions = luaL_checkstring(L, 2); + const int ret = unveil(path, permissions); + + return lua_plunveil_result(L, ret, errno); +} static const luaL_Reg syslib[] = { {"clock", os_clock}, @@ -418,6 +458,8 @@ static const luaL_Reg syslib[] = { {"setlocale", os_setlocale}, {"time", os_time}, {"tmpname", os_tmpname}, + {"pledge", os_pledge}, + {"unveil", os_unveil}, {NULL, NULL} };