diff xrogue/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 0d151573bdb0
children aac28331e71d
line wrap: on
line diff
--- a/xrogue/main.c	Tue May 12 21:39:39 2015 -0400
+++ b/xrogue/main.c	Sat May 16 13:39:26 2015 -0400
@@ -26,8 +26,9 @@
 #include "network.h"
 #include "rogue.h"
 
-#define SCOREFILE "xrogue.scr"
-#define SAVEDIR "."
+FILE *scorefi = NULL;
+FILE *logfile = NULL;
+void open_records(void);
 
 main(argc, argv, envp)
 char **argv;
@@ -83,6 +84,9 @@
     if (whoami[0] == '\0')
         strucpy(whoami, md_getusername(), strlen(md_getusername()));
 
+    open_records();
+    if (!use_savedir)
+        md_normaluser();
     /*
      * check for print-score option
      */
@@ -470,3 +474,18 @@
     exit(0);
 }
 
+void
+open_records(void)
+{
+    if (scorefi == NULL)
+        scorefi = fopen(score_file, "rb+");
+    if (scorefi == NULL)
+        scorefi = fopen(score_file, "wb+");
+    /* If opening fails, that will be handled when trying to write. */
+#ifdef LOGFILE
+    if (logfile == NULL)
+        logfile = fopen(LOGFILE, "a");
+#endif
+    return;
+}
+