diff options
author | Thorsten Lockert <tholo@cvs.openbsd.org> | 1996-12-21 22:06:23 +0000 |
---|---|---|
committer | Thorsten Lockert <tholo@cvs.openbsd.org> | 1996-12-21 22:06:23 +0000 |
commit | 0afc2895abf5a383eff66175d85f6e3ed8486a04 (patch) | |
tree | b5f2a9ac91409453dd9be409ba75c827353054c0 | |
parent | 2f775f77f48c603d20484cbfdb138f241708ea3b (diff) |
Deal correctly with being SGID
-rw-r--r-- | games/rogue/init.c | 5 | ||||
-rw-r--r-- | games/rogue/machdep.c | 4 | ||||
-rw-r--r-- | games/rogue/score.c | 4 |
3 files changed, 13 insertions, 0 deletions
diff --git a/games/rogue/init.c b/games/rogue/init.c index 339a495f95f..60b7b24fc9e 100644 --- a/games/rogue/init.c +++ b/games/rogue/init.c @@ -57,6 +57,7 @@ static char rcsid[] = "$NetBSD: init.c,v 1.4 1995/04/28 23:49:19 mycroft Exp $"; */ #include <stdio.h> +#include <unistd.h> #include "rogue.h" char login_name[MAX_OPT_LEN]; @@ -72,6 +73,7 @@ boolean no_skull = 0; boolean passgo = 0; char *error_file = "rogue.esave"; char *byebye_string = "Okay, bye bye!"; +gid_t gid, egid; extern char *fruit; extern char *save_file; @@ -85,6 +87,9 @@ char *argv[]; char *pn; int seed; + gid = getgid(); + egid = getegid(); + setegid(gid); pn = md_gln(); if ((!pn) || (strlen(pn) >= MAX_OPT_LEN)) { clean_up("Hey! Who are you?"); diff --git a/games/rogue/machdep.c b/games/rogue/machdep.c index 1862d40a6f6..b969f58bdb7 100644 --- a/games/rogue/machdep.c +++ b/games/rogue/machdep.c @@ -454,14 +454,18 @@ int status; md_lock(l) boolean l; { + extern gid_t gid, egid; static int fd; short tries; if (l) { + setegid(egid); if ((fd = open(_PATH_SCOREFILE, O_RDONLY)) < 1) { + setegid(gid); message("cannot lock score file", 0); return; } + setegid(gid); for (tries = 0; tries < 5; tries++) if (!flock(fd, LOCK_EX|LOCK_NB)) return; diff --git a/games/rogue/score.c b/games/rogue/score.c index 814c1d3915f..98635ab3f87 100644 --- a/games/rogue/score.c +++ b/games/rogue/score.c @@ -209,14 +209,18 @@ short other; FILE *fp; long s; boolean pause = score_only; + extern gid_t gid, egid; md_lock(1); + setegid(egid); if ((fp = fopen(_PATH_SCOREFILE, "r+")) == NULL && (fp = fopen(_PATH_SCOREFILE, "w+")) == NULL) { + setegid(gid); message("cannot read/write/create score file", 0); sf_error(); } + setegid(gid); rewind(fp); (void) xxx(1); |