The following patch is a slight improvement of the patch that I posted
on Thursday.  In particular, this patch places saved games exactly where
the man page says they should be placed.

This patch, together with the patch that prevents segmentation faults
(http://marc.info/?l=openbsd-tech&m=152020888711960), should be all that
is needed to make /usr/games/hack playable on OpenBSD 6.2 without
setting the setgid bit.

Remember to create the /usr/share/games/hack directory before trying to
install this patched version of hack.


--- games/hack/config.h.orig    Fri Oct 16 07:37:46 2015
+++ games/hack/config.h Mon Mar  5 02:31:18 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      Mon Mar  5 16:17:31 2018
@@ -62,6 +62,7 @@
  */
 
 #include <sys/stat.h>
+#include <errno.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -538,6 +539,8 @@
        }
 
        /* warn the player if he cannot write the record file */
+       /* warn the player if he cannot read the permanent lock file */
+       /* warn the player if he cannot create the save directory */
        /* perhaps we should also test whether . is writable */
        /* unfortunately the access systemcall is worthless */
        if(wr) {
@@ -545,11 +548,20 @@
 
            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);
+           if(mkdir("save", 0770) && errno != EEXIST) {
+               printf("Warning: cannot create %s/save", dir);
+               getret();
+           }
        }
 }
 #endif
--- games/hack/Makefile.orig    Mon Jul 10 21:30:37 2017
+++ games/hack/Makefile Mon Mar  5 02:31:18 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   Mon Mar  5 15:41:06 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       Mon Mar  5 02:31:18 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