util/sasl.lua
changeset 3549 395d5bb5266e
parent 3442 8cfacc41099e
child 3550 5e5d136d9de0
equal deleted inserted replaced
3548:cd8d1cacc65b 3549:395d5bb5266e
    46 	end
    46 	end
    47 end
    47 end
    48 
    48 
    49 -- create a new SASL object which can be used to authenticate clients
    49 -- create a new SASL object which can be used to authenticate clients
    50 function new(realm, profile)
    50 function new(realm, profile)
    51 	return setmetatable({ profile = profile, realm = realm }, method);
    51 	local mechanisms = {};
       
    52 	for backend, f in pairs(profile) do
       
    53 		if backend_mechanism[backend] then
       
    54 			for _, mechanism in ipairs(backend_mechanism[backend]) do
       
    55 				mechanisms[mechanism] = true;
       
    56 			end
       
    57 		end
       
    58 	end
       
    59 	return setmetatable({ profile = profile, realm = realm, mechs = mechanisms }, method);
    52 end
    60 end
    53 
    61 
    54 -- get a fresh clone with the same realm and profile
    62 -- get a fresh clone with the same realm and profile
    55 function method:clean_clone()
    63 function method:clean_clone()
    56 	return new(self.realm, self.profile)
    64 	return new(self.realm, self.profile)
    57 end
    65 end
    58 
    66 
    59 -- get a list of possible SASL mechanims to use
    67 -- get a list of possible SASL mechanims to use
    60 function method:mechanisms()
    68 function method:mechanisms()
    61 	local mechanisms = self.mechs;
    69 	return self.mechs;
    62 	if not mechanisms then
       
    63 		mechanisms = {}
       
    64 		for backend, f in pairs(self.profile) do
       
    65 			if backend_mechanism[backend] then
       
    66 				for _, mechanism in ipairs(backend_mechanism[backend]) do
       
    67 					mechanisms[mechanism] = true;
       
    68 				end
       
    69 			end
       
    70 		end
       
    71 		self.mechs = mechanisms;
       
    72 	end
       
    73 	return mechanisms;
       
    74 end
    70 end
    75 
    71 
    76 -- select a mechanism to use
    72 -- select a mechanism to use
    77 function method:select(mechanism)
    73 function method:select(mechanism)
    78 	if self.mech_i then
    74 	if self.mech_i then