diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2015-11-17 15:27:25 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2015-11-17 15:27:25 +0000 |
commit | 4c6baf453a0dae840e70c8bd21bdb97f82a81b13 (patch) | |
tree | 02b3eb4ec0c18d3849928570b157e7986124a09a /games | |
parent | a5ed0b5f4e2e8f1cf089e9d0cf0f15af143ad70e (diff) |
remove setgid flag.
in turn, move score files into user's home directory.
will let theo buehler continue with a smaller pledge set.
Diffstat (limited to 'games')
-rw-r--r-- | games/tetris/Makefile | 11 | ||||
-rw-r--r-- | games/tetris/pathnames.h | 38 | ||||
-rw-r--r-- | games/tetris/scores.c | 48 |
3 files changed, 16 insertions, 81 deletions
diff --git a/games/tetris/Makefile b/games/tetris/Makefile index 32190972828..5ed8bb2ef03 100644 --- a/games/tetris/Makefile +++ b/games/tetris/Makefile @@ -1,18 +1,9 @@ -# $OpenBSD: Makefile,v 1.7 2002/05/31 03:46:35 pjanzen Exp $ +# $OpenBSD: Makefile,v 1.8 2015/11/17 15:27:24 tedu Exp $ PROG= tetris SRCS= input.c screen.c shapes.c scores.c tetris.c MAN= tetris.6 DPADD= ${LIBCURSES} LDADD= -lcurses -BINMODE=2555 - -beforeinstall: - @if [ ! -f ${DESTDIR}/var/games/tetris.scores ]; then \ - ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 664 \ - /dev/null ${DESTDIR}/var/games/tetris.scores ; \ - else \ - true ; \ - fi .include <bsd.prog.mk> diff --git a/games/tetris/pathnames.h b/games/tetris/pathnames.h deleted file mode 100644 index 7df05db66ad..00000000000 --- a/games/tetris/pathnames.h +++ /dev/null @@ -1,38 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.3 2003/06/03 03:01:41 millert Exp $ */ -/* $NetBSD: pathnames.h,v 1.2 1995/04/22 07:42:37 cgd Exp $ */ - -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek and Darren F. Provine. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)pathnames.h 8.1 (Berkeley) 5/31/93 - */ - -#define _PATH_SCOREFILE "/var/games/tetris.scores" diff --git a/games/tetris/scores.c b/games/tetris/scores.c index 6903d6221cb..ebb9b9ba281 100644 --- a/games/tetris/scores.c +++ b/games/tetris/scores.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scores.c,v 1.12 2014/11/16 04:49:49 guenther Exp $ */ +/* $OpenBSD: scores.c,v 1.13 2015/11/17 15:27:24 tedu Exp $ */ /* $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $ */ /*- @@ -49,7 +49,6 @@ #include <err.h> #include <fcntl.h> #include <limits.h> -#include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -57,7 +56,6 @@ #include <term.h> #include <unistd.h> -#include "pathnames.h" #include "screen.h" #include "scores.h" #include "tetris.h" @@ -96,52 +94,42 @@ static char *thisuser(void); static void getscores(FILE **fpp) { - int sd, mint, lck, mask, i; + int sd, mint, mask, i; char *mstr, *human; + char scorepath[PATH_MAX]; FILE *sf; if (fpp != NULL) { mint = O_RDWR | O_CREAT; mstr = "r+"; human = "read/write"; - lck = LOCK_EX; + *fpp = NULL; } else { mint = O_RDONLY; mstr = "r"; human = "reading"; - lck = LOCK_SH; } - setegid(egid); - mask = umask(S_IWOTH); - sd = open(_PATH_SCOREFILE, mint, 0666); - (void)umask(mask); - setegid(gid); + if (!getenv("HOME")) + return; + snprintf(scorepath, sizeof(scorepath), "%s/%s", getenv("HOME"), ".tetris.scores"); + sd = open(scorepath, mint, 0666); if (sd < 0) { if (fpp == NULL) { nscores = 0; return; } - err(1, "cannot open %s for %s", _PATH_SCOREFILE, human); + err(1, "cannot open %s for %s", scorepath, human); } - setegid(egid); if ((sf = fdopen(sd, mstr)) == NULL) - err(1, "cannot fdopen %s for %s", _PATH_SCOREFILE, human); - setegid(gid); - - /* - * Grab a lock. - */ - if (flock(sd, lck)) - warn("warning: score file %s cannot be locked", - _PATH_SCOREFILE); + err(1, "cannot fdopen %s for %s", scorepath, human); nscores = fread(scores, sizeof(scores[0]), MAXHISCORES, sf); if (ferror(sf)) - err(1, "error reading %s", _PATH_SCOREFILE); + err(1, "error reading %s", scorepath); for (i = 0; i < nscores; i++) if (scores[i].hs_level < MINLEVEL || scores[i].hs_level > MAXLEVEL) - errx(1, "scorefile %s corrupt", _PATH_SCOREFILE); + errx(1, "scorefile %s corrupt", scorepath); if (fpp) *fpp = sf; @@ -204,8 +192,8 @@ savescore(int level) rewind(sf); if (fwrite(scores, sizeof(*sp), nscores, sf) != nscores || fflush(sf) == EOF) - warnx("error writing %s: %s\n\t-- %s", - _PATH_SCOREFILE, strerror(errno), + warnx("error writing scorefile: %s\n\t-- %s", + strerror(errno), "high scores may be damaged"); } (void)fclose(sf); /* releases lock */ @@ -219,18 +207,13 @@ static char * thisuser(void) { const char *p; - struct passwd *pw; static char u[sizeof(scores[0].hs_name)]; if (u[0]) return (u); p = getlogin(); if (p == NULL || *p == '\0') { - pw = getpwuid(getuid()); - if (pw != NULL) - p = pw->pw_name; - else - p = " ???"; + p = " ???"; } strlcpy(u, p, sizeof(u)); return (u); @@ -315,7 +298,6 @@ checkscores(struct highscore *hs, int num) * - High score on this level. */ if ((pu->times < MAXSCORES && - getpwnam(sp->hs_name) != NULL && sp->hs_time + EXPIRATION >= now) || levelfound[sp->hs_level] == 0) pu->times++; |