Skip to content

Commit

Permalink
Finalized high level implementation for improved security on executio…
Browse files Browse the repository at this point in the history
…n of console commands sent over the net. We now know where the command came from before executing (i.e. local or remote) and also the invocation method used (e.g. remote client console input, DED file etc). However, due to the fact that the remote invocation method MUST be sent over the net - any truly dangerous ccmds should be marked as

CMDF_CLIENT.
In order to implement this a new PKT_COMMAND2 type has been added which obsoletes the old type. Due to these measures any commands sent using the old PKT_COMMAND type will NEVER be executed.
  • Loading branch information
danij committed Sep 19, 2006
1 parent e3b7616 commit b1cb11e
Show file tree
Hide file tree
Showing 20 changed files with 401 additions and 276 deletions.
16 changes: 7 additions & 9 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -18,7 +18,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

Expand Down Expand Up @@ -506,7 +506,7 @@ extern "C" {
// The mouse wheel is considered two extra mouse buttons.
#define DDMB_MWHEELUP 0x1000
#define DDMB_MWHEELDOWN 0x2000

#define DD_MICKEY_ACCURACY 1000

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1129,27 +1129,26 @@ typedef enum blendmode_e {
// Console command.
typedef struct ccmd_s {
char *name;
int (*func) (int src, int argc, char **argv);
int (*func) (byte src, int argc, char **argv);
int flags;
} ccmd_t;

// Command sources (where the console command originated from)
// These are sent with every (sub)ccmd so we can decide whether or not to execute.
enum {
CMDS_UNKNOWN,
CMDS_DDAY, // Sent by the engine
CMDS_GAME, // Sent by the game dll
CMDS_CONSOLE, // Sent via direct console input
CMDS_BIND , // Sent from a binding/alias
CMDS_CONFIG, // Sent via config file
CMDS_PROFILE, // Sent via player profile
CMDS_CMDLINE, // Sent via the command line
CMDS_DED, // Sent based on a def in a DED file eg (state->execute)
CMDS_PKT, // Sent from a client (in a packet)
CMDS_SPKT // Sent from the server (in a packet)
CMDS_DED // Sent based on a def in a DED file eg (state->execute)
};

// Helper macro for defining console command functions.
#define DEFCC(name) int name(int src, int argc, char **argv)
#define DEFCC(name) int name(byte src, int argc, char **argv)

// Console command usage flags.
// (what method(s) CAN NOT be used to invoke a ccmd (used with the CMDS codes above)).
Expand All @@ -1161,8 +1160,7 @@ typedef enum blendmode_e {
#define CMDF_PROFILE 0x20
#define CMDF_CMDLINE 0x40
#define CMDF_DED 0x80
#define CMDF_PKT 0x100 // Not implemented yet
#define CMDF_SPKT 0x200 // Not implemented yet
#define CMDF_CLIENT 0x100 // sent over the net from a client

// Console variable flags.
#define CVF_NO_ARCHIVE 0x1 // Not written in/read from the defaults file.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/con_decl.h
Expand Up @@ -18,7 +18,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

Expand All @@ -41,7 +41,7 @@
{ ccmd_t _c = { name, CCmd##fn, flags }; Con_AddCommand(&_c); }

// A handy helper for declaring console commands.
#define D_CMD(x) int CCmd##x(int src, int argc, char **argv)
#define D_CMD(x) int CCmd##x(byte src, int argc, char **argv)

/*
* Macros for creating new console variables.
Expand Down
23 changes: 12 additions & 11 deletions doomsday/engine/portable/include/con_main.h
Expand Up @@ -18,7 +18,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

Expand All @@ -32,19 +32,19 @@
#include <stdio.h>
#include "dd_share.h"

#define MAX_ARGS 256
#define MAX_ARGS 256

typedef struct {
char cmdLine[2048];
int argc;
char *argv[MAX_ARGS];
char cmdLine[2048];
int argc;
char *argv[MAX_ARGS];
} cmdargs_t;

// A console buffer line.
typedef struct {
int len; // This is the length of the line (no term).
char *text; // This is the text.
int flags;
int len; // This is the length of the line (no term).
char *text; // This is the text.
int flags;
} cbline_t;

// Console commands can set this when they need to return a custom value
Expand Down Expand Up @@ -72,11 +72,12 @@ boolean Con_Responder(event_t *event);
void Con_Drawer(void);
void Con_DrawRuler(int y, int lineHeight, float alpha);
void Con_Printf(const char *format, ...);
void Con_FPrintf(int flags, const char *format, ...); // Flagged printf.
void Con_FPrintf(int flags, const char *format, ...); // Flagged printf.
void Con_SetFont(ddfont_t *cfont);
cbline_t *Con_GetBufferLine(int num);
int Con_Execute(int src, const char *command, int silent);
int Con_Executef(int src, int silent, const char *command, ...);
int Con_Execute(byte src, const char *command, int silent,
boolean netCmd);
int Con_Executef(byte src, int silent, const char *command, ...);

void Con_Message(const char *message, ...);
void Con_Error(const char *error, ...);
Expand Down

0 comments on commit b1cb11e

Please sign in to comment.