X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fsasl_cyrus.lua;h=fd192233d6ed1742255f5e25098c8abf5ce0c3b6;hb=4341e61cc1ca8384a0ca18bad7f8f8f3f1c894b0;hp=7e689f624956438d482bec10f310ffd3356c602e;hpb=c5cfbd9496c392a8963ab37f5e788a6be2fe5806;p=prosody.git diff --git a/util/sasl_cyrus.lua b/util/sasl_cyrus.lua index 7e689f62..fd192233 100644 --- a/util/sasl_cyrus.lua +++ b/util/sasl_cyrus.lua @@ -31,12 +31,22 @@ module "sasl_cyrus" local method = {}; method.__index = method; +local initialized = false; -pcall(cyrussasl.server_init, "prosody") +local function init(service_name) + if not initialized then + if pcall(cyrussasl.server_init, service_name) then + initialized = true; + end + end +end -- create a new SASL object which can be used to authenticate clients function new(realm, service_name) local sasl_i = {}; + + init(service_name); + sasl_i.realm = realm; sasl_i.service_name = service_name; sasl_i.cyrus = cyrussasl.server_new(service_name, nil, nil, nil, nil) @@ -64,17 +74,17 @@ end function method:mechanisms() local mechanisms = {} local cyrus_mechs = cyrussasl.listmech(self.cyrus, nil, "", " ", "") - for w in s_gmatch(cyrus_mechs, "%a+") do + for w in s_gmatch(cyrus_mechs, "[^ ]+") do mechanisms[w] = true; end - self.mechanisms = mechanisms + self.mechs = mechanisms return array.collect(keys(mechanisms)); end -- select a mechanism to use function method:select(mechanism) self.mechanism = mechanism; - return self.mechanisms[mechanism]; + return self.mechs[mechanism]; end -- feed new messages to process into the library