summaryrefslogtreecommitdiffstats
path: root/privileged-main.lua
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2013-03-08 16:42:03 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2013-03-08 16:51:15 +0100
commit3e2d86693f6e8920c97fe296491e7741e31f922c (patch)
tree1c755422fd27c7f192243e8eb7f7811193efa1f6 /privileged-main.lua
parente0cabd6295204fe8a6b54edfc9141302943fdbfb (diff)
downloadprivsep-master.tar.bz2
privsep-master.tar.xz
implement one lua state per connectionHEADmaster
This allows you load various modules into a server lua state and give a performance boost when calling the privileged functions
Diffstat (limited to 'privileged-main.lua')
-rw-r--r--privileged-main.lua59
1 files changed, 0 insertions, 59 deletions
diff --git a/privileged-main.lua b/privileged-main.lua
deleted file mode 100644
index 6aa9681..0000000
--- a/privileged-main.lua
+++ /dev/null
@@ -1,59 +0,0 @@
-msg = ...
-
---print("DEBUG: got message:", msg)
-
-ipcmsg = require("cmsgpack")
-ipcmsg.encode = ipcmsg.pack
-ipcmsg.decode = ipcmsg.unpack
-
-
-function ret_error(errmsg)
- io.stderr:write("ERROR: "..tostring(errmsg).."\n")
- return ipcmsg.encode{ status = false, errmsg = errmsg}
-end
-
-function ret_success(result)
- return ipcmsg.encode{ status = true, errmsg = "success", result = result}
-end
-
-req = ipcmsg.decode(msg)
-
---print("DEBUG: msg decoded")
-
--- path must be absolute for production so users cannot load scripts from
--- non secured dirs
-modules_path = "./modules/"
-
-if type(req.mod) ~= "string" then
- return ret_error("mod is missing in message or is bad format")
-end
-
-if type(req.func) ~= "string" then
- return ret_error("func is missing in message or is wrong format")
-end
-
--- make sure we dont have any path elements in modname so we cannot pass
--- modnames like '../myevilmod'
-mfile = modules_path..string.gsub(req.mod, ".*/", "")..".lua"
-
--- load the module
-m = dofile(mfile)
---print("DEBUG: mfile:", mfile)
---print("DEBUG: '"..req.func.."' type:", type(m[req.func]))
-
--- check that the func we want exists
-if type(m[req.func]) ~= "function" then
- ret_error(func..": not a function in '".. mfile .."'")
-end
-
--- TODO: check permissions here
-print("Calling '"..req.mod.."."..req.func.."'")
-
---print("DEBUG: args:", req.args)
--- execute the func and pack the return values into a table
-result = { m[req.func](unpack(req.args)) }
---result = { m[func](unpack(req.args or {})) }
-
---print("DEBUG: result:", result)
-
-return ret_success(result)