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
|
|
@ -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 @@ static char *funfruit[] = {
|
|||
};
|
||||
#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 @@ char **envp;
|
|||
strcpy(fruit, funfruit[rnd(NFRUIT)]);
|
||||
}
|
||||
|
||||
open_records();
|
||||
if (!use_savedir)
|
||||
md_normaluser();
|
||||
|
||||
/*
|
||||
* check for print-score option
|
||||
*/
|
||||
|
|
@ -242,6 +251,18 @@ char **envp;
|
|||
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.
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@
|
|||
* scoreout() and scorein() to reflect the change. Also update SCORELEN.
|
||||
*/
|
||||
|
||||
extern int scorefd;
|
||||
extern FILE *logfile;
|
||||
|
||||
struct sc_ent {
|
||||
unsigned long sc_score;
|
||||
char sc_name[LINELEN];
|
||||
|
|
@ -201,7 +204,7 @@ short monst;
|
|||
* Open file and read list
|
||||
*/
|
||||
|
||||
if ((fd = open(score_file, O_RDWR | O_CREAT, 0666)) < 0)
|
||||
if ((fd = scorefd) < 0)
|
||||
{
|
||||
printf("\nCannot open score_file.\n");
|
||||
return;
|
||||
|
|
@ -576,7 +579,6 @@ short monst;
|
|||
|
||||
void writelog(unsigned long amount, int flags, short monst) {
|
||||
#ifdef LOGFILE
|
||||
FILE *logfi;
|
||||
char fate[100];
|
||||
char *class;
|
||||
struct linked_list *item;
|
||||
|
|
@ -585,6 +587,8 @@ void writelog(unsigned long amount, int flags, short monst) {
|
|||
|
||||
if (waswizard)
|
||||
return;
|
||||
if (logfile == NULL)
|
||||
return;
|
||||
switch (player.t_ctype) {
|
||||
case C_FIGHTER: class = "Fighter";
|
||||
when C_MAGICIAN: class = "Magician";
|
||||
|
|
@ -609,15 +613,10 @@ void writelog(unsigned long amount, int flags, short monst) {
|
|||
else
|
||||
return;
|
||||
|
||||
logfi = fopen(LOGFILE, "a");
|
||||
if (logfi == NULL) {
|
||||
perror(LOGFILE);
|
||||
return;
|
||||
}
|
||||
fprintf(logfi, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
|
||||
fprintf(logfile, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
|
||||
whoami, pstats.s_lvl, class, level, max_level, quest_item, had_quest,
|
||||
fate);
|
||||
fclose(logfi);
|
||||
fclose(logfile);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue