From 21368785d600aae23e6a383cfd9a2f2b12f53894 Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Wed, 14 Oct 2020 06:33:29 +0200 Subject: [PATCH] Handle incorrect server password --- source/ircd/connection.d | 40 +++++++++++++++++++++++++++++++--------- source/ircd/server.d | 5 +++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/source/ircd/connection.d b/source/ircd/connection.d index 53c1049..610913d 100644 --- a/source/ircd/connection.d +++ b/source/ircd/connection.d @@ -48,9 +48,14 @@ class Connection return nick ~ "!" ~ user ~ "@" ~ hostname; } + @property bool registrationAttempted() + { + return nick !is null && user !is null; + } + @property bool registered() { - return nick !is null && user !is null && _server.isPassCorrect(pass); + return registrationAttempted && (!_server.hasPass || _server.isPassCorrect(pass)); } @property bool isOperator() @@ -61,9 +66,10 @@ class Connection @property string servername() { return _server.name; - } //TODO: Support server linking + } - //TODO: Maybe replace string's opEquals (or make a new string class/struct) to compare with toIRCLower + //TODO: Support server linking + //TODO: Maybe 'replace' string's opEquals (or make a new string class/struct) to compare with toIRCLower //TODO: Read errata this(TCPConnection connection, Server server) @@ -118,6 +124,7 @@ class Connection void closeConnection() { + connected = false; _connection.close(); } @@ -316,6 +323,10 @@ class Connection { sendWelcome(); } + else if (registrationAttempted) + { + onIncorrectPassword(); + } } void onUser(Message message) @@ -346,6 +357,10 @@ class Connection { sendWelcome(); } + else if (registrationAttempted) + { + onIncorrectPassword(); + } } void onPass(Message message) @@ -367,12 +382,6 @@ class Connection } pass = message.parameters[0]; - - if (!_server.isPassCorrect(pass)) - { - //NOTE: The RFCs don't allow ERR_PASSWDMISMATCH as a response to PASS - //TODO: If RFC-strictness is off, do send ERR_PASSWDMISMATCH - } } void onQuit(Message message) @@ -1420,6 +1429,19 @@ class Connection //TODO: If RFC-strictness is off, also send 002, 003, and 004 } + void onIncorrectPassword() + { + //NOTE: The RFCs don't allow ERR_PASSWDMISMATCH as a response to NICK/USER + + version (BasicFixes) + { + send(Message(_server.name, "464", [nick, "Password incorrect"], true)); + } + + //NOTE: The RFCs don't actually specify what should happen here + closeConnection(); + } + string getHost() { auto address = parseAddress(_connection.remoteAddress.toAddressString); diff --git a/source/ircd/server.d b/source/ircd/server.d index 6578b53..0908521 100644 --- a/source/ircd/server.d +++ b/source/ircd/server.d @@ -510,6 +510,11 @@ class Server return pass == _pass; } + bool hasPass() + { + return _pass != null; + } + void listen(ushort port = 6667) { listenTCP(port, &acceptConnection);