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:
parent
1a5e14ad9b
commit
3554339257
9 changed files with 123 additions and 38 deletions
|
|
@ -44,6 +44,15 @@
|
|||
#define SCOREFILE "arogue7.scr"
|
||||
#endif
|
||||
|
||||
#ifndef LOGFILE
|
||||
#define LOGFILE "arogue7.log"
|
||||
#endif
|
||||
|
||||
#ifndef SAVEDIR
|
||||
#define SAVEDIR "."
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Variables for checking to make sure the system isn't too loaded
|
||||
* for people to play
|
||||
|
|
|
|||
|
|
@ -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 struct uwdata wdata, oldwin;
|
|||
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 @@ char **envp;
|
|||
if (whoami[0] == '\0')
|
||||
strucpy(whoami, md_getusername(), strlen(md_getusername()));
|
||||
|
||||
open_records();
|
||||
|
||||
/*
|
||||
* check for print-score option
|
||||
*/
|
||||
|
|
@ -161,6 +167,10 @@ char **envp;
|
|||
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 @@ setup()
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@
|
|||
#define EDITSCORE 2 /* Edit the current score file */
|
||||
#define ADDSCORE 3 /* Add a new score */
|
||||
|
||||
#define LOGFILE "arogue7.log"
|
||||
|
||||
#define NAMELEN 80
|
||||
|
||||
/*
|
||||
|
|
@ -48,6 +46,9 @@ extern struct uwdata wdata, oldwin;
|
|||
extern char oldtext[WTXTNUM][WTXTLEN];
|
||||
#endif
|
||||
|
||||
extern int scorefd;
|
||||
extern FILE *logfile;
|
||||
|
||||
#ifdef NUMNET
|
||||
/* Network machines (for mutual score keeping) */
|
||||
static struct network Network[NUMNET] = {
|
||||
|
|
@ -207,7 +208,6 @@ register short monst;
|
|||
void
|
||||
writelog(unsigned long amount, int flags, short monst)
|
||||
{
|
||||
FILE *logwriter;
|
||||
char had_quest = '0';
|
||||
char fate[LINELEN];
|
||||
struct linked_list *item;
|
||||
|
|
@ -215,6 +215,8 @@ writelog(unsigned long amount, int flags, short monst)
|
|||
#ifdef LOGFILE
|
||||
if (waswizard)
|
||||
return;
|
||||
if (logfile == NULL)
|
||||
return;
|
||||
/* Check for quest item */
|
||||
for (item = pack; item != NULL; item = next(item)) {
|
||||
obj = OBJPTR(item);
|
||||
|
|
@ -233,14 +235,11 @@ writelog(unsigned long amount, int flags, short monst)
|
|||
}
|
||||
else
|
||||
return;
|
||||
/* Open and write */
|
||||
logwriter = fopen(LOGFILE, "a");
|
||||
if (logwriter == NULL)
|
||||
return;
|
||||
fprintf(logwriter, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
|
||||
/* Write */
|
||||
fprintf(logfile, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
|
||||
whoami, pstats.s_lvl, char_class[char_type].name, level, max_level,
|
||||
quest_item, had_quest, fate);
|
||||
fclose(logwriter);
|
||||
fclose(logfile);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
|
@ -295,7 +294,7 @@ short monst;
|
|||
* Open file and read list
|
||||
*/
|
||||
|
||||
if ((fd = open(score_file, O_RDWR | O_CREAT, 0666)) < 0) return;
|
||||
if ((fd = scorefd) < 0) return;
|
||||
outfd = fd;
|
||||
|
||||
#ifndef SYSTEM
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue