util.sasl_cyrus: Automatically initialize Cyrus SASL with the first used service...
authorTobias Markmann <tm@ayena.de>
Tue, 29 Dec 2009 00:03:37 +0000 (01:03 +0100)
committerTobias Markmann <tm@ayena.de>
Tue, 29 Dec 2009 00:03:37 +0000 (01:03 +0100)
util/sasl_cyrus.lua

index 0ed8161ec0a7afb9bf213c33332d1064709212de..fd192233d6ed1742255f5e25098c8abf5ce0c3b6 100644 (file)
@@ -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)