--- Maelstrom-3.0.5/scores.cpp.setgid 2000-09-24 13:55:39.000000000 -0400 +++ Maelstrom-3.0.5/scores.cpp 2002-08-23 00:12:01.000000000 -0400 @@ -6,6 +6,7 @@ #ifdef unix #include #include +#include #endif #include @@ -19,7 +20,7 @@ #define NUM_SCORES 10 // Do not change this! /* Everyone can write to scores file if defined to 0 */ -#define SCORES_PERMMASK 0 +#define SCORES_PERMMASK 646 #define CLR_DIALOG_WIDTH 281 #define CLR_DIALOG_HEIGHT 111 @@ -32,6 +33,7 @@ LibPath path; SDL_RWops *scores_src; int i; + gid_t priv_gid, user_gid; /* Try to load network scores, if we can */ if ( gNetScores ) { @@ -44,6 +46,14 @@ } memset(&hScores, 0, sizeof(hScores)); + priv_gid = sgid; + user_gid = getgid(); + + if (setregid(user_gid, priv_gid)) { + error( + "Unable to set group ID to the effective group id. -- Exiting.\n"); + exit(1); + } scores_src = SDL_RWFromFile(path.Path(MAELSTROM_SCORES), "rb"); if ( scores_src != NULL ) { for ( i=0; i +#include #include "buttonlist.h" #include "load.h" #include "fastrand.h" @@ -28,6 +30,7 @@ Bool gUpdateBuffer; Bool gRunning; int gNoDelay; +gid_t sgid; // Local variables in this file... static ButtonList buttons; @@ -176,6 +179,15 @@ SDL_Event event; LibPath::SetExePath(argv[0]); + /* drop all group permissions and run as normal user. We are SETGID + for safe access to the high score file later. */ + sgid = getegid(); + if (setegid(getgid())) { + error( + "Unable to set effective group ID to the group id. -- Exiting.\n"); + exit(1); + } + #ifndef __WIN95__ /* The first thing we do is calculate our checksum */ (void) checksum(); --- Maelstrom-3.0.5/Maelstrom_Globals.h.setgid 2002-08-23 00:14:58.000000000 -0400 +++ Maelstrom-3.0.5/Maelstrom_Globals.h 2002-08-22 23:59:00.000000000 -0400 @@ -47,6 +47,7 @@ extern Bool gUpdateBuffer; extern Bool gRunning; extern int gNoDelay; +extern gid_t sgid; // in init.cc : extern Sint32 gLastHigh;