diff 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
line wrap: on
line diff
--- a/arogue7/rip.c	Tue May 12 21:39:39 2015 -0400
+++ b/arogue7/rip.c	Sat May 16 13:39:26 2015 -0400
@@ -17,8 +17,6 @@
 #define EDITSCORE 2	/* Edit the current score file */
 #define ADDSCORE 3	/* Add a new score */
 
-#define LOGFILE "arogue7.log"
-
 #define NAMELEN	80
 
 /*
@@ -48,6 +46,9 @@
 extern char oldtext[WTXTNUM][WTXTLEN];
 #endif
 
+extern int scorefd;
+extern FILE *logfile;
+
 #ifdef NUMNET
 /* Network machines (for mutual score keeping) */
 static struct network Network[NUMNET] = {
@@ -207,7 +208,6 @@
 void 
 writelog(unsigned long amount, int flags, short monst)
 {
-    FILE *logwriter;
     char had_quest = '0';
     char fate[LINELEN];
     struct linked_list *item;
@@ -215,6 +215,8 @@
 #ifdef LOGFILE
     if (waswizard)
         return;
+    if (logfile == NULL)
+        return;
     /* Check for quest item */
     for (item = pack; item != NULL; item = next(item)) {
         obj = OBJPTR(item);
@@ -233,14 +235,11 @@
     }
     else
         return;
-    /* Open and write */
-    logwriter = fopen(LOGFILE, "a");
-    if (logwriter == NULL)
-        return;
-    fprintf(logwriter, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
+    /* Write */
+    fprintf(logfile, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
             whoami, pstats.s_lvl, char_class[char_type].name, level, max_level,
             quest_item, had_quest, fate);
-    fclose(logwriter);
+    fclose(logfile);
 #endif
     return;
 }
@@ -295,7 +294,7 @@
      * Open file and read list
      */
 
-    if ((fd = open(score_file, O_RDWR | O_CREAT, 0666)) < 0) return;
+    if ((fd = scorefd) < 0) return;
     outfd = fd;
 
 #ifndef SYSTEM