Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/rcon-mode-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/hl2rcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/sv_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/sv_mode_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]==';');
}

Expand All @@ -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");
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/rcon_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
12 changes: 12 additions & 0 deletions tests/test_mode_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<sizeof(invalid)/sizeof(*invalid);i++) {snprintf(command,sizeof(command),"%s %s",commands[c],invalid[i]);assert(SV_RconModeIngress(command,100,NULL,qtrue));assert(!sockets);}
snprintf(command,sizeof(command),"%s zombies",commands[c]);
assert(SV_RconModeIngress(command,100,NULL,qfalse));assert(!sockets);
assert(SV_RconModeIngress(command,100,NULL,qtrue));assert(sockets==1 && sends==1 && strstr(sent," zombies"));
}
assert(!SV_RconModeCommand("change_game_extra zombies"));
const char *bad[]={"hardcore","Zombies","promod;quit","promod //comment","\"promod\"","promod extra","promod\nquit","../zombies","$(id)","promod\t"};
reset();
for(int p=0;p<100;p++) {assert(SV_RconModeIngress("change_mode zombies",p,NULL,qtrue));assert(!sockets);assert(strstr(output,"Permission denied"));}
Expand Down
19 changes: 11 additions & 8 deletions tests/test_rcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,24 @@ def udp(self, length, quoted=False, wrong=False, command='status', packet=None):
process.communicate()

def test_mode_ingress_requires_authentication_and_complete_wire_frame(self):
self.assertEqual(self.udp(16, command='change_mode promod'), b'INGRESS_ALLOWED')
self.assertEqual(self.udp(16, wrong=True, command='change_mode promod'), b'Bad rcon')
self.assertIn(b'shorter than 8', self.udp(7, command='change_mode promod'))
password = ('Ab9' * 400)[:16]
for suffix in (b'\nquit', b'\0quit', b'\rquit'):
packet = b'\xff' * 4 + f'rcon {password} change_mode promod'.encode() + suffix
self.assertEqual(self.udp(16, packet=packet), b'INGRESS_INVALID')
for name in ('change_game', 'change_mode'):
with self.subTest(command=name):
self.assertEqual(self.udp(16, command=name+' promod'), b'INGRESS_ALLOWED')
self.assertEqual(self.udp(16, wrong=True, command=name+' promod'), b'Bad rcon')
self.assertIn(b'shorter than 8', self.udp(7, command=name+' promod'))
password = ('Ab9' * 400)[:16]
for suffix in (b'\nquit', b'\0quit', b'\rquit'):
packet = b'\xff' * 4 + f'rcon {password} {name} promod'.encode() + suffix
self.assertEqual(self.udp(16, packet=packet), b'INGRESS_INVALID')

def test_source_identity_uses_verified_record_not_numeric_name(self):
result=subprocess.run([str(self.binary),'--source-bound',
'76561198000000999 SyntheticAccountPassword'],text=True,capture_output=True,check=True)
self.assertIn('source_bound_to_verified_record=1 steamid=42',result.stdout)

def test_mode_request_logs_omit_untrusted_arguments(self):
self.assertEqual(self.udp(16,command='change_mode promod MODE_SECRET_CANARY'),b'INGRESS_ALLOWED')
for name in ('change_game', 'change_mode'):
self.assertEqual(self.udp(16,command=name+' promod MODE_SECRET_CANARY'),b'INGRESS_ALLOWED')

def test_udp_credential_commands_omit_arguments_from_logs(self):
for command in ('AdminChangePassword owner MODE_SECRET_CANARY',
Expand Down
Loading