From d81b07bd5ff6d23fbd583df04870ea3a2f8f7af5 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Tue, 28 Feb 2017 12:13:35 +0300 Subject: [PATCH] Improve logging of outbound s2s auth failures --- src/xmpp_stream_out.erl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/xmpp_stream_out.erl b/src/xmpp_stream_out.erl index d663f32df..57f674ec0 100644 --- a/src/xmpp_stream_out.erl +++ b/src/xmpp_stream_out.erl @@ -639,7 +639,9 @@ process_sasl_success(#{mod := Mod, end. -spec process_sasl_failure(sasl_failure(), state()) -> state(). -process_sasl_failure(#sasl_failure{reason = Reason}, #{mod := Mod} = State) -> +process_sasl_failure(#sasl_failure{} = Failure, #{mod := Mod} = State) -> + Reason = format("Peer responded with error: ~s", + [format_sasl_failure(Failure)]), try Mod:handle_auth_failure(<<"EXTERNAL">>, {auth, Reason}, State) catch _:undef -> process_stream_end({auth, Reason}, State) end. @@ -787,6 +789,17 @@ format_tls_error(Reason) when is_atom(Reason) -> format_tls_error(Reason) -> binary_to_list(Reason). +format_sasl_failure(#sasl_failure{reason = Reason, text = Txt}) -> + Slogan = case Reason of + undefined -> "no reason"; + _ -> atom_to_list(Reason) + end, + case xmpp:get_text(Txt) of + <<"">> -> Slogan; + Data -> + binary_to_list(Data) ++ " (" ++ Slogan ++ ")" + end. + -spec format(io:format(), list()) -> binary(). format(Fmt, Args) -> iolist_to_binary(io_lib:format(Fmt, Args)).