From e383b00ff83c99bdf37c3cef37a3bd1da79ef911 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sun, 8 Jan 2023 19:24:21 +0000 Subject: [PATCH] Return an error if a client attempts to authenticate again --- src/client.rs | 8 ++++++-- src/connection.rs | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index 073ba9d..1d015f6 100644 --- a/src/client.rs +++ b/src/client.rs @@ -12,7 +12,7 @@ use tracing::{debug, error, info_span, instrument, warn, Instrument, Span}; use crate::{ channel::Channel, - connection::{InitiatedConnection, MessageSink}, + connection::{InitiatedConnection, MessageSink, SaslAlreadyAuthenticated}, messages::{ Broadcast, ChannelFetchTopic, ChannelInvite, ChannelJoin, ChannelKickUser, ChannelList, ChannelMemberList, ChannelMessage, ChannelPart, ChannelUpdateTopic, FetchClientDetails, @@ -569,7 +569,11 @@ impl StreamHandler> for Client { Command::BOTSERV(_) => {} Command::HOSTSERV(_) => {} Command::MEMOSERV(_) => {} - Command::AUTHENTICATE(_) => {} + Command::AUTHENTICATE(_) => { + self.writer.write( + SaslAlreadyAuthenticated(self.connection.nick.to_string()).into_message(), + ); + } Command::ACCOUNT(_) => {} Command::METADATA(_, _, _) => {} Command::MONITOR(_, _) => {} diff --git a/src/connection.rs b/src/connection.rs index 1c3293c..774ba76 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -343,6 +343,26 @@ impl FromStr for AuthStrategy { } } +/// Returned to the client if they try to call AUTHENTICATE again after negotiation. +pub struct SaslAlreadyAuthenticated(pub String); + +impl SaslAlreadyAuthenticated { + #[must_use] + pub fn into_message(self) -> Message { + Message { + tags: None, + prefix: None, + command: Command::Response( + Response::ERR_SASLALREADY, + vec![ + self.0, + "You have already authenticated using SASL".to_string(), + ], + ), + } + } +} + /// Returned to the client when an invalid SASL strategy is attempted. pub struct SaslStrategyUnsupported(String); -- libgit2 1.7.2