Mercurial > hg > openttd
changeset 18113:e806f5f8d836 draft
(svn r22934) -Fix [FS#4771]: prevent authentication bypass for the admin port when a new game is started
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 15 Sep 2011 18:28:39 +0000 |
parents | 77c8f5f4884a |
children | 5db69a0ba7a2 |
files | src/network/core/tcp_admin.h src/network/network.cpp src/network/network_admin.cpp src/network/network_admin.h |
diffstat | 4 files changed, 33 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/core/tcp_admin.h +++ b/src/network/core/tcp_admin.h @@ -449,6 +449,15 @@ ~NetworkAdminSocketHandler(); NetworkRecvStatus ReceivePackets(); + + /** + * Get the status of the admin. + * @return The status of the admin. + */ + AdminStatus GetAdminStatus() const + { + return this->status; + } }; #endif /* ENABLE_NETWORK */
--- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -755,7 +755,7 @@ } ServerNetworkAdminSocketHandler *as; - FOR_ALL_ADMIN_SOCKETS(as) { + FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) { as->SendNewGame(); as->SendPackets(); } @@ -782,7 +782,7 @@ if (close_admins) { ServerNetworkAdminSocketHandler *as; - FOR_ALL_ADMIN_SOCKETS(as) { + FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) { as->SendShutdown(); as->SendPackets(); }
--- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -165,8 +165,6 @@ /** 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 @@ 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 @@ 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 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 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 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 @@ } 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 @@ 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 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 @@ 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 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 @@ 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 ServerNetworkAdminSocketHandler::WelcomeAll() { ServerNetworkAdminSocketHandler *as; - FOR_ALL_ADMIN_SOCKETS(as) { + FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) { as->SendWelcome(); } } @@ -925,7 +925,7 @@ 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 */
--- a/src/network/network_admin.h +++ b/src/network/network_admin.h @@ -96,6 +96,14 @@ */ #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);