2003-03-09 21:46:47 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : cyrsasl_plain.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2003-03-09 21:46:47 +01:00
|
|
|
%%% Purpose : PLAIN SASL mechanism
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 8 Mar 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2008-07-31 13:18:49 +02:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2008 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
|
|
|
%%%
|
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program; if not, write to the Free Software
|
|
|
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2003-03-09 21:46:47 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(cyrsasl_plain).
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-03-09 21:46:47 +01:00
|
|
|
|
2006-04-07 02:39:24 +02:00
|
|
|
-export([start/1, stop/0, mech_new/3, 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.
|
|
|
|
|
2006-04-07 02:39:24 +02:00
|
|
|
mech_new(_Host, _GetPassword, CheckPassword) ->
|
2005-04-17 20:08:34 +02:00
|
|
|
{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
|
2008-04-22 19:41:30 +02:00
|
|
|
{true, AuthModule} ->
|
|
|
|
{ok, [{username, User}, {authzid, AuthzId},
|
|
|
|
{auth_module, AuthModule}]};
|
2003-03-09 21:46:47 +01:00
|
|
|
_ ->
|
2007-02-20 00:35:42 +01:00
|
|
|
{error, "not-authorized", User}
|
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]).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|