Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/warp - use termios



details:   https://anonhg.NetBSD.org/src/rev/0c110da842ac
branches:  trunk
changeset: 1016205:0c110da842ac
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Nov 11 17:11:19 2020 +0000

description:
- use termios
- enable setgid games
- enable savedir

diffstat:

 games/warp/Makefile |   5 ++++-
 games/warp/config.h |   4 ++--
 games/warp/intrp.c  |   2 +-
 games/warp/score.c  |  10 ++--------
 games/warp/term.c   |  30 +++++++++++++++---------------
 games/warp/term.h   |  31 +++++++++++++++++++------------
 games/warp/warp.h   |   2 +-
 7 files changed, 44 insertions(+), 40 deletions(-)

diffs (214 lines):

diff -r 898254f71741 -r 0c110da842ac games/warp/Makefile
--- a/games/warp/Makefile       Wed Nov 11 11:54:42 2020 +0000
+++ b/games/warp/Makefile       Wed Nov 11 17:11:19 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2020/11/10 08:49:08 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2020/11/11 17:11:19 christos Exp $
 
 .include <bsd.own.mk>
 
@@ -18,6 +18,9 @@
 SETGIDGAME=yes
 MAN=   warp.6
 
+BINGRP= games
+BINMODE=2555
+
 warp.6:
        ${_MKTARGET_CREATE}
        cat ${.CURDIR}/warp.man > ${.TARGET}
diff -r 898254f71741 -r 0c110da842ac games/warp/config.h
--- a/games/warp/config.h       Wed Nov 11 11:54:42 2020 +0000
+++ b/games/warp/config.h       Wed Nov 11 17:11:19 2020 +0000
@@ -20,12 +20,12 @@
  */
 #define        SIGNEDCHAR      /**/
 
-/* TERMIO:
+/* TERMIOS:
  *     This symbol, if defined, indicates that the program should include
  *     termio.h rather than sgtty.h.  There are also differences in the
  *     ioctl() calls that depend on the value of this symbol.
  */
-#undef TERMIO          /**/
+#define        TERMIOS         /**/
 
 /* USENDIR:
  *     This symbol, if defined, indicates that the program should compile
diff -r 898254f71741 -r 0c110da842ac games/warp/intrp.c
--- a/games/warp/intrp.c        Wed Nov 11 11:54:42 2020 +0000
+++ b/games/warp/intrp.c        Wed Nov 11 17:11:19 2020 +0000
@@ -568,7 +568,7 @@
        if (fork())
            wait(0);
        else {
-           setuid(getuid());
+           setgid(getgid());
            if ((tmpfp = fopen(filexp(FULLNAMEFILE),"w")) == NULL)
                exit(1);
            fprintf(tmpfp, "%s\n", buf);
diff -r 898254f71741 -r 0c110da842ac games/warp/score.c
--- a/games/warp/score.c        Wed Nov 11 11:54:42 2020 +0000
+++ b/games/warp/score.c        Wed Nov 11 17:11:19 2020 +0000
@@ -35,20 +35,18 @@
     int i;
     FILE *savfil;
 
-#if 0
     if (stat(SAVEDIR,&filestat)) {
        printf("Cannot access %s\r\n",SAVEDIR);
        finalize(1);
     }
-    if (filestat.st_uid != geteuid()) {
-       printf("Warp will not run right without being setuid.\r\n");
+    if (filestat.st_gid != getegid()) {
+       printf("Warp will not run right without being setgid.\r\n");
        finalize(1);
     }
     if ((filestat.st_mode & 0605) != 0605) {
        printf("%s is not protected correctly (must be u+rw o+rx).\r\n",SAVEDIR);
        finalize(1);
     }
-#endif
     
 #ifdef SCOREFULL
     interp(longlognam, sizeof longlognam, "%N");
@@ -241,9 +239,7 @@
     printf("WHO           SCORE  DF   CDF  E  B  WV  FLAGS\r\n");
     resetty();
     snprintf(spbuf, sizeof(spbuf), "/bin/cat %ssave.*",SAVEDIR);
-#ifndef lint
     execl("/bin/sh", "sh", "-c", spbuf, NULL);
-#endif
     finalize(1);
 }
 
@@ -421,10 +417,8 @@
     snprintf(spbuf, sizeof(spbuf), "Star save ratio:         %1.8f (%d/%d)",
        starscore, numstars, inumstars);
     mvaddstr( 6,5, spbuf);
-#ifndef lint
     bonuses += tmp = (long) (((double)curscore / possiblescore) *
        (starscore*starscore) * smarts * 20);
-#endif
     snprintf(spbuf, sizeof(spbuf), "%6ld", tmp);
     mvaddstr( 6, 68, spbuf);
     row = 7;
diff -r 898254f71741 -r 0c110da842ac games/warp/term.c
--- a/games/warp/term.c Wed Nov 11 11:54:42 2020 +0000
+++ b/games/warp/term.c Wed Nov 11 17:11:19 2020 +0000
@@ -69,8 +69,8 @@
 {
     savetty();                         /* remember current tty state */
 
-#ifdef TERMIO
-    ospeed = _tty.c_cflag & CBAUD;     /* for tputs() */
+#if defined(TERMIO) || defined(TERMIOS)
+    ospeed = cfgetospeed(&_tty);
     ERASECH = _tty.c_cc[VERASE];       /* for finish_command() */
     KILLCH = _tty.c_cc[VKILL];         /* for finish_command() */
 #else
@@ -265,19 +265,19 @@
        for (p=filler+(sizeof filler)-1;!*p;--p)
            *p = PC;
     }
