Mercurial > hg > early-roguelike
diff arogue5/main.c @ 143:7faf4568c295
Advanced Rogue family: overhaul privilege handling.
Advanced Rogue 5 and 7, and XRogue, now open the scorefile and logfile
at startup and then drop any set[ug]id privileges if the savedir is not
being used.
author | John "Elwin" Edwards |
---|---|
date | Sat, 16 May 2015 13:39:26 -0400 |
parents | ee250e3646fd |
children | aac28331e71d |
line wrap: on
line diff
--- a/arogue5/main.c Tue May 12 21:39:39 2015 -0400 +++ b/arogue5/main.c Sat May 16 13:39:26 2015 -0400 @@ -16,6 +16,7 @@ #include <stdlib.h> #include <string.h> #include <fcntl.h> +#include <sys/types.h> #include <sys/stat.h> #include <limits.h> #include <signal.h> @@ -42,6 +43,10 @@ }; #define NFRUIT (sizeof(funfruit) / sizeof (char *)) +int scorefd = -1; +FILE *logfile = NULL; +void open_records(void); + main(argc, argv, envp) char **argv; char **envp; @@ -102,6 +107,10 @@ strcpy(fruit, funfruit[rnd(NFRUIT)]); } + open_records(); + if (!use_savedir) + md_normaluser(); + /* * check for print-score option */ @@ -242,6 +251,18 @@ playit(); } +void +open_records(void) +{ + if (scorefd == -1) + scorefd = open(score_file, O_RDWR | O_CREAT, 0666); +#ifdef LOGFILE + if (logfile == NULL) + logfile = fopen(LOGFILE, "a"); +#endif + return; +} + /* * endit: * Exit the program abnormally.