diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2012-12-17 08:13:36 +0100 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2012-12-17 08:13:36 +0100 |
commit | 7c17ddba9a45f93ae491c11d3baf8ca8625375f0 (patch) | |
tree | 802cb7e11c09e5ac3974dbbc3622e312dc2aaf47 /bin | |
parent | 1e07eccace7c50fd0e7fa3b217eda85add5a6630 (diff) | |
download | privsep-7c17ddba9a45f93ae491c11d3baf8ca8625375f0.tar.bz2 privsep-7c17ddba9a45f93ae491c11d3baf8ca8625375f0.tar.xz |
Fix privsep client to use lua-socket
Diffstat (limited to 'bin')
-rw-r--r-- | bin/Makefile | 1 | ||||
-rw-r--r-- | bin/conn.c | 5 | ||||
-rw-r--r-- | bin/lua-privsep.c | 19 | ||||
-rw-r--r-- | bin/lua-privsep.h | 2 |
4 files changed, 19 insertions, 8 deletions
diff --git a/bin/Makefile b/bin/Makefile index de61268..07a522a 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,6 +1,7 @@ COMPILE_PROG = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $($@-objs) $($@-libs) +CFLAGS ?= -g PKGCONF ?= pkg-config @@ -14,6 +14,8 @@ #include "list.h" #include "conn.h" +#include "lua-privsep.h" + #ifndef DEBUG #define log_debug(x) printf("%s\n", x) @@ -62,8 +64,7 @@ static void conn_recv_cb (struct ev_loop *loop, struct ev_io *w, if (conn->num_read >= sizeof(conn->msg)) goto err; - call_lua(conn->num_read, conn->msg); - return; + call_lua(conn->io.fd, conn->msg, conn->num_read); err: conn_free(loop, conn); 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); } diff --git a/bin/lua-privsep.h b/bin/lua-privsep.h index fae8fcc..9b7e219 100644 --- a/bin/lua-privsep.h +++ b/bin/lua-privsep.h @@ -1,6 +1,6 @@ #ifndef LUA_PRIVSEP_H #define LUA_PRIVSEP_H -int call_lua(const char *msg size_t msglen); +int call_lua(int fd, const char *msg, size_t msglen); #endif |