mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
Move score file to $HOME and add pledge "stdio rpath wpath cpath".
For high score entries, try LOGNAME, then USER, then getlogin() then fall back to ???.
This commit is contained in:
parent
bf2d39770d
commit
c425f3ea0e
@ -1,4 +1,4 @@
|
||||
.\" $OpenBSD: battlestar.6,v 1.17 2015/03/13 19:58:40 jmc Exp $
|
||||
.\" $OpenBSD: battlestar.6,v 1.18 2015/11/29 15:31:06 tb Exp $
|
||||
.\" $NetBSD: battlestar.6,v 1.4 1995/03/21 15:06:42 cgd Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1993
|
||||
@ -30,7 +30,7 @@
|
||||
.\"
|
||||
.\" @(#)battlestar.6 8.1 (Berkeley) 5/31/93
|
||||
.\"
|
||||
.Dd $Mdocdate: March 13 2015 $
|
||||
.Dd $Mdocdate: November 29 2015 $
|
||||
.Dt BATTLESTAR 6
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -150,6 +150,16 @@ If you don't have a compass, you'll have to say R, L, A, or B, which
|
||||
stand for Right, Left, Ahead, and Back.
|
||||
Directions printed in room descriptions are
|
||||
always printed in R, L, A, & B relative directions.
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width Ds
|
||||
.It Ev LOGNAME
|
||||
Name to be recorded in high score file.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width $HOME/.battlestar.scores
|
||||
.It Pa $HOME/.battlestar.scores
|
||||
high score file
|
||||
.El
|
||||
.Sh HISTORY
|
||||
I wrote Battlestar in 1979 in order to experiment with the niceties of
|
||||
the C Language.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: battlestar.c,v 1.16 2009/10/27 23:59:23 deraadt Exp $ */
|
||||
/* $OpenBSD: battlestar.c,v 1.17 2015/11/29 15:31:06 tb Exp $ */
|
||||
/* $NetBSD: battlestar.c,v 1.3 1995/03/21 15:06:47 cgd Exp $ */
|
||||
|
||||
/*
|
||||
@ -47,13 +47,13 @@ main(int argc, char *argv[])
|
||||
{
|
||||
char mainbuf[LINELENGTH];
|
||||
char *next;
|
||||
gid_t gid;
|
||||
|
||||
if (pledge("stdio rpath wpath cpath", NULL) == -1)
|
||||
err(1, "pledge");
|
||||
|
||||
open_score_file();
|
||||
|
||||
/* revoke privs */
|
||||
gid = getgid();
|
||||
setresgid(gid, gid, gid);
|
||||
|
||||
if (argc < 2)
|
||||
initialize(NULL);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: com6.c,v 1.19 2009/10/27 23:59:23 deraadt Exp $ */
|
||||
/* $OpenBSD: com6.c,v 1.20 2015/11/29 15:31:06 tb Exp $ */
|
||||
/* $NetBSD: com6.c,v 1.5 1995/04/27 21:30:23 mycroft Exp $ */
|
||||
|
||||
/*
|
||||
@ -92,8 +92,19 @@ static FILE *score_fp;
|
||||
void
|
||||
open_score_file(void)
|
||||
{
|
||||
if ((score_fp = fopen(_PATH_SCORE, "a")) == NULL)
|
||||
warn("can't append to high scores file (%s)", _PATH_SCORE);
|
||||
const char scorefile[PATH_MAX];
|
||||
const char *home;
|
||||
int ret;
|
||||
|
||||
home = getenv("HOME");
|
||||
if (home == NULL || *home == '\0')
|
||||
err(1, "getenv");
|
||||
ret = snprintf(scorefile, sizeof(scorefile), "%s/%s", home,
|
||||
".battlestar.scores");
|
||||
if (ret < 0 || ret >= PATH_MAX)
|
||||
errc(1, ENAMETOOLONG, "%s/%s", home, ".battlestar.scores");
|
||||
if ((score_fp = fopen(scorefile, "a")) == NULL)
|
||||
warn("can't append to high scores file (%s)", scorefile);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: init.c,v 1.14 2013/08/29 20:22:10 naddy Exp $ */
|
||||
/* $OpenBSD: init.c,v 1.15 2015/11/29 15:31:06 tb Exp $ */
|
||||
/* $NetBSD: init.c,v 1.4 1995/03/21 15:07:35 cgd Exp $ */
|
||||
|
||||
/*
|
||||
@ -72,13 +72,17 @@ initialize(const char *filename)
|
||||
static const char *
|
||||
getutmp(void)
|
||||
{
|
||||
struct passwd *ptr;
|
||||
const char *name;
|
||||
|
||||
ptr = getpwuid(getuid());
|
||||
if (ptr == NULL)
|
||||
return(NULL);
|
||||
else
|
||||
return(strdup(ptr->pw_name));
|
||||
name = getenv("LOGNAME");
|
||||
if (name == NULL || *name == 0)
|
||||
name = getenv("USER");
|
||||
if (name == NULL || *name == 0)
|
||||
name = getlogin();
|
||||
if (name == NULL || *name == 0)
|
||||
name = " ??? ";
|
||||
|
||||
return(strdup(name));
|
||||
}
|
||||
|
||||
/* Hereditary wizards. A configuration file might make more sense. */
|
||||
|
Loading…
Reference in New Issue
Block a user