Files
ServerCore/ConsoleServer.h
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

55 lines
1.2 KiB
C++

#ifndef __ConsoleServer_h__
# define __ConsoleServer_h__
# include "TCPServer.h"
# include "Command.h"
# include "EPoll.h"
# include "LogListener.h"
# include "TLSInfo.h"
# include <functional>
# include <string>
namespace core {
class TCPSocket;
class TCPSession;
///
///
///
class ConsoleServer : public TCPServer, public coreutils::LogListener {
public:
//
// credentialChecker, when provided, is consulted by
// ConsoleSession's login flow (see its own doc comment) instead
// of the previous unconditional accept-anything behavior. Left
// defaulting to nullptr so any other, unrelated use of
// ConsoleServer that never cared about authentication is
// unaffected.
//
ConsoleServer(EPoll &ePoll, IPAddress address, TLSInfo *tlsInfo,
std::function<bool(std::string, std::string)> credentialChecker = nullptr);
//
//
//
void logSend(std::string out) override;
TCPSession * getSocketAccept(EPoll &ePoll) override;
bool checkCredentials(std::string user, std::string password);
private:
std::function<bool(std::string, std::string)> credentialChecker;
};
}
#endif