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.
This commit is contained in:
John "Elwin" Edwards 2015-05-16 13:39:26 -04:00
parent 1a5e14ad9b
commit 3554339257
9 changed files with 123 additions and 38 deletions

View file

@ -26,8 +26,9 @@
#include "network.h"
#include "rogue.h"
#define SCOREFILE "xrogue.scr"
#define SAVEDIR "."
FILE *scorefi = NULL;
FILE *logfile = NULL;
void open_records(void);
main(argc, argv, envp)
char **argv;
@ -83,6 +84,9 @@ char **envp;
if (whoami[0] == '\0')
strucpy(whoami, md_getusername(), strlen(md_getusername()));
open_records();
if (!use_savedir)
md_normaluser();
/*
* check for print-score option
*/
@ -470,3 +474,18 @@ int flag;
exit(0);
}
void
open_records(void)
{
if (scorefi == NULL)
scorefi = fopen(score_file, "rb+");
if (scorefi == NULL)
scorefi = fopen(score_file, "wb+");
/* If opening fails, that will be handled when trying to write. */
#ifdef LOGFILE
if (logfile == NULL)
logfile = fopen(LOGFILE, "a");
#endif
return;
}