Skip to content

Commit 6265904

Browse files
committed
add unveil to list of exported functions
1 parent 7d03ff6 commit 6265904

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2+
PROJECT(lua-openbsd)
23

34
FIND_PACKAGE(PkgConfig)
45
INCLUDE(CheckFunctionExists)
@@ -13,6 +14,7 @@ ADD_DEFINITIONS("-Wall -Werror")
1314
CHECK_FUNCTION_EXISTS("pledge" HAVE_PLEDGE)
1415
CHECK_FUNCTION_EXISTS("arc4random" HAVE_ARC4RANDOM)
1516
CHECK_FUNCTION_EXISTS("arc4random_uniform" HAVE_ARC4RANDOM_UNIFORM)
17+
CHECK_FUNCTION_EXISTS("unveil" HAVE_UNVEIL)
1618
CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/config.h.in"
1719
"${CMAKE_BINARY_DIR}/config.h")
1820

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Implements:
55
o pledge()
66
o arc4random()
77
o arc4random_uniform()
8+
o unveil()
89

910
Works and has been tested on Lua 5.1, 5.2 and 5.3.
1011

config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
*/
1414
#cmakedefine HAVE_ARC4RANDOM_UNIFORM
1515

16+
/* Do we have unveil()?
17+
*/
18+
#cmakedefine HAVE_UNVEIL
19+
1620
#endif

example/openbsd-example.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
o = require("openbsd")
22

3+
-- Test out unveil
4+
ret = o.unveil(".", "rwx")
5+
print("unveil: " .. ret)
6+
37
-- Same as pledge("rpath", NULL)
48
ret, s = o.pledge("rpath stdio")
59
print(ret, s)
610

7-
-- Same as pledge("rpath", { NULL })
8-
ret, s = o.pledge("rpath stdio", {})
9-
print(ret, s)
10-
1111
-- Same as pledge("rpath stdio wpath", "rpath stdio")
1212
ret, s = o.pledge("rpath stdio wpath", "rpath stdio")
1313

src/lua-openbsd.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ int lua_arc4random_uniform(lua_State *L)
7878
return 1;
7979
}
8080

81+
int lua_unveil(lua_State *L)
82+
{
83+
char const *path = NULL, *mode = NULL;
84+
int ret = 0;
85+
86+
#ifndef HAVE_UNVEIL
87+
lo_die(L, "unveil: not supported");
88+
#endif
89+
90+
luaL_argcheck(L, lua_isstring(L, 1), 1,
91+
"unveil: first argument must be string");
92+
luaL_argcheck(L, lua_isstring(L, 2), 1,
93+
"unveil: second argument must be string");
94+
95+
path = lua_tostring(L, 1);
96+
mode = lua_tostring(L, 2);
97+
98+
ret = unveil(path, mode);
99+
lua_pushnumber(L, ret);
100+
101+
return 1;
102+
}
103+
81104
#if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501
82105
/* Adapted from Lua 5.2.0
83106
*/
@@ -100,6 +123,7 @@ static const struct luaL_Reg l_pledge[] = {
100123
{ "pledge", lua_pledge },
101124
{ "arc4random", lua_arc4random },
102125
{ "arc4random_uniform", lua_arc4random_uniform },
126+
{ "unveil", lua_unveil },
103127
{ NULL, NULL },
104128
};
105129

0 commit comments

Comments
 (0)