From 36f340bd47acb8baf6515e7754448dbb1e48a5a8 Mon Sep 17 00:00:00 2001 From: hubertf Date: Wed, 21 Jul 1999 03:56:53 +0000 Subject: Drop setgid privileges early. Derived from OpenBSD and sent in as PR 5970 by Joseph Myers . --- battlestar/battlestar.c | 7 +++++-- battlestar/com6.c | 28 ++++++++++++++++++---------- battlestar/extern.h | 3 ++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/battlestar/battlestar.c b/battlestar/battlestar.c index acafb5c1..9eb63707 100644 --- a/battlestar/battlestar.c +++ b/battlestar/battlestar.c @@ -1,4 +1,4 @@ -/* $NetBSD: battlestar.c,v 1.6 1997/10/11 02:06:55 lukem Exp $ */ +/* $NetBSD: battlestar.c,v 1.7 1999/07/21 03:56:53 hubertf Exp $ */ /* * Copyright (c) 1983, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ #if 0 static char sccsid[] = "@(#)battlestar.c 8.2 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: battlestar.c,v 1.6 1997/10/11 02:06:55 lukem Exp $"); +__RCSID("$NetBSD: battlestar.c,v 1.7 1999/07/21 03:56:53 hubertf Exp $"); #endif #endif /* not lint */ @@ -66,6 +66,9 @@ main(argc, argv) char mainbuf[LINELENGTH]; char *next; + /* Open the score file then revoke setgid privileges */ + open_score_file(); + setregid(getgid(), getgid()); initialize(argc < 2 || strcmp(argv[1], "-r")); start: news(); diff --git a/battlestar/com6.c b/battlestar/com6.c index 9132880e..50939f8e 100644 --- a/battlestar/com6.c +++ b/battlestar/com6.c @@ -1,4 +1,4 @@ -/* $NetBSD: com6.c,v 1.10 1999/02/10 01:36:50 hubertf Exp $ */ +/* $NetBSD: com6.c,v 1.11 1999/07/21 03:56:53 hubertf Exp $ */ /* * Copyright (c) 1983, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)com6.c 8.2 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: com6.c,v 1.10 1999/02/10 01:36:50 hubertf Exp $"); +__RCSID("$NetBSD: com6.c,v 1.11 1999/07/21 03:56:53 hubertf Exp $"); #endif #endif /* not lint */ @@ -105,11 +105,20 @@ live() exit(0); } +static FILE *score_fp; + +void +open_score_file() +{ + score_fp = fopen(_PATH_SCORE, "a"); + if (score_fp == NULL) + warn("open %s for append", _PATH_SCORE); +} + void post(ch) char ch; { - FILE *fp; struct timeval tv; time_t tvsec; char *date; @@ -122,17 +131,16 @@ post(ch) tvsec = (time_t) tv.tv_sec; date = ctime(&tvsec); date[24] = '\0'; - if ((fp = fopen(_PATH_SCORE, "a")) != NULL) { - fprintf(fp, "%s %8s %c%20s", date, uname, ch, rate()); + if (score_fp != NULL) { + fprintf(score_fp, "%s %8s %c%20s", date, uname, ch, rate()); if (wiz) - fprintf(fp, " wizard\n"); + fprintf(score_fp, " wizard\n"); else if (tempwiz) - fprintf(fp, " WIZARD!\n"); + fprintf(score_fp, " WIZARD!\n"); else - fprintf(fp, "\n"); - } else - warn("fopen %s", _PATH_SCORE); + fprintf(score_fp, "\n"); + } sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0); } diff --git a/battlestar/extern.h b/battlestar/extern.h index afe2c0e2..7231ceb5 100644 --- a/battlestar/extern.h +++ b/battlestar/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.10 1999/02/10 01:36:50 hubertf Exp $ */ +/* $NetBSD: extern.h,v 1.11 1999/07/21 03:56:53 hubertf Exp $ */ /* * Copyright (c) 1983, 1993 @@ -340,6 +340,7 @@ void murder __P((void)); void news __P((void)); void newway __P((int)); void notarget __P((void)); +void open_score_file __P((void)); void parse __P((void)); void post __P((char)); void printobjs __P((void)); -- cgit v1.2.3-56-ge451