diff arogue5/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 ee250e3646fd
children 80a590e67206
line wrap: on
line diff
--- a/arogue5/rip.c	Tue May 12 21:39:39 2015 -0400
+++ b/arogue5/rip.c	Sat May 16 13:39:26 2015 -0400
@@ -36,6 +36,9 @@
  * scoreout() and scorein() to reflect the change.  Also update SCORELEN.
  */
 
+extern int scorefd;
+extern FILE *logfile;
+
 struct sc_ent {
     unsigned long	sc_score;
     char	sc_name[LINELEN];
@@ -201,7 +204,7 @@
      * Open file and read list
      */
 
-    if ((fd = open(score_file, O_RDWR | O_CREAT, 0666)) < 0) 
+    if ((fd = scorefd) < 0) 
     {
        printf("\nCannot open score_file.\n");
        return;
@@ -576,7 +579,6 @@
 
 void writelog(unsigned long amount, int flags, short monst) {
 #ifdef LOGFILE
-  FILE *logfi;
   char fate[100];
   char *class;
   struct linked_list *item;
@@ -585,6 +587,8 @@
 
   if (waswizard)
     return;
+  if (logfile == NULL)
+    return;
   switch (player.t_ctype) {
     case C_FIGHTER:	class = "Fighter";
     when C_MAGICIAN:	class = "Magician";
@@ -609,15 +613,10 @@
   else
     return;
 
-  logfi = fopen(LOGFILE, "a");
-  if (logfi == NULL) {
-    perror(LOGFILE);
-    return;
-  }
-  fprintf(logfi, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount, 
+  fprintf(logfile, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount, 
           whoami, pstats.s_lvl, class, level, max_level, quest_item, had_quest, 
           fate);
-  fclose(logfi);
+  fclose(logfile);
 #endif
   return;
 }