Mercurial > prosody-hg
comparison util/sasl.lua @ 288:dc53343af9ac
Set username in a SASL object.
| author | Tobias Markmann <tm@ayena.de> |
|---|---|
| date | Sat, 15 Nov 2008 20:28:09 +0100 |
| parents | 372d0891e8fd |
| children | 33175ad2f682 |
comparison
equal
deleted
inserted
replaced
| 286:7e4908d4bdf6 | 288:dc53343af9ac |
|---|---|
| 17 module "sasl" | 17 module "sasl" |
| 18 | 18 |
| 19 local function new_plain(realm, password_handler) | 19 local function new_plain(realm, password_handler) |
| 20 local object = { mechanism = "PLAIN", realm = realm, password_handler = password_handler} | 20 local object = { mechanism = "PLAIN", realm = realm, password_handler = password_handler} |
| 21 object.feed = function(self, message) | 21 object.feed = function(self, message) |
| 22 log("debug", "feed: "..message) | 22 --print(message:gsub("%W", function (c) return string.format("\\%d", string.byte(c)) end)); |
| 23 | |
| 24 if message == "" or message == nil then return "failure", "malformed-request" end | |
| 23 local response = message | 25 local response = message |
| 24 local authorization = s_match(response, "([^&%z]+)") | 26 local authorization = s_match(response, "([^&%z]+)") |
| 25 local authentication = s_match(response, "%z([^&%z]+)%z") | 27 local authentication = s_match(response, "%z([^&%z]+)%z") |
| 26 local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") | 28 local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") |
| 27 | 29 |
| 29 | 31 |
| 30 local claimed_password = "" | 32 local claimed_password = "" |
| 31 if password_encoding == nil then claimed_password = password | 33 if password_encoding == nil then claimed_password = password |
| 32 else claimed_password = password_encoding(password) end | 34 else claimed_password = password_encoding(password) end |
| 33 | 35 |
| 36 self.username = authentication | |
| 34 if claimed_password == correct_password then | 37 if claimed_password == correct_password then |
| 38 log("debug", "success") | |
| 35 return "success", nil | 39 return "success", nil |
| 36 else | 40 else |
| 41 log("debug", "failure") | |
| 37 return "failure", "not-authorized" | 42 return "failure", "not-authorized" |
| 38 end | 43 end |
| 39 end | 44 end |
| 40 return object | 45 return object |
| 41 end | 46 end |
