From 6eff467615806d8dd5a8bac71bad4e5ca27b5c84 Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 11 Nov 2020 17:11:19 +0000 Subject: - use termios - enable setgid games - enable savedir --- warp/Makefile | 5 ++++- warp/config.h | 4 ++-- warp/intrp.c | 2 +- warp/score.c | 10 ++-------- warp/term.c | 32 ++++++++++++++++---------------- warp/term.h | 31 +++++++++++++++++++------------ warp/warp.h | 2 +- 7 files changed, 45 insertions(+), 41 deletions(-) diff --git a/warp/Makefile b/warp/Makefile index e48fbf3e..7e13a4cc 100644 --- a/warp/Makefile +++ b/warp/Makefile @@ -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 @@ -18,6 +18,9 @@ HIDEGAME=hidegame SETGIDGAME=yes MAN= warp.6 +BINGRP= games +BINMODE=2555 + warp.6: ${_MKTARGET_CREATE} cat ${.CURDIR}/warp.man > ${.TARGET} diff --git a/warp/config.h b/warp/config.h index 70f07296..c4b30b45 100644 --- a/warp/config.h +++ b/warp/config.h @@ -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 --git a/warp/intrp.c b/warp/intrp.c index 5a370aba..6b6b8be4 100644 --- a/warp/intrp.c +++ b/warp/intrp.c @@ -568,7 +568,7 @@ getrealname(uid_t uid) if (fork()) wait(0); else { - setuid(getuid()); + setgid(getgid()); if ((tmpfp = fopen(filexp(FULLNAMEFILE),"w")) == NULL) exit(1); fprintf(tmpfp, "%s\n", buf); diff --git a/warp/score.c b/warp/score.c index 16272669..3736f4a3 100644 --- a/warp/score.c +++ b/warp/score.c @@ -35,20 +35,18 @@ score_init(void) 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 @@ wscore(void) 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 @@ wavescore(void) 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 --git a/warp/term.c b/warp/term.c index 47a230ed..af20896b 100644 --- a/warp/term.c +++ b/warp/term.c @@ -69,8 +69,8 @@ term_init(void) { 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 @@ term_set(char *tcbuf) /* temp area for "uncompiled" termcap entry */ 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; - - gfillen = ospeed >= B9600 ? (int /*XXX: speed_t*/)(sizeof filler) : - ospeed == B4800 ? 13 : - ospeed == B2400 ? 7 : - ospeed == B1200 ? 4 : - (1+BCsize); - if (ospeed < B2400) + 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 = (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 @@ tryagain: } got_canonical: -#ifndef TERMIO +#if !defined(TERMIO) && !defined(TERMIOS) if (*whatbuf == '\r') *whatbuf = '\n'; #endif diff --git a/warp/term.h b/warp/term.h index 52ade745..3798a24c 100644 --- a/warp/term.h +++ b/warp/term.h @@ -181,9 +181,16 @@ EXT char INTRCH INIT('\03'); /* 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 @@ EXT bool bizarre INIT(false); /* do we need to restore terminal? */ /* 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 --git a/warp/warp.h b/warp/warp.h index f8e54c76..24abfdc3 100644 --- a/warp/warp.h +++ b/warp/warp.h @@ -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" -- cgit v1.2.3-56-ge451