diff options
author | alex <alex@FreeBSD.org> | 1996-10-15 01:53:48 +0000 |
---|---|---|
committer | alex <alex@FreeBSD.org> | 1996-10-15 01:53:48 +0000 |
commit | 4b6e5c4c291e78bbabf104576e9ee98db0f7459c (patch) | |
tree | c6b10d3b246fd7fb07adc258f523124cffa41ff3 /games/adventure | |
parent | f685f888235f9b9a7259a5de4e7a37a579776ad2 (diff) | |
download | FreeBSD-src-4b6e5c4c291e78bbabf104576e9ee98db0f7459c.zip FreeBSD-src-4b6e5c4c291e78bbabf104576e9ee98db0f7459c.tar.gz |
Set the effective user id to that of the real user id when
saving/restoring a game (necessary when adventure is invoked via dm).
Diffstat (limited to 'games/adventure')
-rw-r--r-- | games/adventure/save.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/games/adventure/save.c b/games/adventure/save.c index 6501fbd..6784fef 100644 --- a/games/adventure/save.c +++ b/games/adventure/save.c @@ -42,6 +42,7 @@ static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93"; #include <stdio.h> #include <stdlib.h> +#include <sys/types.h> #include "hdr.h" struct savestruct @@ -124,17 +125,22 @@ char *outfile; /* to output the data using checksum to start random #s */ char *s; long sum; int i; + uid_t euid_save; crc_start(); for (p = save_array; p->address != NULL; p++) sum = crc(p->address, p->width); srandom((int) sum); + euid_save = geteuid(); + seteuid(getuid()); + if ((out = fopen(outfile, "wb")) == NULL) { fprintf(stderr, "Hmm. The name \"%s\" appears to be magically blocked.\n", outfile); + seteuid(euid_save); return 1; } fwrite(&sum, sizeof(sum), 1, out); /* Here's the random() key */ @@ -145,6 +151,7 @@ char *outfile; /* to output the data using checksum to start random #s */ fwrite(p->address, p->width, 1, out); } fclose(out); + seteuid(euid_save); return 0; } @@ -156,12 +163,17 @@ char *infile; char *s; long sum, cksum; int i; + uid_t euid_save; + + euid_save = geteuid(); + seteuid(euid_save); if ((in = fopen(infile, "rb")) == NULL) { fprintf(stderr, "Hmm. The file \"%s\" appears to be magically blocked.\n", infile); + seteuid(euid_save); return 1; } fread(&sum, sizeof(sum), 1, in); /* Get the seed */ @@ -173,6 +185,7 @@ char *infile; *s = (*s ^ random()) & 0xFF; /* Lightly decrypt */ } fclose(in); + seteuid(euid_save); crc_start(); /* See if she cheated */ for (p = save_array; p->address != NULL; p++) |