Beforeinstall scores and log file to prevent them owned by

first who run snake
snake.c: cleanup, use srandomdev() now, fix created file permissions
This commit is contained in:
Andrey A. Chernov 1997-09-24 02:34:53 +00:00
parent 269e4d4538
commit 1ed24bcde4
2 changed files with 13 additions and 7 deletions

View File

@ -8,5 +8,11 @@ LDADD= -lm -ltermcap -lcompat
HIDEGAME=hidegame
MLINKS= snake.6 snscore.6
beforeinstall:
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 664 /dev/null \
${DESTDIR}/var/games/snakerawscores
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 664 /dev/null \
${DESTDIR}/var/games/snake.log
.include "../../Makefile.inc"
.include <bsd.prog.mk>

View File

@ -58,6 +58,8 @@ static char sccsid[] = "@(#)snake.c 8.2 (Berkeley) 1/7/94";
#include <fcntl.h>
#include <pwd.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include "snake.h"
#include "pathnames.h"
@ -103,18 +105,16 @@ char **argv;
extern char *optarg;
extern int optind;
int ch, i, j, k;
long atol();
void stop();
rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0644);
rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0664);
logfile = fopen(_PATH_LOGFILE, "a");
/* revoke privs */
setegid(getgid());
setgid(getgid());
(void)time(&tv);
srandom((int)tv);
srandomdev();
while ((ch = getopt(argc, argv, "l:w:")) != EOF)
switch((char)ch) {
@ -494,14 +494,14 @@ int iscore, flag;
/* Figure out what happened in the past */
read(rawscores, &allbscore, sizeof(short));
read(rawscores, &allbwho, sizeof(short));
lseek(rawscores, ((long)uid)*sizeof(short), 0);
lseek(rawscores, ((off_t)uid)*sizeof(short), 0);
read(rawscores, &oldbest, sizeof(short));
if (!flag)
return (score > oldbest ? 1 : 0);
/* Update this jokers best */
if (score > oldbest) {
lseek(rawscores, ((long)uid)*sizeof(short), 0);
lseek(rawscores, ((off_t)uid)*sizeof(short), 0);
write(rawscores, &score, sizeof(short));
pr("You bettered your previous best of $%d\n", oldbest);
} else
@ -510,7 +510,7 @@ int iscore, flag;
/* See if we have a new champ */
p = getpwuid(allbwho);
if (p == NULL || score > allbscore) {
lseek(rawscores, (long)0, 0);
lseek(rawscores, (off_t)0, 0);
write(rawscores, &score, sizeof(short));
write(rawscores, &uid, sizeof(short));
if (allbwho)