]> granicus.if.org Git - ejabberd/commitdiff
Correctly process errors from new cyrsasl API
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 2 Jan 2017 12:02:03 +0000 (15:02 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 2 Jan 2017 12:02:03 +0000 (15:02 +0300)
src/ejabberd_c2s.erl

index 6d84d8d93724529d324eb6973b76ad6f24137d2e..8693fcee5971e071588f6557755ceef6b3b5bd08 100644 (file)
@@ -719,17 +719,22 @@ wait_for_feature_request(#sasl_auth{mechanism = Mech,
            fsm_next_state(wait_for_sasl_response,
                           StateData#state{sasl_state = NewSASLState});
        {error, Error, Username} ->
-           ?INFO_MSG("(~w) Failed authentication for ~s@~s from ~s",
+           {Reason, ErrTxt} = cyrsasl:format_error(Mech, Error),
+           ?INFO_MSG("(~w) Failed authentication for ~s@~s from ~s: ~s",
                      [StateData#state.socket,
                       Username, StateData#state.server,
-                      ejabberd_config:may_hide_data(jlib:ip_to_list(StateData#state.ip))]),
+                      ejabberd_config:may_hide_data(jlib:ip_to_list(StateData#state.ip)),
+                      ErrTxt]),
            ejabberd_hooks:run(c2s_auth_result, StateData#state.server,
                               [false, Username, StateData#state.server,
                                StateData#state.ip]),
-           send_element(StateData, #sasl_failure{reason = Error}),
+           send_element(StateData, #sasl_failure{reason = Reason,
+                                                 text = xmpp:mk_text(ErrTxt)}),
            fsm_next_state(wait_for_feature_request, StateData);
        {error, Error} ->
-           send_element(StateData, #sasl_failure{reason = Error}),
+           {Reason, ErrTxt} = cyrsasl:format_error(Mech, Error),
+           send_element(StateData, #sasl_failure{reason = Reason,
+                                                 text = xmpp:mk_text(ErrTxt)}),
            fsm_next_state(wait_for_feature_request, StateData)
     end;
 wait_for_feature_request(#starttls{},
@@ -839,17 +844,22 @@ wait_for_sasl_response(#sasl_response{text = ClientIn}, StateData) ->
            fsm_next_state(wait_for_sasl_response,
                           StateData#state{sasl_state = NewSASLState});
        {error, Error, Username} ->
-           ?INFO_MSG("(~w) Failed authentication for ~s@~s from ~s",
+           {Reason, ErrTxt} = cyrsasl:format_error(StateData#state.sasl_state, Error),
+           ?INFO_MSG("(~w) Failed authentication for ~s@~s from ~s: ~s",
                      [StateData#state.socket,
                       Username, StateData#state.server,
-                      ejabberd_config:may_hide_data(jlib:ip_to_list(StateData#state.ip))]),
+                      ejabberd_config:may_hide_data(jlib:ip_to_list(StateData#state.ip)),
+                      ErrTxt]),
            ejabberd_hooks:run(c2s_auth_result, StateData#state.server,
                               [false, Username, StateData#state.server,
                                StateData#state.ip]),
-           send_element(StateData, #sasl_failure{reason = Error}),
+           send_element(StateData, #sasl_failure{reason = Reason,
+                                                 text = xmpp:mk_text(ErrTxt)}),
            fsm_next_state(wait_for_feature_request, StateData);
        {error, Error} ->
-           send_element(StateData, #sasl_failure{reason = Error}),
+           {Reason, ErrTxt} = cyrsasl:format_error(StateData#state.sasl_state, Error),
+           send_element(StateData, #sasl_failure{reason = Reason,
+                                                 text = xmpp:mk_text(ErrTxt)}),
            fsm_next_state(wait_for_feature_request, StateData)
     end;
 wait_for_sasl_response(timeout, StateData) ->