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]).