Support also SASL PLAIN auth messages described in RFC4616 (EJAB-1132)

SVN Revision: 2841
This commit is contained in:
Badlop 2009-12-29 18:45:02 +00:00
parent 3da20486c1
commit 6f3aeead07
1 changed files with 27 additions and 2 deletions

View File

@ -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
%% <NUL>login@domain<NUL>pwd
[User, Domain] ->
[UserMaybeDomain, User, Password];
%% <NUL>login<NUL>pwd
[User] ->
["", User, Password]
end;
%% login@domain<NUL>login<NUL>pwd
[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]).