aboutsummaryrefslogtreecommitdiff
path: root/games/battlestar
diff options
context:
space:
mode:
authorEivind Eklund <eivind@FreeBSD.org>1997-09-01 00:34:51 +0000
committerEivind Eklund <eivind@FreeBSD.org>1997-09-01 00:34:51 +0000
commit34a13bf4cb36b9ba554bf9593c9b180b91988d8d (patch)
tree2afc8210fc2a0f5e9bb905721c895b27fcab5fec /games/battlestar
parente3ffd60e0a4993e1ee9f1b08e33547aff372de75 (diff)
Notes
Diffstat (limited to 'games/battlestar')
-rw-r--r--games/battlestar/battlestar.c6
-rw-r--r--games/battlestar/com6.c28
-rw-r--r--games/battlestar/externs.h3
-rw-r--r--games/battlestar/save.c11
4 files changed, 36 insertions, 12 deletions
diff --git a/games/battlestar/battlestar.c b/games/battlestar/battlestar.c
index 48fb8b368910..144e72fe114f 100644
--- a/games/battlestar/battlestar.c
+++ b/games/battlestar/battlestar.c
@@ -57,6 +57,12 @@ char **argv;
char mainbuf[LINELENGTH];
char *next;
+ open_score_file();
+
+ /* revoke privs. */
+ egid = getegid();
+ setegid(getgid());
+
initialize(argc < 2 || strcmp(argv[1], "-r"));
start:
news();
diff --git a/games/battlestar/com6.c b/games/battlestar/com6.c
index 146bb8c90665..5d196314e3ee 100644
--- a/games/battlestar/com6.c
+++ b/games/battlestar/com6.c
@@ -91,10 +91,17 @@ live()
#include <sys/time.h>
+static FILE *score_fp;
+
+open_score_file()
+{
+ if ((score_fp = fopen(_PATH_SCORE,"a")) == NULL)
+ perror(_PATH_SCORE);
+}
+
post(ch)
char ch;
{
- FILE *fp;
struct timeval tv;
char *date, *ctime();
int s = sigblock(sigmask(SIGINT));
@@ -102,16 +109,15 @@ char ch;
gettimeofday(&tv, (struct timezone *)0); /* can't call time */
date = ctime(&tv.tv_sec);
date[24] = '\0';
- if (fp = fopen(_PATH_SCORE,"a")) {
- fprintf(fp, "%s %8s %c%20s", date, uname, ch, rate());
- if (wiz)
- fprintf(fp, " wizard\n");
- else if (tempwiz)
- fprintf(fp, " WIZARD!\n");
- else
- fprintf(fp, "\n");
- } else
- perror(_PATH_SCORE);
+
+ fprintf(score_fp, "%s %8s %c%20s", date, uname, ch, rate());
+ if (wiz)
+ fprintf(score_fp, " wizard\n");
+ else if (tempwiz)
+ fprintf(score_fp, " WIZARD!\n");
+ else
+ fprintf(score_fp, "\n");
+
sigsetmask(s);
}
diff --git a/games/battlestar/externs.h b/games/battlestar/externs.h
index 2d853521cfdb..d6ff2c9710fc 100644
--- a/games/battlestar/externs.h
+++ b/games/battlestar/externs.h
@@ -33,6 +33,7 @@
* @(#)externs.h 8.1 (Berkeley) 5/31/93
*/
+#include <errno.h>
#include <sys/param.h>
#include <sys/signal.h>
#include <stdio.h>
@@ -298,3 +299,5 @@ struct objs {
};
struct objs dayobjs[];
struct objs nightobjs[];
+
+gid_t egid;
diff --git a/games/battlestar/save.c b/games/battlestar/save.c
index ec4b4f5ea450..8b7250664902 100644
--- a/games/battlestar/save.c
+++ b/games/battlestar/save.c
@@ -55,10 +55,13 @@ 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);
@@ -112,30 +115,36 @@ 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);
if (fd < 0) {
fprintf(stderr, "Can't create %s\n", home1);
+ setegid(getgid());
return;
}
} else {
- if (sbuf.st_nlink > 1) {
+ if (sbuf.st_mode & 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);