tReally _does_ work with GTK+ 1.2.9 now (drops _all_ privileges, even the saved… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit dce44c4d5f93daa2fee494d82233ad03ce10fd94 | |
parent 445c533b2ee5fa5f4f33fbf0b88b1a21bd75c213 | |
Author: Ben Webb <[email protected]> | |
Date: Wed, 11 Apr 2001 20:24:16 +0000 | |
Really _does_ work with GTK+ 1.2.9 now (drops _all_ privileges, even the | |
saved group ID) | |
Diffstat: | |
M src/curses_client.c | 4 ++++ | |
M src/dopewars.c | 17 ----------------- | |
M src/dopewars.h | 3 --- | |
M src/gtk_client.c | 4 ++++ | |
M src/serverside.c | 71 +++++++++++++++++------------… | |
M src/serverside.h | 3 ++- | |
M src/winmain.c | 2 -- | |
7 files changed, 48 insertions(+), 56 deletions(-) | |
--- | |
diff --git a/src/curses_client.c b/src/curses_client.c | |
t@@ -1824,6 +1824,8 @@ void CursesLoop() { | |
start_curses(); | |
Width=COLS; Depth=LINES; | |
+ InitHighScoreFile(); | |
+ | |
/* Set up message handlers */ | |
ClientMessageHandlerPt = HandleClientMessage; | |
SocketWriteTestPt = NULL; | |
t@@ -1849,6 +1851,8 @@ void CursesLoop() { | |
} | |
g_free(Name); | |
end_curses(); | |
+ | |
+ CloseHighScoreFile(); | |
} | |
#else | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -43,8 +43,6 @@ | |
#include "tstring.h" | |
#include "AIPlayer.h" | |
-static gid_t RealGID,EffGID; | |
- | |
int ClientSock,ListenSock; | |
char Network,Client,Server,NotifyMetaServer,AIPlayer; | |
/* dopewars acting as standalone TCP server: | |
t@@ -1666,25 +1664,10 @@ void HandleCmdLine(int argc,char *argv[]) { | |
} | |
} | |
-void GetGroupIDs() { | |
- RealGID = getgid(); | |
- EffGID = getegid(); | |
-} | |
- | |
-void DropPrivileges() { | |
- if (setgid(RealGID)!=0) perror("setgid"); | |
-} | |
- | |
-void GoPrivileged() { | |
- if (setgid(EffGID)!=0) perror("setgid"); | |
-} | |
- | |
#ifndef CYGWIN | |
/* Standard program entry - Win32 uses WinMain() instead, in winmain.c */ | |
int main(int argc,char *argv[]) { | |
- GetGroupIDs(); | |
- DropPrivileges(); | |
#ifdef ENABLE_NLS | |
setlocale(LC_ALL,""); | |
bindtextdomain(PACKAGE,LOCALEDIR); | |
diff --git a/src/dopewars.h b/src/dopewars.h | |
t@@ -405,7 +405,4 @@ void PrintConfigValue(int GlobalIndex,int StructIndex,gboo… | |
void SetConfigValue(int GlobalIndex,int StructIndex,gboolean IndexGiven, | |
GScanner *scanner); | |
gboolean IsCop(Player *Play); | |
-void GetGroupIDs(); | |
-void DropPrivileges(); | |
-void GoPrivileged(); | |
#endif | |
diff --git a/src/gtk_client.c b/src/gtk_client.c | |
t@@ -1618,6 +1618,8 @@ char GtkLoop(int *argc,char **argv[],char ReturnOnFail) { | |
GtkAdjustment *adj; | |
gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]); | |
+ InitHighScoreFile(); | |
+ | |
#ifdef CYGWIN | |
win32_init(hInstance,hPrevInstance); | |
#else | |
t@@ -1709,6 +1711,8 @@ char GtkLoop(int *argc,char **argv[],char ReturnOnFail) { | |
gtk_widget_show(window); | |
gtk_main(); | |
+ | |
+ CloseHighScoreFile(); | |
return TRUE; | |
} | |
diff --git a/src/serverside.c b/src/serverside.c | |
t@@ -65,6 +65,9 @@ GSList *FirstServer=NULL; | |
static GScanner *Scanner; | |
+/* Handle to the high score file */ | |
+static FILE *ScoreFP=NULL; | |
+ | |
/* Pointer to the filename of a pid file (if non-NULL) */ | |
char *PidFile; | |
t@@ -564,14 +567,9 @@ gboolean ReadServerKey(GString *LineBuf,gboolean *EndOfLi… | |
void StartServer() { | |
struct sockaddr_in ServerAddr; | |
struct sigaction sact; | |
+ | |
Scanner=g_scanner_new(&ScannerConfig); | |
Scanner->input_name="(stdin)"; | |
- if (!CheckHighScoreFile()) { | |
- g_error(_("Cannot open high score file %s.\n" | |
- "Either ensure you have permissions to access this file and " | |
- "directory, or\nspecify an alternate high score file with " | |
- "the -f command line option."),HiScoreFile); | |
- } | |
CreatePidFile(); | |
/* Make the output line-buffered, so that the log file (if used) is */ | |
t@@ -741,6 +739,8 @@ void ServerLoop() { | |
GString *LineBuf; | |
gboolean EndOfLine; | |
+ InitHighScoreFile(); | |
+ | |
StartServer(); | |
LineBuf=g_string_new(""); | |
t@@ -826,6 +826,8 @@ void ServerLoop() { | |
} | |
StopServer(); | |
g_string_free(LineBuf,TRUE); | |
+ | |
+ CloseHighScoreFile(); | |
} | |
#endif /* NETWORKING */ | |
t@@ -872,33 +874,39 @@ void HighScoreTypeWrite(struct HISCORE *HiScore,FILE *fp… | |
} | |
} | |
-gboolean CheckHighScoreFile() { | |
-/* Tests to see whether the high score file is is read-and-writable */ | |
- FILE *fp; | |
- GoPrivileged(); | |
- fp=fopen(HiScoreFile,"a+"); | |
- DropPrivileges(); | |
- if (fp) { | |
- fclose(fp); | |
- return TRUE; | |
- } else { | |
- return FALSE; | |
+void CloseHighScoreFile() { | |
+/* Closes the high score file opened by InitHighScoreFile, below */ | |
+ if (ScoreFP) fclose(ScoreFP); | |
+} | |
+ | |
+void InitHighScoreFile() { | |
+/* Opens the high score file for later use, and then drops privileges. */ | |
+/* If the high score file cannot be found, exits the program with an error. */ | |
+ | |
+ if (ScoreFP) return; /* If already opened, then we're done */ | |
+ | |
+ ScoreFP=fopen(HiScoreFile,"a+"); | |
+ | |
+ if (setregid(getgid(),getgid())!=0) perror("setregid"); | |
+ | |
+ if (!ScoreFP) { | |
+ g_warning(_("Cannot open high score file %s.\n" | |
+ "Either ensure you have permissions to access this file and " | |
+ "directory, or\nspecify an alternate high score file with " | |
+ "the -f command line option."),HiScoreFile); | |
+ exit(1); | |
} | |
} | |
int HighScoreRead(struct HISCORE *MultiScore,struct HISCORE *AntiqueScore) { | |
/* Reads all the high scores into MultiScore and */ | |
/* AntiqueScore (antique mode scores). Returns 1 on success, 0 on failure. */ | |
- FILE *fp; | |
memset(MultiScore,0,sizeof(struct HISCORE)*NUMHISCORE); | |
memset(AntiqueScore,0,sizeof(struct HISCORE)*NUMHISCORE); | |
- GoPrivileged(); | |
- fp=fopen(HiScoreFile,"r"); | |
- DropPrivileges(); | |
- if (fp) { | |
- HighScoreTypeRead(AntiqueScore,fp); | |
- HighScoreTypeRead(MultiScore,fp); | |
- fclose(fp); | |
+ if (ScoreFP) { | |
+ rewind(ScoreFP); | |
+ HighScoreTypeRead(AntiqueScore,ScoreFP); | |
+ HighScoreTypeRead(MultiScore,ScoreFP); | |
} else return 0; | |
return 1; | |
} | |
t@@ -906,14 +914,11 @@ int HighScoreRead(struct HISCORE *MultiScore,struct HISC… | |
int HighScoreWrite(struct HISCORE *MultiScore,struct HISCORE *AntiqueScore) { | |
/* Writes out all the high scores from MultiScore and AntiqueScore; returns */ | |
/* 1 on success, 0 on failure. */ | |
- FILE *fp; | |
- GoPrivileged(); | |
- fp=fopen(HiScoreFile,"w"); | |
- DropPrivileges(); | |
- if (fp) { | |
- HighScoreTypeWrite(AntiqueScore,fp); | |
- HighScoreTypeWrite(MultiScore,fp); | |
- fclose(fp); | |
+ if (ScoreFP) { | |
+ ftruncate(fileno(ScoreFP),0); | |
+ rewind(ScoreFP); | |
+ HighScoreTypeWrite(AntiqueScore,ScoreFP); | |
+ HighScoreTypeWrite(MultiScore,ScoreFP); | |
} else return 0; | |
return 1; | |
} | |
diff --git a/src/serverside.h b/src/serverside.h | |
t@@ -65,7 +65,8 @@ void SetFightTimeout(Player *Play); | |
void ClearFightTimeout(Player *Play); | |
int GetMinimumTimeout(GSList *First); | |
GSList *HandleTimeouts(GSList *First); | |
-gboolean CheckHighScoreFile(); | |
+void InitHighScoreFile(); | |
+void CloseHighScoreFile(); | |
int HighScoreRead(struct HISCORE *MultiScore,struct HISCORE *AntiqueScore); | |
void CopsAttackPlayer(Player *Play); | |
void AttackPlayer(Player *Play,Player *Attacked); | |
diff --git a/src/winmain.c b/src/winmain.c | |
t@@ -59,8 +59,6 @@ int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst… | |
LPSTR lpszCmdParam,int nCmdShow) { | |
gchar **split; | |
int argc; | |
- GetGroupIDs(); | |
- DropPrivileges(); | |
#ifdef ENABLE_NLS | |
setlocale(LC_ALL,""); | |
bindtextdomain(PACKAGE,LOCALEDIR); |