]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lua sandbox: export the list of original names
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 11 Nov 2016 14:19:27 +0000 (15:19 +0100)
committerŠtěpán Balážik <stepan.balazik@nic.cz>
Fri, 3 Feb 2017 15:36:01 +0000 (16:36 +0100)
That will allow us to discover the top-level symbols for completion.
For others we can e.g.: for n in pairs(net) do print(n); end
I must admit I fail to understand some of the related lua magic.

daemon/lua/sandbox.lua

index 4a5b3cb6d8a6b06143e28655d1d2b7b1003c4b8d..743dfaa0edd087734344275a629aa8cc1098340c 100644 (file)
@@ -160,7 +160,14 @@ end
 -- Make sandboxed environment
 local function make_sandbox(defined)
        local __protected = { modules = true, cache = true, net = true, trust_anchors = true }
-       return setmetatable({}, {
+
+       -- Compute and export the list of top-level names (hidden otherwise)
+       local nl = ""
+       for n in pairs(defined) do
+               nl = nl .. n .. "\n"
+       end
+
+       return setmetatable({ __orig_name_list = nl }, {
                __index = defined,
                __newindex = function (t, k, v)
                        if __protected[k] then