summaryrefslogtreecommitdiffstats
path: root/bin/lua-privsep.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/lua-privsep.c')
-rw-r--r--bin/lua-privsep.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/bin/lua-privsep.c b/bin/lua-privsep.c
index 0307d7c..d6d750c 100644
--- a/bin/lua-privsep.c
+++ b/bin/lua-privsep.c
@@ -4,6 +4,9 @@
#include <lauxlib.h>
#include <lualib.h>
+#include "conn.h"
+#include "lua-privsep.h"
+
#ifndef PRIVSEP_PATH
#define PRIVSEP_PATH "./"
#endif
@@ -32,10 +35,12 @@ static int traceback (lua_State *L) {
return 1;
}
-int call_lua(const char *msg, size_t msglen)
+int call_lua(int fd, const char *msg, size_t msglen)
{
const char *luamain = PRIVSEP_PATH "privileged-main.lua";
- int i, traceback_index;
+ int traceback_index;
+ const char *retbuf;
+ size_t retsize;
lua_State *L = luaL_newstate();
luaL_openlibs(L);
@@ -48,10 +53,14 @@ int call_lua(const char *msg, size_t msglen)
lua_pushlstring(L, msg, msglen);
- if (lua_pcall(L, 1, 0, traceback_index))
- return luaL_error(L, "error");
+ if (lua_pcall(L, 1, 1, traceback_index))
+ return luaL_error(L, "error");
- return 0;
+ if (!lua_isstring(L, -1))
+ error(L, "function must return string");
+
+ retbuf = lua_tolstring(L, -1, &retsize);
+ return write(fd, retbuf, retsize);
}