summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-09-15 18:28:39 +0000
committerrubidium <rubidium@openttd.org>2011-09-15 18:28:39 +0000
commit998bbde49ea1ef919ea42498af4760dbac603bc2 (patch)
treeb04b782e989f45261cf7f8c565afca581771afcd /src/network
parentfd79d18c3fb3909cf339a253002ff795d54b33f8 (diff)
downloadopenttd-998bbde49ea1ef919ea42498af4760dbac603bc2.tar.xz
(svn r22934) -Fix [FS#4771]: prevent authentication bypass for the admin port when a new game is started
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/tcp_admin.h9
-rw-r--r--src/network/network.cpp4
-rw-r--r--src/network/network_admin.cpp28
-rw-r--r--src/network/network_admin.h8
4 files changed, 33 insertions, 16 deletions
diff --git a/src/network/core/tcp_admin.h b/src/network/core/tcp_admin.h
index ee34725f6..c0491f0cc 100644
--- a/src/network/core/tcp_admin.h
+++ b/src/network/core/tcp_admin.h
@@ -449,6 +449,15 @@ public:
~NetworkAdminSocketHandler();
NetworkRecvStatus ReceivePackets();
+
+ /**
+ * Get the status of the admin.
+ * @return The status of the admin.
+ */
+ AdminStatus GetAdminStatus() const
+ {
+ return this->status;
+ }
};
#endif /* ENABLE_NETWORK */
diff --git a/src/network/network.cpp b/src/network/network.cpp
index b9125e12d..0b6e9c35a 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -755,7 +755,7 @@ void NetworkReboot()
}
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
as->SendNewGame();
as->SendPackets();
}
@@ -782,7 +782,7 @@ void NetworkDisconnect(bool blocking, bool close_admins)
if (close_admins) {
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
as->SendShutdown();
as->SendPackets();
}
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp
index caded2cf9..96f7f2924 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -165,8 +165,6 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol()
/** Send a welcome message to the admin. */
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome()
{
- this->status = ADMIN_STATUS_ACTIVE;
-
Packet *p = new Packet(ADMIN_PACKET_SERVER_WELCOME);
p->Send_string(_settings_client.network.server_name);
@@ -612,6 +610,8 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p)
return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
}
+ this->status = ADMIN_STATUS_ACTIVE;
+
DEBUG(net, 1, "[admin] '%s' (%s) has connected", this->admin_name, this->admin_version);
return this->SendProtocol();
@@ -743,7 +743,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *p)
void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client)
{
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) {
as->SendClientInfo(cs);
if (new_client) {
@@ -760,7 +760,7 @@ void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client)
void NetworkAdminClientUpdate(const NetworkClientInfo *ci)
{
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) {
as->SendClientUpdate(ci);
}
@@ -774,7 +774,7 @@ void NetworkAdminClientUpdate(const NetworkClientInfo *ci)
void NetworkAdminClientQuit(ClientID client_id)
{
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) {
as->SendClientQuit(client_id);
}
@@ -789,7 +789,7 @@ void NetworkAdminClientQuit(ClientID client_id)
void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code)
{
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
if (as->update_frequency[ADMIN_UPDATE_CLIENT_INFO] & ADMIN_FREQUENCY_AUTOMATIC) {
as->SendClientError(client_id, error_code);
}
@@ -809,7 +809,7 @@ void NetworkAdminCompanyInfo(const Company *company, bool new_company)
}
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
if (as->update_frequency[ADMIN_UPDATE_COMPANY_INFO] != ADMIN_FREQUENCY_AUTOMATIC) continue;
as->SendCompanyInfo(company);
@@ -828,7 +828,7 @@ void NetworkAdminCompanyUpdate(const Company *company)
if (company == NULL) return;
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
if (as->update_frequency[ADMIN_UPDATE_COMPANY_INFO] != ADMIN_FREQUENCY_AUTOMATIC) continue;
as->SendCompanyUpdate(company);
@@ -843,7 +843,7 @@ void NetworkAdminCompanyUpdate(const Company *company)
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
{
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
as->SendCompanyRemove(company_id, bcrr);
}
}
@@ -857,7 +857,7 @@ void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_i
if (from_admin) return;
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
if (as->update_frequency[ADMIN_UPDATE_CHAT] & ADMIN_FREQUENCY_AUTOMATIC) {
as->SendChat(action, desttype, client_id, msg, data);
}
@@ -883,7 +883,7 @@ void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code,
void NetworkAdminConsole(const char *origin, const char *string)
{
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
if (as->update_frequency[ADMIN_UPDATE_CONSOLE] & ADMIN_FREQUENCY_AUTOMATIC) {
as->SendConsole(origin, string);
}
@@ -900,7 +900,7 @@ void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacke
ClientID client_id = owner == NULL ? _network_own_client_id : owner->client_id;
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
if (as->update_frequency[ADMIN_UPDATE_CMD_LOGGING] & ADMIN_FREQUENCY_AUTOMATIC) {
as->SendCmdLogging(client_id, cp);
}
@@ -913,7 +913,7 @@ void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacke
void ServerNetworkAdminSocketHandler::WelcomeAll()
{
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
as->SendWelcome();
}
}
@@ -925,7 +925,7 @@ void ServerNetworkAdminSocketHandler::WelcomeAll()
void NetworkAdminUpdate(AdminUpdateFrequency freq)
{
ServerNetworkAdminSocketHandler *as;
- FOR_ALL_ADMIN_SOCKETS(as) {
+ FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
for (int i = 0; i < ADMIN_UPDATE_END; i++) {
if (as->update_frequency[i] & freq) {
/* Update the admin for the required details */
diff --git a/src/network/network_admin.h b/src/network/network_admin.h
index 01e00e334..cbb058655 100644
--- a/src/network/network_admin.h
+++ b/src/network/network_admin.h
@@ -96,6 +96,14 @@ public:
*/
#define FOR_ALL_ADMIN_SOCKETS(var) FOR_ALL_ADMIN_SOCKETS_FROM(var, 0)
+/**
+ * Iterate over all the active sockets.
+ * @param var The variable to iterate with.
+ */
+#define FOR_ALL_ACTIVE_ADMIN_SOCKETS(var) \
+ FOR_ALL_ADMIN_SOCKETS(var) \
+ if (var->GetAdminStatus() == ADMIN_STATUS_ACTIVE)
+
void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client = false);
void NetworkAdminClientUpdate(const NetworkClientInfo *ci);
void NetworkAdminClientQuit(ClientID client_id);