Merge 0.10->trunk
[prosody.git] / util / sasl.lua
index 0d90880dcda40a6f15b70e768e5132a8c4bbd706..5845f34a45e31cedfb20c07ec1592ef5ff833bdb 100644 (file)
@@ -18,9 +18,8 @@ local type = type
 local setmetatable = setmetatable;
 local assert = assert;
 local require = require;
-local print = print
 
-module "sasl"
+local _ENV = nil;
 
 --[[
 Authentication Backend Prototypes:
@@ -67,7 +66,7 @@ local function registerMechanism(name, backends, f, cb_backends)
 end
 
 -- create a new SASL object which can be used to authenticate clients
-function new(realm, profile)
+local function new(realm, profile)
        local mechanisms = profile.mechanisms;
        if not mechanisms then
                mechanisms = {};
@@ -101,14 +100,16 @@ end
 function method:mechanisms()
        local current_mechs = {};
        for mech, _ in pairs(self.mechs) do
-               if mechanism_channelbindings[mech] and self.profile.cb then
-                       local ok = false;
-                       for cb_name, _ in pairs(self.profile.cb) do
-                               if mechanism_channelbindings[mech][cb_name] then
-                                       ok = true;
+               if mechanism_channelbindings[mech] then
+                       if self.profile.cb then
+                               local ok = false;
+                               for cb_name, _ in pairs(self.profile.cb) do
+                                       if mechanism_channelbindings[mech][cb_name] then
+                                               ok = true;
+                                       end
                                end
+                               if ok == true then current_mechs[mech] = true; end
                        end
-                       if ok == true then current_mechs[mech] = true; end
                else
                        current_mechs[mech] = true;
                end
@@ -137,4 +138,7 @@ require "util.sasl.anonymous" .init(registerMechanism);
 require "util.sasl.scram"     .init(registerMechanism);
 require "util.sasl.external"  .init(registerMechanism);
 
-return _M;
+return {
+       registerMechanism = registerMechanism;
+       new = new;
+};