X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fsasl.lua;h=afb3861b08f90d70db33d9657da4df77efe43036;hb=8ea668bb9a0b77bff5e11aa4214ba00c906dbda2;hp=93b79a86a63de48333bc482b0a0de155c3db3aa3;hpb=5efbda89592bfd80ab53fbaea4396461395aac2b;p=prosody.git diff --git a/util/sasl.lua b/util/sasl.lua index 93b79a86..afb3861b 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -35,7 +35,7 @@ local mechanisms = {}; local backend_mechanism = {}; -- register a new SASL mechanims -local function registerMechanism(name, backends, f) +function registerMechanism(name, backends, f) assert(type(name) == "string", "Parameter name MUST be a string."); assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table."); assert(type(f) == "function", "Parameter f MUST be a function."); @@ -48,13 +48,17 @@ end -- create a new SASL object which can be used to authenticate clients function new(realm, profile) - local mechanisms = {}; - for backend, f in pairs(profile) do - if backend_mechanism[backend] then - for _, mechanism in ipairs(backend_mechanism[backend]) do - mechanisms[mechanism] = true; + local mechanisms = profile.mechanisms; + if not mechanisms then + mechanisms = {}; + for backend, f in pairs(profile) do + if backend_mechanism[backend] then + for _, mechanism in ipairs(backend_mechanism[backend]) do + mechanisms[mechanism] = true; + end end end + profile.mechanisms = mechanisms; end return setmetatable({ profile = profile, realm = realm, mechs = mechanisms }, method); end