Mercurial > hg > early-roguelike
diff arogue7/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 | 796e2a10cd41 |
children | aac28331e71d |
line wrap: on
line diff
--- a/arogue7/main.c Tue May 12 21:39:39 2015 -0400 +++ b/arogue7/main.c Sat May 16 13:39:26 2015 -0400 @@ -16,6 +16,8 @@ #include <stdlib.h> #include <string.h> #include <signal.h> +#include <sys/types.h> +#include <fcntl.h> #ifdef BSD #include <sys/time.h> #else @@ -31,7 +33,9 @@ extern char oldtext[WTXTNUM][WTXTLEN]; #endif -#define SAVEDIR "." +int scorefd = -1; +FILE *logfile = NULL; +void open_records(void); main(argc, argv, envp) char **argv; @@ -91,6 +95,8 @@ if (whoami[0] == '\0') strucpy(whoami, md_getusername(), strlen(md_getusername())); + open_records(); + /* * check for print-score option */ @@ -161,6 +167,10 @@ if (!restore(file_name, envp)) exit(1); } + else + { + md_normaluser(); + } if (argc == 2) if (!restore(argv[1], envp)) /* Note: restore will never return */ exit(1); @@ -539,6 +549,18 @@ nonl(); } +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; +} + /* * playit: * The main loop of the program. Loop until the game is over,