comparison arogue7/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 1a64fd0bfea6
children ca876944b196
comparison
equal deleted inserted replaced
142:6b5fbd7c3ece 143:7faf4568c295
15 /* Print flags for scoring */ 15 /* Print flags for scoring */
16 #define REALLIFE 1 /* Print out machine and logname */ 16 #define REALLIFE 1 /* Print out machine and logname */
17 #define EDITSCORE 2 /* Edit the current score file */ 17 #define EDITSCORE 2 /* Edit the current score file */
18 #define ADDSCORE 3 /* Add a new score */ 18 #define ADDSCORE 3 /* Add a new score */
19 19
20 #define LOGFILE "arogue7.log"
21
22 #define NAMELEN 80 20 #define NAMELEN 80
23 21
24 /* 22 /*
25 * File for the fun ends 23 * File for the fun ends
26 * Death or a total win 24 * Death or a total win
45 #ifdef PC7300 43 #ifdef PC7300
46 #include "sys/window.h" 44 #include "sys/window.h"
47 extern struct uwdata wdata, oldwin; 45 extern struct uwdata wdata, oldwin;
48 extern char oldtext[WTXTNUM][WTXTLEN]; 46 extern char oldtext[WTXTNUM][WTXTLEN];
49 #endif 47 #endif
48
49 extern int scorefd;
50 extern FILE *logfile;
50 51
51 #ifdef NUMNET 52 #ifdef NUMNET
52 /* Network machines (for mutual score keeping) */ 53 /* Network machines (for mutual score keeping) */
53 static struct network Network[NUMNET] = { 54 static struct network Network[NUMNET] = {
54 { "ihwpt", "/t1/michael/bin/rg" }, 55 { "ihwpt", "/t1/michael/bin/rg" },
205 /* Writes an entry in the log file */ 206 /* Writes an entry in the log file */
206 207
207 void 208 void
208 writelog(unsigned long amount, int flags, short monst) 209 writelog(unsigned long amount, int flags, short monst)
209 { 210 {
210 FILE *logwriter;
211 char had_quest = '0'; 211 char had_quest = '0';
212 char fate[LINELEN]; 212 char fate[LINELEN];
213 struct linked_list *item; 213 struct linked_list *item;
214 struct object *obj; 214 struct object *obj;
215 #ifdef LOGFILE 215 #ifdef LOGFILE
216 if (waswizard) 216 if (waswizard)
217 return; 217 return;
218 if (logfile == NULL)
219 return;
218 /* Check for quest item */ 220 /* Check for quest item */
219 for (item = pack; item != NULL; item = next(item)) { 221 for (item = pack; item != NULL; item = next(item)) {
220 obj = OBJPTR(item); 222 obj = OBJPTR(item);
221 if (obj->o_type == RELIC && obj->o_which == quest_item) 223 if (obj->o_type == RELIC && obj->o_which == quest_item)
222 had_quest = '1'; 224 had_quest = '1';
231 else if (flags == WINNER) { 233 else if (flags == WINNER) {
232 strcpy(fate, "escaped"); 234 strcpy(fate, "escaped");
233 } 235 }
234 else 236 else
235 return; 237 return;
236 /* Open and write */ 238 /* Write */
237 logwriter = fopen(LOGFILE, "a"); 239 fprintf(logfile, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
238 if (logwriter == NULL)
239 return;
240 fprintf(logwriter, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
241 whoami, pstats.s_lvl, char_class[char_type].name, level, max_level, 240 whoami, pstats.s_lvl, char_class[char_type].name, level, max_level,
242 quest_item, had_quest, fate); 241 quest_item, had_quest, fate);
243 fclose(logwriter); 242 fclose(logfile);
244 #endif 243 #endif
245 return; 244 return;
246 } 245 }
247 246
248 /* 247 /*
293 292
294 /* 293 /*
295 * Open file and read list 294 * Open file and read list
296 */ 295 */
297 296
298 if ((fd = open(score_file, O_RDWR | O_CREAT, 0666)) < 0) return; 297 if ((fd = scorefd) < 0) return;
299 outfd = fd; 298 outfd = fd;
300 299
301 #ifndef SYSTEM 300 #ifndef SYSTEM
302 thissys = md_gethostname(); 301 thissys = md_gethostname();
303 #else 302 #else