Mercurial > hg > early-roguelike
comparison xrogue/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 | 0d151573bdb0 |
children | aac28331e71d |
comparison
equal
deleted
inserted
replaced
142:6b5fbd7c3ece | 143:7faf4568c295 |
---|---|
24 | 24 |
25 #include "mach_dep.h" | 25 #include "mach_dep.h" |
26 #include "network.h" | 26 #include "network.h" |
27 #include "rogue.h" | 27 #include "rogue.h" |
28 | 28 |
29 #define SCOREFILE "xrogue.scr" | 29 FILE *scorefi = NULL; |
30 #define SAVEDIR "." | 30 FILE *logfile = NULL; |
31 void open_records(void); | |
31 | 32 |
32 main(argc, argv, envp) | 33 main(argc, argv, envp) |
33 char **argv; | 34 char **argv; |
34 char **envp; | 35 char **envp; |
35 { | 36 { |
81 parse_opts(env); | 82 parse_opts(env); |
82 | 83 |
83 if (whoami[0] == '\0') | 84 if (whoami[0] == '\0') |
84 strucpy(whoami, md_getusername(), strlen(md_getusername())); | 85 strucpy(whoami, md_getusername(), strlen(md_getusername())); |
85 | 86 |
87 open_records(); | |
88 if (!use_savedir) | |
89 md_normaluser(); | |
86 /* | 90 /* |
87 * check for print-score option | 91 * check for print-score option |
88 */ | 92 */ |
89 if (argc == 2 && strcmp(argv[1], "-s") == 0) | 93 if (argc == 2 && strcmp(argv[1], "-s") == 0) |
90 { | 94 { |
468 } | 472 } |
469 | 473 |
470 exit(0); | 474 exit(0); |
471 } | 475 } |
472 | 476 |
477 void | |
478 open_records(void) | |
479 { | |
480 if (scorefi == NULL) | |
481 scorefi = fopen(score_file, "rb+"); | |
482 if (scorefi == NULL) | |
483 scorefi = fopen(score_file, "wb+"); | |
484 /* If opening fails, that will be handled when trying to write. */ | |
485 #ifdef LOGFILE | |
486 if (logfile == NULL) | |
487 logfile = fopen(LOGFILE, "a"); | |
488 #endif | |
489 return; | |
490 } | |
491 |