aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-11-29 18:30:33 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-11-29 18:30:33 +0500
commit8fcbba4b0fccb299121083d97cab065e51fba9d1 (patch)
tree0897f3b98743848d263e64f617dbd4fb9ef47ae9 /util
parentee490c5eabc83cb65e8fb2d83590fb62ba0c1140 (diff)
downloadprosody-8fcbba4b0fccb299121083d97cab065e51fba9d1.tar.gz
prosody-8fcbba4b0fccb299121083d97cab065e51fba9d1.zip
util.sasl.plain: A little refactoring.
Diffstat (limited to 'util')
-rw-r--r--util/sasl/plain.lua23
1 files changed, 10 insertions, 13 deletions
diff --git a/util/sasl/plain.lua b/util/sasl/plain.lua
index 9ebfa15d..a4c8765d 100644
--- a/util/sasl/plain.lua
+++ b/util/sasl/plain.lua
@@ -17,26 +17,23 @@ local log = require "util.logger".init("sasl");
module "plain"
---=========================
---SASL PLAIN according to RFC 4616
+-- ================================
+-- SASL PLAIN according to RFC 4616
local function plain(self, message)
- local response = message
-
- local authorization, authentication, password;
- if response then
- authorization = s_match(response, "([^%z]+)")
- authentication = s_match(response, "%z([^%z]+)%z")
- password = s_match(response, "%z[^%z]+%z([^%z]+)")
+ if not message then
+ return "failure", "malformed-request";
end
-
- if authentication == nil or password == nil then
+
+ local authorization, authentication, password = s_match(message, "^([^%z]+)%z([^%z]+)%z([^%z]+)");
+
+ if not authorization then
return "failure", "malformed-request";
end
-
+
-- SASLprep password and authentication
authentication = saslprep(authentication);
password = saslprep(password);
-
+
if (not password) or (password == "") or (not authentication) or (authentication == "") then
log("debug", "Username or password violates SASLprep.");
return "failure", "malformed-request", "Invalid username or password.";