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:
parent
aa791ad0c4
commit
07e459d577
@ -52,7 +52,6 @@
|
|||||||
-behaviour(cyrsasl).
|
-behaviour(cyrsasl).
|
||||||
|
|
||||||
-define(SERVER, ?MODULE).
|
-define(SERVER, ?MODULE).
|
||||||
-define(MSG, ?DEBUG).
|
|
||||||
-define(SERVICE, "xmpp").
|
-define(SERVICE, "xmpp").
|
||||||
|
|
||||||
-record(state, {sasl,
|
-record(state, {sasl,
|
||||||
@ -91,35 +90,35 @@ stop() ->
|
|||||||
mech_new(#sasl_params{host=Host, realm=Realm, socket=Socket}) ->
|
mech_new(#sasl_params{host=Host, realm=Realm, socket=Socket}) ->
|
||||||
case ejabberd_socket:gethostname(Socket) of
|
case ejabberd_socket:gethostname(Socket) of
|
||||||
{ok, FQDN} ->
|
{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
|
case esasl:server_start(?SERVER, "GSSAPI", ?SERVICE, FQDN) of
|
||||||
{ok, Sasl} ->
|
{ok, Sasl} ->
|
||||||
{ok, #state{sasl=Sasl,host=Host,realm=Realm}};
|
{ok, #state{sasl=Sasl,host=Host,realm=Realm}};
|
||||||
{error, {gsasl_error, Error}} ->
|
{error, {gsasl_error, Error}} ->
|
||||||
{ok, Str} = esasl:str_error(?SERVER, 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"}};
|
{ok, #state{needsmore=error,error="internal-server-error"}};
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
?MSG("esasl error: ~p", [Error]),
|
?DEBUG("esasl error: ~p", [Error]),
|
||||||
{ok, #state{needsmore=error,error="internal-server-error"}}
|
{ok, #state{needsmore=error,error="internal-server-error"}}
|
||||||
end;
|
end;
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
?MSG("gethostname error: ~p", [Error]),
|
?DEBUG("gethostname error: ~p", [Error]),
|
||||||
{ok, #state{needsmore=error,error="internal-server-error"}}
|
{ok, #state{needsmore=error,error="internal-server-error"}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
mech_step(State, ClientIn) when is_list(ClientIn) ->
|
mech_step(State, ClientIn) when is_list(ClientIn) ->
|
||||||
catch do_step(State, ClientIn).
|
catch do_step(State, ClientIn).
|
||||||
|
|
||||||
do_step(#state{needsmore=error,error=Error}=State, _) ->
|
do_step(#state{needsmore=error,error=Error}=_State, _) ->
|
||||||
{error, Error};
|
{error, Error};
|
||||||
do_step(#state{needsmore=false}=State, _) ->
|
do_step(#state{needsmore=false}=State, _) ->
|
||||||
check_user(State);
|
check_user(State);
|
||||||
do_step(#state{needsmore=true,sasl=Sasl,step=Step}=State, ClientIn) ->
|
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
|
case esasl:step(Sasl, list_to_binary(ClientIn)) of
|
||||||
{ok, RspAuth} ->
|
{ok, RspAuth} ->
|
||||||
?MSG("ok~n", []),
|
?DEBUG("ok~n", []),
|
||||||
{ok, Display_name} = esasl:property_get(Sasl, gssapi_display_name),
|
{ok, Display_name} = esasl:property_get(Sasl, gssapi_display_name),
|
||||||
{ok, Authzid} = esasl:property_get(Sasl, authzid),
|
{ok, Authzid} = esasl:property_get(Sasl, authzid),
|
||||||
{Authid, [$@ | Auth_realm]} =
|
{Authid, [$@ | Auth_realm]} =
|
||||||
@ -129,7 +128,7 @@ do_step(#state{needsmore=true,sasl=Sasl,step=Step}=State, ClientIn) ->
|
|||||||
authrealm=Auth_realm},
|
authrealm=Auth_realm},
|
||||||
handle_step_ok(State1, binary_to_list(RspAuth));
|
handle_step_ok(State1, binary_to_list(RspAuth));
|
||||||
{needsmore, RspAuth} ->
|
{needsmore, RspAuth} ->
|
||||||
?MSG("needsmore~n", []),
|
?DEBUG("needsmore~n", []),
|
||||||
if (Step > 0) and (ClientIn =:= []) and (RspAuth =:= <<>>) ->
|
if (Step > 0) and (ClientIn =:= []) and (RspAuth =:= <<>>) ->
|
||||||
{error, "not-authorized"};
|
{error, "not-authorized"};
|
||||||
true ->
|
true ->
|
||||||
@ -143,13 +142,13 @@ do_step(#state{needsmore=true,sasl=Sasl,step=Step}=State, ClientIn) ->
|
|||||||
handle_step_ok(State, []) ->
|
handle_step_ok(State, []) ->
|
||||||
check_user(State);
|
check_user(State);
|
||||||
handle_step_ok(#state{step=Step}=State, RspAuth) ->
|
handle_step_ok(#state{step=Step}=State, RspAuth) ->
|
||||||
?MSG("continue~n", []),
|
?DEBUG("continue~n", []),
|
||||||
{continue, RspAuth, State#state{needsmore=false,step=Step+1}}.
|
{continue, RspAuth, State#state{needsmore=false,step=Step+1}}.
|
||||||
|
|
||||||
check_user(#state{authid=Authid,authzid=Authzid,
|
check_user(#state{authid=Authid,authzid=Authzid,
|
||||||
authrealm=Auth_realm,host=Host,realm=Realm}) ->
|
authrealm=Auth_realm,host=Host,realm=Realm}) ->
|
||||||
if Realm =/= Auth_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"});
|
throw({error, "not-authorized"});
|
||||||
true ->
|
true ->
|
||||||
ok
|
ok
|
||||||
@ -157,11 +156,11 @@ check_user(#state{authid=Authid,authzid=Authzid,
|
|||||||
|
|
||||||
case ejabberd_auth:is_user_exists(Authid, Host) of
|
case ejabberd_auth:is_user_exists(Authid, Host) of
|
||||||
false ->
|
false ->
|
||||||
?MSG("bad user ~p~n",[Authid]),
|
?DEBUG("bad user ~p~n",[Authid]),
|
||||||
throw({error, "not-authorized"});
|
throw({error, "not-authorized"});
|
||||||
true ->
|
true ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
|
|
||||||
?MSG("GSSAPI authenticated ~p ~p~n", [Authid, Authzid]),
|
?DEBUG("GSSAPI authenticated ~p ~p~n", [Authid, Authzid]),
|
||||||
{ok, [{username, Authid}, {authzid, Authzid}]}.
|
{ok, [{username, Authid}, {authzid, Authzid}]}.
|
||||||
|
@ -50,7 +50,7 @@ start(_Opts) ->
|
|||||||
stop() ->
|
stop() ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
mech_new(_Host, _GetPassword, CheckPassword, _CheckPasswordDigest) ->
|
mech_new(#sasl_params{check_password = CheckPassword}) ->
|
||||||
{ok, #state{check_password = CheckPassword}}.
|
{ok, #state{check_password = CheckPassword}}.
|
||||||
|
|
||||||
%% @spec (State, ClientIn) -> Ok | Error
|
%% @spec (State, ClientIn) -> Ok | Error
|
||||||
|
@ -383,7 +383,7 @@ wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) ->
|
|||||||
exmpp_stream:features(
|
exmpp_stream:features(
|
||||||
TLSFeature ++
|
TLSFeature ++
|
||||||
CompressFeature ++
|
CompressFeature ++
|
||||||
SASL_Mechs ++
|
Mechs ++
|
||||||
Other_Feats)),
|
Other_Feats)),
|
||||||
fsm_next_state(wait_for_feature_request,
|
fsm_next_state(wait_for_feature_request,
|
||||||
StateData#state{
|
StateData#state{
|
||||||
|
@ -240,10 +240,10 @@ gethostname(#socket_state{socket = Socket} = State) ->
|
|||||||
?DEBUG("gethostname result ~p~n",
|
?DEBUG("gethostname result ~p~n",
|
||||||
[HostEnt#hostent.h_name]),
|
[HostEnt#hostent.h_name]),
|
||||||
{ok, HostEnt#hostent.h_name};
|
{ok, HostEnt#hostent.h_name};
|
||||||
{error, Reason} = E ->
|
{error, _Reason} = E ->
|
||||||
E
|
E
|
||||||
end;
|
end;
|
||||||
{error, Reason} = E ->
|
{error, _Reason} = E ->
|
||||||
E
|
E
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user