diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2013-03-08 16:42:03 +0100 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2013-03-08 16:51:15 +0100 |
commit | 3e2d86693f6e8920c97fe296491e7741e31f922c (patch) | |
tree | 1c755422fd27c7f192243e8eb7f7811193efa1f6 /privsep.lua | |
parent | e0cabd6295204fe8a6b54edfc9141302943fdbfb (diff) | |
download | privsep-master.tar.bz2 privsep-master.tar.xz |
This allows you load various modules into a server lua state and give
a performance boost when calling the privileged functions
Diffstat (limited to 'privsep.lua')
-rw-r--r-- | privsep.lua | 40 |
1 files changed, 0 insertions, 40 deletions
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 - |