From 3e2d86693f6e8920c97fe296491e7741e31f922c Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 8 Mar 2013 16:42:03 +0100 Subject: implement one lua state per connection This allows you load various modules into a server lua state and give a performance boost when calling the privileged functions --- privsep.lua | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 privsep.lua (limited to 'privsep.lua') diff --git a/privsep.lua b/privsep.lua deleted file mode 100644 index b6e8f95..0000000 --- a/privsep.lua +++ /dev/null @@ -1,40 +0,0 @@ - -ipcmsg = require("cmsgpack") -ipcmsg.encode = ipcmsg.pack -ipcmsg.decode = ipcmsg.unpack - -socket = require("socket") -socket.unix = require("socket.unix") - - -local modules_path = "./modules" - -local privsep = {} - -function privsep.call_privileged(mod, func, sectoken, args) - local c = assert(socket.unix()) - assert(c:connect("/var/run/privsep/root.sock")) - - local req = { mod = mod, func = func, args = args, sectoken = sectoken } - c:send(ipcmsg.encode(req)) - local retmsg, errmsg = c:receive("*a") - if retmsg then - local data = ipcmsg.decode(retmsg) - return unpack(data.result or {}) - end - return nil -end - -function privsep.wrap(modname, sessionid) - local mod = dofile(modules_path.."/"..modname..".lua") - local f = {} - for k,v in pairs(mod) do - f[k] = function(...) - return privsep.call_privileged(modname, k, sessionid, {...}) - end - end - return f -end - -return privsep - -- cgit v1.2.3