From e3289c4103895721e83cc963f52042c999958dc3 Mon Sep 17 00:00:00 2001 From: ghptc Date: Tue, 27 Oct 2026 18:27:55 -0300 Subject: [PATCH] fix(rcon): add authenticated change_game alias --- docs/rcon-mode-bridge.md | 4 +++- src/hl2rcon.c | 2 +- src/sv_cmds.c | 5 +++-- src/sv_main.c | 2 +- src/sv_mode_bridge.c | 10 +++++----- tests/rcon_harness.c | 3 ++- tests/test_mode_bridge.c | 12 ++++++++++++ tests/test_rcon.py | 19 +++++++++++-------- 8 files changed, 38 insertions(+), 19 deletions(-) diff --git a/docs/rcon-mode-bridge.md b/docs/rcon-mode-bridge.md index d750248c..d9ecdafd 100644 --- a/docs/rcon-mode-bridge.md +++ b/docs/rcon-mode-bridge.md @@ -3,7 +3,9 @@ Baseline: protected master `701a7c5df46c5723705dad0408afa44fb89b0ad9`. The previous `change_mode` preflight remains nonmutating for console, command buffers and GSC. Authenticated UDP and Source RCON have a separate native ingress -for exactly `change_mode promod`, `change_mode zombies`, or `change_mode` status. +for exactly `change_game promod`, `change_game zombies`, or `change_game` status. +`change_mode` remains a backward-compatible alias through the same dispatcher; +both names have identical framing, authorization and argument-redaction checks. Both registration and ingress require power 100. A command-power metadata change cannot lower the native floor. No console/GSC invocation inherits an ambient "authenticated" flag. diff --git a/src/hl2rcon.c b/src/hl2rcon.c index 60058e5a..be32fbf1 100644 --- a/src/hl2rcon.c +++ b/src/hl2rcon.c @@ -608,7 +608,7 @@ int HL2Rcon_SourceRconEvent(netadr_t *from, msg_t *msg, int connectionId){ MSG_ReadByte(msg); Com_Printf(CON_CHANNEL_DONT_FILTER,"Rcon from: %s command: %s\n", NET_AdrToString(from), - SV_RconModeCommand(command) ? "change_mode request (arguments omitted)" : "remote command (arguments omitted)"); + SV_RconModeCommand(command) ? "change_game request (arguments omitted)" : "remote command (arguments omitted)"); sourceRcon.redirectUser = connectionId+1; sourceRcon.writeerror = 0; diff --git a/src/sv_cmds.c b/src/sv_cmds.c index 5c293d3a..d4433d0f 100644 --- a/src/sv_cmds.c +++ b/src/sv_cmds.c @@ -2385,7 +2385,7 @@ static void SV_ChangeMode_f(void) * in the handler as well as the existing authenticated command ingress. */ if (Cmd_GetInvokerPower() != 100) { - Com_Printf(CON_CHANNEL_DONT_FILTER, "change_mode requires administrative power 100.\n"); + Com_Printf(CON_CHANNEL_DONT_FILTER, "change_game requires administrative power 100.\n"); return; } if (Cmd_Argc() == 1) @@ -2396,7 +2396,7 @@ static void SV_ChangeMode_f(void) } if (Cmd_Argc() != 2) { - Com_Printf(CON_CHANNEL_DONT_FILTER, "Usage: change_mode [mode-id]\n"); + Com_Printf(CON_CHANNEL_DONT_FILTER, "Usage: change_game [promod|zombies] (change_mode alias)\n"); return; } mode = Cmd_Argv(1); @@ -2425,6 +2425,7 @@ void SV_AddOperatorCommands() //Former safe commands Cmd_AddPCommand ("systeminfo", SV_Systeminfo_f, 1); Cmd_AddPCommand ("serverinfo", SV_Serverinfo_f, 1); + Cmd_AddPCommand ("change_game", SV_ChangeMode_f, 100); Cmd_AddPCommand ("change_mode", SV_ChangeMode_f, 100); Cmd_AddPCommand ("map", SV_Map_f, 60); Cmd_AddCommand ("map_rotate", SV_MapRotate_f); diff --git a/src/sv_main.c b/src/sv_main.c index 0863d172..bf09eb31 100644 --- a/src/sv_main.c +++ b/src/sv_main.c @@ -1532,7 +1532,7 @@ __optimize3 __regparm2 static void SVC_RemoteCommand( netadr_t *from, msg_t *msg cmd_aux++; Com_Printf (CON_CHANNEL_SERVER,"Rcon from %s: %s\n", NET_AdrToString (from), - SV_RconModeCommand(cmd_aux) ? "change_mode request (arguments omitted)" : "remote command (arguments omitted)" ); + SV_RconModeCommand(cmd_aux) ? "change_game request (arguments omitted)" : "remote command (arguments omitted)" ); Com_BeginRedirect (sv_outputbuf, SV_OUTPUTBUF_LENGTH, SV_FlushRedirect); if (SV_RconModeIngress(cmd_aux, 100, from, diff --git a/src/sv_mode_bridge.c b/src/sv_mode_bridge.c index 1f118078..38c4261f 100644 --- a/src/sv_mode_bridge.c +++ b/src/sv_mode_bridge.c @@ -105,7 +105,7 @@ qboolean SV_RconModeFraming(const byte *wire, int length) qboolean SV_RconModeCommand(const char *raw) { while(*raw==' ') ++raw; - return !Q_stricmpn(raw,"change_mode",11) && + return (!Q_stricmpn(raw,"change_game",11) || !Q_stricmpn(raw,"change_mode",11)) && (!raw[11] || raw[11]==' ' || raw[11]=='\t' || raw[11]=='\n' || raw[11]=='\r' || raw[11]==';'); } @@ -116,12 +116,12 @@ qboolean SV_RconModeIngress(const char *raw, int power, const netadr_t *reply, q /* Recognize malformed variants too, so they cannot fall through tokenization. */ while(*raw==' ') ++raw; if(!SV_RconModeCommand(raw)) return qfalse; - if(power!=100) { Com_Printf(CON_CHANNEL_DONT_FILTER,"Permission denied: change_mode requires power 100.\n"); return qtrue; } + if(power!=100) { Com_Printf(CON_CHANNEL_DONT_FILTER,"Permission denied: change_game requires power 100.\n"); return qtrue; } argument=raw+11; if(!framing || (*argument && *argument!=' ')) { Com_Printf(CON_CHANNEL_DONT_FILTER,"Invalid mode request.\n"); return qtrue; } while(*argument==' ') ++argument; if(*argument && strcmp(argument,"promod") && strcmp(argument,"zombies")) { - Com_Printf(CON_CHANNEL_DONT_FILTER,"Unsupported mode. Use exactly change_mode promod or change_mode zombies. Invalid mode request; runtime unchanged.\n"); return qtrue; + Com_Printf(CON_CHANNEL_DONT_FILTER,"Unsupported mode. Use exactly change_game promod or change_game zombies. Invalid mode request; runtime unchanged.\n"); return qtrue; } #ifdef _WIN32 Com_Printf(CON_CHANNEL_DONT_FILTER,"Host controller unavailable on this platform. Runtime unchanged.\n"); @@ -134,10 +134,10 @@ qboolean SV_RconModeIngress(const char *raw, int power, const netadr_t *reply, q Com_Printf(CON_CHANNEL_DONT_FILTER,"Host controller unavailable; cached status may be stale.\n"); } else { if(channel>=0 && !request_id[0]) close_channel(); - if(channel>=0) Com_Printf(CON_CHANNEL_DONT_FILTER,"Transition request already in progress; use change_mode for status.\n"); + if(channel>=0) Com_Printf(CON_CHANNEL_DONT_FILTER,"Transition request already in progress; use change_game for status.\n"); else if(submit(argument,reply)) { snprintf(cached,sizeof(cached),"operation=%s mode=%s result=submitted phase=pending",request_id,argument); - Com_Printf(CON_CHANNEL_DONT_FILTER,"MODE_STATUS %s (not yet accepted). Use change_mode for status after reconnect.\n",cached); + Com_Printf(CON_CHANNEL_DONT_FILTER,"MODE_STATUS %s (not yet accepted). Use change_game for status after reconnect.\n",cached); } else Com_Printf(CON_CHANNEL_DONT_FILTER,"Host controller unavailable. Runtime unchanged.\n"); } #endif diff --git a/tests/rcon_harness.c b/tests/rcon_harness.c index e5638671..8bcfc45d 100644 --- a/tests/rcon_harness.c +++ b/tests/rcon_harness.c @@ -28,8 +28,9 @@ static struct { netadr_t redirectAddress; } svs; static struct { int rconBucket; } querylimit; static int executed, ban_seconds, source_id; qboolean SV_RconModeFraming(const byte *wire, int length); +qboolean SV_RconModeCommand(const char *raw); static qboolean SV_RconModeIngress(const char *raw,int power,const netadr_t *peer,qboolean framing) { - (void)peer; assert(power==100); if(strncmp(raw,"change_mode",11)) return qfalse; + (void)peer; assert(power==100); if(!SV_RconModeCommand(raw)) return qfalse; strcpy(response,framing?"INGRESS_ALLOWED":"INGRESS_INVALID"); return qtrue; } static void Cmd_TokenizeStringInternal(const char *, qboolean, cmdTokenizeParams_t *); diff --git a/tests/test_mode_bridge.c b/tests/test_mode_bridge.c index 390fca28..463f27d5 100644 --- a/tests/test_mode_bridge.c +++ b/tests/test_mode_bridge.c @@ -42,6 +42,18 @@ static void receive(const char *code,const char *id,const char *mode,const char incoming_size=snprintf((char*)incoming,sizeof(incoming),"C4M1 %s %s %s %s",code,id,mode,phase); } int main(void) { + const char *commands[]={"change_game","change_mode"}; + for(unsigned c=0;c<2;c++) { + char command[160]; + reset(); + for(int p=0;p<100;p++) {snprintf(command,sizeof(command),"%s zombies",commands[c]);assert(SV_RconModeIngress(command,p,NULL,qtrue));assert(!sockets);} + const char *invalid[]={"promod;quit","promod extra","../zombies","$(id)","promod\nquit"}; + for(unsigned i=0;i