Mercurial > hg > early-roguelike
comparison arogue5/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 | ee250e3646fd |
children | aac28331e71d |
comparison
equal
deleted
inserted
replaced
142:6b5fbd7c3ece | 143:7faf4568c295 |
---|---|
14 | 14 |
15 #include "curses.h" | 15 #include "curses.h" |
16 #include <stdlib.h> | 16 #include <stdlib.h> |
17 #include <string.h> | 17 #include <string.h> |
18 #include <fcntl.h> | 18 #include <fcntl.h> |
19 #include <sys/types.h> | |
19 #include <sys/stat.h> | 20 #include <sys/stat.h> |
20 #include <limits.h> | 21 #include <limits.h> |
21 #include <signal.h> | 22 #include <signal.h> |
22 #include <time.h> | 23 #include <time.h> |
23 #include "mach_dep.h" | 24 #include "mach_dep.h" |
39 "sapodilla", "soursop", "sweetsop", "whortleberry", | 40 "sapodilla", "soursop", "sweetsop", "whortleberry", |
40 "jellybean", "apple", "strawberry", "blueberry", | 41 "jellybean", "apple", "strawberry", "blueberry", |
41 "peach", "banana" | 42 "peach", "banana" |
42 }; | 43 }; |
43 #define NFRUIT (sizeof(funfruit) / sizeof (char *)) | 44 #define NFRUIT (sizeof(funfruit) / sizeof (char *)) |
45 | |
46 int scorefd = -1; | |
47 FILE *logfile = NULL; | |
48 void open_records(void); | |
44 | 49 |
45 main(argc, argv, envp) | 50 main(argc, argv, envp) |
46 char **argv; | 51 char **argv; |
47 char **envp; | 52 char **envp; |
48 { | 53 { |
99 | 104 |
100 if (env == NULL || fruit[0] == '\0') { | 105 if (env == NULL || fruit[0] == '\0') { |
101 md_srand((long)(getpid()+time(0))); | 106 md_srand((long)(getpid()+time(0))); |
102 strcpy(fruit, funfruit[rnd(NFRUIT)]); | 107 strcpy(fruit, funfruit[rnd(NFRUIT)]); |
103 } | 108 } |
109 | |
110 open_records(); | |
111 if (!use_savedir) | |
112 md_normaluser(); | |
104 | 113 |
105 /* | 114 /* |
106 * check for print-score option | 115 * check for print-score option |
107 */ | 116 */ |
108 if (argc == 2 && strcmp(argv[1], "-s") == 0) | 117 if (argc == 2 && strcmp(argv[1], "-s") == 0) |
240 rel_magic[quest_item].mi_name); | 249 rel_magic[quest_item].mi_name); |
241 mpos = 0; | 250 mpos = 0; |
242 playit(); | 251 playit(); |
243 } | 252 } |
244 | 253 |
254 void | |
255 open_records(void) | |
256 { | |
257 if (scorefd == -1) | |
258 scorefd = open(score_file, O_RDWR | O_CREAT, 0666); | |
259 #ifdef LOGFILE | |
260 if (logfile == NULL) | |
261 logfile = fopen(LOGFILE, "a"); | |
262 #endif | |
263 return; | |
264 } | |
265 | |
245 /* | 266 /* |
246 * endit: | 267 * endit: |
247 * Exit the program abnormally. | 268 * Exit the program abnormally. |
248 */ | 269 */ |
249 void | 270 void |