Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37533595
en ru br
Репозитории ALT
S:3.0.6-alt3.1.qa1
5.1: 3.0.6-alt3.1
4.0: 3.0.6-alt1
3.0: 3.0.6-alt1
www.altlinux.org/Changes

Группа :: Игры/Аркады
Пакет: Maelstrom

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: Maelstrom-3.0.5-setgid.patch
Скачать


--- 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 <sys/types.h>
 #include <sys/stat.h>
+#include <unistd.h>
 #endif
 #include <stdio.h>
 
@@ -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<NUM_SCORES; ++i ) {
@@ -54,6 +64,11 @@
 		}
 		SDL_RWclose(scores_src);
 	}
+	if (setegid(getgid())) {
+	    error(
+	"Unable to set group ID to that of the user. -- Exiting.\n");
+	    exit(1);
+	}
 }
 
 void SaveScores(void)
@@ -64,6 +79,7 @@
 #ifdef unix
 	int omask;
 #endif
+	gid_t user_gid, priv_gid;
 
 	/* Don't save network scores */
 	if ( gNetScores )
@@ -72,6 +88,15 @@
 #ifdef unix
 	omask=umask(SCORES_PERMMASK);
 #endif
+
+	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), "wb");
 	if ( scores_src != NULL ) {
 		for ( i=0; i<NUM_SCORES; ++i ) {
@@ -85,6 +110,11 @@
 		error("Warning: Couldn't save scores to %s\n",
 						path.Path(MAELSTROM_SCORES));
 	}
+	if (setegid(getgid())) {
+	    error(
+	"Unable to set group ID to that of the user. -- Exiting.\n");
+	    exit(1);
+	}
 #ifdef unix
 	umask(omask);
 #endif
--- Maelstrom-3.0.5/main.cpp.setgid	2000-09-24 13:55:56.000000000 -0400
+++ Maelstrom-3.0.5/main.cpp	2002-08-22 23:56:05.000000000 -0400
@@ -11,6 +11,8 @@
 /* ------------------------------------------------------------- */
 
 #include "Maelstrom_Globals.h"
+#include <sys/types.h>
+#include <unistd.h>
 #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;
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin