aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2012-06-08 05:04:38 +0200
committerFlorian Zeitz <florob@babelmonkeys.de>2012-06-08 05:04:38 +0200
commitd49b9bc2abb50b22ae3d6739d96423e9dadfeda8 (patch)
tree28c1bcbab960b28cc27f30e8ab0c04e30f11da2d /plugins
parent217e6d011c8d8ae2c44034fc9138925d77c3c10b (diff)
downloadprosody-d49b9bc2abb50b22ae3d6739d96423e9dadfeda8.tar.gz
prosody-d49b9bc2abb50b22ae3d6739d96423e9dadfeda8.zip
Eliminate direct setfenv usage
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_telnet.lua16
-rw-r--r--plugins/storage/sqlbasic.lib.lua4
2 files changed, 10 insertions, 10 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua
index b56f9291..8787427e 100644
--- a/plugins/mod_admin_telnet.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -21,6 +21,8 @@ local jid = require "util.jid";
local jid_bare, jid_split = jid.bare, jid.split;
local set, array = require "util.set", require "util.array";
local cert_verify_identity = require "util.x509".verify_identity;
+local envload = require "util.envload".envload;
+local envloadfile = require "util.envload".envloadfile;
local commands = module:shared("commands")
local def_env = module:shared("env");
@@ -29,9 +31,9 @@ local default_env_mt = { __index = def_env };
local function redirect_output(_G, session)
local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end });
env.dofile = function(name)
- local f, err = loadfile(name);
+ local f, err = envloadfile(name, env);
if not f then return f, err; end
- return setfenv(f, env)();
+ return f();
end;
return env;
end
@@ -98,9 +100,10 @@ function console_listener.onincoming(conn, data)
session.env._ = data;
local chunkname = "=console";
- local chunk, err = loadstring("return "..data, chunkname);
+ local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil
+ local chunk, err = envload("return "..data, chunkname, env);
if not chunk then
- chunk, err = loadstring(data, chunkname);
+ chunk, err = envload(data, chunkname, env);
if not chunk then
err = err:gsub("^%[string .-%]:%d+: ", "");
err = err:gsub("^:%d+: ", "");
@@ -110,8 +113,6 @@ function console_listener.onincoming(conn, data)
end
end
- setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil);
-
local ranok, taskok, message = pcall(chunk);
if not (ranok or message or useglobalenv) and commands[data:lower()] then
@@ -880,8 +881,7 @@ if option and option ~= "short" and option ~= "full" and option ~= "graphic" the
if type(option) == "string" then
session.print(option)
elseif type(option) == "function" then
- setfenv(option, redirect_output(_G, session));
- pcall(option, session);
+ module:log("warn", "Using functions as value for the console_banner option is no longer supported");
end
end
end
diff --git a/plugins/storage/sqlbasic.lib.lua b/plugins/storage/sqlbasic.lib.lua
index f1202287..ab3648f9 100644
--- a/plugins/storage/sqlbasic.lib.lua
+++ b/plugins/storage/sqlbasic.lib.lua
@@ -3,12 +3,12 @@
-- This driver stores data as simple key-values
local ser = require "util.serialization".serialize;
+local envload = require "util.envload".envload;
local deser = function(data)
module:log("debug", "deser: %s", tostring(data));
if not data then return nil; end
- local f = loadstring("return "..data);
+ local f = envload("return "..data, nil, {});
if not f then return nil; end
- setfenv(f, {});
local s, d = pcall(f);
if not s then return nil; end
return d;