The game /usr/games/hack is currently broken.

 http://marc.info/?l=openbsd-cvs&m=147343518631317

A patch that fixes /usr/games/hack is included below.  The patch moves
the hackdir from /var/games to a user-specified directory.  Procedures
for specifying the directory (either on the command line, or with an
environment variable) are described on the hack man page.

The main change is that if two users want to share a hackdir (so that
they have a common high-score list, for example), they will need to
create a directory that they both have access to.  For example, if both
users are in the same group, they could create a directory that is owned
by that group.

The patch also moves the read-only datafiles from /var/games/hackdir to
/usr/share/games/hack.  Before attempting to install the patched version
of hack, be sure to create the /usr/share/games/hack directory.

Also, I noticed that the rumors file wasn't being installed by the
Makefile.  I fixed that bug, too.


--- games/hack/config.h.orig    Fri Oct 16 07:37:46 2015
+++ games/hack/config.h Wed Feb 28 22:27:25 2018
@@ -77,10 +77,10 @@
 #define WIZARD  "bruno"        /* the person allowed to use the -D option */
 #define RECORD "record"/* the file containing the list of topscorers */
 #define        NEWS    "news"  /* the file containing the latest hack news */
-#define        HELP    "help"  /* the file containing a description of the 
commands */
-#define        SHELP   "hh"    /* abbreviated form of the same */
-#define        RUMORFILE       "rumors"        /* a file with fortune cookies 
*/
-#define        DATAFILE        "data"  /* a file giving the meaning of symbols 
used */
+#define        HELP    "/usr/share/games/hack/help"    /* the file containing 
a description of the commands */
+#define        SHELP   "/usr/share/games/hack/hh"      /* abbreviated form of 
the same */
+#define        RUMORFILE       "/usr/share/games/hack/rumors"  /* a file with 
fortune cookies */
+#define        DATAFILE        "/usr/share/games/hack/data"    /* a file 
giving the meaning of symbols used */
 #define        FMASK   0660    /* file creation mask */
 #define        HLOCK   "perm"  /* an empty file used for locking purposes */
 #define LLOCK  "safelock"      /* link to previous */
@@ -93,7 +93,7 @@
  * (This might be preferable for security reasons.)
  * #define DEF_PAGER   ".../mydir/mypager"
  */
-#define        DEF_PAGER       _PATH_PAGER
+/* #define     DEF_PAGER       _PATH_PAGER */
 
 /*
  * If you define MAIL, then the player will be notified of new mail
@@ -120,7 +120,7 @@
 #ifdef QUEST
 #define HACKDIR _PATH_QUEST
 #else /* QUEST */
-#define HACKDIR        _PATH_HACK
+/* #define HACKDIR     _PATH_HACK */
 #endif /* QUEST */
 
 /*
@@ -130,7 +130,7 @@
  * since the user might create files in a directory of his choice.
  * Of course SECURE is meaningful only if HACKDIR is defined.
  */
-#define SECURE                 /* do setuid(getuid()) after chdir() */
+/* #define SECURE */                   /* do setuid(getuid()) after chdir() */
 
 /*
  * If it is desirable to limit the number of people that can play Hack
--- games/hack/hack.main.c.orig Sat Jan  9 21:54:11 2016
+++ games/hack/hack.main.c      Wed Feb 28 21:03:02 2018
@@ -89,7 +89,7 @@
 #ifdef DEF_PAGER
 char *catmore;                         /* default pager */
 #endif
-char SAVEF[PL_NSIZ + 11] = "save/";    /* save/99999player */
+char SAVEF[PL_NSIZ + 6] = "";  /* 99999player */
 char obuf[BUFSIZ];     /* BUFSIZ is defined in stdio.h */
 
 extern char *nomovemsg;
@@ -295,7 +295,7 @@
        }
 #endif
        setftty();
-       (void) snprintf(SAVEF, sizeof SAVEF, "save/%u%s", getuid(), plname);
+       (void) snprintf(SAVEF, sizeof SAVEF, "%u%s", getuid(), plname);
        regularize(SAVEF+5);            /* avoid . or / in name */
        if((fd = open(SAVEF, O_RDONLY)) >= 0 &&
           (uptodate(fd) || unlink(SAVEF) == 666)) {
@@ -538,6 +538,7 @@
        }
 
        /* warn the player if he cannot write the record file */
+       /* warn the player if he cannot read the permanent lock file */
        /* perhaps we should also test whether . is writable */
        /* unfortunately the access systemcall is worthless */
        if(wr) {
@@ -545,8 +546,13 @@
 
            if(dir == NULL)
                dir = ".";
-           if((fd = open(RECORD, O_RDWR)) < 0) {
+           if((fd = open(RECORD, O_RDWR | O_CREAT, FMASK)) < 0) {
                printf("Warning: cannot write %s/%s", dir, RECORD);
+               getret();
+           } else
+               (void) close(fd);
+           if((fd = open(HLOCK, O_RDONLY | O_CREAT, FMASK)) < 0) {
+               printf("Warning: cannot read %s/%s", dir, HLOCK);
                getret();
            } else
                (void) close(fd);
--- games/hack/Makefile.orig    Mon Jul 10 21:30:37 2017
+++ games/hack/Makefile Wed Feb 28 16:39:15 2018
@@ -27,12 +27,7 @@
        ${HOSTCC} ${CFLAGS} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} 
${.CURDIR}/${.PREFIX}.c ${LDADD}
 
 beforeinstall: 
-       ${INSTALL} ${INSTALL_COPY} -o root -g games -m 660 /dev/null \
-           ${DESTDIR}/var/games/hackdir/perm
-       ${INSTALL} ${INSTALL_COPY} -o root -g games -m 660 /dev/null \
-           ${DESTDIR}/var/games/hackdir/record
        ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 
${.CURDIR}/help \
-           ${.CURDIR}/hh ${.CURDIR}/data ${DESTDIR}/var/games/hackdir
-       rm -f ${DESTDIR}/var/games/hackdir/bones*
+           ${.CURDIR}/hh ${.CURDIR}/data ${.CURDIR}/rumors 
${DESTDIR}/usr/share/games/hack
 
 .include <bsd.prog.mk>
--- games/hack/hack.6.orig      Fri Sep  9 15:32:28 2016
+++ games/hack/hack.6   Wed Feb 28 11:53:25 2018
@@ -75,13 +75,6 @@
 .Op Fl d Ar directory
 .Op Ar playername ...
 .Sh DESCRIPTION
-.Bf -symbolic
-.Nm
-is currently unusable because it relies on
-.Xr setgid 2
-to allow multiple users read and write access to the same files.
-.Ef
-.Pp
 .Nm
 is a display oriented dungeons & dragons - like game.
 Both display and command structure resemble rogue.
--- etc/mtree/4.4BSD.dist.orig  Tue Oct 10 03:41:26 2017
+++ etc/mtree/4.4BSD.dist       Wed Feb 28 22:36:11 2018
@@ -438,6 +438,8 @@
             ..
             fortune
             ..
+            hack
+            ..
             quiz.db
             ..
         ..
@@ -627,10 +629,6 @@
 
     # ./var/games
     games                      uname=root gname=games mode=0775
-        hackdir                        uname=root gname=games mode=0775
-            save               uname=root gname=games mode=0770
-            ..
-        ..
         save                   uname=root gname=games mode=0775
         ..
         phantasia              uname=root gname=games mode=0775

Reply via email to