From 6f3aeead078143303f7e661f8bdbe11485e1d2e5 Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 29 Dec 2009 18:45:02 +0000 Subject: [PATCH] Support also SASL PLAIN auth messages described in RFC4616 (EJAB-1132) SVN Revision: 2841 --- src/cyrsasl_plain.erl | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/cyrsasl_plain.erl b/src/cyrsasl_plain.erl index 12576c77a..1d6c61c84 100644 --- a/src/cyrsasl_plain.erl +++ b/src/cyrsasl_plain.erl @@ -70,7 +70,7 @@ mech_new(_Host, _GetPassword, CheckPassword, _CheckPasswordDigest) -> %% Reason = term() mech_step(State, ClientIn) -> - case parse(ClientIn) of + case prepare(ClientIn) of [AuthzId, User, Password] -> case (State#state.check_password)(User, Password) of {true, AuthModule} -> @@ -83,6 +83,24 @@ mech_step(State, ClientIn) -> {error, 'bad-protocol'} end. +prepare(ClientIn) -> + case parse(ClientIn) of + [[], UserMaybeDomain, Password] -> + case parse_domain(UserMaybeDomain) of + %% login@domainpwd + [User, Domain] -> + [UserMaybeDomain, User, Password]; + %% loginpwd + [User] -> + ["", User, Password] + end; + %% login@domainloginpwd + [AuthzId, User, Password] -> + [AuthzId, User, Password]; + _ -> + error + end. + %% @hidden @@ -101,5 +119,12 @@ parse1([], S, T) -> lists:reverse([lists:reverse(S) | T]). +parse_domain(S) -> + parse_domain1(S, "", []). - +parse_domain1([$@ | Cs], S, T) -> + parse_domain1(Cs, "", [lists:reverse(S) | T]); +parse_domain1([C | Cs], S, T) -> + parse_domain1(Cs, [C | S], T); +parse_domain1([], S, T) -> + lists:reverse([lists:reverse(S) | T]).