Add real authentication to ConsoleServer/ConsoleSession, fix CommandList help

ConsoleSession's login flow never actually checked anything: the
entered username was discarded and the password was never compared,
so any input (including blank) reached the command prompt. Confirmed
live via an unauthenticated login against BARANTMail's admin console
on port 1027, which was reachable externally. ConsoleServer now takes
an optional credentialChecker callback consulted by the WAIT_PASSWORD
state; omitting it preserves the old accept-anything behavior for any
other use of this class.

Separately, the console never prompted until the client's first line
arrived - that line was silently discarded just to kick the state
machine off, shifting every subsequent line one slot early. Harmless
under the old accept-anything login, but it broke real credential
checking outright (the typed password was compared against the typed
username, etc). ConsoleSession::onConnected() now starts the state
machine immediately on connect instead.

CommandList::processCommand() was a no-op stub - the intended
"typing help lists the registered commands" body was commented out,
and even referenced a Command::getName() that was never added to the
base class. The map's own key from add() already is the registered
name, so this just walks it directly.
This commit is contained in:
Brad Arant committed 2026-09-06 04:05:59 +00:00
1 parent 2676aaf84c
commit 1a15f6ced8
5 files changed
+80 -7

No files matched your search

+9 -2
View File
@@ -56,8 +56,15 @@ namespace core {
}
int CommandList::processCommand(coreutils::ZString &request, TCPSession &session) {
// for(Command *command : commands)
// session.out << command->getName() << std::endl;
// The intent was always "typing help lists the available
// commands" - this was left as a no-op stub (the commented-out
// body even called a Command::getName() that was never added to
// the base class) so every registered CommandList - including
// the top-level one behind the "help" command itself - silently
// did nothing. The map's own key IS the registered name (see
// add()), so no getName() is needed at all - just walk it directly.
for (auto &pair : commands)
session.out << pair.first << std::string("\r\n");
return true;
}