2003-03-09 21:46:47 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : cyrsasl_plain.erl
|
|
|
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
|
|
|
%%% Purpose : PLAIN SASL mechanism
|
|
|
|
%%% Created : 8 Mar 2003 by Alexey Shchepin <alexey@sevcom.net>
|
|
|
|
%%% Id : $Id$
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(cyrsasl_plain).
|
|
|
|
-author('alexey@sevcom.net').
|
|
|
|
-vsn('$Revision$ ').
|
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
-export([start/1, stop/0, mech_new/2, mech_step/2, parse/1]).
|
2003-03-09 21:46:47 +01:00
|
|
|
|
|
|
|
-behaviour(cyrsasl).
|
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
-record(state, {check_password}).
|
|
|
|
|
|
|
|
start(_Opts) ->
|
2005-07-13 05:24:13 +02:00
|
|
|
cyrsasl:register_mechanism("PLAIN", ?MODULE, false),
|
2003-03-09 21:46:47 +01:00
|
|
|
ok.
|
|
|
|
|
|
|
|
stop() ->
|
|
|
|
ok.
|
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
mech_new(_GetPassword, CheckPassword) ->
|
|
|
|
{ok, #state{check_password = CheckPassword}}.
|
2003-03-09 21:46:47 +01:00
|
|
|
|
|
|
|
mech_step(State, ClientIn) ->
|
|
|
|
case parse(ClientIn) of
|
2003-06-07 19:30:25 +02:00
|
|
|
[AuthzId, User, Password] ->
|
2005-04-17 20:08:34 +02:00
|
|
|
case (State#state.check_password)(User, Password) of
|
2003-03-09 21:46:47 +01:00
|
|
|
true ->
|
2003-06-07 19:30:25 +02:00
|
|
|
{ok, [{username, User}, {authzid, AuthzId}]};
|
2003-03-09 21:46:47 +01:00
|
|
|
_ ->
|
2003-06-07 19:30:25 +02:00
|
|
|
{error, "bad-auth"}
|
2003-03-09 21:46:47 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2003-06-07 19:30:25 +02:00
|
|
|
{error, "bad-protocol"}
|
2003-03-09 21:46:47 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
parse(S) ->
|
|
|
|
parse1(S, "", []).
|
|
|
|
|
|
|
|
parse1([0 | Cs], S, T) ->
|
|
|
|
parse1(Cs, "", [lists:reverse(S) | T]);
|
|
|
|
parse1([C | Cs], S, T) ->
|
|
|
|
parse1(Cs, [C | S], T);
|
|
|
|
%parse1([], [], T) ->
|
|
|
|
% lists:reverse(T);
|
|
|
|
parse1([], S, T) ->
|
|
|
|
lists:reverse([lists:reverse(S) | T]).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|