Software /
code /
prosody
Comparison
util/sasl.lua @ 6777:5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 21 Feb 2015 10:36:37 +0100 |
parent | 6036:f9e108f7db21 |
child | 8382:e5d00bf4a4d5 |
comparison
equal
deleted
inserted
replaced
6774:3965662ae091 | 6777:5de6b93d0190 |
---|---|
17 local type = type | 17 local type = type |
18 local setmetatable = setmetatable; | 18 local setmetatable = setmetatable; |
19 local assert = assert; | 19 local assert = assert; |
20 local require = require; | 20 local require = require; |
21 | 21 |
22 module "sasl" | 22 local _ENV = nil; |
23 | 23 |
24 --[[ | 24 --[[ |
25 Authentication Backend Prototypes: | 25 Authentication Backend Prototypes: |
26 | 26 |
27 state = false : disabled | 27 state = false : disabled |
45 local mechanisms = {}; | 45 local mechanisms = {}; |
46 local backend_mechanism = {}; | 46 local backend_mechanism = {}; |
47 local mechanism_channelbindings = {}; | 47 local mechanism_channelbindings = {}; |
48 | 48 |
49 -- register a new SASL mechanims | 49 -- register a new SASL mechanims |
50 function registerMechanism(name, backends, f, cb_backends) | 50 local function registerMechanism(name, backends, f, cb_backends) |
51 assert(type(name) == "string", "Parameter name MUST be a string."); | 51 assert(type(name) == "string", "Parameter name MUST be a string."); |
52 assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table."); | 52 assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table."); |
53 assert(type(f) == "function", "Parameter f MUST be a function."); | 53 assert(type(f) == "function", "Parameter f MUST be a function."); |
54 if cb_backends then assert(type(cb_backends) == "table"); end | 54 if cb_backends then assert(type(cb_backends) == "table"); end |
55 mechanisms[name] = f | 55 mechanisms[name] = f |
64 t_insert(backend_mechanism[backend_name], name); | 64 t_insert(backend_mechanism[backend_name], name); |
65 end | 65 end |
66 end | 66 end |
67 | 67 |
68 -- create a new SASL object which can be used to authenticate clients | 68 -- create a new SASL object which can be used to authenticate clients |
69 function new(realm, profile) | 69 local function new(realm, profile) |
70 local mechanisms = profile.mechanisms; | 70 local mechanisms = profile.mechanisms; |
71 if not mechanisms then | 71 if not mechanisms then |
72 mechanisms = {}; | 72 mechanisms = {}; |
73 for backend, f in pairs(profile) do | 73 for backend, f in pairs(profile) do |
74 if backend_mechanism[backend] then | 74 if backend_mechanism[backend] then |
136 require "util.sasl.digest-md5".init(registerMechanism); | 136 require "util.sasl.digest-md5".init(registerMechanism); |
137 require "util.sasl.anonymous" .init(registerMechanism); | 137 require "util.sasl.anonymous" .init(registerMechanism); |
138 require "util.sasl.scram" .init(registerMechanism); | 138 require "util.sasl.scram" .init(registerMechanism); |
139 require "util.sasl.external" .init(registerMechanism); | 139 require "util.sasl.external" .init(registerMechanism); |
140 | 140 |
141 return _M; | 141 return { |
142 registerMechanism = registerMechanism; | |
143 new = new; | |
144 }; |