diff options
-rw-r--r-- | games/robots/main.c | 31 | ||||
-rw-r--r-- | games/robots/pathnames.h | 35 | ||||
-rw-r--r-- | games/robots/robots.6 | 8 | ||||
-rw-r--r-- | games/robots/robots.h | 4 | ||||
-rw-r--r-- | games/robots/score.c | 7 |
5 files changed, 29 insertions, 56 deletions
diff --git a/games/robots/main.c b/games/robots/main.c index 7ba98c7cf5b..7e1224eb007 100644 --- a/games/robots/main.c +++ b/games/robots/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.20 2015/08/26 00:29:24 rzalamena Exp $ */ +/* $OpenBSD: main.c,v 1.21 2015/11/29 15:13:19 tb Exp $ */ /* $NetBSD: main.c,v 1.5 1995/04/22 10:08:54 cgd Exp $ */ /* @@ -43,22 +43,31 @@ int main(int ac, char *av[]) { bool show_only; - extern char *Scorefile; + extern char Scorefile[PATH_MAX]; int score_wfd; /* high score writable file descriptor */ int score_err = 0; /* hold errno from score file open */ int ch; + int ret; extern int optind; - gid_t gid; + char *home; #ifdef FANCY char *sp; #endif - if ((score_wfd = open(Scorefile, O_RDWR)) < 0) - score_err = errno; + if (pledge("stdio rpath wpath cpath getpw tty", NULL) == -1) + err(1, "pledge"); + + home = getenv("HOME"); + if (home == NULL || *home == '\0') + err(1, "getenv"); - /* revoke privs */ - gid = getgid(); - setresgid(gid, gid, gid); + ret = snprintf(Scorefile, sizeof(Scorefile), "%s/%s", home, + ".robots.scores"); + if (ret < 0 || ret >= PATH_MAX) + errc(1, ENAMETOOLONG, "%s/%s", home, ".robots.scores"); + + if ((score_wfd = open(Scorefile, O_RDWR | O_CREAT, 0666)) < 0) + score_err = errno; show_only = FALSE; while ((ch = getopt(ac, av, "srajt")) != -1) @@ -90,11 +99,13 @@ main(int ac, char *av[]) if (ac > 1) usage(); if (ac == 1) { - Scorefile = av[0]; + if (strlcpy(Scorefile, av[0], sizeof(Scorefile)) >= + sizeof(Scorefile)) + errc(1, ENAMETOOLONG, "%s", av[0]); if (score_wfd >= 0) close(score_wfd); /* This file requires no special privileges. */ - if ((score_wfd = open(Scorefile, O_RDWR)) < 0) + if ((score_wfd = open(Scorefile, O_RDWR | O_CREAT, 0666)) < 0) score_err = errno; #ifdef FANCY sp = strrchr(Scorefile, '/'); diff --git a/games/robots/pathnames.h b/games/robots/pathnames.h deleted file mode 100644 index 7dc9d3aafb0..00000000000 --- a/games/robots/pathnames.h +++ /dev/null @@ -1,35 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.3 2003/06/03 03:01:41 millert Exp $ */ -/* $NetBSD: pathnames.h,v 1.3 1995/04/22 10:09:01 cgd Exp $ */ - -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * 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_SCORE "/var/games/robots_roll" diff --git a/games/robots/robots.6 b/games/robots/robots.6 index 2edd703b6c8..2192113314c 100644 --- a/games/robots/robots.6 +++ b/games/robots/robots.6 @@ -1,4 +1,4 @@ -.\" $OpenBSD: robots.6,v 1.13 2014/09/08 01:27:54 schwarze Exp $ +.\" $OpenBSD: robots.6,v 1.14 2015/11/29 15:13:19 tb Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)robots.6 8.1 (Berkeley) 5/31/93 .\" -.Dd $Mdocdate: September 8 2014 $ +.Dd $Mdocdate: November 29 2015 $ .Dt ROBOTS 6 .Os .Sh NAME @@ -137,8 +137,8 @@ This is a little disconcerting until you get used to it, and then it is very nice. .El .Sh FILES -.Bl -tag -width /var/games/robots_roll -compact -.It Pa /var/games/robots_roll +.Bl -tag -width $HOME/.robots.scores -compact +.It Pa $HOME/.robots.scores the score file .El .Sh AUTHORS diff --git a/games/robots/robots.h b/games/robots/robots.h index cefce8ad2b5..3a4e2b66bb2 100644 --- a/games/robots/robots.h +++ b/games/robots/robots.h @@ -1,4 +1,4 @@ -/* $OpenBSD: robots.h,v 1.9 2015/08/26 00:29:24 rzalamena Exp $ */ +/* $OpenBSD: robots.h,v 1.10 2015/11/29 15:13:19 tb Exp $ */ /* $NetBSD: robots.h,v 1.5 1995/04/24 12:24:54 cgd Exp $ */ /* @@ -88,8 +88,6 @@ typedef struct { char s_name[LOGIN_NAME_MAX]; } SCORE; -typedef struct passwd PASSWD; - /* * global variables */ diff --git a/games/robots/score.c b/games/robots/score.c index 9b41adb7b49..c7dbe235fd1 100644 --- a/games/robots/score.c +++ b/games/robots/score.c @@ -1,4 +1,4 @@ -/* $OpenBSD: score.c,v 1.11 2014/11/16 04:49:48 guenther Exp $ */ +/* $OpenBSD: score.c,v 1.12 2015/11/29 15:13:19 tb Exp $ */ /* $NetBSD: score.c,v 1.3 1995/04/22 10:09:12 cgd Exp $ */ /* @@ -31,9 +31,8 @@ */ #include "robots.h" -#include "pathnames.h" -char *Scorefile = _PATH_SCORE; +char Scorefile[PATH_MAX]; #ifndef MAX_PER_UID #define MAX_PER_UID 5 @@ -130,7 +129,7 @@ score(int score_wfd) void set_name(SCORE *scp) { - PASSWD *pp; + struct passwd *pp; if ((pp = getpwuid(scp->s_uid)) == NULL) pp->pw_name = "???"; |