diff options
Diffstat (limited to 'privileged-main.lua')
-rw-r--r-- | privileged-main.lua | 59 |
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) |