summaryrefslogtreecommitdiffstats
path: root/games/battlestar
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1997-09-24 09:42:33 +0000
committerache <ache@FreeBSD.org>1997-09-24 09:42:33 +0000
commit3fadb9c28981b6b4fb1c176b6ed61e7fe45645e2 (patch)
treeb1e83ad62559ee0a63e6e542dcb79f06216fcba6 /games/battlestar
parent4ee52dafc7e64afa361c0ad4c7724a0c86943552 (diff)
downloadFreeBSD-src-3fadb9c28981b6b4fb1c176b6ed61e7fe45645e2.zip
FreeBSD-src-3fadb9c28981b6b4fb1c176b6ed61e7fe45645e2.tar.gz
Revoke privs once at earlier stage and not mess with setegid in save
Fix save: missing creation modes arg and wrong symlink test Small C cleanup
Diffstat (limited to 'games/battlestar')
-rw-r--r--games/battlestar/battlestar.c3
-rw-r--r--games/battlestar/save.c16
2 files changed, 4 insertions, 15 deletions
diff --git a/games/battlestar/battlestar.c b/games/battlestar/battlestar.c
index 144e72f..c03b4d5 100644
--- a/games/battlestar/battlestar.c
+++ b/games/battlestar/battlestar.c
@@ -60,8 +60,7 @@ char **argv;
open_score_file();
/* revoke privs. */
- egid = getegid();
- setegid(getgid());
+ setgid(getgid());
initialize(argc < 2 || strcmp(argv[1], "-r"));
start:
diff --git a/games/battlestar/save.c b/games/battlestar/save.c
index 8b72506..df61213 100644
--- a/games/battlestar/save.c
+++ b/games/battlestar/save.c
@@ -39,12 +39,12 @@ static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
#include <sys/stat.h>
#include <sys/param.h> /* MAXPATHLEN */
#include <fcntl.h>
+#include <stdlib.h>
#include "externs.h"
void
restore()
{
- char *getenv();
char *home;
char home1[MAXPATHLEN];
register int n;
@@ -55,13 +55,10 @@ restore()
sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home);
else return;
- setegid(egid);
if ((fp = fopen(home1, "r")) == 0) {
perror(home1);
- setegid(getgid());
return;
}
- setegid(getgid());
fread(&WEIGHT, sizeof WEIGHT, 1, fp);
fread(&CUMBER, sizeof CUMBER, 1, fp);
fread(&gclock, sizeof gclock, 1, fp);
@@ -103,7 +100,6 @@ void
save()
{
struct stat sbuf;
- char *getenv();
char *home;
char home1[MAXPATHLEN];
register int n;
@@ -115,36 +111,30 @@ save()
return;
sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home);
- setegid(egid);
/* Try to open the file safely. */
if (stat(home1, &sbuf) < 0) {
- fd = open(home1, O_WRONLY|O_CREAT|O_EXCL);
+ fd = open(home1, O_WRONLY|O_CREAT|O_EXCL, 0600);
if (fd < 0) {
fprintf(stderr, "Can't create %s\n", home1);
- setegid(getgid());
return;
}
} else {
- if (sbuf.st_mode & S_IFLNK) {
+ if ((sbuf.st_mode & S_IFLNK) == S_IFLNK) {
fprintf(stderr, "No symlinks!\n");
- setegid(getgid());
return;
}
fd = open(home1, O_WRONLY|O_EXCL);
if (fd < 0) {
fprintf(stderr, "Can't open %s for writing\n", home1);
- setegid(getgid());
return;
}
}
if ((fp = fdopen(fd, "w")) == 0) {
perror(home1);
- setegid(getgid());
return;
}
- setegid(getgid());
printf("Saved in %s.\n", home1);
fwrite(&WEIGHT, sizeof WEIGHT, 1, fp);
OpenPOWER on IntegriCloud