comparison arogue7/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 796e2a10cd41
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 <signal.h> 18 #include <signal.h>
19 #include <sys/types.h>
20 #include <fcntl.h>
19 #ifdef BSD 21 #ifdef BSD
20 #include <sys/time.h> 22 #include <sys/time.h>
21 #else 23 #else
22 #include <time.h> 24 #include <time.h>
23 #endif 25 #endif
29 #include <ctype.h> 31 #include <ctype.h>
30 extern struct uwdata wdata, oldwin; 32 extern struct uwdata wdata, oldwin;
31 extern char oldtext[WTXTNUM][WTXTLEN]; 33 extern char oldtext[WTXTNUM][WTXTLEN];
32 #endif 34 #endif
33 35
34 #define SAVEDIR "." 36 int scorefd = -1;
37 FILE *logfile = NULL;
38 void open_records(void);
35 39
36 main(argc, argv, envp) 40 main(argc, argv, envp)
37 char **argv; 41 char **argv;
38 char **envp; 42 char **envp;
39 { 43 {
89 parse_opts(env); 93 parse_opts(env);
90 94
91 if (whoami[0] == '\0') 95 if (whoami[0] == '\0')
92 strucpy(whoami, md_getusername(), strlen(md_getusername())); 96 strucpy(whoami, md_getusername(), strlen(md_getusername()));
93 97
98 open_records();
99
94 /* 100 /*
95 * check for print-score option 101 * check for print-score option
96 */ 102 */
97 if (argc == 2 && strcmp(argv[1], "-s") == 0) 103 if (argc == 2 && strcmp(argv[1], "-s") == 0)
98 { 104 {
158 164
159 if (use_savedir) 165 if (use_savedir)
160 { 166 {
161 if (!restore(file_name, envp)) 167 if (!restore(file_name, envp))
162 exit(1); 168 exit(1);
169 }
170 else
171 {
172 md_normaluser();
163 } 173 }
164 if (argc == 2) 174 if (argc == 2)
165 if (!restore(argv[1], envp)) /* Note: restore will never return */ 175 if (!restore(argv[1], envp)) /* Note: restore will never return */
166 exit(1); 176 exit(1);
167 lowtime = (int) time(&now); 177 lowtime = (int) time(&now);
537 raw(); /* Cbreak mode */ 547 raw(); /* Cbreak mode */
538 noecho(); /* Echo off */ 548 noecho(); /* Echo off */
539 nonl(); 549 nonl();
540 } 550 }
541 551
552 void
553 open_records(void)
554 {
555 if (scorefd == -1)
556 scorefd = open(score_file, O_RDWR | O_CREAT, 0666);
557 #ifdef LOGFILE
558 if (logfile == NULL)
559 logfile = fopen(LOGFILE, "a");
560 #endif
561 return;
562 }
563
542 /* 564 /*
543 * playit: 565 * playit:
544 * The main loop of the program. Loop until the game is over, 566 * The main loop of the program. Loop until the game is over,
545 * refreshing things and looking at the proper times. 567 * refreshing things and looking at the proper times.
546 */ 568 */