---=========================
---SASL PLAIN
-local function sasl_mechanism_plain(self, message)
- local response = message
- local authorization = s_match(response, "([^&%z]+)")
- local authentication = s_match(response, "%z([^&%z]+)%z")
- local password = s_match(response, "%z[^&%z]+%z([^&%z]+)")
-
- if authentication == nil or password == nil then
- return "failure", "malformed-request";
- end
-
- local correct, state = false, false;
- if self.profile.plain then
- local correct_password;
- correct_password, state = self.profile.plain(authentication, self.realm);
- if correct_password == password then correct = true; else correct = false; end
- elseif self.profile.plain_test then
- correct, state = self.profile.plain_test(authentication, self.realm, password);
- end
-
- self.username = authentication
- if not state then
- return "failure", "account-disabled";
- end
-
- if correct then
- return "success";
- else
- return "failure", "not-authorized";
- end
+-- load the mechanisms
+load_mechs = {"plain", "digest-md5", "anonymous", "scram"}
+for _, mech in ipairs(load_mechs) do
+ local name = "util.sasl."..mech;
+ local m = require(name);
+ m.init(registerMechanism)