mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
xmpp_stream_in: Run auth result callbacks earlier
Call Mod:handle_auth_success/4 and Mod:handle_auth_failure/4 before sending the SASL response rather than afterwards. This way, callbacks can send a custom response and disconnect.
This commit is contained in:
parent
22e43ebd8a
commit
c2235860ab
@ -836,13 +836,13 @@ process_sasl_success(Props, ServerOut,
|
|||||||
AuthModule = proplists:get_value(auth_module, Props),
|
AuthModule = proplists:get_value(auth_module, Props),
|
||||||
Socket1 = xmpp_socket:reset_stream(Socket),
|
Socket1 = xmpp_socket:reset_stream(Socket),
|
||||||
State0 = State#{socket => Socket1},
|
State0 = State#{socket => Socket1},
|
||||||
State1 = send_pkt(State0, #sasl_success{text = ServerOut}),
|
State1 = try Mod:handle_auth_success(User, Mech, AuthModule, State0)
|
||||||
|
catch _:undef -> State
|
||||||
|
end,
|
||||||
case is_disconnected(State1) of
|
case is_disconnected(State1) of
|
||||||
true -> State1;
|
true -> State1;
|
||||||
false ->
|
false ->
|
||||||
State2 = try Mod:handle_auth_success(User, Mech, AuthModule, State1)
|
State2 = send_pkt(State1, #sasl_success{text = ServerOut}),
|
||||||
catch _:undef -> State1
|
|
||||||
end,
|
|
||||||
case is_disconnected(State2) of
|
case is_disconnected(State2) of
|
||||||
true -> State2;
|
true -> State2;
|
||||||
false ->
|
false ->
|
||||||
@ -867,16 +867,22 @@ process_sasl_continue(ServerOut, NewSASLState, State) ->
|
|||||||
process_sasl_failure(Err, User,
|
process_sasl_failure(Err, User,
|
||||||
#{mod := Mod, sasl_mech := Mech, lang := Lang} = State) ->
|
#{mod := Mod, sasl_mech := Mech, lang := Lang} = State) ->
|
||||||
{Reason, Text} = format_sasl_error(Mech, Err),
|
{Reason, Text} = format_sasl_error(Mech, Err),
|
||||||
State1 = send_pkt(State, #sasl_failure{reason = Reason,
|
State1 = try Mod:handle_auth_failure(User, Mech, Text, State)
|
||||||
text = xmpp:mk_text(Text, Lang)}),
|
catch _:undef -> State
|
||||||
|
end,
|
||||||
case is_disconnected(State1) of
|
case is_disconnected(State1) of
|
||||||
true -> State1;
|
true -> State1;
|
||||||
false ->
|
false ->
|
||||||
State2 = try Mod:handle_auth_failure(User, Mech, Text, State1)
|
State2 = send_pkt(State1,
|
||||||
catch _:undef -> State1
|
#sasl_failure{reason = Reason,
|
||||||
end,
|
text = xmpp:mk_text(Text, Lang)}),
|
||||||
State3 = maps:remove(sasl_state, maps:remove(sasl_mech, State2)),
|
case is_disconnected(State2) of
|
||||||
State3#{stream_state => wait_for_sasl_request}
|
true -> State2;
|
||||||
|
false ->
|
||||||
|
State3 = maps:remove(sasl_state,
|
||||||
|
maps:remove(sasl_mech, State2)),
|
||||||
|
State3#{stream_state => wait_for_sasl_request}
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec process_sasl_abort(state()) -> state().
|
-spec process_sasl_abort(state()) -> state().
|
||||||
|
Loading…
Reference in New Issue
Block a user