Files
ServerCore/ConsoleServer.cpp
T
Brad Arant 1a15f6ced8 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.
2026-09-06 04:05:59 +00:00

28 lines
860 B
C++

#include "ConsoleServer.h"
#include "ConsoleSession.h"
#include "Command.h"
#include "Log.h"
namespace core {
ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address, TLSInfo *tlsInfo,
std::function<bool(std::string, std::string)> credentialChecker)
: TCPServer(ePoll, address, tlsInfo, " ", 10, "Console Server"), credentialChecker(credentialChecker) {
coreutils::Log(this);
}
void ConsoleServer::logSend(std::string out) {
for(auto *session : sessions)
((ConsoleSession *)session)->writeLog(out);
}
TCPSession * ConsoleServer::getSocketAccept(EPoll &ePoll) {
return new ConsoleSession(ePoll, this);
}
bool ConsoleServer::checkCredentials(std::string user, std::string password) {
return credentialChecker ? credentialChecker(user, password) : true;
}
}