diff options
Diffstat (limited to 'games/battlestar')
-rw-r--r-- | games/battlestar/battlestar.c | 6 | ||||
-rw-r--r-- | games/battlestar/com6.c | 28 | ||||
-rw-r--r-- | games/battlestar/externs.h | 3 | ||||
-rw-r--r-- | games/battlestar/save.c | 11 |
4 files changed, 36 insertions, 12 deletions
diff --git a/games/battlestar/battlestar.c b/games/battlestar/battlestar.c index 48fb8b3..144e72f 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 146bb8c..5d19631 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 2d85352..d6ff2c9 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 ec4b4f5..8b72506 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); |