Phantasia was one of the games broken by removal of setgid.  But it has
another problem that led me to start rummaging around in the code.

The games set in the releases includes pre-generated world files which get
installed when you upgrade the OS which overwrite any existing game files.
So upgrading will delete the scoreboard and your active characters.

I've been able to play Phantasia by adding my user to the games group which
allows access to the files in /var/games/phantasia and the game plays fine
with multiple users.  I am not sure if that is a recommended solution to
accessing the shared files.  Past discussion indicated desire to remove
such shared files altogether.

The attached diff is just a conversation starter.  There are a couple of
possible directions to go in.  What I have here is removal of the pre-
generated world files from the games set to stop overwriting an existing
game world and instead including Phantasia's setup utility that generates
those files for the game.  A user can then run the setup to start playing
or reset an existing world as desired.

Some alternative options are to move the games files into $HOME or go a
similar route as hack(6) and allow user defined directories to be
configured to remove the /var/games shared directory usage.  A simple
solution could be to continue to generate the files as part of the release
but into /usr/share/games and let users copy them into place.

Regardless of how we want to deal with the shared files, I want to at least
stop deleting an existing game world and characters during an upgrade.

Again, this is so I can get feedback on direction.  I haven't tested the
release packaging or installation related changes yet but hopefully it
demonstrates what I'm talking about.

Tim.


Index: games/phantasia/Makefile
===================================================================
RCS file: /cvs/src/games/phantasia/Makefile,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile
--- games/phantasia/Makefile    24 Nov 2015 03:10:10 -0000      1.18
+++ games/phantasia/Makefile    7 May 2021 23:44:30 -0000
@@ -17,15 +17,15 @@ phantglobs.o.bld: phantglobs.c
        ${HOSTCC} -c ${CFLAGS} -o ${.TARGET} ${.CURDIR}/phantglobs.c
 
 setup: phantglobs.o.bld setup.o monsters.asc ${DPADD} 
-       ${HOSTCC} ${CFLAGS} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} \
+       ${HOSTCC} ${CFLAGS} ${LDFLAGS} ${LDSTATIC} -o phantasia-${.TARGET} \
                  phantglobs.o.bld setup.o ${LDADD}
 
 phantasia.6: phantasia.6tbl
        cp ${.ALLSRC} ${.TARGET}
 
-beforeinstall: 
-       ./setup -m ${.CURDIR}/monsters.asc
-       chown root:games ${DESTDIR}/var/games/phantasia/*
+beforeinstall:
+       ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 
${.CURDIR}/monsters.asc \
+               ${DESTDIR}/usr/share/games/phantasia
 
 # Make Phantasia map.  Change the map commands reflect your installation.
 # PLOTDEVICE is used for plotting the map.  Change as appropriate.
Index: games/phantasia/misc.c
===================================================================
RCS file: /cvs/src/games/phantasia/misc.c,v
retrieving revision 1.21
diff -u -p -r1.21 misc.c
--- games/phantasia/misc.c      10 Jan 2016 13:35:10 -0000      1.21
+++ games/phantasia/misc.c      7 May 2021 23:44:31 -0000
@@ -1411,7 +1411,7 @@ error(char *whichfile)
        cleanup(FALSE);
 
        warn("%s", whichfile);
-       fprintf(stderr, "Please run 'setup' to determine the problem.\n");
+       fprintf(stderr, "Please run 'phantasia-setup' to determine the 
problem.\n");
        exit(1);
 }
 /**/
Index: games/phantasia/setup.c
===================================================================
RCS file: /cvs/src/games/phantasia/setup.c,v
retrieving revision 1.20
diff -u -p -r1.20 setup.c
--- games/phantasia/setup.c     28 Jun 2019 13:32:52 -0000      1.20
+++ games/phantasia/setup.c     7 May 2021 23:44:31 -0000
@@ -5,6 +5,7 @@
  * setup.c - set up all files for Phantasia
  */
 #include <sys/stat.h>
+#include <errno.h>
 
 #include <fcntl.h>
 #include <math.h>
