Fail if username or password don't pass SASLprep.
[prosody.git] / prosody
diff --git a/prosody b/prosody
index dc28c771b2cee7c97935e4739b95790df20624c0..e22e59454ab3070649284db4fe938bc2bb49e610 100755 (executable)
--- a/prosody
+++ b/prosody
@@ -32,7 +32,26 @@ end
 
 -- Required to be able to find packages installed with luarocks
 pcall(require, "luarocks.require")
-require "util.require";
+
+-- Replace require with one that doesn't pollute _G
+do
+       local _realG = _G;
+       local _real_require = require;
+       function require(...)
+               local curr_env = getfenv(2);
+               local curr_env_mt = getmetatable(getfenv(2));
+               local _realG_mt = getmetatable(_realG);
+               if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then
+                       local old_newindex
+                       old_newindex, _realG_mt.__newindex = _realG_mt.__newindex, curr_env;
+                       local ret = _real_require(...);
+                       _realG_mt.__newindex = old_newindex;
+                       return ret;
+               end
+               return _real_require(...);
+       end
+end
+
 
 config = require "core.configmanager"
 
@@ -202,7 +221,7 @@ function prepare_to_start()
        prosody.events.fire_event("server-starting");
 
        -- Load SSL settings from config, and create a ctx table
-       local global_ssl_ctx = ssl and config.get("*", "core", "ssl");
+       local global_ssl_ctx = rawget(_G, "ssl") and config.get("*", "core", "ssl");
        if global_ssl_ctx then
                local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
                setmetatable(global_ssl_ctx, { __index = default_ssl_ctx });
@@ -263,7 +282,7 @@ end
 function loop()
        -- Error handler for errors that make it this far
        local function catch_uncaught_error(err)
-               if err:match("%d*: interrupted!$") then
+               if type(err) == "string" and err:match("%d*: interrupted!$") then
                        return "quitting";
                end