-    charsperhalfsec = ospeed >= B9600 ? 480 :
-                     ospeed == B4800 ? 240 :
-                     ospeed == B2400 ? 120 :
-                     ospeed == B1200 ? 60 :
-                     ospeed == B600 ? 30 :
-             /* speed is 300 (?) */   15;
+    charsperhalfsec = (speed_t)ospeed >= B9600 ? (speed_t)480 :
+                     (speed_t)ospeed == B4800 ? (speed_t)240 :
+                     (speed_t)ospeed == B2400 ? (speed_t)120 :
+                     (speed_t)ospeed == B1200 ? (speed_t)60 :
+                     (speed_t)ospeed == B600 ? (speed_t)30 :
+             /* speed is 300 (?) */   (speed_t)15;
 
-    gfillen = ospeed >= B9600 ? (int /*XXX: speed_t*/)(sizeof filler) :
-             ospeed == B4800 ? 13 :
-             ospeed == B2400 ? 7 :
-             ospeed == B1200 ? 4 :
-                               (1+BCsize);
-    if (ospeed < B2400)
+    gfillen = (speed_t)ospeed >= B9600 ? (speed_t)(sizeof filler) :
+             (speed_t)ospeed == B4800 ? (speed_t)13 :
+             (speed_t)ospeed == B2400 ? (speed_t)7 :
+             (speed_t)ospeed == B1200 ? (speed_t)4 :
+                               (speed_t)(1+BCsize);
+    if ((speed_t)ospeed < B2400)
        lowspeed = true;
 
     strcpy(term,ttyname(2));
@@ -767,7 +767,7 @@
     }
 
 got_canonical:
-#ifndef TERMIO
+#if !defined(TERMIO) && !defined(TERMIOS)
     if (*whatbuf == '\r')
        *whatbuf = '\n';
 #endif
diff -r 898254f71741 -r 0c110da842ac games/warp/term.h
--- a/games/warp/term.h Wed Nov 11 11:54:42 2020 +0000
+++ b/games/warp/term.h Wed Nov 11 17:11:19 2020 +0000
@@ -181,9 +181,16 @@
 
 /* stuff wanted by terminal mode diddling routines */
 
-#ifdef TERMIO
+#ifdef TERMIOS
+EXT struct termios _tty, _oldtty;
+#elif defined(TERMIO)
+typedef int speed_t;
 EXT struct termio _tty, _oldtty;
+#define tcsetattr(fd, how, ti) ioctl(fd, how, ti)
+#define tcgetattr(fd, ti) ioctl(fd, TCGETA, ti)
+#define cfgetospeed(ti) ((ti)->c_cflag & CBAUD)
 #else
+typedef int speed_t;
 EXT struct sgttyb _tty;
 EXT int _res_flg INIT(0);
 #endif
@@ -193,18 +200,18 @@
 
 /* terminal mode diddling routines */
 
-#ifdef TERMIO
+#if defined(TERMIO) || defined(TERMIOS)
   
-#define raw() ((bizarre=1),_tty.c_lflag &=~ISIG,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty))
-#define noraw() ((bizarre=1),_tty.c_lflag |= ISIG,_tty.c_cc[VEOF] = CEOF,ioctl(_tty_ch,TCSETAF,&_tty))
-#define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty))
-#define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,ioctl(_tty_ch,TCSETAF,&_tty))
-#define echo()  ((bizarre=1),_tty.c_lflag |= ECHO, ioctl(_tty_ch, TCSETAW, &_tty))
-#define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, ioctl(_tty_ch, TCSETAW, &_tty))
-#define nl()    ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
-#define nonl()  ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
-#define        savetty() (ioctl(_tty_ch, TCGETA, &_oldtty),ioctl(_tty_ch, TCGETA, &_tty))
-#define        resetty() ((bizarre=0),ioctl(_tty_ch, TCSETAF, &_oldtty))
+#define raw() ((bizarre=1),_tty.c_lflag &=~ISIG,_tty.c_cc[VMIN] = 1,tcsetattr(_tty_ch,TCSAFLUSH,&_tty))
+#define noraw() ((bizarre=1),_tty.c_lflag |= ISIG,_tty.c_cc[VEOF] = CEOF,tcsetattr(_tty_ch,TCSAFLUSH,&_tty))
+#define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,tcsetattr(_tty_ch,TCSAFLUSH,&_tty))
+#define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,tcsetattr(_tty_ch,TCSAFLUSH,&_tty))
+#define echo()  ((bizarre=1),_tty.c_lflag |= ECHO, tcsetattr(_tty_ch, TCSANOW, &_tty))
+#define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, tcsetattr(_tty_ch, TCSANOW, &_tty))
+#define nl()    ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,tcsetattr(_tty_ch, TCSANOW, &_tty))
+#define nonl()  ((bizarre=1),_tty.c_iflag &=~ICRNL,_tty.c_oflag &=~ONLCR,tcsetattr(_tty_ch, TCSANOW, &_tty))
+#define        savetty() (tcgetattr(_tty_ch, &_oldtty),tcgetattr(_tty_ch, &_tty))
+#define        resetty() ((bizarre=0),tcsetattr(_tty_ch, TCSAFLUSH, &_oldtty))
 #define unflush_output()
 
 #else
diff -r 898254f71741 -r 0c110da842ac games/warp/warp.h
--- a/games/warp/warp.h Wed Nov 11 11:54:42 2020 +0000
+++ b/games/warp/warp.h Wed Nov 11 17:11:19 2020 +0000
@@ -43,7 +43,7 @@
  * access.)
  */
 
-#define SAVEDIR "/var/games"
+#define SAVEDIR "/var/games/warp"
 #define NEWSFILE "warp.news"
 #define HELPFILE "warp.doc"
 #define LOCKFILE ".warp.lock"



Home | Main Index | Thread Index | Old Index