@@ -65,7 +66,7 @@ static char *files[] = {              /* all files t
        NULL,
 };
 
-char *monsterfile="monsters.asc";
+char *monsterfile="/usr/share/games/phantasia/monsters.asc";
 
 int
 main(int argc, char *argv[])
@@ -77,6 +78,11 @@ main(int argc, char *argv[])
        int ch;
        char path[PATH_MAX], *prefix;
 
+       if (geteuid()) {
+               fprintf(stderr, "Error:  needs to be run as root\n");
+               return(1);
+       }
+
        while ((ch = getopt(argc, argv, "hm:")) != -1)
                switch(ch) {
                case 'm':
@@ -89,17 +95,21 @@ main(int argc, char *argv[])
        argc -= optind;
        argv += optind;
 
+    umask(0002);               /* owner and group read/write and read for 
world for te directory */
+
+    /* create data directory */
+    if(mkdir("/var/games/phantasia", 0775) && errno != EEXIST) 
+       Error("Cannot create %s.\n", "/var/games/phantasia");
+
     umask(0117);               /* only owner can read/write created files */
 
-    prefix = getenv("DESTDIR");
 
     /* try to create data files */
     filename = &files[0];
     while (*filename != NULL)
        /* create each file */
        {
-       snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", *filename);
-       if (stat(path, &fbuf) == 0)
+       if (stat(*filename, &fbuf) == 0)
            /* file exists; remove it */
            {
            if (!strcmp(*filename, _PATH_PEOPLE))
@@ -116,12 +126,12 @@ main(int argc, char *argv[])
                continue;
                }
 
-           if (unlink(path) == -1)
-               Error("Cannot unlink %s.\n", path);
+           if (unlink(*filename) == -1)
+               Error("Cannot unlink %s.\n", *filename);
            }
 
-       if ((fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0660)) == -1)
-           Error("Cannot create %s.\n", path);
+       if ((fd = open(*filename, O_CREAT | O_TRUNC | O_WRONLY, 0660)) == -1)
+           Error("Cannot create %s.\n", *filename);
 
        close(fd);                      /* close newly created file */
 
@@ -132,9 +142,8 @@ main(int argc, char *argv[])
     Enrgyvoid.ev_active = true;
     Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
     Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
-    snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", _PATH_VOID);
-    if ((fp = fopen(path, "w")) == NULL)
-       Error("Cannot update %s.\n", path);
+    if ((fp = fopen(_PATH_VOID, "w")) == NULL)
+       Error("Cannot update %s.\n", _PATH_VOID);
     else
        {
        fwrite(&Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
@@ -142,15 +151,14 @@ main(int argc, char *argv[])
        }
 
     /* create binary monster data base */
-    snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", _PATH_MONST);
-    if ((Monstfp = fopen(path, "w")) == NULL)
-       Error("Cannot update %s.\n", path);
+    if ((Monstfp = fopen(_PATH_MONST, "w")) == NULL)
+       Error("Cannot update %s.\n", _PATH_MONST);
     else
        {
        if ((fp = fopen(monsterfile, "r")) == NULL)
            {
            fclose(Monstfp);
-           Error("cannot open %s to create monster database.\n", 
"monsters.asc");
+           Error("cannot open %s to create monster database.\n", monsterfile);
            }
        else
            {
Index: distrib/sets/lists/game/mi
===================================================================
RCS file: /cvs/src/distrib/sets/lists/game/mi,v
retrieving revision 1.28
diff -u -p -r1.28 mi
--- distrib/sets/lists/game/mi  6 Apr 2019 17:44:51 -0000       1.28
+++ distrib/sets/lists/game/mi  8 May 2021 16:39:25 -0000
@@ -25,6 +25,7 @@
 ./usr/games/morse
 ./usr/games/number
 ./usr/games/phantasia
+./usr/games/phantasia-setup
 ./usr/games/pig
 ./usr/games/pom
 ./usr/games/ppt
@@ -89,6 +90,8 @@
 ./usr/share/games/hack/help
 ./usr/share/games/hack/hh
 ./usr/share/games/hack/rumors
+./usr/share/games/phantasia
+./usr/share/games/phantasia/monsters.asc
 ./usr/share/games/quiz.db
 ./usr/share/games/quiz.db/africa
 ./usr/share/games/quiz.db/america
@@ -165,13 +168,4 @@
 ./usr/share/man/man6/worm.6
 ./usr/share/man/man6/worms.6
 ./usr/share/man/man6/wump.6
-./var/games/phantasia
-./var/games/phantasia/characs
-./var/games/phantasia/gold
-./var/games/phantasia/lastdead
-./var/games/phantasia/mess
-./var/games/phantasia/monsters
-./var/games/phantasia/motd
-./var/games/phantasia/scoreboard
-./var/games/phantasia/void
 ./var/games/save

Reply via email to