From 063e6b127ecf92ca5bf8c4ecb137b60e3e7aa216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 12 Aug 2020 09:40:36 +0200 Subject: Handle SASL failures by displaying a message and aborting the connection --- src/irc/irc_client.cpp | 25 ++++++++++++++++++++++++- src/irc/irc_client.hpp | 3 ++- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index 351f9f8..3ae5ac6 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -85,8 +85,14 @@ static const std::unordered_mapchannels_to_join.clear(); } else // try the next port this->start(); @@ -1372,6 +1379,22 @@ void IrcClient::on_sasl_success(const IrcMessage &) this->cap_end(); } +void IrcClient::on_sasl_failure(const IrcMessage& message) +{ + this->sasl_state = SaslState::failure; + const auto reason = message.arguments[1]; + // Send an error message for all room that the user wanted to join + for (const auto& tuple: this->channels_to_join) + { + Iid iid(std::get<0>(tuple) + "%" + this->hostname, this->chantypes); + this->bridge.send_presence_error(iid, this->current_nick, + "cancel", "item-not-found", + "", reason); + } + this->channels_to_join.clear(); + this->send_quit_command(reason); +} + void IrcClient::on_sasl_login(const IrcMessage &message) { const auto& login = message.arguments[2]; diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp index 9f77e29..ac2f6a9 100644 --- a/src/irc/irc_client.hpp +++ b/src/irc/irc_client.hpp @@ -247,8 +247,9 @@ private: public: #ifdef WITH_SASL void on_authenticate(const IrcMessage& message); - void on_sasl_success(const IrcMessage& message); void on_sasl_login(const IrcMessage& message); + void on_sasl_success(const IrcMessage& message); + void on_sasl_failure(const IrcMessage& message); #endif /** * The channel has been completely joined (self presence, topic, all names -- cgit v1.2.3