25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Various fixes (EJAB-831)

This commit is contained in:
Badlop 2010-04-15 17:22:42 +02:00
parent aa791ad0c4
commit 07e459d577
4 changed files with 16 additions and 17 deletions

View File

@ -52,7 +52,6 @@
-behaviour(cyrsasl).
-define(SERVER, ?MODULE).
-define(MSG, ?DEBUG).
-define(SERVICE, "xmpp").
-record(state, {sasl,
@ -91,35 +90,35 @@ stop() ->
mech_new(#sasl_params{host=Host, realm=Realm, socket=Socket}) ->
case ejabberd_socket:gethostname(Socket) of
{ok, FQDN} ->
?MSG("mech_new ~p ~p ~p~n", [Host, Realm, FQDN]),
?DEBUG("mech_new ~p ~p ~p~n", [Host, Realm, FQDN]),
case esasl:server_start(?SERVER, "GSSAPI", ?SERVICE, FQDN) of
{ok, Sasl} ->
{ok, #state{sasl=Sasl,host=Host,realm=Realm}};
{error, {gsasl_error, Error}} ->
{ok, Str} = esasl:str_error(?SERVER, Error),
?MSG("esasl error: ~p", [Str]),
?DEBUG("esasl error: ~p", [Str]),
{ok, #state{needsmore=error,error="internal-server-error"}};
{error, Error} ->
?MSG("esasl error: ~p", [Error]),
?DEBUG("esasl error: ~p", [Error]),
{ok, #state{needsmore=error,error="internal-server-error"}}
end;
{error, Error} ->
?MSG("gethostname error: ~p", [Error]),
?DEBUG("gethostname error: ~p", [Error]),
{ok, #state{needsmore=error,error="internal-server-error"}}
end.
mech_step(State, ClientIn) when is_list(ClientIn) ->
catch do_step(State, ClientIn).
do_step(#state{needsmore=error,error=Error}=State, _) ->
do_step(#state{needsmore=error,error=Error}=_State, _) ->
{error, Error};
do_step(#state{needsmore=false}=State, _) ->
check_user(State);
do_step(#state{needsmore=true,sasl=Sasl,step=Step}=State, ClientIn) ->
?MSG("mech_step~n", []),
?DEBUG("mech_step~n", []),
case esasl:step(Sasl, list_to_binary(ClientIn)) of
{ok, RspAuth} ->
?MSG("ok~n", []),
?DEBUG("ok~n", []),
{ok, Display_name} = esasl:property_get(Sasl, gssapi_display_name),
{ok, Authzid} = esasl:property_get(Sasl, authzid),
{Authid, [$@ | Auth_realm]} =
@ -129,7 +128,7 @@ do_step(#state{needsmore=true,sasl=Sasl,step=Step}=State, ClientIn) ->
authrealm=Auth_realm},
handle_step_ok(State1, binary_to_list(RspAuth));
{needsmore, RspAuth} ->
?MSG("needsmore~n", []),
?DEBUG("needsmore~n", []),
if (Step > 0) and (ClientIn =:= []) and (RspAuth =:= <<>>) ->
{error, "not-authorized"};
true ->
@ -143,13 +142,13 @@ do_step(#state{needsmore=true,sasl=Sasl,step=Step}=State, ClientIn) ->
handle_step_ok(State, []) ->
check_user(State);
handle_step_ok(#state{step=Step}=State, RspAuth) ->
?MSG("continue~n", []),
?DEBUG("continue~n", []),
{continue, RspAuth, State#state{needsmore=false,step=Step+1}}.
check_user(#state{authid=Authid,authzid=Authzid,
authrealm=Auth_realm,host=Host,realm=Realm}) ->
if Realm =/= Auth_realm ->
?MSG("bad realm ~p (expected ~p)~n",[Auth_realm, Realm]),
?DEBUG("bad realm ~p (expected ~p)~n",[Auth_realm, Realm]),
throw({error, "not-authorized"});
true ->
ok
@ -157,11 +156,11 @@ check_user(#state{authid=Authid,authzid=Authzid,
case ejabberd_auth:is_user_exists(Authid, Host) of
false ->
?MSG("bad user ~p~n",[Authid]),
?DEBUG("bad user ~p~n",[Authid]),
throw({error, "not-authorized"});
true ->
ok
end,
?MSG("GSSAPI authenticated ~p ~p~n", [Authid, Authzid]),
?DEBUG("GSSAPI authenticated ~p ~p~n", [Authid, Authzid]),
{ok, [{username, Authid}, {authzid, Authzid}]}.

View File

@ -50,7 +50,7 @@ start(_Opts) ->
stop() ->
ok.
mech_new(_Host, _GetPassword, CheckPassword, _CheckPasswordDigest) ->
mech_new(#sasl_params{check_password = CheckPassword}) ->
{ok, #state{check_password = CheckPassword}}.
%% @spec (State, ClientIn) -> Ok | Error

View File

@ -383,7 +383,7 @@ wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) ->
exmpp_stream:features(
TLSFeature ++
CompressFeature ++
SASL_Mechs ++
Mechs ++
Other_Feats)),
fsm_next_state(wait_for_feature_request,
StateData#state{

View File

@ -240,10 +240,10 @@ gethostname(#socket_state{socket = Socket} = State) ->
?DEBUG("gethostname result ~p~n",
[HostEnt#hostent.h_name]),
{ok, HostEnt#hostent.h_name};
{error, Reason} = E ->
{error, _Reason} = E ->
E
end;
{error, Reason} = E ->
{error, _Reason} = E ->
E
end.