comparison xrogue/rip.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 dd137c35c3b1
children 5a77931393f4
comparison
equal deleted inserted replaced
142:6b5fbd7c3ece 143:7faf4568c295
17 */ 17 */
18 18
19 #define REALLIFE 1 /* Print out machine and logname */ 19 #define REALLIFE 1 /* Print out machine and logname */
20 #define EDITSCORE 2 /* Edit the current score file */ 20 #define EDITSCORE 2 /* Edit the current score file */
21 #define ADDSCORE 3 /* Add a new score */ 21 #define ADDSCORE 3 /* Add a new score */
22
23 #define LOGFILE "xrogue.log"
24 22
25 #include <curses.h> 23 #include <curses.h>
26 #include <time.h> 24 #include <time.h>
27 #include <signal.h> 25 #include <signal.h>
28 #include <ctype.h> 26 #include <ctype.h>
56 NULL 54 NULL
57 }; 55 };
58 56
59 char *killname(); 57 char *killname();
60 58
59 extern FILE *scorefi, *logfile;
60
61 /*UNUSED*/ 61 /*UNUSED*/
62 void 62 void
63 byebye(sig) 63 byebye(sig)
64 int sig; 64 int sig;
65 { 65 {
136 /* Writes an entry in the log file */ 136 /* Writes an entry in the log file */
137 137
138 void 138 void
139 writelog(unsigned long amount, int flags, short monst) 139 writelog(unsigned long amount, int flags, short monst)
140 { 140 {
141 FILE *logwriter;
142 char had_quest = '0'; 141 char had_quest = '0';
143 char fate[LINELEN]; 142 char fate[LINELEN];
144 struct linked_list *item; 143 struct linked_list *item;
145 struct object *obj; 144 struct object *obj;
146 #ifdef LOGFILE 145 #ifdef LOGFILE
147 if (waswizard) 146 if (waswizard)
148 return; 147 return;
148 if (logfile == NULL)
149 {
150 /* Error message? */
151 return;
152 }
149 /* Adjustments to the score */ 153 /* Adjustments to the score */
150 if (level == 0 && max_level == 0) 154 if (level == 0 && max_level == 0)
151 amount = 0; 155 amount = 0;
152 if (flags == CHICKEN) 156 if (flags == CHICKEN)
153 amount /= 100; 157 amount /= 100;
167 else if (flags == WINNER) { 171 else if (flags == WINNER) {
168 strcpy(fate, "escaped"); 172 strcpy(fate, "escaped");
169 } 173 }
170 else 174 else
171 return; 175 return;
172 /* Open and write */ 176 /* Write the line */
173 logwriter = fopen(LOGFILE, "a"); 177 fprintf(logfile, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
174 if (logwriter == NULL)
175 return;
176 fprintf(logwriter, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
177 whoami, pstats.s_lvl, char_class[char_type].name, level, max_level, 178 whoami, pstats.s_lvl, char_class[char_type].name, level, max_level,
178 quest_item, had_quest, fate); 179 quest_item, had_quest, fate);
179 fclose(logwriter); 180 fclose(logfile);
180 #endif 181 #endif
181 return; 182 return;
182 } 183 }
183 184
184 /* 185 /*
232 233
233 /* 234 /*
234 * Open file and read list 235 * Open file and read list
235 */ 236 */
236 237
237 if ((outf = fopen(score_file, "rb+")) == NULL) 238 if (scorefi == NULL)
238 { 239 {
239 if ((outf = fopen(score_file, "wb+")) == NULL) 240 mvprintw(lines - 1, 0, "Unable to open or create score file: %s",score_file);
240 { 241 refresh();
241 mvprintw(lines - 1, 0, "Unable to open or create score file: %s",score_file); 242 return;
242 refresh(); 243 }
243 return; 244 else
244 } 245 {
246 outf = scorefi;
245 } 247 }
246 248
247 thissys = md_gethostname(); 249 thissys = md_gethostname();
248 250
249 /* 251 /*