diff options
author | markm <markm@FreeBSD.org> | 2001-12-20 13:06:50 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 2001-12-20 13:06:50 +0000 |
commit | fb75415d8276feaba6d6d62600bd9642cca5cb6b (patch) | |
tree | bdabcc7cc70f8fffda574525cdfef6ebab18e815 /usr.bin | |
parent | 4c8ded1c65ebe0909ae49e4a481e4eb012fab9b7 (diff) | |
download | FreeBSD-src-fb75415d8276feaba6d6d62600bd9642cca5cb6b.zip FreeBSD-src-fb75415d8276feaba6d6d62600bd9642cca5cb6b.tar.gz |
Import of OpenBSD's tip (which was the tip code of a month ago, modulo
OpenBSD commits).
Diffstat (limited to 'usr.bin')
28 files changed, 1538 insertions, 1443 deletions
diff --git a/usr.bin/tip/libacu/biz22.c b/usr.bin/tip/libacu/biz22.c index 63fb11c..cd5ca4a 100644 --- a/usr.bin/tip/libacu/biz22.c +++ b/usr.bin/tip/libacu/biz22.c @@ -1,3 +1,6 @@ +/* $OpenBSD: biz22.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: biz22.c,v 1.6 1997/02/11 09:24:11 mrg Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,10 +35,12 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)biz22.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: biz22.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" #define DISCONNECT_CMD "\20\04" /* disconnection string */ @@ -44,6 +49,9 @@ static void sigALRM(); static int timeout = 0; static jmp_buf timeoutbuf; +static int cmd(), detect(); +void biz22_disconnect(); + /* * Dial up on a BIZCOMP Model 1022 with either * tone dialing (mod = "V") @@ -53,9 +61,8 @@ static int biz_dialer(num, mod) char *num, *mod; { - register int connected = 0; + int connected = 0; char cbuf[40]; - static int cmd(), detect(); if (boolean(value(VERBOSE))) printf("\nstarting call..."); @@ -67,15 +74,13 @@ biz_dialer(num, mod) printf("can't initialize bizcomp..."); return (0); } - strcpy(cbuf, "\02.\r"); + (void)strcpy(cbuf, "\02.\r"); cbuf[1] = *mod; if (cmd(cbuf)) { printf("can't set dialing mode..."); return (0); } - strcpy(cbuf, "\02D"); - strcat(cbuf, num); - strcat(cbuf, "\r"); + (void)snprintf(cbuf, sizeof(cbuf), "\02D%s\r", num); write(FD, cbuf, strlen(cbuf)); if (!detect("7\r")) { printf("can't get dial tone..."); @@ -89,11 +94,11 @@ biz_dialer(num, mod) * 1 \r success */ connected = detect("1\r"); -#if ACULOG +#ifdef ACULOG if (timeout) { char line[80]; - sprintf(line, "%d second dial timeout", + (void)sprintf(line, "%ld second dial timeout", number(value(DIALTIMEOUT))); logent(value(HOST), num, "biz1022", line); } @@ -103,6 +108,7 @@ biz_dialer(num, mod) return (connected); } +int biz22w_dialer(num, acu) char *num, *acu; { @@ -110,6 +116,7 @@ biz22w_dialer(num, acu) return (biz_dialer(num, "W")); } +int biz22f_dialer(num, acu) char *num, *acu; { @@ -117,15 +124,15 @@ biz22f_dialer(num, acu) return (biz_dialer(num, "V")); } +void biz22_disconnect() { - int rw = 2; - write(FD, DISCONNECT_CMD, 4); sleep(2); - ioctl(FD, TIOCFLUSH, &rw); + tcflush(FD, TCIOFLUSH); } +void biz22_abort() { @@ -142,7 +149,7 @@ sigALRM() static int cmd(s) - register char *s; + char *s; { sig_t f; char c; @@ -164,7 +171,7 @@ cmd(s) static int detect(s) - register char *s; + char *s; { sig_t f; char c; diff --git a/usr.bin/tip/libacu/biz31.c b/usr.bin/tip/libacu/biz31.c index 9553a6d..5522d65 100644 --- a/usr.bin/tip/libacu/biz31.c +++ b/usr.bin/tip/libacu/biz31.c @@ -1,3 +1,6 @@ +/* $OpenBSD: biz31.c,v 1.6 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: biz31.c,v 1.5 1997/02/11 09:24:14 mrg Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,10 +35,12 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)biz31.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: biz31.c,v 1.6 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" #define MAXRETRY 3 /* sync up retry count */ @@ -54,7 +59,7 @@ static int biz_dialer(num, mod) char *num, *mod; { - register int connected = 0; + int connected = 0; if (!bizsync(FD)) { logent(value(HOST), "", "biz", "out of sync"); @@ -82,11 +87,11 @@ biz_dialer(num, mod) * ` CONNECTION\r\n^G' success */ connected = detect(" "); -#if ACULOG +#ifdef ACULOG if (timeout) { char line[80]; - sprintf(line, "%d second dial timeout", + (void)sprintf(line, "%ld second dial timeout", number(value(DIALTIMEOUT))); logent(value(HOST), num, "biz", line); } @@ -119,7 +124,7 @@ biz31_disconnect() write(FD, DISCONNECT_CMD, 4); sleep(2); - ioctl(FD, TIOCFLUSH); + tcflush(FD, TCIOFLUSH); } biz31_abort() @@ -130,7 +135,7 @@ biz31_abort() static int echo(s) - register char *s; + char *s; { char c; @@ -162,7 +167,7 @@ sigALRM() static int detect(s) - register char *s; + char *s; { sig_t f; char c; @@ -187,7 +192,7 @@ detect(s) static int flush(s) - register char *s; + char *s; { sig_t f; char c; @@ -222,12 +227,12 @@ bizsync(fd) # define chars(b) (b) # define IOCTL FIONREAD #endif - register int already = 0; + int already = 0; char buf[10]; retry: if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0) - ioctl(fd, TIOCFLUSH); + tcflush(FD, TCIOFLUSH); write(fd, "\rp>\r", 4); sleep(1); if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) { diff --git a/usr.bin/tip/libacu/courier.c b/usr.bin/tip/libacu/courier.c index f4aeab3..728ccc9 100644 --- a/usr.bin/tip/libacu/courier.c +++ b/usr.bin/tip/libacu/courier.c @@ -1,3 +1,6 @@ +/* $OpenBSD: courier.c,v 1.9 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: courier.c,v 1.7 1997/02/11 09:24:16 mrg Exp $ */ + /* * Copyright (c) 1986, 1993 * The Regents of the University of California. All rights reserved. @@ -32,16 +35,18 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)courier.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: courier.c,v 1.9 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ /* * Routines for calling up on a Courier modem. * Derived from Hayes driver. */ -#include "tipconf.h" #include "tip.h" -#include "acucommon.h" +#include <sys/ioctl.h> #include <stdio.h> #define MAXRETRY 5 @@ -50,30 +55,35 @@ static void sigALRM(); static int timeout = 0; static int connected = 0; static jmp_buf timeoutbuf, intbuf; -static int coursync(); +static int coursync(), cour_connect(), cour_swallow(); +void cour_nap(); + +void cour_disconnect __P((void)); +int cour_dialer(num, acu) - register char *num; + char *num; char *acu; { - register char *cp; -#if ACULOG + char *cp; +#ifdef ACULOG char line[80]; #endif - static int cour_connect(), cour_swallow(); + struct termios cntrl; if (boolean(value(VERBOSE))) printf("Using \"%s\"\n", acu); - acu_hupcl (); - + tcgetattr(FD, &cntrl); + cntrl.c_cflag |= HUPCL; + tcsetattr(FD, TCSAFLUSH, &cntrl); /* * Get in synch. */ if (!coursync()) { badsynch: printf("can't synchronize with courier\n"); -#if ACULOG +#ifdef ACULOG logent(value(HOST), num, "courier", "can't synch up"); #endif return (0); @@ -84,7 +94,7 @@ badsynch: if (boolean(value(VERBOSE))) cour_verbose_read(); #endif - ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */ + tcflush(FD, TCIOFLUSH); cour_write(FD, "AT C1 E0 H0 Q0 X6 V1\r", 21); if (!cour_swallow("\r\nOK\r\n")) goto badsynch; @@ -96,9 +106,9 @@ badsynch: cour_write(FD, num, strlen(num)); cour_write(FD, "\r", 1); connected = cour_connect(); -#if ACULOG +#ifdef ACULOG if (timeout) { - sprintf(line, "%d second dial timeout", + (void)sprintf(line, "%ld second dial timeout", number(value(DIALTIMEOUT))); logent(value(HOST), num, "cour", line); } @@ -108,6 +118,7 @@ badsynch: return (connected); } +void cour_disconnect() { /* first hang up the modem*/ @@ -118,6 +129,7 @@ cour_disconnect() close(FD); } +void cour_abort() { cour_write(FD, "\r", 1); /* send anything to abort the call */ @@ -134,8 +146,8 @@ sigALRM() static int cour_swallow(match) - register char *match; - { + char *match; +{ sig_t f; char c; @@ -222,8 +234,12 @@ again: for (bm = baud_msg ; bm->msg ; bm++) if (strcmp(bm->msg, dialer_buf+sizeof("CONNECT")-1) == 0) { - if (!acu_setspeed(bm->baud)) - goto error; + struct termios cntrl; + + tcgetattr(FD, &cntrl); + cfsetospeed(&cntrl, bm->baud); + cfsetispeed(&cntrl, bm->baud); + tcsetattr(FD, TCSAFLUSH, &cntrl); signal(SIGALRM, f); #ifdef DEBUG if (boolean(value(VERBOSE))) @@ -239,9 +255,7 @@ again: putchar(c); #endif } -error1: printf("%s\r\n", dialer_buf); -error: signal(SIGALRM, f); return (0); } @@ -258,7 +272,7 @@ coursync() char buf[40]; while (already++ < MAXRETRY) { - ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */ + tcflush(FD, TCIOFLUSH); cour_write(FD, "\rAT Z\r", 6); /* reset modem */ bzero(buf, sizeof(buf)); sleep(1); @@ -269,8 +283,8 @@ coursync() buf[len] = '\0'; printf("coursync: (\"%s\")\n\r", buf); #endif - if (index(buf, '0') || - (index(buf, 'O') && index(buf, 'K'))) + if (strchr(buf, '0') || + (strchr(buf, 'O') && strchr(buf, 'K'))) return(1); } /* @@ -292,6 +306,7 @@ coursync() return (0); } +static void cour_write(fd, cp, n) int fd; char *cp; @@ -301,11 +316,11 @@ int n; if (boolean(value(VERBOSE))) write(1, cp, n); #endif - acu_flush (); + tcdrain(fd); cour_nap(); for ( ; n-- ; cp++) { write(fd, cp, 1); - acu_flush (); + tcdrain(fd); cour_nap(); } } @@ -326,9 +341,14 @@ cour_verbose_read() } #endif +/* Give the courier 50 milliseconds between characters */ +void cour_nap() { - acu_nap (50); -} + struct timespec ts; -/* end of courier.c */ + ts.tv_sec = 0; + ts.tv_nsec = 50 * 1000000; + + nanosleep(&ts, NULL); +} diff --git a/usr.bin/tip/libacu/df.c b/usr.bin/tip/libacu/df.c index fc60ad3..2fa0a0b 100644 --- a/usr.bin/tip/libacu/df.c +++ b/usr.bin/tip/libacu/df.c @@ -1,3 +1,6 @@ +/* $OpenBSD: df.c,v 1.5 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: df.c,v 1.4 1995/10/29 00:49:51 pk Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,19 +35,22 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)df.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: df.c,v 1.5 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ /* * Dial the DF02-AC or DF03-AC */ -#include "tipconf.h" #include "tip.h" static jmp_buf Sjbuf; static void timeout(); +int df02_dialer(num, acu) char *num, *acu; { @@ -52,6 +58,7 @@ df02_dialer(num, acu) return (df_dialer(num, acu, 0)); } +int df03_dialer(num, acu) char *num, *acu; { @@ -59,16 +66,19 @@ df03_dialer(num, acu) return (df_dialer(num, acu, 1)); } +int df_dialer(num, acu, df03) char *num, *acu; int df03; { - register int f = FD; - int speed = 0, rw = 2; + int f = FD; + struct termios cntrl; + int speed = 0; char c = '\0'; - acu_hupcl (); - + tcgetattr(f, &cntrl); + cntrl.c_cflag |= HUPCL; + tcsetattr(f, TCSANOW, &cntrl); if (setjmp(Sjbuf)) { printf("connection timed out\r\n"); df_disconnect(); @@ -81,8 +91,12 @@ df_dialer(num, acu, df03) if (df03) { int st = TIOCM_ST; /* secondary Transmit flag */ - if ((speed = acu_getspeed ()) != B1200) { /* must dial at 1200 baud */ - acu_setspeed (B1200); + tcgetattr(f, &cntrl); + speed = cfgetospeed(&cntrl); + if (speed != B1200) { /* must dial at 1200 baud */ + cfsetospeed(&cntrl, B1200); + cfsetispeed(&cntrl, B1200); + tcsetattr(f, TCSAFLUSH, &cntrl); ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */ } else ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */ @@ -90,30 +104,32 @@ df_dialer(num, acu, df03) #endif signal(SIGALRM, timeout); alarm(5 * strlen(num) + 10); - ioctl(f, TIOCFLUSH, &rw); + tcflush(f, TCIOFLUSH); write(f, "\001", 1); sleep(1); write(f, "\002", 1); write(f, num, strlen(num)); read(f, &c, 1); #ifdef TIOCMSET - if (df03 && speed) { - acu_setspeed (speed); + if (df03 && speed != B1200) { + cfsetospeed(&cntrl, speed); + cfsetispeed(&cntrl, speed); + tcsetattr(f, TCSAFLUSH, &cntrl); } #endif return (c == 'A'); } +void df_disconnect() { - int rw = 2; - write(FD, "\001", 1); sleep(1); - ioctl(FD, TIOCFLUSH, &rw); + tcflush(FD, TCIOFLUSH); } +void df_abort() { diff --git a/usr.bin/tip/libacu/dn11.c b/usr.bin/tip/libacu/dn11.c index 52749da..3f34615 100644 --- a/usr.bin/tip/libacu/dn11.c +++ b/usr.bin/tip/libacu/dn11.c @@ -1,3 +1,6 @@ +/* $OpenBSD: dn11.c,v 1.5 2001/11/19 19:02:16 mpech Exp $ */ +/* $NetBSD: dn11.c,v 1.4 1995/10/29 00:49:53 pk Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,27 +35,29 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)dn11.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: dn11.c,v 1.5 2001/11/19 19:02:16 mpech Exp $"; #endif /* not lint */ /* * Routines for dialing up on DN-11 */ -#include "tipconf.h" #include "tip.h" -int dn_abort(); +void dn_abort(); void alarmtr(); static jmp_buf jmpbuf; static int child = -1, dn; +int dn_dialer(num, acu) char *num, *acu; { - extern errno; - char *p, *q, phone[40]; - int lt, nw, connected = 1; - register int timelim; + int lt, nw; + int timelim; + struct termios cntrl; if (boolean(value(VERBOSE))) printf("\nstarting call..."); @@ -96,18 +101,9 @@ dn_dialer(num, acu) return (0); } alarm(0); - -#if HAVE_TERMIOS - { - struct termios term; - tcgetattr (dn, &term); - term.c_cflag |= HUPCL; - tcsetattr (dn, TCSANOW, &term); - } -#elif defined(TIOCHPCL) - ioctl(dn, TIOCHPCL, 0); -#endif - + tcgetattr(dn, &cntrl); + cntrl.c_cflag |= HUPCL; + tcsetattr(dn, TCSANOW, &cntrl); signal(SIGALRM, SIG_DFL); while ((nw = wait(<)) != child && nw != -1) ; @@ -131,6 +127,7 @@ alarmtr() * Insurance, for some reason we don't seem to be * hanging up... */ +void dn_disconnect() { @@ -140,6 +137,7 @@ dn_disconnect() close(FD); } +void dn_abort() { diff --git a/usr.bin/tip/libacu/hayes.c b/usr.bin/tip/libacu/hayes.c index 6cc6c06..19ee8f8 100644 --- a/usr.bin/tip/libacu/hayes.c +++ b/usr.bin/tip/libacu/hayes.c @@ -1,3 +1,6 @@ +/* $OpenBSD: hayes.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: hayes.c,v 1.6 1997/02/11 09:24:17 mrg Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,7 +35,10 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)hayes.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: hayes.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ /* @@ -58,9 +64,11 @@ static char sccsid[] = "@(#)hayes.c 8.1 (Berkeley) 6/6/93"; * mode only. This would make it consistent with normal * interactive use thru the command 'tip dialer'. */ -#include "tipconf.h" #include "tip.h" +#include <termios.h> +#include <sys/ioctl.h> + #define min(a,b) ((a < b) ? a : b) static void sigALRM(); @@ -76,14 +84,16 @@ static char dumbuf[DUMBUFLEN]; #define FAILED 4 static int state = IDLE; +int hay_dialer(num, acu) - register char *num; + char *num; char *acu; { - register char *cp; - register int connected = 0; + char *cp; + int connected = 0; char dummy; -#if ACULOG + struct termios cntrl; +#ifdef ACULOG char line[80]; #endif if (hay_sync() == 0) /* make sure we can talk to the modem */ @@ -91,12 +101,17 @@ hay_dialer(num, acu) if (boolean(value(VERBOSE))) printf("\ndialing..."); fflush(stdout); - acu_hupcl (); - acu_flush (); + tcgetattr(FD, &cntrl); + cntrl.c_cflag |= HUPCL; + tcsetattr(FD, TCSANOW, &cntrl); + tcflush(FD, TCIOFLUSH); write(FD, "ATv0\r", 5); /* tell modem to use short status codes */ gobble("\r"); gobble("\r"); write(FD, "ATTD", 4); /* send dial command */ + for (cp = num; *cp; cp++) + if (*cp == '=') + *cp = ','; write(FD, num, strlen(num)); state = DIALING; write(FD, "\r", 1); @@ -113,10 +128,10 @@ hay_dialer(num, acu) state = FAILED; return (connected); /* lets get out of here.. */ } - ioctl(FD, TIOCFLUSH, 0); -#if ACULOG + tcflush(FD, TCIOFLUSH); +#ifdef ACULOG if (timeout) { - sprintf(line, "%d second dial timeout", + (void)sprintf(line, "%ld second dial timeout", number(value(DIALTIMEOUT))); logent(value(HOST), num, "hayes", line); } @@ -127,11 +142,9 @@ hay_dialer(num, acu) } +void hay_disconnect() { - char c; - int len, rlen; - /* first hang up the modem*/ #ifdef DEBUG printf("\rdisconnecting modem....\n\r"); @@ -142,11 +155,10 @@ hay_disconnect() goodbye(); } +void hay_abort() { - char c; - write(FD, "\r", 1); /* send anything to abort the call */ hay_disconnect(); } @@ -162,7 +174,7 @@ sigALRM() static char gobble(match) - register char *match; + char *match; { char c; sig_t f; @@ -196,8 +208,9 @@ gobble(match) return (status); } +static void error_rep(c) - register char c; + char c; { printf("\n\r"); switch (c) { @@ -236,16 +249,17 @@ error_rep(c) /* * set modem back to normal verbose status codes. */ +void goodbye() { - int len, rlen; + int len; char c; - ioctl(FD, TIOCFLUSH, &len); /* get rid of trash */ + tcflush(FD, TCIOFLUSH); if (hay_sync()) { sleep(1); #ifndef DEBUG - ioctl(FD, TIOCFLUSH, 0); + tcflush(FD, TCIOFLUSH); #endif write(FD, "ATH0\r", 5); /* insurance */ #ifndef DEBUG @@ -273,13 +287,14 @@ goodbye() printf("read (%d): %s\r\n", rlen, dumbuf); #endif } - ioctl(FD, TIOCFLUSH, 0); /* clear the input buffer */ + tcflush(FD, TCIOFLUSH); ioctl(FD, TIOCCDTR, 0); /* clear DTR (insurance) */ close(FD); } #define MAXRETRY 5 +int hay_sync() { int len, retry = 0; @@ -290,8 +305,8 @@ hay_sync() ioctl(FD, FIONREAD, &len); if (len) { len = read(FD, dumbuf, min(len, DUMBUFLEN)); - if (index(dumbuf, '0') || - (index(dumbuf, 'O') && index(dumbuf, 'K'))) + if (strchr(dumbuf, '0') || + (strchr(dumbuf, 'O') && strchr(dumbuf, 'K'))) return(1); #ifdef DEBUG dumbuf[len] = '\0'; diff --git a/usr.bin/tip/libacu/t3000.c b/usr.bin/tip/libacu/t3000.c index 1f1a1f0..1f05091 100644 --- a/usr.bin/tip/libacu/t3000.c +++ b/usr.bin/tip/libacu/t3000.c @@ -1,3 +1,6 @@ +/* $OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: t3000.c,v 1.5 1997/02/11 09:24:18 mrg Exp $ */ + /* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -32,16 +35,19 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)t3000.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ /* * Routines for calling up on a Telebit T3000 modem. * Derived from Courier driver. */ -#include "tipconf.h" #include "tip.h" -#include "acucommon.h" + +#include <sys/ioctl.h> #include <stdio.h> #define MAXRETRY 5 @@ -50,29 +56,33 @@ static void sigALRM(); static int timeout = 0; static int connected = 0; static jmp_buf timeoutbuf, intbuf; -static int t3000_sync(); +static int t3000_sync(), t3000_connect(), t3000_swallow(); +static void t3000_nap(); +int t3000_dialer(num, acu) - register char *num; + char *num; char *acu; { - register char *cp; -#if ACULOG + char *cp; + struct termios cntrl; +#ifdef ACULOG char line[80]; #endif - static int t3000_connect(), t3000_swallow(); if (boolean(value(VERBOSE))) printf("Using \"%s\"\n", acu); - acu_hupcl (); + tcgetattr(FD, &cntrl); + cntrl.c_cflag |= HUPCL; + tcsetattr(FD, TCSANOW, &cntrl); /* * Get in synch. */ if (!t3000_sync()) { badsynch: printf("can't synchronize with t3000\n"); -#if ACULOG +#ifdef ACULOG logent(value(HOST), num, "t3000", "can't synch up"); #endif return (0); @@ -83,7 +93,7 @@ badsynch: if (boolean(value(VERBOSE))) t3000_verbose_read(); #endif - ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */ + tcflush(FD, TCIOFLUSH); t3000_write(FD, "AT E0 H0 Q0 X4 V1\r", 18); if (!t3000_swallow("\r\nOK\r\n")) goto badsynch; @@ -95,9 +105,9 @@ badsynch: t3000_write(FD, num, strlen(num)); t3000_write(FD, "\r", 1); connected = t3000_connect(); -#if ACULOG +#ifdef ACULOG if (timeout) { - sprintf(line, "%d second dial timeout", + (void)sprintf(line, "%ld second dial timeout", number(value(DIALTIMEOUT))); logent(value(HOST), num, "t3000", line); } @@ -107,6 +117,7 @@ badsynch: return (connected); } +void t3000_disconnect() { /* first hang up the modem*/ @@ -117,6 +128,7 @@ t3000_disconnect() close(FD); } +void t3000_abort() { t3000_write(FD, "\r", 1); /* send anything to abort the call */ @@ -133,8 +145,8 @@ sigALRM() static int t3000_swallow(match) - register char *match; - { + char *match; +{ sig_t f; char c; @@ -235,8 +247,12 @@ again: for (bm = tbaud_msg ; bm->msg ; bm++) if (strcmp(bm->msg, dialer_buf+sizeof("CONNECT")-1) == 0) { - if (!(acu_setspeed (bm->baud) || (bm->baud2 && acu_setspeed (bm->baud2)))) - goto error; + struct termios cntrl; + + tcgetattr(FD, &cntrl); + cfsetospeed(&cntrl, bm->baud); + cfsetispeed(&cntrl, bm->baud); + tcsetattr(FD, TCSAFLUSH, &cntrl); signal(SIGALRM, f); #ifdef DEBUG if (boolean(value(VERBOSE))) @@ -252,9 +268,7 @@ again: putchar(c); #endif } -error1: printf("%s\r\n", dialer_buf); -error: signal(SIGALRM, f); return (0); } @@ -271,7 +285,7 @@ t3000_sync() char buf[40]; while (already++ < MAXRETRY) { - ioctl(FD, TIOCFLUSH, 0); /* flush any clutter */ + tcflush(FD, TCIOFLUSH); t3000_write(FD, "\rAT Z\r", 6); /* reset modem */ bzero(buf, sizeof(buf)); sleep(2); @@ -285,8 +299,8 @@ if (len == 0) len = 1; buf[len] = '\0'; printf("t3000_sync: (\"%s\")\n\r", buf); #endif - if (index(buf, '0') || - (index(buf, 'O') && index(buf, 'K'))) + if (strchr(buf, '0') || + (strchr(buf, 'O') && strchr(buf, 'K'))) return(1); } /* @@ -308,6 +322,7 @@ if (len == 0) len = 1; return (0); } +static int t3000_write(fd, cp, n) int fd; char *cp; @@ -317,11 +332,11 @@ int n; if (boolean(value(VERBOSE))) write(1, cp, n); #endif - acu_flush (); + tcdrain(fd); t3000_nap(); for ( ; n-- ; cp++) { write(fd, cp, 1); - acu_flush (); + tcdrain(fd); t3000_nap(); } } @@ -342,9 +357,14 @@ t3000_verbose_read() } #endif +/* Give the t3000 50 milliseconds between characters */ +void t3000_nap() { - acu_nap (50); -} + struct timespec ts; -/* end of t3000.c */ + ts.tv_sec = 0; + ts.tv_nsec = 50 * 1000000; + + nanosleep(&ts, NULL); +} diff --git a/usr.bin/tip/libacu/v3451.c b/usr.bin/tip/libacu/v3451.c index a98c4d4..1440c55 100644 --- a/usr.bin/tip/libacu/v3451.c +++ b/usr.bin/tip/libacu/v3451.c @@ -1,3 +1,6 @@ +/* $OpenBSD: v3451.c,v 1.6 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: v3451.c,v 1.6 1997/02/11 09:24:20 mrg Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,30 +35,32 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)v3451.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: v3451.c,v 1.6 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ /* * Routines for calling up on a Vadic 3451 Modem */ -#include "tipconf.h" #include "tip.h" static jmp_buf Sjbuf; +static int expect(), notin(), prefix(); +static void vawrite(), alarmtr(); + +int v3451_dialer(num, acu) - register char *num; + char *num; char *acu; { sig_t func; int ok; - int slow = number(value(BAUDRATE)) < 1200, rw = 2; + int slow = number(value(BAUDRATE)) < 1200; char phone[50]; -#if ACULOG - char line[80]; -#endif - static int expect(); - static void vawrite(); + struct termios cntrl; /* * Get in synch @@ -66,27 +71,28 @@ v3451_dialer(num, acu) vawrite("\005\r", 2 + slow); if (!expect("READY")) { printf("can't synchronize with vadic 3451\n"); -#if ACULOG +#ifdef ACULOG logent(value(HOST), num, "vadic", "can't synch up"); #endif return (0); } - acu_hupcl (); + tcgetattr(FD, &cntrl); + term.c_cflag |= HUPCL; + tcsetattr(FD, TCSANOW, &cntrl); sleep(1); vawrite("D\r", 2 + slow); if (!expect("NUMBER?")) { printf("Vadic will not accept dial command\n"); -#if ACULOG +#ifdef ACULOG logent(value(HOST), num, "vadic", "will not accept dial"); #endif return (0); } - strcpy(phone, num); - strcat(phone, "\r"); + (void)snprintf(phone, sizeof phone, "%s\r", num); vawrite(phone, 1 + slow); if (!expect(phone)) { printf("Vadic will not accept phone number\n"); -#if ACULOG +#ifdef ACULOG logent(value(HOST), num, "vadic", "will not accept number"); #endif return (0); @@ -101,7 +107,7 @@ v3451_dialer(num, acu) vawrite("\r", 1 + slow); if (!expect("DIALING:")) { printf("Vadic failed to dial\n"); -#if ACULOG +#ifdef ACULOG logent(value(HOST), num, "vadic", "failed to dial"); #endif return (0); @@ -112,21 +118,23 @@ v3451_dialer(num, acu) signal(SIGINT, func); if (!ok) { printf("call failed\n"); -#if ACULOG +#ifdef ACULOG logent(value(HOST), num, "vadic", "call failed"); #endif return (0); } - ioctl(FD, TIOCFLUSH, &rw); + tcflush(FD, TCIOFLUSH); return (1); } +void v3451_disconnect() { close(FD); } +void v3451_abort() { @@ -135,7 +143,7 @@ v3451_abort() static void vawrite(cp, delay) - register char *cp; + char *cp; int delay; { @@ -143,15 +151,13 @@ vawrite(cp, delay) write(FD, cp, 1); } -static +static int expect(cp) - register char *cp; + char *cp; { char buf[300]; - register char *rp = buf; + char *rp = buf; int timeout = 30, online = 0; - static int notin(); - static void alarmtr(); if (strcmp(cp, "\"\"") == 0) return (1); @@ -194,7 +200,6 @@ static int notin(sh, lg) char *sh, *lg; { - static int prefix(); for (; *lg; lg++) if (prefix(sh, lg)) @@ -202,11 +207,11 @@ notin(sh, lg) return (1); } -static +static int prefix(s1, s2) - register char *s1, *s2; + char *s1, *s2; { - register char c; + char c; while ((c = *s1++) == *s2++) if (c == '\0') diff --git a/usr.bin/tip/libacu/v831.c b/usr.bin/tip/libacu/v831.c index b670c2a..005e5d9 100644 --- a/usr.bin/tip/libacu/v831.c +++ b/usr.bin/tip/libacu/v831.c @@ -1,3 +1,6 @@ +/* $OpenBSD: v831.c,v 1.6 2001/11/19 19:02:16 mpech Exp $ */ +/* $NetBSD: v831.c,v 1.5 1996/12/29 10:42:01 cgd Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,28 +35,32 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)v831.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: v831.c,v 1.6 2001/11/19 19:02:16 mpech Exp $"; #endif /* not lint */ /* * Routines for dialing up on Vadic 831 */ -#include "tipconf.h" #include "tip.h" +#include <termios.h> -int v831_abort(); +void v831_abort(); static void alarmtr(); -extern int errno; +static int dialit(); +static char *sanitize(); static jmp_buf jmpbuf; static int child = -1; +int v831_dialer(num, acu) char *num, *acu; { - int status, pid, connected = 1; - register int timelim; - static int dialit(); + int status, pid; + int timelim; if (boolean(value(VERBOSE))) printf("\nstarting call..."); @@ -102,9 +109,6 @@ v831_dialer(num, acu) return (0); } alarm(0); -#ifdef notdef - ioctl(AC, TIOCHPCL, 0); -#endif signal(SIGALRM, SIG_DFL); while ((pid = wait(&status)) != child && pid != -1) ; @@ -126,20 +130,27 @@ alarmtr() * Insurance, for some reason we don't seem to be * hanging up... */ +void v831_disconnect() { + struct termios cntrl; + sleep(2); #ifdef DEBUG printf("[disconnect: FD=%d]\n", FD); #endif if (FD > 0) { ioctl(FD, TIOCCDTR, 0); - acu_setspeec (0); - ioctl(FD, TIOCNXCL, 0); + tcgetattr(FD, &cntrl); + cfsetospeed(&cntrl, 0); + cfsetispeed(&cntrl, 0); + tcsetattr(FD, TCSAFLUSH, &cntrl); + ioctl(FD, TIOCNXCL, NULL); } close(FD); } +void v831_abort() { @@ -150,7 +161,7 @@ v831_abort() if (child > 0) kill(child, SIGKILL); if (AC > 0) - ioctl(FD, TIOCNXCL, 0); + ioctl(FD, TIOCNXCL, NULL); close(AC); if (FD > 0) ioctl(FD, TIOCCDTR, 0); @@ -178,13 +189,13 @@ struct vaconfig { static int dialit(phonenum, acu) - register char *phonenum; + char *phonenum; char *acu; { - register struct vaconfig *vp; + struct vaconfig *vp; + struct termios cntrl; char c; - int i, two = 2; - static char *sanitize(); + int i; phonenum = sanitize(phonenum); #ifdef DEBUG @@ -199,28 +210,13 @@ dialit(phonenum, acu) printf("Unable to locate dialer (%s)\n", acu); return ('K'); } - { -#if HAVE_TERMIOS - struct termios termios; - tcgetattr (AC, &termios); - termios.c_iflag = 0; -#ifndef _POSIX_SOURCE - termios.c_lflag = (PENDIN|ECHOKE|ECHOE); -#else - termios.c_lflag = (PENDIN|ECHOE); -#endif - termios.c_cflag = (CLOCAL|HUPCL|CREAD|CS8); - termios.c_ispeed = termios.c_ospeed = B2400; - tcsetattr (AC, TCSANOW, &termios); -#else /* HAVE_TERMIOS */ - struct sgttyb cntrl; - ioctl(AC, TIOCGETP, &cntrl); - cntrl.sg_ispeed = cntrl.sg_ospeed = B2400; - cntrl.sg_flags = RAW | EVENP | ODDP; - ioctl(AC, TIOCSETP, &cntrl); - #endif - } - ioctl(AC, TIOCFLUSH, &two); + tcgetattr(AC, &cntrl); + cfsetospeed(&cntrl, B2400); + cfsetispeed(&cntrl, B2400); + cntrl.c_cflag |= PARODD | PARENB; + cntrl.c_lflag &= ~(ISIG | ICANON); + tcsetattr(AC, TCSANOW, &cntrl); + tcflush(AC, TCIOFLUSH); pc(STX); pc(vp->vc_rack); pc(vp->vc_modem); @@ -255,10 +251,10 @@ dialit(phonenum, acu) static char * sanitize(s) - register char *s; + char *s; { static char buf[128]; - register char *cp; + char *cp; for (cp = buf; *s; s++) { if (!isdigit(*s) && *s == '<' && *s != '_') diff --git a/usr.bin/tip/libacu/ventel.c b/usr.bin/tip/libacu/ventel.c index 73733e5..48035c1 100644 --- a/usr.bin/tip/libacu/ventel.c +++ b/usr.bin/tip/libacu/ventel.c @@ -1,3 +1,6 @@ +/* $OpenBSD: ventel.c,v 1.7 2001/11/19 19:02:16 mpech Exp $ */ +/* $NetBSD: ventel.c,v 1.6 1997/02/11 09:24:21 mrg Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,15 +35,19 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)ventel.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: ventel.c,v 1.7 2001/11/19 19:02:16 mpech Exp $"; #endif /* not lint */ /* * Routines for calling up on a Ventel Modem * The Ventel is expected to be strapped for local echo (just like uucp) */ -#include "tipconf.h" #include "tip.h" +#include <termios.h> +#include <sys/ioctl.h> #define MAXRETRY 5 @@ -48,6 +55,9 @@ static void sigALRM(); static int timeout = 0; static jmp_buf timeoutbuf; +static int gobble(), vensync(); +static void echo(); + /* * some sleep calls have been replaced by this macro * because some ventel modems require two <cr>s in less than @@ -55,25 +65,25 @@ static jmp_buf timeoutbuf; */ #define delay(num,denom) busyloop(CPUSPEED*num/denom) #define CPUSPEED 1000000 /* VAX 780 is 1MIPS */ -#define DELAY(n) { register long N = (n); while (--N > 0); } -busyloop(n) { DELAY(n); } +#define DELAY(n) do { long N = (n); while (--N > 0); } while (0) +#define busyloop(n) do { DELAY(n); } while (0) +int ven_dialer(num, acu) - register char *num; + char *num; char *acu; { - register char *cp; - register int connected = 0; - char *msg, *index(), line[80]; - static int gobble(), vensync(); - static void echo(); + char *cp; + int connected = 0; + char *msg, line[80]; + struct termios cntrl; /* * Get in synch with a couple of carriage returns */ if (!vensync(FD)) { printf("can't synchronize with ventel\n"); -#if ACULOG +#ifdef ACULOG logent(value(HOST), num, "ventel", "can't synch up"); #endif return (0); @@ -81,7 +91,9 @@ ven_dialer(num, acu) if (boolean(value(VERBOSE))) printf("\ndialing..."); fflush(stdout); - acu_hupcl (); + tcgetattr(FD, &cntrl); + cntrl.c_cflag |= HUPCL; + tcsetattr(FD, TCSANOW, &cntrl); echo("#k$\r$\n$D$I$A$L$:$ "); for (cp = num; *cp; cp++) { delay(1, 10); @@ -92,10 +104,10 @@ ven_dialer(num, acu) gobble('\n', line); if (gobble('\n', line)) connected = gobble('!', line); - acu_flush (); -#if ACULOG + tcflush(FD, TCIOFLUSH); +#ifdef ACULOG if (timeout) { - sprintf(line, "%d second dial timeout", + (void)sprintf(line, "%ld second dial timeout", number(value(DIALTIMEOUT))); logent(value(HOST), num, "ventel", line); } @@ -105,10 +117,10 @@ ven_dialer(num, acu) if (connected || timeout || !boolean(value(VERBOSE))) return (connected); /* call failed, parse response for user */ - cp = index(line, '\r'); + cp = strchr(line, '\r'); if (cp) *cp = '\0'; - for (cp = line; cp = index(cp, ' '); cp++) + for (cp = line; cp = strchr(cp, ' '); cp++) if (cp[1] == ' ') break; if (cp) { @@ -125,12 +137,14 @@ ven_dialer(num, acu) return (connected); } +void ven_disconnect() { close(FD); } +void ven_abort() { @@ -140,7 +154,7 @@ ven_abort() static void echo(s) - register char *s; + char *s; { char c; @@ -172,10 +186,10 @@ sigALRM() static int gobble(match, response) - register char match; + char match; char response[]; { - register char *cp = response; + char *cp = response; sig_t f; char c; diff --git a/usr.bin/tip/tip/Makefile b/usr.bin/tip/tip/Makefile index 39b89b0..8d269d6 100644 --- a/usr.bin/tip/tip/Makefile +++ b/usr.bin/tip/tip/Makefile @@ -1,4 +1,4 @@ -# @(#)Makefile 8.1 (Berkeley) 6/6/93 +# $OpenBSD: Makefile,v 1.9 2001/09/23 06:15:30 pvalchev Exp $ # # Files are: # /etc/remote remote host description file @@ -6,19 +6,44 @@ # mode 6?? # /var/log/aculog ACU accounting file, owned by ${OWNER} and # mode 6?? {if ACULOG defined} +# Presently supports: +# BIZCOMP +# DEC DF02-AC, DF03-AC +# DEC DN-11/Able Quadracall +# HAYES and Hayes emulators +# USR COURIER (2400 baud) +# VENTEL 212+ +# VADIC 831 RS232 adaptor +# VADIC 3451 +# TELEBIT T3000 +# +# Configuration defines: +# DF02, DF03, DN11 ACU's supported +# BIZ1031, BIZ1022, VENTEL, V831, V3451, HAYES, COURIER, T3000 +# ACULOG turn on tip logging of ACU use +# PRISTINE no phone #'s put in ACU log file +# CONNECT worthless command +# DEFBR default baud rate to make connection at +# DEFFS default frame size for FTP buffering of +# writes on local side +# BUFSIZ buffer sizing from stdio, must be fed +# explicitly to remcap.c if not 1024 +# CONNECT enable ~C command (connect pgm to remote) + +PROG= tip +LINKS= ${BINDIR}/tip ${BINDIR}/cu +MLINKS= tip.1 cu.1 +CFLAGS+=-I${.CURDIR} -ansi -pedantic \ + -DDEFBR=9600 -DDEFFS=BUFSIZ -DACULOG -DPRISTINE -DCONNECT \ + -DV831 -DVENTEL -DHAYES -DCOURIER -DT3000 +.PATH: ${.CURDIR}/aculib +SRCS= acu.c acutab.c cmds.c cmdtab.c cu.c hunt.c log.c partab.c \ + remote.c tip.c tipout.c uucplock.c value.c vars.c \ + biz22.c courier.c df.c dn11.c hayes.c t3000.c v3451.c v831.c ventel.c + +# -- acutab is configuration dependent, and so depends on the Makefile +# -- remote.o depends on the Makefile because of DEFBR and DEFFS +# -- log.o depends on the Makefile because of ACULOG +acutab.o log.o remote.o: Makefile -CFLAGS+=-g -LIBACU=../libacu/libacu.a -BINDIR=/usr/bin -BINOWN=uucp -BINGRP=dialer -BINMODE=4510 -LDADD+=$(LIBACU) -LINKS=${BINDIR}/tip -MAN1=tip.1 -MAN5=modems.5 -SRCS=acu.c acutab.c cmds.c cmdtab.c cu.c hunt.c log.c partab.c \ - remote.c tip.c tipout.c uucplock.c value.c vars.c -PROG=tip -$(OBJS): tipconf.h .include <bsd.prog.mk> diff --git a/usr.bin/tip/tip/acu.c b/usr.bin/tip/tip/acu.c index 54ae4cd..91549e9 100644 --- a/usr.bin/tip/tip/acu.c +++ b/usr.bin/tip/tip/acu.c @@ -1,3 +1,6 @@ +/* $OpenBSD: acu.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: acu.c,v 1.4 1996/12/29 10:34:03 cgd Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,16 +35,14 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)acu.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: acu.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" -#if UNIDIALER -acu_t* unidialer_getmodem (const char *modem_name); -#endif - static acu_t *acu = NOACU; static int conflag; static void acuabort(); @@ -66,14 +67,14 @@ static jmp_buf jmpbuf; char * connect() { - register char *cp = PN; + char *cp = PN; char *phnum, string[256]; FILE *fd; - int tried = 0; + volatile int tried = 0; if (!DU) { /* regular connect message */ if (CM != NOSTR) - pwrite(FD, CM, size(CM)); + parwrite(FD, CM, size(CM)); logent(value(HOST), "", DV, "call completed"); return (NOSTR); } @@ -89,7 +90,7 @@ connect() printf("\ncall aborted\n"); logent(value(HOST), "", "", "call aborted"); if (acu != NOACU) { - boolean(value(VERBOSE)) = FALSE; + setboolean(value(VERBOSE), FALSE); if (conflag) disconnect(NOSTR); else @@ -101,20 +102,19 @@ connect() return ("unknown ACU type"); if (*cp != '@') { while (*cp) { - for (phnum = cp; *cp && *cp != ','; cp++) - ; - if (*cp) + phnum = cp; + cp = strpbrk(cp, ","); + if (*cp != '\0') *cp++ = '\0'; - - if (conflag = (*acu->acu_dialer)(phnum, CU)) { - if (CM != NOSTR) - pwrite(FD, CM, size(CM)); - logent(value(HOST), phnum, acu->acu_name, - "call completed"); - return (NOSTR); - } else - logent(value(HOST), phnum, acu->acu_name, - "call failed"); + + if (strlen(phnum) == 0) + continue; + + conflag = (*acu->acu_dialer)(phnum, CU); + if (conflag) + break; + + logent(value(HOST), phnum, acu->acu_name, "call failed"); tried++; } } else { @@ -123,47 +123,44 @@ connect() return ("can't open phone number file"); } while (fgets(string, sizeof(string), fd) != NOSTR) { - for (cp = string; !any(*cp, " \t\n"); cp++) - ; - if (*cp == '\n') { - fclose(fd); - return ("unrecognizable host name"); - } - *cp++ = '\0'; - if (strcmp(string, value(HOST))) - continue; - while (any(*cp, " \t")) - cp++; - if (*cp == '\n') { - fclose(fd); - return ("missing phone number"); - } - for (phnum = cp; *cp && *cp != ',' && *cp != '\n'; cp++) - ; - if (*cp) + cp = &string[strcspn(string, " \t\n")]; + if (*cp != '\0') *cp++ = '\0'; + + if (strcmp(string, value(HOST)) != 0) + continue; + + cp += strspn(cp, " \t\n"); + phnum = cp; + *(cp + strcspn(cp, ",\n")) = '\0'; + + if (strlen(phnum) == 0) + continue; + + conflag = (*acu->acu_dialer)(phnum, CU); + if (conflag) + break; - if (conflag = (*acu->acu_dialer)(phnum, CU)) { - fclose(fd); - if (CM != NOSTR) - pwrite(FD, CM, size(CM)); - logent(value(HOST), phnum, acu->acu_name, - "call completed"); - return (NOSTR); - } else - logent(value(HOST), phnum, acu->acu_name, - "call failed"); + logent(value(HOST), phnum, acu->acu_name, "call failed"); tried++; } fclose(fd); } - if (!tried) + if (conflag) { + if (CM != NOSTR) + parwrite(FD, CM, size(CM)); + logent(value(HOST), phnum, acu->acu_name, "call completed"); + return (NOSTR); + } else if (!tried) { logent(value(HOST), "", acu->acu_name, "missing phone number"); - else + return ("missing phone number"); + } else { (*acu->acu_abort)(); - return (tried ? "call failed" : "missing phone number"); + return ("call failed"); + } } +void disconnect(reason) char *reason; { @@ -189,18 +186,13 @@ acuabort(s) static acu_t * acutype(s) - register char *s; + char *s; { - register acu_t *p; + acu_t *p; extern acu_t acutable[]; for (p = acutable; p->acu_name != '\0'; p++) if (!strcmp(s, p->acu_name)) return (p); - - #if UNIDIALER - return unidialer_getmodem (s); - #else return (NOACU); - #endif } diff --git a/usr.bin/tip/tip/acutab.c b/usr.bin/tip/tip/acutab.c index 3254e8a..193b8cc 100644 --- a/usr.bin/tip/tip/acutab.c +++ b/usr.bin/tip/tip/acutab.c @@ -1,3 +1,6 @@ +/* $OpenBSD: acutab.c,v 1.2 1996/06/26 05:40:41 deraadt Exp $ */ +/* $NetBSD: acutab.c,v 1.3 1994/12/08 09:30:41 jtc Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,37 +35,26 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)acutab.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: acutab.c,v 1.2 1996/06/26 05:40:41 deraadt Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" -extern int df02_dialer(), df03_dialer(), - biz31f_dialer(), +extern int df02_dialer(), df03_dialer(), df_disconnect(), df_abort(), + biz31f_dialer(), biz31_disconnect(), biz31_abort(), biz31w_dialer(), - biz22f_dialer(), + biz22f_dialer(), biz22_disconnect(), biz22_abort(), biz22w_dialer(), - ven_dialer(), - hay_dialer(), - cour_dialer(), - multitech_dialer(), - t3000_dialer(), - v3451_dialer(), - v831_dialer(), - dn_dialer(); - -extern void df_disconnect(), df_abort(), - biz31_disconnect(), biz31_abort(), - biz22_disconnect(), biz22_abort(), - ven_disconnect(), ven_abort(), - hay_disconnect(), hay_abort(), - cour_disconnect(), cour_abort(), - multitech_disconnect(), multitech_abort(), - t3000_disconnect(), t3000_abort(), - v3451_disconnect(), v3451_abort(), - v831_disconnect(), v831_abort(), - dn_disconnect(), dn_abort(); + ven_dialer(), ven_disconnect(), ven_abort(), + hay_dialer(), hay_disconnect(), hay_abort(), + cour_dialer(), cour_disconnect(), cour_abort(), + t3000_dialer(), t3000_disconnect(), t3000_abort(), + v3451_dialer(), v3451_disconnect(), v3451_abort(), + v831_dialer(), v831_disconnect(), v831_abort(), + dn_dialer(), dn_disconnect(), dn_abort(); acu_t acutable[] = { #if BIZ1031 @@ -82,29 +74,26 @@ acu_t acutable[] = { #if DN11 "dn11", dn_dialer, dn_disconnect, dn_abort, #endif -#if VENTEL +#ifdef VENTEL "ventel",ven_dialer, ven_disconnect, ven_abort, #endif -#if HAYES +#ifdef HAYES "hayes",hay_dialer, hay_disconnect, hay_abort, #endif -#if COURIER +#ifdef COURIER "courier",cour_dialer, cour_disconnect, cour_abort, #endif -#if MULTITECH - "multitech",multitech_dialer, multitech_disconnect, multitech_abort, -#endif -#if T3000 +#ifdef T3000 "t3000",t3000_dialer, t3000_disconnect, t3000_abort, #endif -#if V3451 -#if !V831 +#ifdef V3451 +#ifndef V831 "vadic",v3451_dialer, v3451_disconnect, v3451_abort, #endif "v3451",v3451_dialer, v3451_disconnect, v3451_abort, #endif -#if V831 -#if !V3451 +#ifdef V831 +#ifndef V3451 "vadic",v831_dialer, v831_disconnect, v831_abort, #endif "v831",v831_dialer, v831_disconnect, v831_abort, diff --git a/usr.bin/tip/tip/cmds.c b/usr.bin/tip/tip/cmds.c index 3e764a1..07d7f51 100644 --- a/usr.bin/tip/tip/cmds.c +++ b/usr.bin/tip/tip/cmds.c @@ -1,3 +1,6 @@ +/* $OpenBSD: cmds.c,v 1.13 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: cmds.c,v 1.7 1997/02/11 09:24:03 mrg Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,14 +35,16 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: cmds.c,v 1.13 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" #include "pathnames.h" -#include <stdio.h> +#include <vis.h> /* * tip @@ -57,48 +62,11 @@ void timeout(); /* timeout function called on alarm */ void stopsnd(); /* SIGINT handler during file transfers */ void intcopy(); /* interrupt routine for file transfers */ -void -usedefchars () -{ -#if HAVE_TERMIOS - int cnt; - struct termios ttermios; - ttermios = ctermios; - for (cnt = 0; cnt < NCCS; cnt++) - ttermios.c_cc [cnt] = otermios.c_cc [cnt]; - tcsetattr (0, TCSANOW, &ttermios); -#else - ioctl(0, TIOCSETC, &defchars); -#endif -} - -void -usetchars () -{ -#if HAVE_TERMIOS - tcsetattr (0, TCSANOW, &ctermios); -#else - ioctl(0, TIOCSETC, &tchars); -#endif -} - -void -flush_remote () -{ -#ifdef TIOCFLUSH - int cmd = 0; - ioctl (FD, TIOCFLUSH, &cmd); -#else - struct sgttyb buf; - ioctl (FD, TIOCGETP, &buf); /* this does a */ - ioctl (FD, TIOCSETP, &buf); /* wflushtty */ -#endif -} - /* * FTP - remote ==> local * get a file from the remote host */ +void getfl(c) char c; { @@ -108,7 +76,7 @@ getfl(c) /* * get the UNIX receiving file's name */ - if (prompt("Local file name? ", copyname)) + if (prompt("Local file name? ", copyname, sizeof(copyname))) return; cp = expand(copyname); if ((sfd = creat(cp, 0666)) < 0) { @@ -119,7 +87,7 @@ getfl(c) /* * collect parameters */ - if (prompt("List command for remote system? ", buf)) { + if (prompt("List command for remote system? ", buf, sizeof(buf))) { unlink(copyname); return; } @@ -129,15 +97,17 @@ getfl(c) /* * Cu-like take command */ +void cu_take(cc) char cc; { int fd, argc; char line[BUFSIZ], *expand(), *cp; - if (prompt("[take] ", copyname)) + if (prompt("[take] ", copyname, sizeof(copyname))) return; - if ((argc = args(copyname, argv)) < 1 || argc > 2) { + if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || + argc > 2) { printf("usage: <take> from [to]\r\n"); return; } @@ -148,124 +118,30 @@ cu_take(cc) printf("\r\n%s: cannot create\r\n", argv[1]); return; } - (void)sprintf(line, "cat %s ; echo \"\" ; echo ___tip_end_of_file_marker___", argv[0]); - xfer(line, fd, "\n___tip_end_of_file_marker___\n"); -} - -extern jmp_buf intbuf; - -xfer(buf, fd, eofchars) - char *buf, *eofchars; -{ - register int ct; - char c, *match; - register int cnt, eof, v; - time_t start; - sig_t f; - char r; - FILE *ff; - - v = boolean(value(VERBOSE)); - - if ((ff = fdopen (fd, "w")) == NULL) { - perror("file open"); - return; - } - if ((cnt = number(value(FRAMESIZE))) != BUFSIZ) - if (setvbuf(ff, NULL, _IOFBF, cnt) != 0) { - perror("file allocation"); - (void)fclose(ff); - return; - } - - pwrite(FD, buf, size(buf)); - quit = 0; - kill(pid, SIGIOT); - read(repdes[0], (char *)&ccc, 1); /* Wait until read process stops */ - - /* - * finish command - */ - r = '\r'; - pwrite(FD, &r, 1); - do - read(FD, &c, 1); - while ((c&0177) != '\n'); - - usedefchars (); - - (void) setjmp(intbuf); - f = signal(SIGINT, intcopy); - start = time(0); - match = eofchars; - for (ct = 0; !quit;) { - eof = read(FD, &c, 1) <= 0; - c &= 0177; - if (quit) - continue; - if (eof) - break; - if (c == 0) - continue; /* ignore nulls */ - if (c == '\r') - continue; - if (c != *match && match > eofchars) { - register char *p = eofchars; - while (p < match) { - if (*p == '\n'&& v) - (void)printf("\r%d", ++ct); - fputc(*p++, ff); - } - match = eofchars; - } - if (c == *match) { - if (*++match == '\0') - break; - } else { - if (c == '\n' && v) - (void)printf("\r%d", ++ct); - fputc(c, ff); - } - } - if (v) - prtime(" lines transferred in ", time(0)-start); - usetchars (); - write(fildes[1], (char *)&ccc, 1); - signal(SIGINT, f); - (void)fclose(ff); + (void)snprintf(line, sizeof(line), "cat %s;echo \01", argv[0]); + transfer(line, fd, "\01"); } static jmp_buf intbuf; + /* * Bulk transfer routine -- * used by getfl(), cu_take(), and pipefile() */ +void transfer(buf, fd, eofchars) char *buf, *eofchars; + int fd; { - register int ct; + int ct; char c, buffer[BUFSIZ]; - register char *p = buffer; - register int cnt, eof, v; + char *p = buffer; + int cnt, eof; time_t start; sig_t f; char r; - FILE *ff; - v = boolean(value(VERBOSE)); - - if ((ff = fdopen (fd, "w")) == NULL) { - perror("file open"); - return; - } - if ((cnt = number(value(FRAMESIZE))) != BUFSIZ) - if (setvbuf(ff, NULL, _IOFBF, cnt) != 0) { - perror("file allocation"); - (void)fclose(ff); - return; - } - - pwrite(FD, buf, size(buf)); + parwrite(FD, buf, size(buf)); quit = 0; kill(pid, SIGIOT); read(repdes[0], (char *)&ccc, 1); /* Wait until read process stops */ @@ -274,17 +150,18 @@ transfer(buf, fd, eofchars) * finish command */ r = '\r'; - pwrite(FD, &r, 1); + parwrite(FD, &r, 1); do read(FD, &c, 1); - while ((c&0177) != '\n'); - usedefchars (); + while ((c&STRIP_PAR) != '\n'); + tcsetattr(0, TCSAFLUSH, &defchars); + (void) setjmp(intbuf); f = signal(SIGINT, intcopy); start = time(0); for (ct = 0; !quit;) { eof = read(FD, &c, 1) <= 0; - c &= 0177; + c &= STRIP_PAR; if (quit) continue; if (eof || any(c, eofchars)) @@ -293,30 +170,42 @@ transfer(buf, fd, eofchars) continue; /* ignore nulls */ if (c == '\r') continue; - if (c == '\n' && v) + *p++ = c; + + if (c == '\n' && boolean(value(VERBOSE))) printf("\r%d", ++ct); - fputc(c, ff); + if ((cnt = (p-buffer)) == number(value(FRAMESIZE))) { + if (write(fd, buffer, cnt) != cnt) { + printf("\r\nwrite error\r\n"); + quit = 1; + } + p = buffer; + } } - if (v) + if ((cnt = (p-buffer))) + if (write(fd, buffer, cnt) != cnt) + printf("\r\nwrite error\r\n"); + + if (boolean(value(VERBOSE))) prtime(" lines transferred in ", time(0)-start); - usetchars (); + tcsetattr(0, TCSAFLUSH, &term); write(fildes[1], (char *)&ccc, 1); signal(SIGINT, f); - (void)fclose(ff); + close(fd); } /* * FTP - remote ==> local process * send remote input to local process via pipe */ +void pipefile() { int cpid, pdes[2]; char buf[256]; int status, p; - extern int errno; - if (prompt("Local command? ", buf)) + if (prompt("Local command? ", buf, sizeof(buf))) return; if (pipe(pdes)) { @@ -328,7 +217,7 @@ pipefile() printf("can't fork!\r\n"); return; } else if (cpid) { - if (prompt("List command for remote system? ", buf)) { + if (prompt("List command for remote system? ", buf, sizeof(buf))) { close(pdes[0]), close(pdes[1]); kill (cpid, SIGKILL); } else { @@ -340,7 +229,7 @@ pipefile() ; } } else { - register int f; + int f; dup2(pdes[0], 0); close(pdes[0]); @@ -368,6 +257,7 @@ stopsnd() * send local file to remote host * terminate transmission with pseudo EOF sequence */ +void sendfile(cc) char cc; { @@ -379,7 +269,7 @@ sendfile(cc) /* * get file name */ - if (prompt("Local file name? ", fname)) + if (prompt("Local file name? ", fname, sizeof(fname))) return; /* @@ -391,15 +281,15 @@ sendfile(cc) return; } transmit(fd, value(EOFWRITE), NULL); - if (!boolean(value(ECHOCHECK))) { - flush_remote (); - } + if (!boolean(value(ECHOCHECK))) + tcdrain(FD); } /* * Bulk transfer routine to remote host -- * used by sendfile() and cu_put() */ +void transmit(fd, eofchars, command) FILE *fd; char *eofchars, *command; @@ -412,7 +302,7 @@ transmit(fd, eofchars, command) kill(pid, SIGIOT); /* put TIPOUT into a wait state */ stop = 0; f = signal(SIGINT, stopsnd); - usedefchars (); + tcsetattr(0, TCSAFLUSH, &defchars); read(repdes[0], (char *)&ccc, 1); if (command != NULL) { for (pc = command; *pc; pc++) @@ -420,7 +310,7 @@ transmit(fd, eofchars, command) if (boolean(value(ECHOCHECK))) read(FD, (char *)&c, 1); /* trailing \n */ else { - flush_remote (); + tcdrain(FD); sleep(5); /* wait for remote stty to take effect */ } } @@ -462,7 +352,7 @@ transmit(fd, eofchars, command) printf("\r%d", ++lcount); if (boolean(value(ECHOCHECK))) { timedout = 0; - alarm((int)value(ETIMEOUT)); + alarm((long)value(ETIMEOUT)); do { /* wait for prompt */ read(FD, (char *)&c, 1); if (timedout || stop) { @@ -471,30 +361,34 @@ transmit(fd, eofchars, command) alarm(0); goto out; } - } while ((c&0177) != character(value(PROMPT))); + } while ((c&STRIP_PAR) != character(value(PROMPT))); alarm(0); } } out: if (lastc != '\n' && !boolean(value(RAWFTP))) send('\r'); - for (pc = eofchars; *pc; pc++) - send(*pc); + if (eofchars) { + for (pc = eofchars; *pc; pc++) + send(*pc); + } stop_t = time(0); fclose(fd); signal(SIGINT, f); - if (boolean(value(VERBOSE))) + if (boolean(value(VERBOSE))) { if (boolean(value(RAWFTP))) prtime(" chars transferred in ", stop_t-start_t); else prtime(" lines transferred in ", stop_t-start_t); + } write(fildes[1], (char *)&ccc, 1); - usetchars (); + tcsetattr(0, TCSAFLUSH, &term); } /* * Cu-like put command */ +void cu_put(cc) char cc; { @@ -504,9 +398,10 @@ cu_put(cc) char *expand(); char *copynamex; - if (prompt("[put] ", copyname)) + if (prompt("[put] ", copyname, sizeof(copyname))) return; - if ((argc = args(copyname, argv)) < 1 || argc > 2) { + if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || + argc > 2) { printf("usage: <put> from [to]\r\n"); return; } @@ -518,9 +413,10 @@ cu_put(cc) return; } if (boolean(value(ECHOCHECK))) - sprintf(line, "cat>%s\r", argv[1]); + (void)snprintf(line, sizeof(line), "cat>%s\r", argv[1]); else - sprintf(line, "stty -echo;cat>%s;stty echo\r", argv[1]); + (void)snprintf(line, sizeof(line), + "stty -echo;cat>%s;stty echo\r", argv[1]); transmit(fd, "\04", line); } @@ -528,14 +424,15 @@ cu_put(cc) * FTP - send single character * wait for echo & handle timeout */ +void send(c) - char c; + int c; { char cc; int retry = 0; cc = c; - pwrite(FD, &cc, 1); + parwrite(FD, &cc, 1); #ifdef notdef if (number(value(CDELAY)) > 0 && c != '\r') nap(number(value(CDELAY))); @@ -549,14 +446,14 @@ send(c) } tryagain: timedout = 0; - alarm((int)value(ETIMEOUT)); + alarm((long)value(ETIMEOUT)); read(FD, &cc, 1); alarm(0); if (timedout) { printf("\r\ntimeout error (%s)\r\n", ctrl(c)); if (retry++ > 3) return; - pwrite(FD, &null, 1); /* poke it */ + parwrite(FD, &null, 1); /* poke it */ goto tryagain; } } @@ -572,19 +469,20 @@ timeout() * Stolen from consh() -- puts a remote file on the output of a local command. * Identical to consh() except for where stdout goes. */ +void pipeout(c) { char buf[256]; int cpid, status, p; - time_t start; + time_t start = time(NULL); putchar(c); - if (prompt("Local command? ", buf)) + if (prompt("Local command? ", buf, sizeof(buf))) return; kill(pid, SIGIOT); /* put TIPOUT into a wait state */ signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); - usedefchars (); + tcsetattr(0, TCSAFLUSH, &defchars); read(repdes[0], (char *)&ccc, 1); /* * Set up file descriptors in the child and @@ -593,11 +491,11 @@ pipeout(c) if ((cpid = fork()) < 0) printf("can't fork!\r\n"); else if (cpid) { - start = time(0); + start = time(NULL); while ((p = wait(&status)) > 0 && p != cpid) ; } else { - register int i; + int i; dup2(FD, 1); for (i = 3; i < 20; i++) @@ -611,27 +509,33 @@ pipeout(c) if (boolean(value(VERBOSE))) prtime("away for ", time(0)-start); write(fildes[1], (char *)&ccc, 1); - usetchars (); + tcsetattr(0, TCSAFLUSH, &term); signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); } -#if CONNECT - -int -tiplink (char *cmd, unsigned int flags) +#ifdef CONNECT +/* + * Fork a program with: + * 0 <-> remote tty in + * 1 <-> remote tty out + * 2 <-> local tty out + */ +void +consh(c) { + char buf[256]; int cpid, status, p; - time_t start; - - if (flags & TL_SIGNAL_TIPOUT) { - kill(pid, SIGIOT); /* put TIPOUT into a wait state */ - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - usedefchars (); - read(repdes[0], (char *)&ccc, 1); - } + time_t start = time(NULL); + putchar(c); + if (prompt("Local command? ", buf, sizeof(buf))) + return; + kill(pid, SIGIOT); /* put TIPOUT into a wait state */ + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + tcsetattr(0, TCSAFLUSH, &defchars); + read(repdes[0], (char *)&ccc, 1); /* * Set up file descriptors in the child and * let it go... @@ -643,62 +547,41 @@ tiplink (char *cmd, unsigned int flags) while ((p = wait(&status)) > 0 && p != cpid) ; } else { - register int fd; + int i; dup2(FD, 0); dup2(3, 1); - for (fd = 3; fd < 20; fd++) - close (fd); + for (i = 3; i < 20; i++) + close(i); signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); - execute (cmd); - printf("can't find `%s'\r\n", cmd); + execute(buf); + printf("can't find `%s'\r\n", buf); exit(0); } - - if (flags & TL_VERBOSE && boolean(value(VERBOSE))) + if (boolean(value(VERBOSE))) prtime("away for ", time(0)-start); - - if (flags & TL_SIGNAL_TIPOUT) { - write(fildes[1], (char *)&ccc, 1); - usetchars (); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - } - - return 0; -} - -/* - * Fork a program with: - * 0 <-> remote tty in - * 1 <-> remote tty out - * 2 <-> local tty out - */ -consh(c) -{ - char buf[256]; - putchar(c); - if (prompt("Local command? ", buf)) - return; - tiplink (buf, TL_SIGNAL_TIPOUT | TL_VERBOSE); + write(fildes[1], (char *)&ccc, 1); + tcsetattr(0, TCSAFLUSH, &term); + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); } #endif /* * Escape to local shell */ +void shell() { int shpid, status; - extern char **environ; char *cp; printf("[sh]\r\n"); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); unraw(); - if (shpid = fork()) { + if ((shpid = fork())) { while (shpid != wait(&status)); raw(); printf("\r\n!\r\n"); @@ -708,12 +591,12 @@ shell() } else { signal(SIGQUIT, SIG_DFL); signal(SIGINT, SIG_DFL); - if ((cp = rindex(value(SHELL), '/')) == NULL) + if ((cp = strrchr(value(SHELL), '/')) == NULL) cp = value(SHELL); else cp++; shell_uid(); - execl(value(SHELL), cp, 0); + execl(value(SHELL), cp, (char *)NULL); printf("\r\ncan't execl!\r\n"); exit(1); } @@ -723,6 +606,7 @@ shell() * TIPIN portion of scripting * initiate the conversation with TIPOUT */ +void setscript() { char c; @@ -745,12 +629,13 @@ setscript() * Change current working directory of * local portion of tip */ +void chdirectory() { - char dirname[80]; - register char *cp = dirname; + char dirname[PATH_MAX]; + char *cp = dirname; - if (prompt("[cd] ", dirname)) { + if (prompt("[cd] ", dirname, sizeof(dirname))) { if (stoprompt) return; cp = value(HOME); @@ -760,6 +645,7 @@ chdirectory() printf("!\r\n"); } +void tipabort(msg) char *msg; { @@ -775,19 +661,16 @@ tipabort(msg) exit(0); } +void finish() { - char *abortmsg = NOSTR, *dismsg; - - if (LO != NOSTR && tiplink (LO, TL_SIGNAL_TIPOUT) != 0) { - abortmsg = "logout failed"; - } + char *dismsg; if ((dismsg = value(DISCONNECT)) != NOSTR) { write(FD, dismsg, strlen(dismsg)); - sleep (2); + sleep(5); } - tipabort(abortmsg); + tipabort(NOSTR); } void @@ -798,25 +681,28 @@ intcopy() longjmp(intbuf, 1); } +void execute(s) char *s; { - register char *cp; + char *cp; - if ((cp = rindex(value(SHELL), '/')) == NULL) + if ((cp = strrchr(value(SHELL), '/')) == NULL) cp = value(SHELL); else cp++; shell_uid(); - execl(value(SHELL), cp, "-c", s, 0); + execl(value(SHELL), cp, "-c", s, (char *)NULL); } -args(buf, a) +int +args(buf, a, num) char *buf, *a[]; + int num; { - register char *p = buf, *start; - register char **parg = a; - register int n = 0; + char *p = buf, *start; + char **parg = a; + int n = 0; do { while (*p && (*p == ' ' || *p == '\t')) @@ -830,16 +716,17 @@ args(buf, a) parg++, n++; if (*p) *p++ = '\0'; - } while (*p); + } while (*p && n < num); return(n); } +void prtime(s, a) char *s; time_t a; { - register i; + int i; int nums[3]; for (i = 0; i < 3; i++) { @@ -854,11 +741,12 @@ prtime(s, a) printf("\r\n!\r\n"); } +void variable() { char buf[256]; - if (prompt("[set] ", buf)) + if (prompt("[set] ", buf, sizeof(buf))) return; vlex(buf); if (vtable[BEAUTIFY].v_access&CHANGED) { @@ -893,48 +781,69 @@ variable() } if (vtable[PARITY].v_access&CHANGED) { vtable[PARITY].v_access &= ~CHANGED; - setparity(); + setparity(NOSTR); } } +void +listvariables() +{ + value_t *p; + char buf[BUFSIZ]; + + puts("v\r"); + for (p = vtable; p->v_name; p++) { + fputs(p->v_name, stdout); + switch (p->v_type&TMASK) { + case STRING: + if (p->v_value) { + strnvis(buf, p->v_value, sizeof(buf), + VIS_WHITE|VIS_OCTAL); + printf(" %s", buf); + } + putchar('\r'); + putchar('\n'); + break; + case NUMBER: + printf(" %ld\r\n", number(p->v_value)); + break; + case BOOL: + printf(" %s\r\n", + boolean(p->v_value) == '!' ? "false" : "true"); + break; + case CHAR: + vis(buf, character(p->v_value), VIS_WHITE|VIS_OCTAL, 0); + printf(" %s\r\n", buf); + break; + } + } +} + /* * Turn tandem mode on or off for remote tty. */ +void tandem(option) char *option; { -#if HAVE_TERMIOS - struct termios ttermios; - tcgetattr (FD, &ttermios); - if (strcmp(option,"on") == 0) { - ttermios.c_iflag |= IXOFF; - ctermios.c_iflag |= IXOFF; - } - else { - ttermios.c_iflag &= ~IXOFF; - ctermios.c_iflag &= ~IXOFF; - } - tcsetattr (FD, TCSANOW, &ttermios); - tcsetattr (0, TCSANOW, &ctermios); -#else /* HAVE_TERMIOS */ - struct sgttyb rmtty; - - ioctl(FD, TIOCGETP, &rmtty); - if (strcmp(option,"on") == 0) { - rmtty.sg_flags |= TANDEM; - arg.sg_flags |= TANDEM; + struct termios rmtty; + + tcgetattr(FD, &rmtty); + if (strcmp(option, "on") == 0) { + rmtty.c_iflag |= IXOFF; + term.c_iflag |= IXOFF; } else { - rmtty.sg_flags &= ~TANDEM; - arg.sg_flags &= ~TANDEM; + rmtty.c_iflag &= ~IXOFF; + term.c_iflag &= ~IXOFF; } - ioctl(FD, TIOCSETP, &rmtty); - ioctl(0, TIOCSETP, &arg); -#endif /* HAVE_TERMIOS */ + tcsetattr(FD, TCSADRAIN, &rmtty); + tcsetattr(0, TCSADRAIN, &term); } /* * Send a break. */ +void genbrk() { @@ -946,6 +855,7 @@ genbrk() /* * Suspend tip */ +void suspend(c) char c; { @@ -965,9 +875,9 @@ expand(name) { static char xname[BUFSIZ]; char cmdbuf[BUFSIZ]; - register int pid, l, rc; - register char *cp, *Shell; - int s, pivec[2], (*sigint)(); + int pid, l; + char *cp, *Shell; + int s, pivec[2]; if (!anyof(name, "~{[*?$`'\"\\")) return(name); @@ -977,7 +887,7 @@ expand(name) /* signal(SIGINT, sigint) */ return(name); } - sprintf(cmdbuf, "echo %s", name); + (void)snprintf(cmdbuf, sizeof(cmdbuf), "echo %s", name); if ((pid = vfork()) == 0) { Shell = value(SHELL); if (Shell == NOSTR) @@ -988,7 +898,7 @@ expand(name) close(pivec[1]); close(2); shell_uid(); - execl(Shell, Shell, "-c", cmdbuf, 0); + execl(Shell, Shell, "-c", cmdbuf, (char *)NULL); _exit(1); } if (pid == -1) { @@ -1029,13 +939,13 @@ expand(name) /* * Are any of the characters in the two strings the same? */ - +int anyof(s1, s2) - register char *s1, *s2; + char *s1, *s2; { - register int c; + int c; - while (c = *s1++) + while ((c = *s1++)) if (any(c, s2)) return(1); return(0); diff --git a/usr.bin/tip/tip/cmdtab.c b/usr.bin/tip/tip/cmdtab.c index 12ecc07..7f77e27 100644 --- a/usr.bin/tip/tip/cmdtab.c +++ b/usr.bin/tip/tip/cmdtab.c @@ -1,3 +1,6 @@ +/* $OpenBSD: cmdtab.c,v 1.3 2001/09/09 17:58:41 millert Exp $ */ +/* $NetBSD: cmdtab.c,v 1.3 1994/12/08 09:30:46 jtc Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,15 +35,17 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.3 2001/09/09 17:58:41 millert Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" extern int shell(), getfl(), sendfile(), chdirectory(); extern int finish(), help(), pipefile(), pipeout(), consh(), variable(); -extern int cu_take(), cu_put(), dollar(), genbrk(), suspend(); +extern int cu_take(), cu_put(), dollar(), genbrk(), suspend(), listvariables(); esctable_t etable[] = { { '!', NORM, "shell", shell }, @@ -50,7 +55,7 @@ esctable_t etable[] = { { 'p', NORM, "put file to remote UNIX", cu_put }, { '|', NORM, "pipe remote file", pipefile }, { '$', NORM, "pipe local command to remote host", pipeout }, -#if CONNECT +#ifdef CONNECT { 'C', NORM, "connect program to remote host",consh }, #endif { 'c', NORM, "change directory", chdirectory }, @@ -59,6 +64,7 @@ esctable_t etable[] = { {CTRL('y'),NORM,"suspend tip (local+remote)", suspend }, {CTRL('z'),NORM,"suspend tip (local only)", suspend }, { 's', NORM, "set variable", variable }, + { 'v', NORM, "list variables", listvariables }, { '?', NORM, "get this summary", help }, { '#', NORM, "send break", genbrk }, { 0, 0, 0 } diff --git a/usr.bin/tip/tip/cu.c b/usr.bin/tip/tip/cu.c index bab8492..8a44845 100644 --- a/usr.bin/tip/tip/cu.c +++ b/usr.bin/tip/tip/cu.c @@ -1,3 +1,6 @@ +/* $OpenBSD: cu.c,v 1.10 2001/09/26 06:07:28 pvalchev Exp $ */ +/* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,71 +35,100 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: cu.c,v 1.10 2001/09/26 06:07:28 pvalchev Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" void cleanup(); - -#if INCLUDE_CU_INTERFACE +void cuusage(); /* * Botch the interface to look like cu's */ +void cumain(argc, argv) + int argc; char *argv[]; { - register int i; + int ch, i; + long l; + char *cp; static char sbuf[12]; - if (argc < 2) { - printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n"); - exit(8); - } + if (argc < 2) + cuusage(); CU = DV = NOSTR; BR = DEFBR; - for (; argc > 1; argv++, argc--) { - if (argv[1][0] != '-') - PN = argv[1]; - else switch (argv[1][1]) { - - case 't': - HW = 1, DU = -1; - --argc; - continue; - + while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) { + switch(ch) { case 'a': - CU = argv[2]; ++argv; --argc; + CU = optarg; + break; + case 'l': + if (DV != NULL) { + fprintf(stderr, + "%s: cannot specificy multiple -l options\n", + __progname); + exit(3); + } + if (strchr(optarg, '/')) + DV = optarg; + else + asprintf(&DV, "/dev/%s", optarg); break; - case 's': - if (argc < 3 || speed(atoi(argv[2])) == 0) { - fprintf(stderr, "cu: unsupported speed %s\n", - argv[2]); + l = strtol(optarg, &cp, 10); + if (*cp != '\0' || l < 0 || l >= INT_MAX || + speed((int)l) == 0) { + fprintf(stderr, "%s: unsupported speed %s\n", + __progname, optarg); exit(3); } - BR = atoi(argv[2]); ++argv; --argc; + BR = (int)l; break; - - case 'l': - DV = argv[2]; ++argv; --argc; + case 'h': + setboolean(value(LECHO), TRUE); + HD = TRUE; + break; + case 't': + HW = 1, DU = -1; + break; + case 'o': + setparity("odd"); + break; + case 'e': + setparity("even"); break; - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (CU) - CU[strlen(CU)-1] = argv[1][1]; + CU[strlen(CU)-1] = ch; if (DV) - DV[strlen(DV)-1] = argv[1][1]; + DV[strlen(DV)-1] = ch; break; - default: - printf("Bad flag %s", argv[1]); + cuusage(); break; } } + argc -= optind; + argv += optind; + + switch (argc) { + case 1: + PN = argv[0]; + break; + case 0: + break; + default: + cuusage(); + break; + } + signal(SIGINT, cleanup); signal(SIGQUIT, cleanup); signal(SIGHUP, cleanup); @@ -106,7 +138,7 @@ cumain(argc, argv) * The "cu" host name is used to define the * attributes of the generic dialer. */ - (void)sprintf(sbuf, "cu%d", BR); + (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR); if ((i = hunt(sbuf)) == 0) { printf("all ports busy\n"); exit(3); @@ -121,7 +153,7 @@ cumain(argc, argv) user_uid(); vinit(); setparity("none"); - boolean(value(VERBOSE)) = 0; + setboolean(value(VERBOSE), FALSE); if (HW) ttysetup(speed(BR)); if (connect()) { @@ -133,4 +165,11 @@ cumain(argc, argv) if (!HW) ttysetup(speed(BR)); } -#endif /* INCLUDE_CU_INTERFACE */ + +void +cuusage() +{ + fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] " + "[phone-number]\n"); + exit(8); +} diff --git a/usr.bin/tip/tip/hunt.c b/usr.bin/tip/tip/hunt.c index 97e3a6a..60aaa23 100644 --- a/usr.bin/tip/tip/hunt.c +++ b/usr.bin/tip/tip/hunt.c @@ -1,3 +1,6 @@ +/* $OpenBSD: hunt.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: hunt.c,v 1.6 1997/04/20 00:02:10 mellon Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,14 +35,15 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)hunt.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: hunt.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" extern char *getremote(); -extern char *rindex(); static jmp_buf deadline; static int deadfl; @@ -51,16 +55,22 @@ dead() longjmp(deadline, 1); } +long hunt(name) char *name; { - register char *cp; + char *cp; sig_t f; f = signal(SIGALRM, dead); - while (cp = getremote(name)) { + while ((cp = getremote(name))) { deadfl = 0; - uucplock = rindex(cp, '/')+1; + uucplock = strrchr(cp, '/'); + if (uucplock == NULL) + uucplock = cp; + else + uucplock++; + if (uu_lock(uucplock) < 0) continue; /* @@ -74,7 +84,8 @@ hunt(name) break; if (setjmp(deadline) == 0) { alarm(10); - FD = open(cp, O_RDWR); + FD = open(cp, (O_RDWR | + (boolean(value(DC)) ? O_NONBLOCK : 0))); } alarm(0); if (FD < 0) { @@ -82,25 +93,18 @@ hunt(name) deadfl = 1; } if (!deadfl) { + struct termios cntrl; + + tcgetattr(FD, &cntrl); + if (!boolean(value(DC))) + cntrl.c_cflag |= HUPCL; + tcsetattr(FD, TCSAFLUSH, &cntrl); ioctl(FD, TIOCEXCL, 0); -#if HAVE_TERMIOS - { - struct termios t; - if (tcgetattr(FD, &t) == 0) { - t.c_cflag |= HUPCL; - (void)tcsetattr(FD, TCSANOW, &t); - } - } -#else /* HAVE_TERMIOS */ -#ifdef TIOCHPCL - ioctl(FD, TIOCHPCL, 0); -#endif -#endif /* HAVE_TERMIOS */ signal(SIGALRM, SIG_DFL); - return ((int)cp); + return ((long)cp); } (void)uu_unlock(uucplock); } signal(SIGALRM, f); - return (deadfl ? -1 : (int)cp); + return (deadfl ? -1 : (long)cp); } diff --git a/usr.bin/tip/tip/log.c b/usr.bin/tip/tip/log.c index 16e918a..1a715c0 100644 --- a/usr.bin/tip/tip/log.c +++ b/usr.bin/tip/tip/log.c @@ -1,3 +1,6 @@ +/* $OpenBSD: log.c,v 1.5 2001/09/09 19:30:49 millert Exp $ */ +/* $NetBSD: log.c,v 1.4 1994/12/24 17:56:28 cgd Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,43 +35,46 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: log.c,v 1.5 2001/09/09 19:30:49 millert Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" -#if ACULOG +#ifdef ACULOG static FILE *flog = NULL; /* * Log file maintenance routines */ - +void logent(group, num, acu, message) char *group, *num, *acu, *message; { char *user, *timestamp; struct passwd *pwd; - long t; + time_t t; if (flog == NULL) return; if (flock(fileno(flog), LOCK_EX) < 0) { - perror("tip: flock"); + perror("flock"); return; } - if ((user = getlogin()) == NOSTR) + if ((user = getlogin()) == NOSTR) { if ((pwd = getpwuid(getuid())) == NOPWD) user = "???"; else user = pwd->pw_name; + } t = time(0); timestamp = ctime(&t); timestamp[24] = '\0'; fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", user, timestamp, group, -#if PRISTINE +#ifdef PRISTINE "", #else num, @@ -78,6 +84,7 @@ logent(group, num, acu, message) (void) flock(fileno(flog), LOCK_UN); } +void loginit() { flog = fopen(value(LOG), "a"); diff --git a/usr.bin/tip/tip/partab.c b/usr.bin/tip/tip/partab.c index 1da4e23..b0e4dc2 100644 --- a/usr.bin/tip/tip/partab.c +++ b/usr.bin/tip/tip/partab.c @@ -1,3 +1,6 @@ +/* $OpenBSD: partab.c,v 1.3 1997/04/02 01:47:02 millert Exp $ */ +/* $NetBSD: partab.c,v 1.4 1996/12/29 10:38:21 cgd Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,13 +35,16 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)partab.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: partab.c,v 1.3 1997/04/02 01:47:02 millert Exp $"; #endif /* not lint */ /* * Even parity table for 0-0177 */ -char evenpartab[] = { +const unsigned char evenpartab[] = { 0000,0201,0202,0003,0204,0005,0006,0207, 0210,0011,0012,0213,0014,0215,0216,0017, 0220,0021,0022,0223,0024,0225,0226,0027, diff --git a/usr.bin/tip/tip/pathnames.h b/usr.bin/tip/tip/pathnames.h index 89730a9..cc7cbf4 100644 --- a/usr.bin/tip/tip/pathnames.h +++ b/usr.bin/tip/tip/pathnames.h @@ -1,3 +1,6 @@ +/* $OpenBSD: pathnames.h,v 1.2 1996/06/26 05:40:45 deraadt Exp $ */ +/* $NetBSD: pathnames.h,v 1.3 1994/12/08 09:30:59 jtc Exp $ */ + /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -35,24 +38,7 @@ #include <paths.h> -/* - Specify path to ACU (modem) log -*/ #define _PATH_ACULOG "/var/log/aculog" - -/* - Specify path and format of lock files -*/ -/* #define _PATH_LOCKDIRNAME "/usr/spool/uucp/LCK..%s" */ -/* #define _PATH_LOCKDIRNAME "/etc/locks/LCK..%s" */ -/* #define _PATH_LOCKDIRNAME "/usr/spool/locks/LCK..%s" */ -/* #define _PATH_LOCKDIRNAME "/usr/spool/uucp/LCK/LCK..%s" */ -#define _PATH_LOCKDIRNAME "/var/spool/lock/LCK..%s" - -/* - Specify location for system wide databases -*/ -#define _PATH_MODEMS "/etc/modems" +#define _PATH_LOCKDIRNAME "/var/spool/lock/LCK..%s" #define _PATH_PHONES "/etc/phones" #define _PATH_REMOTE "/etc/remote" - diff --git a/usr.bin/tip/tip/remote.c b/usr.bin/tip/tip/remote.c index 333a915..f2aaeb2 100644 --- a/usr.bin/tip/tip/remote.c +++ b/usr.bin/tip/tip/remote.c @@ -1,3 +1,6 @@ +/* $OpenBSD: remote.c,v 1.10 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: remote.c,v 1.5 1997/04/20 00:02:45 mellon Exp $ */ + /* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -39,16 +42,17 @@ static char copyright[] = #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: remote.c,v 1.10 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ -#include <sys/syslimits.h> #include <stdio.h> #include <stdlib.h> -#include "tipconf.h" -#include "tip.h" #include "pathnames.h" +#include "tip.h" /* * Attributes to be gleened from remote host description @@ -56,62 +60,29 @@ static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93"; */ static char **caps[] = { &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI, - &ES, &EX, &FO, &RC, &RE, &PA, &LI, &LO + &ES, &EX, &FO, &RC, &RE, &PA }; static char *capstrings[] = { "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr", - "di", "es", "ex", "fo", "rc", "re", "pa", "li", "lo", 0 + "di", "es", "ex", "fo", "rc", "re", "pa", 0 }; static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; #define cgetflag(f) (cgetcap(bp, f, ':') != NULL) -/* - Expand the start tilde sequence at the start of the - specified path. Optionally, free space allocated to - path before reinitializing it. -*/ -static int -expand_tilde (char **path, void (*free) (char *p)) -{ - int rc = 0; - char buffer [PATH_MAX]; - char *tailp; - if ((tailp = strchr (*path + 1, '/')) != NULL) - { - struct passwd *pwd; - *tailp++ = '\0'; - if (*(*path + 1) == '\0') - strcpy (buffer, getlogin ()); - else - strcpy (buffer, *path + 1); - if ((pwd = getpwnam (buffer)) != NULL) - { - strcpy (buffer, pwd->pw_dir); - strcat (buffer, "/"); - strcat (buffer, tailp); - if (free) - free (*path); - *path = strdup (buffer); - rc++; - } - return rc; - } -} - -static +static void getremcap(host) - register char *host; + char *host; { - register char **p, ***q; + char **p, ***q; char *bp; char *rempath; int stat; rempath = getenv("REMOTE"); - if (rempath != NULL) + if (rempath != NULL) { if (*rempath != '/') /* we have an entry */ cgetset(rempath); @@ -119,6 +90,7 @@ getremcap(host) db_array[1] = rempath; db_array[2] = _PATH_REMOTE; } + } if ((stat = cgetent(&bp, db_array, host)) < 0) { if (DV || @@ -134,15 +106,17 @@ getremcap(host) } switch(stat) { case -1: - fprintf(stderr, "tip: unknown host %s\n", host); + fprintf(stderr, "%s: unknown host %s\n", __progname, + host); break; case -2: fprintf(stderr, - "tip: can't open host description file\n"); + "%s: can't open host description file\n", + __progname); break; case -3: fprintf(stderr, - "tip: possible reference loop in host description file\n"); + "%s: possible reference loop in host description file\n", __progname); break; } exit(3); @@ -169,6 +143,10 @@ getremcap(host) fprintf(stderr, "%s: missing phone number\n", host); exit(3); } + if (DU && AT == NOSTR) { + fprintf(stderr, "%s: missing acu type\n", host); + exit(3); + } HD = cgetflag("hd"); @@ -179,58 +157,35 @@ getremcap(host) if (!HW) HW = (CU == NOSTR) || (DU && equal(DV, CU)); HO = host; - - /* - If login script, verify access - */ - if (LI != NOSTR) { - if (*LI == '~') - (void) expand_tilde (&LI, NULL); - if (access (LI, F_OK | X_OK) != 0) { - printf("tip (warning): can't open login script \"%s\"\n", LI); - LI = NOSTR; - } - } - - /* - If logout script, verify access - */ - if (LO != NOSTR) { - if (*LO == '~') - (void) expand_tilde (&LO, NULL); - if (access (LO, F_OK | X_OK) != 0) { - printf("tip (warning): can't open logout script \"%s\"\n", LO); - LO = NOSTR; - } - } - /* * see if uppercase mode should be turned on initially */ if (cgetflag("ra")) - boolean(value(RAISE)) = 1; + setboolean(value(RAISE), 1); if (cgetflag("ec")) - boolean(value(ECHOCHECK)) = 1; + setboolean(value(ECHOCHECK), 1); if (cgetflag("be")) - boolean(value(BEAUTIFY)) = 1; + setboolean(value(BEAUTIFY), 1); if (cgetflag("nb")) - boolean(value(BEAUTIFY)) = 0; + setboolean(value(BEAUTIFY), 0); if (cgetflag("sc")) - boolean(value(SCRIPT)) = 1; + setboolean(value(SCRIPT), 1); if (cgetflag("tb")) - boolean(value(TABEXPAND)) = 1; + setboolean(value(TABEXPAND), 1); if (cgetflag("vb")) - boolean(value(VERBOSE)) = 1; + setboolean(value(VERBOSE), 1); if (cgetflag("nv")) - boolean(value(VERBOSE)) = 0; + setboolean(value(VERBOSE), 0); if (cgetflag("ta")) - boolean(value(TAND)) = 1; + setboolean(value(TAND), 1); if (cgetflag("nt")) - boolean(value(TAND)) = 0; + setboolean(value(TAND), 0); if (cgetflag("rw")) - boolean(value(RAWFTP)) = 1; + setboolean(value(RAWFTP), 1); if (cgetflag("hd")) - boolean(value(HALFDUPLEX)) = 1; + setboolean(value(HALFDUPLEX), 1); + if (cgetflag("dc")) + setboolean(value(DC), 1); if (RE == NOSTR) RE = (char *)"tip.record"; if (EX == NOSTR) @@ -255,13 +210,13 @@ char * getremote(host) char *host; { - register char *cp; + char *cp; static char *next; static int lookedup = 0; if (!lookedup) { if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { - fprintf(stderr, "tip: no host specified\n"); + fprintf(stderr, "%s: no host specified\n", __progname); exit(3); } getremcap(host); @@ -274,7 +229,7 @@ getremote(host) */ if (next == NOSTR) return (NOSTR); - if ((cp = index(next, ',')) == NULL) { + if ((cp = strchr(next, ',')) == NULL) { DV = next; next = NOSTR; } else { diff --git a/usr.bin/tip/tip/tip.1 b/usr.bin/tip/tip/tip.1 index caae520..805d77c 100644 --- a/usr.bin/tip/tip/tip.1 +++ b/usr.bin/tip/tip/tip.1 @@ -1,3 +1,6 @@ +.\" $OpenBSD: tip.1,v 1.19 2001/09/23 06:15:30 pvalchev Exp $ +.\" $NetBSD: tip.1,v 1.7 1994/12/08 09:31:05 jtc Exp $ +.\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -31,101 +34,160 @@ .\" .\" @(#)tip.1 8.4 (Berkeley) 4/18/94 .\" -.Dd April 18, 1994 +.Dd September 9, 2001 .Dt TIP 1 -.Os BSD 4 +.Os .Sh NAME .Nm tip , .Nm cu .Nd connect to a remote system .Sh SYNOPSIS .Nm tip -.Op Fl v -.Fl Ns Ns Ar speed -.Ar system\-name -.Nm tip -.Op Fl v -.Fl Ns Ns Ar speed -.Ar phone\-number +.Op Fl nv +.Op Fl Ar speed +.Op Ar system\-name .Nm cu -.Ar phone\-number -.Op Fl t -.Op Fl s Ar speed +.Op Fl ehot .Op Fl a Ar acu .Op Fl l Ar line +.Op Fl s Ar speed .Op Fl # +.Op Ar phone\-number .Sh DESCRIPTION -.Nm Tip +.Nm and -.Ar cu -establish a full-duplex connection to another machine, -giving the appearance of being logged in directly on the -remote cpu. It goes without saying that you must have a login -on the machine (or equivalent) to which you wish to connect. +.Nm cu +establish a full-duplex connection to another machine, giving the +appearance of being logged in directly on the remote CPU. +It goes without saying that you must have a login on the machine (or +equivalent) to which you wish to connect. The preferred interface is -.Nm tip . +.Nm tip . The -.Ar cu +.Nm cu interface is included for those people attached to the ``call .Ux Ns '' -command of version 7. This manual page +command of +.At v7 . +This manual page describes only -.Nm tip . +.Nm tip . .Pp -Available Option: -.Bl -tag -width indent +The options are as follows: +.Bl -tag -width 4n +.It Fl a Ar acu +Set the acu. +.It Fl l Ar line +For +.Nm cu , +specify the line to use. Either of the forms like +.Pa tty00 +or +.Pa /dev/tty00 +are permitted. +.It Fl n +No escape (disable tilde). +.It Fl s Ar speed +For +.Nm cu , +set the speed of the connection. Defaults to 9600. .It Fl v Set verbose mode. .El .Pp +If +.Ar speed +is specified it will override any baudrate specified in the system +description being used. +.Pp +If neither +.Ar speed +nor +.Ar system-name +are specified, +.Ar system-name +will be set to the value of the +.Ev HOST +environment variable. +.Pp +If +.Ar speed +is specified but +.Ar system-name +is not, +.Ar system-name +will be set to a value of 'tip' with +.Ar speed +appended. +e.g. +.Ic tip -1200 +will set +.Ar system-name +to 'tip1200'. +.Pp Typed characters are normally transmitted directly to the remote -machine (which does the echoing as well). A tilde (`~') appearing -as the first character of a line is an escape signal; the following -are recognized: -.Bl -tag -width flag +machine (which does the echoing as well). +A tilde +.Pq Ql ~ +appearing as the first character of a line is an escape signal; the +following are recognized: +.Bl -tag -offset indent -width Fl .It Ic \&~^D No or Ic \&~ . -Drop the connection and exit -(you may still be logged in on the -remote machine). -.It Ic \&~c Op Ar name +Drop the connection and exit (you may still be logged in on the remote +machine). +.It Ic \&~c Op Ar name Change directory to .Ar name -(no argument -implies change to your home directory). +(no argument implies change to your home directory). .It Ic \&~! -Escape to a shell (exiting the shell will -return you to tip). +Escape to a shell (exiting the shell will return you to +.Nm tip Ns ). .It Ic \&~> Copy file from local to remote. -.Nm Tip +.Nm prompts for the name of a local file to transmit. .It Ic \&~< Copy file from remote to local. -.Nm Tip -prompts first for the name of the file to be sent, then for -a command to be executed on the remote machine. -.It Ic \&~p Ar from Op Ar to +.Nm +prompts first for the name of the file to be sent, then for a command +to be executed on the remote machine. +.It Ic \&~p Ar from Op Ar to Send a file to a remote .Ux -host. The put command causes the remote +host. +The put command causes the remote .Ux -system to run the command string ``cat > 'to''', while -.Nm tip -sends it the ``from'' -file. If the ``to'' file isn't specified the ``from'' file name is used. -This command is actually a +system to run the command string +.Dq cat > 'to' , +while +.Nm +sends it the +.Dq from +file. +If the +.Dq to +file isn't specified the +.Dq from +file name is used. +this command is actually a .Ux -specific version of the ``~>'' command. -.It Ic \&~t Ar from Op Ar to +specific version of the +.Ic ~> +command. +.It Ic \&~t Ar from Op Ar to Take a file from a remote .Ux host. -As in the put command the ``to'' file -defaults to the ``from'' file name if it isn't specified. -The remote host -executes the command string ``cat 'from';echo ^A'' to send the file to -.Nm tip . +As in the put command the +.Dq to +file defaults to the +.Dq from +file name if it isn't specified. +The remote host executes the command string +.Dq cat 'from';echo ^A +to send the file to +.Nm tip . .It Ic \&~| Pipe the output from a remote command to a local .Ux @@ -142,318 +204,375 @@ The command string sent to the local system is processed by the shell. .It Ic \&~C Fork a child process on the local system to perform special protocols -such as \s-1XMODEM\s+1. The child program will be run with the following -somewhat unusual arrangement of file descriptors: -.nf -.in +1i +such as \s-1XMODEM\s+1. +The child program will be run with the following somewhat unusual +arrangement of file descriptors: +.Bd -literal -offset indent 0 <-> local tty in 1 <-> local tty out 2 <-> local tty out 3 <-> remote tty in 4 <-> remote tty out -.in -1i -.fi +.Ed .It Ic \&~# Send a .Dv BREAK to the remote system. -For systems which don't support the -necessary -.Ar ioctl -call the break is simulated by a sequence of line speed changes -and -.Dv DEL -characters. +For systems which don't support the necessary +.Fn ioctl +call the break is simulated by a sequence of line speed changes and +DEL characters. .It Ic \&~s Set a variable (see the discussion below). +.It Ic \&~v +List all variables and their values (if set). .It Ic \&~^Z Stop -.Nm tip +.Nm (only available with job control). .It Ic \&~^Y -Stop only the ``local side'' of -.Nm tip -(only available with job control); -the ``remote side'' of -.Nm tip , +Stop only the +.Dq local side +of +.Nm +(only available with job control); the +.Dq remote side +of +.Nm tip , the side that displays output from the remote host, is left running. .It Ic \&~? -Get a summary of the tilde escapes +Get a summary of the tilde escapes. +.El +.Pp +To find the system description and thus the operating characteristics +of +.Ar system-name , +.Nm +searches for a system description with a name identical to +.Ar system-name . +The search order is +.Bl -enum -offset indent +.It +If the environment variable +.Ev REMOTE +does not start with a +.Ql \&/ +it is assumed to be a system description, and is considered first. +.It +If the environment variable +.Ev REMOTE +begins with a +.Ql \&/ +it is assumed to be a path to a +.Xr remote 5 +database, and the specified database is searched. +.It +The default +.Xr remote 5 +database, +.Pa /etc/remote , +is searched. .El .Pp -.Nm Tip -uses the file -.Pa /etc/remote -to find how to reach a particular -system and to find out how it should operate while talking -to the system; -refer to -.Xr remote 5 -for a full description. -Each system has a default baud rate with which to -establish a connection. If this value is not suitable, the baud rate -to be used may be specified on the command line, e.g. +See +.Xr remote 5 +for full documentation on system descriptions. +.Pp +The +.Ar ba +capability is used in system descriptions to specify the baud rate +with which to establish a connection. +If the value specified is not suitable, the baud rate to be used may +be given on the command line, e.g., .Ql "tip -300 mds" . .Pp When -.Nm tip -establishes a connection it sends out a -connection message to the remote system; the default value, if any, -is defined in -.Pa /etc/remote -(see -.Xr remote 5 ) . +.Nm +establishes a connection it sends out the connection message +specified in the +.Ar cm +capability of the system description being used. .Pp When -.Nm tip -prompts for an argument (e.g. during setup of -a file transfer) the line typed may be edited with the standard -erase and kill characters. A null line in response to a prompt, -or an interrupt, will abort the dialogue and return you to the -remote machine. +.Nm +prompts for an argument (e.g., during setup of a file transfer) the +line typed may be edited with the standard erase and kill characters. +A null line in response to a prompt, or an interrupt, will abort the +dialogue and return you to the remote machine. .Pp -.Nm Tip -guards against multiple users connecting to a remote system -by opening modems and terminal lines with exclusive access, -and by honoring the locking protocol used by +.Nm +guards against multiple users connecting to a remote system by opening +modems and terminal lines with exclusive access, and by honoring the +locking protocol used by .Xr uucico 8 . .Pp During file transfers -.Nm tip +.Nm provides a running count of the number of lines transferred. -When using the ~> and ~< commands, the ``eofread'' and ``eofwrite'' -variables are used to recognize end-of-file when reading, and -specify end-of-file when writing (see below). File transfers -normally depend on tandem mode for flow control. If the remote -system does not support tandem mode, ``echocheck'' may be set -to indicate -.Nm tip +When using the +.Ic ~> +and +.Ic ~< +commands, the +.Dq eofread +and +.Dq eofwrite +variables are used to recognize end-of-file when reading, and specify +end-of-file when writing (see below). +File transfers normally depend on tandem mode for flow control. +If the remote system does not support tandem mode, +.Dq echocheck +may be set to indicate +.Nm should synchronize with the remote system on the echo of each transmitted character. .Pp When -.Nm tip -must dial a phone number to connect to a system it will print -various messages indicating its actions. -.Nm Tip -supports modems that use the AT command set. -.Nm Tip -uses the file -.Pa /etc/modems -to find out how to operate with a particular -modem; refer to -.Xr modems 5 -for a full description. +.Nm +must dial a phone number to connect to a system it will print various +messages indicating its actions. +.Nm +supports a variety of auto-call units and modems with the +.Ar at +capability in system descriptions. +.Pp +Support for Ventel 212+ (ventel), Hayes AT-style (hayes), +USRobotics Courier (courier), Telebit T3000 (t3000) and +Racal-Vadic 831 (vadic) units is enabled by default. +.Pp +Support for Bizcomp 1031[fw] (biz31[fw]), Bizcomp 1022[fw] +(biz22[fw]), DEC DF0[23]-AC (df0[23]), DEC DN-11 (dn11) and +Racal-Vadic 3451 (v3451) units can be added by recompiling +.Xr tip 1 +with the appropriate defines. +.Pp +Note that if support for both the Racal-Vadic 831 and 3451 is enabled +they are referred to as the v831 and v3451 respectively. +If only one of the two is supported, it is referred to as vadic. .Ss VARIABLES -.Nm Tip -maintains a set of -.Ar variables -which control its operation. +.Nm +maintains a set of variables which control its operation. Some of these variables are read-only to normal users (root is allowed -to change anything of interest). Variables may be displayed -and set through the ``s'' escape. The syntax for variables is patterned -after -.Xr vi 1 +to change anything of interest). +Variables may be displayed and set through the +.Sq s +escape. +The syntax for variables is patterned after +.Xr vi 1 and -.Xr Mail 1 . -Supplying ``all'' +.Xr Mail 1 . +Supplying +.Dq all as an argument to the set command displays all variables readable by -the user. Alternatively, the user may request display of a particular -variable by attaching a `?' to the end. For example ``escape?'' +the user. +Alternatively, the user may request display of a particular variable +by attaching a +.Ql ? +to the end. +For example, +.Dq escape? displays the current escape character. .Pp -Variables are numeric, string, character, or boolean values. Boolean -variables are set merely by specifying their name; they may be reset -by prepending a `!' to the name. Other variable types are set by -concatenating an `=' and the value. The entire assignment must not -have any blanks in it. A single set command may be used to interrogate -as well as set a number of variables. +Variables are numeric, string, character, or boolean values. +Boolean variables are set merely by specifying their name; they may be +reset by prepending a +.Ql ! +to the name. +Other variable types are set by concatenating an +.Ql = +and the value. +The entire assignment must not have any blanks in it. +A single set command may be used to interrogate as well as set a +number of variables. Variables may be initialized at run time by placing set commands -(without the ``~s'' prefix in a file +(without the +.Ql ~s +prefix in a file .Pa .tiprc -in one's home directory). The +in one's home directory). +The .Fl v option causes -.Nm tip +.Nm to display the sets as they are made. Certain common variables have abbreviations. -The following is a list of common variables, -their abbreviations, and their default values. +The following is a list of common variables, their abbreviations, and +their default values: .Bl -tag -width Ar .It Ar beautify -(bool) Discard unprintable characters when a session is being scripted; -abbreviated -.Ar be . +(bool) Discard unprintable characters when a session is being +scripted; abbreviated +.Ar be . .It Ar baudrate (num) The baud rate at which the connection was established; abbreviated -.Ar ba . +.Ar ba . .It Ar dialtimeout -(num) When dialing a phone number, the time (in seconds) -to wait for a connection to be established; abbreviated -.Ar dial . +(num) When dialing a phone number, the time (in seconds) to wait for a +connection to be established; abbreviated +.Ar dial . .It Ar echocheck (bool) Synchronize with the remote host during file transfer by waiting for the echo of the last character transmitted; default is -.Ar off . +.Ar off . .It Ar eofread (str) The set of characters which signify an end-of-transmission -during a ~< file transfer command; abbreviated -.Ar eofr . +during a +.Ic ~< +file transfer command; abbreviated +.Ar eofr . .It Ar eofwrite -(str) The string sent to indicate end-of-transmission during -a ~> file transfer command; abbreviated -.Ar eofw . +(str) The string sent to indicate end-of-transmission during a +.Ic ~> +file transfer command; abbreviated +.Ar eofw . .It Ar eol (str) The set of characters which indicate an end-of-line. -.Nm Tip +.Nm will recognize escape characters only after an end-of-line. .It Ar escape (char) The command prefix (escape) character; abbreviated -.Ar es ; -default value is `~'. +.Ar es ; +default value is +.Ql ~ . .It Ar exceptions -(str) The set of characters which should not be discarded -due to the beautification switch; abbreviated -.Ar ex ; -default value is ``\et\en\ef\eb''. +(str) The set of characters which should not be discarded due to the +beautification switch; abbreviated +.Ar ex ; +default value is +.Dq \et\en\ef\eb . .It Ar force (char) The character used to force literal data transmission; abbreviated -.Ar fo ; -default value is `^P'. +.Ar fo ; +default value is +.Ql ^P . .It Ar framesize -(num) The amount of data (in bytes) to buffer between file system +(num) The amount of data (in bytes) to buffer between filesystem writes when receiving files; abbreviated -.Ar fr . +.Ar fr . .It Ar host (str) The name of the host to which you are connected; abbreviated -.Ar ho . -.It Ar login -(str) Pathname of a login shell script to run once connected; standard input -and output are redirected to the remote host. Leading tildes in the pathname -are expanded expansion; abbreviated -.Ar li . -.It Ar logout -(str) Pathname of a shell script to run before disconnecting; standard input -and output are redirected to the remote host. Leading tildes in the pathname -are expanded expansion; abbreviated -.Ar lo . +.Ar ho . .It Ar prompt (char) The character which indicates an end-of-line on the remote host; abbreviated -.Ar pr ; -default value is `\en'. This value is used to synchronize during -data transfers. The count of lines transferred during a file transfer -command is based on receipt of this character. +.Ar pr ; +default value is +.Ql \en . +This value is used to synchronize during data transfers. +The count of lines transferred during a file transfer command is based +on receipt of this character. .It Ar raise (bool) Upper case mapping mode; abbreviated -.Ar ra ; +.Ar ra ; default value is -.Ar off . -When this mode is enabled, all lower case letters will be mapped to -upper case by -.Nm tip +.Ar off . +When this mode is enabled, all lowercase letters will be mapped to +uppercase by +.Nm for transmission to the remote machine. .It Ar raisechar -(char) The input character used to toggle upper case mapping mode; +(char) The input character used to toggle uppercase mapping mode; abbreviated -.Ar rc ; -default value is `^A'. +.Ar rc ; +default value is +.Ql ^A . .It Ar record (str) The name of the file in which a session script is recorded; abbreviated -.Ar rec ; -default value is ``tip.record''. +.Ar rec ; +default value is +.Dq tip.record . .It Ar script (bool) Session scripting mode; abbreviated -.Ar sc ; +.Ar sc ; default is -.Ar off . +.Ar off . When .Ar script is -.Li true , -.Nm tip -will record everything transmitted by the remote machine in -the script record file specified in -.Ar record . +.Li true , +.Nm +will record everything transmitted by the remote machine in the script +record file specified in +.Ar record . If the .Ar beautify switch is on, only printable .Tn ASCII -characters will be included in -the script file (those characters betwee 040 and 0177). The -variable +characters will be included in the script file (those characters +between 040 and 0177). +The variable .Ar exceptions is used to indicate characters which are an exception to the normal beautification rules. .It Ar tabexpand (bool) Expand tabs to spaces during file transfers; abbreviated -.Ar tab ; +.Ar tab ; default value is -.Ar false . +.Ar false . Each tab is expanded to 8 spaces. .It Ar verbose (bool) Verbose mode; abbreviated -.Ar verb ; +.Ar verb ; default is -.Ar true . +.Ar true . When verbose mode is enabled, -.Nm tip -prints messages while dialing, shows the current number -of lines transferred during a file transfer operations, -and more. +.Nm +prints messages while dialing, shows the current number of lines +transferred during a file transfer operations, and more. .El .Sh ENVIRONMENT -.Nm Tip -uses the following environment variables: .Bl -tag -width Fl .It Ev SHELL -(str) The name of the shell to use for the ~! command; default -value is ``/bin/sh'', or taken from the environment. +The name of the shell to use for the +.Ic ~! +command; default value is +.Dq /bin/sh . .It Ev HOME -(str) The home directory to use for the ~c command; default -value is taken from the environment. +The home directory to use for the +.Ic ~c +command. .It Ev HOST -Check for a default host if none specified. +The default value for +.Ar system-name +if none is specified via the command line. +.It Ev REMOTE +A system description, or an absolute path to a +.Xr remote 5 +system description database. +.It Ev PHONES +A path to a +.Xr phones 5 +database. .El -.Pp -The variables -.Ev ${REMOTE} -and -.Ev ${PHONES} -are also exported. .Sh FILES -.Bl -tag -width /var/spool/lock/LCK..* -compact -.It Pa /etc/modems -Global modem configuration data base. +.Bl -tag -width "/var/spool/lock/LCK..*" -compact .It Pa /etc/remote -Global system descriptions. +global +.Xr remote 5 +database .It Pa /etc/phones -Global phone number data base. -.It ${REMOTE} -Private system descriptions. -.It ${PHONES} -Private phone numbers. -.It ~/.tiprc -Initialization file. +default +.Xr phones 5 +file +.It Pa ~/.tiprc +initialization file .It Pa tip.record -Record file. -.It /var/log/aculog -Line access log. +record file +.It Pa /var/log/aculog +line access log .It Pa /var/spool/lock/LCK..* -Lock file to avoid conflicts with -.Xr uucp . +lock file to avoid conflicts with +.Xr uucp .El -.Sh DIAGNOSTICS -Diagnostics are, hopefully, self explanatory. .Sh SEE ALSO -.Xr remote 5 , -.Xr phones 5 +.Xr phones 5 , +.Xr remote 5 .Sh HISTORY The -.Nm tip +.Nm appeared command in .Bx 4.2 . .Sh BUGS diff --git a/usr.bin/tip/tip/tip.c b/usr.bin/tip/tip/tip.c index 3482d00..64cd760 100644 --- a/usr.bin/tip/tip/tip.c +++ b/usr.bin/tip/tip/tip.c @@ -1,3 +1,6 @@ +/* $OpenBSD: tip.c,v 1.15 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: tip.c,v 1.13 1997/04/20 00:03:05 mellon Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -38,74 +41,61 @@ static char copyright[] = #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: tip.c,v 1.15 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ /* - Forward declarations -*/ -void ttysetup (int speed); - -/* * tip - UNIX link to other systems * tip [-v] [-speed] system-name * or * cu phone-number [-s speed] [-l line] [-a acu] */ - -#include "tipconf.h" #include "tip.h" #include "pathnames.h" /* * Baud rate mapping table */ -#if !HAVE_TERMIOS -CONST int bauds[] = { +int rates[] = { 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, -1 }; -#endif - -#if !HAVE_TERMIOS -int disc = OTTYDISC; /* tip normally runs this way */ -#endif +int disc = TTYDISC; /* tip normally runs this way */ void intprompt(); void timeout(); void cleanup(); -void tipdone(); -char *sname(); char PNbuf[256]; /* This limits the size of a number */ -void +int main(argc, argv) + int argc; char *argv[]; { char *system = NOSTR; - register int i; - register char *p; + int i; + char *p; char sbuf[12]; gid = getgid(); egid = getegid(); uid = getuid(); euid = geteuid(); - -#if INCLUDE_CU_INTERFACE - if (equal(sname(argv[0]), "cu")) { + if (equal(__progname, "cu")) { cumode = 1; cumain(argc, argv); goto cucommon; } -#endif /* INCLUDE_CU_INTERFACE */ if (argc > 4) { fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n"); exit(1); } if (!isatty(0)) { - fprintf(stderr, "tip: must be interactive\n"); + fprintf(stderr, "%s: must be interactive\n", __progname); exit(1); } @@ -118,13 +108,18 @@ main(argc, argv) vflag++; break; + case 'n': + noesc++; + break; + case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': BR = atoi(&argv[1][1]); break; default: - fprintf(stderr, "tip: %s, unknown option\n", argv[1]); + fprintf(stderr, "%s: %s, unknown option\n", __progname, + argv[1]); break; } } @@ -139,15 +134,15 @@ main(argc, argv) * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(system) > sizeof PNbuf - 1) { - fprintf(stderr, "tip: phone number too long (max = %d bytes)\n", - sizeof PNbuf - 1); + fprintf(stderr, "%s: phone number too long (max = %d bytes)\n", + __progname, (int)sizeof(PNbuf) - 1); exit(1); } strncpy( PNbuf, system, sizeof PNbuf - 1 ); for (p = system; *p; p++) *p = '\0'; PN = PNbuf; - (void)sprintf(sbuf, "tip%d", BR); + (void)snprintf(sbuf, sizeof(sbuf), "tip%ld", BR); system = sbuf; notnumber: @@ -155,7 +150,6 @@ notnumber: (void)signal(SIGQUIT, cleanup); (void)signal(SIGHUP, cleanup); (void)signal(SIGTERM, cleanup); - (void)signal(SIGUSR1, tipdone); if ((i = hunt(system)) == 0) { printf("all ports busy\n"); @@ -170,36 +164,38 @@ notnumber: loginit(); /* + * Now that we have the logfile and the ACU open + * return to the real uid and gid. These things will + * be closed on exit. Swap real and effective uid's + * so we can get the original permissions back + * for removing the uucp lock. + */ + user_uid(); + + /* * Kludge, their's no easy way to get the initialization * in the right order, so force it here */ if ((PH = getenv("PHONES")) == NOSTR) PH = _PATH_PHONES; vinit(); /* init variables */ - setparity("even"); /* set the parity table */ - if ((i = speed(number(value(BAUDRATE)))) == NULL) { - printf("tip: bad baud rate %d\n", number(value(BAUDRATE))); + setparity("none"); /* set the parity table */ + if ((i = speed(number(value(BAUDRATE)))) == 0) { + printf("%s: bad baud rate %ld\n", __progname, + number(value(BAUDRATE))); + daemon_uid(); (void)uu_unlock(uucplock); exit(3); } /* - * Now that we have the logfile and the ACU open - * return to the real uid and gid. These things will - * be closed on exit. Swap real and effective uid's - * so we can get the original permissions back - * for removing the uucp lock. - */ - user_uid(); - - /* * Hardwired connections require the * line speed set before they make any transmissions * (this is particularly true of things like a DF03-AC) */ if (HW) ttysetup(i); - if (p = connect()) { + if ((p = connect())) { printf("\07%s\n[EOT]\n", p); daemon_uid(); (void)uu_unlock(uucplock); @@ -213,33 +209,28 @@ cucommon: * the "cu" version of tip. */ -#if HAVE_TERMIOS - tcgetattr (0, &otermios); - ctermios = otermios; -#ifndef _POSIX_SOURCE - ctermios.c_iflag = (IMAXBEL|IXANY|ISTRIP|IXON|BRKINT); - ctermios.c_lflag = (PENDIN|IEXTEN|ISIG|ECHOCTL|ECHOE|ECHOKE); -#else - ctermios.c_iflag = (ISTRIP|IXON|BRKINT); - ctermios.c_lflag = (PENDIN|IEXTEN|ISIG|ECHOE); -#endif - ctermios.c_cflag = (CLOCAL|HUPCL|CREAD|CS8); - ctermios.c_cc[VINTR] = ctermios.c_cc[VQUIT] = -1; - ctermios.c_cc[VSUSP] = ctermios.c_cc[VDSUSP] = ctermios.c_cc[VDISCARD] = - ctermios.c_cc[VLNEXT] = -1; -#else /* HAVE_TERMIOS */ - ioctl(0, TIOCGETP, (char *)&defarg); - ioctl(0, TIOCGETC, (char *)&defchars); - ioctl(0, TIOCGLTC, (char *)&deflchars); - ioctl(0, TIOCGETD, (char *)&odisc); - arg = defarg; - arg.sg_flags = ANYP | CBREAK; - tchars = defchars; - tchars.t_intrc = tchars.t_quitc = -1; - ltchars = deflchars; - ltchars.t_suspc = ltchars.t_dsuspc = ltchars.t_flushc - = ltchars.t_lnextc = -1; -#endif /* HAVE_TERMIOS */ + i = fcntl(FD, F_GETFL); + if (i == -1) { + perror("fcntl"); + cleanup(); + } + i = fcntl(FD, F_SETFL, i & ~O_NONBLOCK); + if (i == -1) { + perror("fcntl"); + cleanup(); + } + + tcgetattr(0, &defterm); + term = defterm; + term.c_lflag &= ~(ICANON|IEXTEN|ECHO); + term.c_iflag &= ~(INPCK|ICRNL); + term.c_oflag &= ~OPOST; + term.c_cc[VMIN] = 1; + term.c_cc[VTIME] = 0; + defchars = term; + term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] = + term.c_cc[VDSUSP] = term.c_cc[VDISCARD] = + term.c_cc[VLNEXT] = _POSIX_VDISABLE; raw(); pipe(fildes); pipe(repdes); @@ -253,16 +244,12 @@ cucommon: * so, fork one process for local side and one for remote. */ printf(cumode ? "Connected\r\n" : "\07connected\r\n"); - - if (LI != NOSTR && tiplink (LI, 0) != 0) { - tipabort ("login failed"); - } - - if (pid = fork()) + if ((pid = fork())) tipin(); else tipout(); /*NOTREACHED*/ + exit(0); } void @@ -271,18 +258,11 @@ cleanup() daemon_uid(); (void)uu_unlock(uucplock); -#if !HAVE_TERMIOS if (odisc) ioctl(0, TIOCSETD, (char *)&odisc); -#endif exit(0); } -void -tipdone() -{ - tipabort("Hangup."); -} /* * Muck with user ID's. We are setuid to the owner of the lock * directory when we start. user_uid() reverses real and effective @@ -293,6 +273,7 @@ tipdone() */ static int uidswapped; +void user_uid() { if (uidswapped == 0) { @@ -301,6 +282,7 @@ user_uid() } } +void daemon_uid() { @@ -310,9 +292,10 @@ daemon_uid() } } +void shell_uid() { - + setegid(gid); seteuid(uid); } @@ -320,34 +303,19 @@ shell_uid() * put the controlling keyboard into raw mode */ void -raw () +raw() { -#if HAVE_TERMIOS - tcsetattr (0, TCSANOW, &ctermios); -#else /* HAVE_TERMIOS */ - - ioctl(0, TIOCSETP, &arg); - ioctl(0, TIOCSETC, &tchars); - ioctl(0, TIOCSLTC, <chars); - ioctl(0, TIOCSETD, (char *)&disc); -#endif /* HAVE_TERMIOS */ + tcsetattr(0, TCSADRAIN, &term); } /* * return keyboard to normal mode */ +void unraw() { -#if HAVE_TERMIOS - tcsetattr (0, TCSANOW, &otermios); -#else /* HAVE_TERMIOS */ - - ioctl(0, TIOCSETD, (char *)&odisc); - ioctl(0, TIOCSETP, (char *)&defarg); - ioctl(0, TIOCSETC, (char *)&defchars); - ioctl(0, TIOCSLTC, (char *)&deflchars); -#endif /* HAVE_TERMIOS */ + tcsetattr(0, TCSADRAIN, &defterm); } static jmp_buf promptbuf; @@ -357,11 +325,14 @@ static jmp_buf promptbuf; * in from the terminal. Handles signals & allows use of * normal erase and kill characters. */ -prompt(s, p) +int +prompt(s, p, sz) char *s; - register char *p; + char *p; + size_t sz; { - register char *b = p; + int c; + char *b = p; sig_t oint, oquit; stoprompt = 0; @@ -370,7 +341,7 @@ prompt(s, p) unraw(); printf("%s", s); if (setjmp(promptbuf) == 0) - while ((*p = getchar()) != EOF && *p != '\n') + while ((c = getchar()) != EOF && (*p = c) != '\n' && --sz > 0) p++; *p = '\0'; @@ -396,6 +367,7 @@ intprompt() /* * ****TIPIN TIPIN**** */ +void tipin() { char gch, bol = 1; @@ -413,25 +385,27 @@ tipin() } while (1) { - gch = getchar()&0177; + gch = getchar()&STRIP_PAR; if ((gch == character(value(ESCAPE))) && bol) { - if (!(gch = escape())) - continue; + if (!noesc) { + if (!(gch = escape())) + continue; + } } else if (!cumode && gch == character(value(RAISECHAR))) { - boolean(value(RAISE)) = !boolean(value(RAISE)); + setboolean(value(RAISE), !boolean(value(RAISE))); continue; } else if (gch == '\r') { bol = 1; - pwrite(FD, &gch, 1); + parwrite(FD, &gch, 1); if (boolean(value(HALFDUPLEX))) printf("\r\n"); continue; } else if (!cumode && gch == character(value(FORCE))) - gch = getchar()&0177; + gch = getchar()&STRIP_PAR; bol = any(gch, value(EOL)); if (boolean(value(RAISE)) && islower(gch)) gch = toupper(gch); - pwrite(FD, &gch, 1); + parwrite(FD, &gch, 1); if (boolean(value(HALFDUPLEX))) printf("%c", gch); } @@ -443,13 +417,14 @@ extern esctable_t etable[]; * Escape handler -- * called on recognition of ``escapec'' at the beginning of a line */ +int escape() { - register char gch; - register esctable_t *p; + char gch; + esctable_t *p; char c = character(value(ESCAPE)); - gch = (getchar()&0177); + gch = (getchar()&STRIP_PAR); for (p = etable; p->e_char; p++) if (p->e_char == gch) { if ((p->e_flags&PRIV) && uid) @@ -460,38 +435,39 @@ escape() } /* ESCAPE ESCAPE forces ESCAPE */ if (c != gch) - pwrite(FD, &c, 1); + parwrite(FD, &c, 1); return (gch); } +int speed(n) int n; { -#if HAVE_TERMIOS - return (n); -#else - register CONST int *p; + int *p; - for (p = bauds; *p != -1; p++) + for (p = rates; *p != -1; p++) if (*p == n) - return (p - bauds); - return (NULL); -#endif + return n; + return 0; } -any(c, p) - register char c, *p; +int +any(cc, p) + int cc; + char *p; { + char c = cc; while (p && *p) if (*p++ == c) return (1); return (0); } +int size(s) - register char *s; + char *s; { - register int i = 0; + int i = 0; while (s && *s++) i++; @@ -500,12 +476,12 @@ size(s) char * interp(s) - register char *s; + char *s; { static char buf[256]; - register char *p = buf, c, *q; + char *p = buf, c, *q; - while (c = *s++) { + while ((c = *s++)) { for (q = "\nn\rr\tt\ff\033E\bb"; *q; q++) if (*q++ == c) { *p++ = '\\'; *p++ = *q; @@ -544,10 +520,11 @@ ctrl(c) /* * Help command */ +void help(c) char c; { - register esctable_t *p; + esctable_t *p; printf("%c\r\n", c); for (p = etable; p->e_char; p++) { @@ -563,67 +540,43 @@ help(c) * Set up the "remote" tty's state */ void -ttysetup (int speed) +ttysetup(speed) + int speed; { -#if HAVE_TERMIOS - struct termios termios; - tcgetattr (FD, &termios); + struct termios cntrl; + + tcgetattr(FD, &cntrl); + cfsetospeed(&cntrl, speed); + cfsetispeed(&cntrl, speed); + cntrl.c_cflag &= ~(CSIZE|PARENB); + cntrl.c_cflag |= CS8; + if (boolean(value(DC))) + cntrl.c_cflag |= CLOCAL; + cntrl.c_iflag &= ~(ISTRIP|ICRNL); + cntrl.c_oflag &= ~OPOST; + cntrl.c_lflag &= ~(ICANON|ISIG|IEXTEN|ECHO); + cntrl.c_cc[VMIN] = 1; + cntrl.c_cc[VTIME] = 0; if (boolean(value(TAND))) - termios.c_iflag = IXOFF; - else - termios.c_iflag = 0; -#ifndef _POSIX_SOURCE - termios.c_lflag = (PENDIN|ECHOKE|ECHOE); -#else - termios.c_lflag = (PENDIN|ECHOE); -#endif - termios.c_cflag = (CLOCAL|HUPCL|CREAD|CS8); - termios.c_ispeed = termios.c_ospeed = speed; - tcsetattr (FD, TCSANOW, &termios); -#else /* HAVE_TERMIOS */ - unsigned bits = LDECCTQ; - - arg.sg_ispeed = arg.sg_ospeed = speed; - arg.sg_flags = RAW; - if (boolean(value(TAND))) - arg.sg_flags |= TANDEM; - ioctl(FD, TIOCSETP, (char *)&arg); - ioctl(FD, TIOCLBIS, (char *)&bits); -#endif /* HAVE_TERMIOS */ -} - -/* - * Return "simple" name from a file name, - * strip leading directories. - */ -char * -sname(s) - register char *s; -{ - register char *p = s; - - while (*s) - if (*s++ == '/') - p = s; - return (p); + cntrl.c_iflag |= IXOFF; + tcsetattr(FD, TCSAFLUSH, &cntrl); } static char partab[0200]; -static int bits8; /* * Do a write to the remote machine with the correct parity. * We are doing 8 bit wide output, so we just generate a character * with the right parity and output it. */ -pwrite(fd, buf, n) +void +parwrite(fd, buf, n) int fd; char *buf; - register int n; + int n; { - register int i; - register char *bp; - extern int errno; + int i; + char *bp; bp = buf; if (bits8 == 0) @@ -634,8 +587,6 @@ pwrite(fd, buf, n) if (write(fd, buf, n) < 0) { if (errno == EIO) tipabort("Lost carrier."); - if (errno == ENODEV) - tipabort("tty not available."); /* this is questionable */ perror("write"); } @@ -644,12 +595,13 @@ pwrite(fd, buf, n) /* * Build a parity table with appropriate high-order bit. */ +void setparity(defparity) char *defparity; { - register int i, flip, clr, set; + int i, flip, clr, set; char *parity; - extern char evenpartab[]; + extern const unsigned char evenpartab[]; if (value(PARITY) == NOSTR) value(PARITY) = defparity; @@ -673,5 +625,5 @@ setparity(defparity) (void) fflush(stderr); } for (i = 0; i < 0200; i++) - partab[i] = evenpartab[i] ^ flip | set & clr; + partab[i] = (evenpartab[i] ^ flip | set) & clr; } diff --git a/usr.bin/tip/tip/tip.h b/usr.bin/tip/tip/tip.h index fb45ce0..4c5ab20 100644 --- a/usr.bin/tip/tip/tip.h +++ b/usr.bin/tip/tip/tip.h @@ -1,3 +1,6 @@ +/* $OpenBSD: tip.h,v 1.11 2001/09/09 19:30:49 millert Exp $ */ +/* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */ + /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -39,18 +42,12 @@ */ #include <sys/types.h> -#include <machine/endian.h> #include <sys/file.h> #include <sys/time.h> +#include <sys/wait.h> +#include <sys/ioctl.h> -#if HAVE_TERMIOS -#include <sys/ioctl.h> /* for TIOCHPCL */ -#include <sys/filio.h> /* for FIONREAD */ -#include <sys/termios.h> -#else -#include <sgtty.h> -#endif - +#include <termios.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -60,6 +57,7 @@ #include <setjmp.h> #include <unistd.h> #include <errno.h> +#include <limits.h> /* * Remote host attributes @@ -79,14 +77,11 @@ char *PH; /* phone number file */ char *RM; /* remote file name */ char *HO; /* host name */ -char *LI; /* login script */ -char *LO; /* logout script */ - long BR; /* line speed for conversation */ long FS; /* frame size for transfers */ -char DU; /* this host is dialed up */ -char HW; /* this device is hardwired, see hunt.c */ +short DU; /* this host is dialed up */ +short HW; /* this device is hardwired, see hunt.c */ char *ES; /* escape character */ char *EX; /* exceptions */ char *FO; /* force (literal next) char*/ @@ -96,7 +91,8 @@ char *PR; /* remote prompt */ long DL; /* line delay for file transfers to remote */ long CL; /* char delay for file transfers to remote */ long ET; /* echocheck timeout */ -char HD; /* this host is half duplex - do local echo */ +short HD; /* this host is half duplex - do local echo */ +short DC; /* this host is directly connected. */ /* * String value table @@ -139,8 +135,8 @@ typedef struct { char *acu_name; int (*acu_dialer)(); - void (*acu_disconnect)(); - void (*acu_abort)(); + int (*acu_disconnect)(); + int (*acu_abort)(); } acu_t; @@ -152,30 +148,18 @@ typedef * initialize it in vars.c, so we cast it as needed to keep lint * happy. */ -typedef - union { - int zz_number; - short zz_boolean[2]; - char zz_character[4]; - int *zz_address; - } - zzhack; #define value(v) vtable[v].v_value -#define number(v) ((((zzhack *)(&(v))))->zz_number) - -#if BYTE_ORDER == LITTLE_ENDIAN -#define boolean(v) ((((zzhack *)(&(v))))->zz_boolean[0]) -#define character(v) ((((zzhack *)(&(v))))->zz_character[0]) -#endif - -#if BYTE_ORDER == BIG_ENDIAN -#define boolean(v) ((((zzhack *)(&(v))))->zz_boolean[1]) -#define character(v) ((((zzhack *)(&(v))))->zz_character[3]) -#endif +#define number(v) ((long)(v)) +#define boolean(v) ((short)(long)(v)) +#define character(v) ((char)(long)(v)) +#define address(v) ((long *)(v)) -#define address(v) ((((zzhack *)(&(v))))->zz_address) +#define setnumber(v,n) do { (v) = (char *)(long)(n); } while (0) +#define setboolean(v,n) do { (v) = (char *)(long)(n); } while (0) +#define setcharacter(v,n) do { (v) = (char *)(long)(n); } while (0) +#define setaddress(v,n) do { (v) = (char *)(n); } while (0) /* * Escape command table definitions -- @@ -197,9 +181,10 @@ typedef #define PRIV 02 /* priviledged, root execute only */ extern int vflag; /* verbose during reading of .tiprc file */ +extern int noesc; /* no escape `~' char */ extern value_t vtable[]; /* variable table */ -#if !ACULOG +#ifndef ACULOG #define logent(a, b, c, d) #define loginit() #endif @@ -209,62 +194,49 @@ extern value_t vtable[]; /* variable table */ * value(DEFINE) turns into a static address. */ -/* -'a,.!awk '{ printf("\%s \%s \%d\n", $1, $2, NR - 1); }' -*/ +#define BEAUTIFY 0 +#define BAUDRATE 1 +#define DIALTIMEOUT 2 +#define EOFREAD 3 +#define EOFWRITE 4 +#define EOL 5 +#define ESCAPE 6 +#define EXCEPTIONS 7 +#define FORCE 8 +#define FRAMESIZE 9 +#define HOST 10 +#define LOG 11 +#define PHONES 12 +#define PROMPT 13 +#define RAISE 14 +#define RAISECHAR 15 +#define RECORD 16 +#define REMOTE 17 +#define SCRIPT 18 +#define TABEXPAND 19 +#define VERBOSE 20 +#define SHELL 21 +#define HOME 22 +#define ECHOCHECK 23 +#define DISCONNECT 24 +#define TAND 25 +#define LDELAY 26 +#define CDELAY 27 +#define ETIMEOUT 28 +#define RAWFTP 29 +#define HALFDUPLEX 30 +#define LECHO 31 +#define PARITY 32 -#define BEAUTIFY 0 -#define BAUDRATE 1 -#define DIALTIMEOUT 2 -#define EOFREAD 3 -#define EOFWRITE 4 -#define EOL 5 -#define ESCAPE 6 -#define EXCEPTIONS 7 -#define FORCE 8 -#define FRAMESIZE 9 -#define HOST 10 -#define LOG 11 -#define LOGIN 12 -#define LOGOUT 13 -#define PHONES 14 -#define PROMPT 15 -#define RAISE 16 -#define RAISECHAR 17 -#define RECORD 18 -#define REMOTE 19 -#define SCRIPT 20 -#define TABEXPAND 21 -#define VERBOSE 22 -#define SHELL 23 -#define HOME 24 -#define ECHOCHECK 25 -#define DISCONNECT 26 -#define TAND 27 -#define LDELAY 28 -#define CDELAY 29 -#define ETIMEOUT 30 -#define RAWFTP 31 -#define HALFDUPLEX 32 -#define LECHO 33 -#define PARITY 34 #define NOVAL ((value_t *)NULL) #define NOACU ((acu_t *)NULL) #define NOSTR ((char *)NULL) #define NOFILE ((FILE *)NULL) #define NOPWD ((struct passwd *)0) -#if HAVE_TERMIOS -struct termios otermios; -struct termios ctermios; -#else /* HAVE_TERMIOS */ -struct sgttyb arg; /* current mode of local terminal */ -struct sgttyb defarg; /* initial mode of local terminal */ -struct tchars tchars; /* current state of terminal */ -struct tchars defchars; /* initial state of terminal */ -struct ltchars ltchars; /* current local characters of terminal */ -struct ltchars deflchars; /* initial local characters of terminal */ -#endif /* HAVE_TERMIOS */ +struct termios term; /* current mode of terminal */ +struct termios defterm; /* initial mode of terminal */ +struct termios defchars; /* current mode with initial chars */ FILE *fscript; /* FILE for scripting */ @@ -273,6 +245,7 @@ int repdes[2]; /* read process sychronization channel */ int FD; /* open file descriptor to remote host */ int AC; /* open file descriptor to dialer (v831 only) */ int vflag; /* print .tiprc initialization sequence */ +int noesc; /* no `~' escape char */ int sfd; /* for ~< operation */ int pid; /* pid of tipout */ uid_t uid, euid; /* real and effective user id's */ @@ -283,26 +256,57 @@ int intflag; /* recognized interrupt */ int stoprompt; /* for interrupting a prompt session */ int timedout; /* ~> transfer timedout */ int cumode; /* simulating the "cu" program */ +int bits8; /* terminal is is 8-bit mode */ +#define STRIP_PAR (bits8 ? 0377 : 0177) -char fname[80]; /* file name buffer for ~< */ -char copyname[80]; /* file name buffer for ~> */ +char fname[PATH_MAX]; /* file name buffer for ~< */ +char copyname[PATH_MAX]; /* file name buffer for ~> */ char ccc; /* synchronization character */ char ch; /* for tipout */ char *uucplock; /* name of lock file for uucp's */ -int odisc; /* initial tty line discipline */ -extern int disc; /* current tty discpline */ +int odisc; /* initial tty line discipline */ +extern int disc; /* current tty discpline */ + +extern char *__progname; /* program name */ extern char *ctrl(); extern char *vinterp(); extern char *connect(); -int tipabort __P((char *)); - -#define TL_VERBOSE 0x00000001 -#define TL_SIGNAL_TIPOUT 0x00000002 - -int tiplink (char *cmd, unsigned int flags); -void raw (); - -/* end of tip.h */ +char *sname __P((char *s)); +int any __P((int cc, char *p)); +int anyof __P((char *s1, char *s2)); +int args __P((char *buf, char *a[], int num)); +int escape __P((void)); +int prompt __P((char *s, char *p, size_t sz)); +int size __P((char *s)); +int speed __P((int n)); +int uu_lock __P((char *ttyname)); +int uu_unlock __P((char *ttyname)); +int vstring __P((char *s, char *v)); +long hunt __P((char *name)); +void cumain __P((int argc, char *argv[])); +void daemon_uid __P((void)); +void disconnect __P((char *reason)); +void execute __P((char *s)); +void logent __P((char *group, char *num, char *acu, char *message)); +void loginit __P((void)); +void prtime __P((char *s, time_t a)); +void parwrite __P((int fd, char *buf, int n)); +void raw __P((void)); +void send __P((int c)); +void setparity __P((char *defparity)); +void setscript __P((void)); +void shell_uid __P((void)); +void tandem __P((char *option)); +void tipabort __P((char *msg)); +void tipin __P((void)); +void tipout __P((void)); +void transfer __P((char *buf, int fd, char *eofchars)); +void transmit __P((FILE *fd, char *eofchars, char *command)); +void ttysetup __P((int speed)); +void unraw __P((void)); +void user_uid __P((void)); +void vinit __P((void)); +void vlex __P((char *s)); diff --git a/usr.bin/tip/tip/tipout.c b/usr.bin/tip/tip/tipout.c index 246cfb7..d1ff53c 100644 --- a/usr.bin/tip/tip/tipout.c +++ b/usr.bin/tip/tip/tipout.c @@ -1,3 +1,6 @@ +/* $OpenBSD: tipout.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: tipout.c,v 1.5 1996/12/29 10:34:12 cgd Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,7 +35,10 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)tipout.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: tipout.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ #include "tip.h" @@ -66,11 +72,11 @@ void intEMT() { char c, line[256]; - register char *pline = line; + char *pline = line; char reply; read(fildes[0], &c, 1); - while (c != '\n') { + while (c != '\n' && pline - line < sizeof(line)) { *pline++ = c; read(fildes[0], &c, 1); } @@ -78,14 +84,14 @@ intEMT() if (boolean(value(SCRIPT)) && fscript != NULL) fclose(fscript); if (pline == line) { - boolean(value(SCRIPT)) = FALSE; + setboolean(value(SCRIPT), FALSE); reply = 'y'; } else { if ((fscript = fopen(line, "a")) == NULL) reply = 'n'; else { reply = 'y'; - boolean(value(SCRIPT)) = TRUE; + setboolean(value(SCRIPT), TRUE); } } write(repdes[1], &reply, 1); @@ -105,20 +111,20 @@ void intSYS() { - boolean(value(BEAUTIFY)) = !boolean(value(BEAUTIFY)); + setboolean(value(BEAUTIFY), !boolean(value(BEAUTIFY))); longjmp(sigbuf, 1); } /* * ****TIPOUT TIPOUT**** */ +void tipout() { char buf[BUFSIZ]; - register char *cp; - register int cnt; - extern int errno; - int omask; + char *cp; + int cnt; + sigset_t mask, omask; signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); @@ -128,29 +134,29 @@ tipout() signal(SIGHUP, intTERM); /* for dial-ups */ signal(SIGSYS, intSYS); /* beautify toggle */ (void) setjmp(sigbuf); - for (omask = 0;; sigsetmask(omask)) { + sigprocmask(SIG_BLOCK, NULL, &omask); + for (;;) { + sigprocmask(SIG_SETMASK, &omask, NULL); cnt = read(FD, buf, BUFSIZ); if (cnt <= 0) { /* lost carrier */ if (cnt < 0 && errno == EIO) { - sigblock(sigmask(SIGTERM)); - intTERM(); - /*NOTREACHED*/ - } else if (cnt == 0 && errno == ENOENT) { - kill(getppid(),SIGUSR1); - sigblock(sigmask(SIGTERM)); + sigemptyset(&mask); + sigaddset(&mask, SIGTERM); + sigprocmask(SIG_BLOCK, &mask, NULL); intTERM(); /*NOTREACHED*/ - } else { - printf("%d %d\r",cnt,errno); - fflush(stdout); } continue; } -#define ALLSIGS sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS) - omask = sigblock(ALLSIGS); + sigemptyset(&mask); + sigaddset(&mask, SIGEMT); + sigaddset(&mask, SIGTERM); + sigaddset(&mask, SIGIOT); + sigaddset(&mask, SIGSYS); + sigprocmask(SIG_BLOCK, &mask, NULL); for (cp = buf; cp < buf + cnt; cp++) - *cp &= 0177; + *cp &= STRIP_PAR; write(1, buf, cnt); if (boolean(value(SCRIPT)) && fscript != NULL) { if (!boolean(value(BEAUTIFY))) { diff --git a/usr.bin/tip/tip/uucplock.c b/usr.bin/tip/tip/uucplock.c index 235f516..a2a703b 100644 --- a/usr.bin/tip/tip/uucplock.c +++ b/usr.bin/tip/tip/uucplock.c @@ -1,3 +1,6 @@ +/* $OpenBSD: uucplock.c,v 1.6 1998/07/13 02:11:44 millert Exp $ */ +/* $NetBSD: uucplock.c,v 1.7 1997/02/11 09:24:08 mrg Exp $ */ + /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -32,34 +35,39 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: uucplock.c,v 1.6 1998/07/13 02:11:44 millert Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/file.h> #include <sys/dir.h> +#include <stdio.h> +#include <string.h> +#include <signal.h> +#include <unistd.h> +#include <stdlib.h> #include <errno.h> - -#include "tipconf.h" #include "pathnames.h" -/* Forward declarations */ -static int put_pid (int fd, int pid); -static int get_pid (int fd); - /* * uucp style locking routines * return: 0 - success * -1 - failure */ -uu_lock (char *ttyname) +int +uu_lock(ttyname) + char *ttyname; { int fd, pid; char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN]; - off_t lseek(); + char text_pid[81]; + int len; - (void)sprintf(tbuf, _PATH_LOCKDIRNAME, ttyname); + (void)snprintf(tbuf, sizeof tbuf, _PATH_LOCKDIRNAME, ttyname); fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660); if (fd < 0) { /* @@ -68,14 +76,19 @@ uu_lock (char *ttyname) */ fd = open(tbuf, O_RDWR, 0); if (fd < 0) { - perror("lock open"); + perror(tbuf); + fprintf(stderr, "Can't open lock file.\n"); return(-1); } - if (get_pid (fd) == -1) { + len = read(fd, text_pid, sizeof(text_pid)-1); + if(len<=0) { + perror(tbuf); (void)close(fd); - perror("lock read"); + fprintf(stderr, "Can't read lock file.\n"); return(-1); } + text_pid[len] = 0; + pid = atol(text_pid); if (kill(pid, 0) == 0 || errno != ESRCH) { (void)close(fd); /* process is still running */ @@ -85,15 +98,20 @@ uu_lock (char *ttyname) * The process that locked the file isn't running, so * we'll lock it ourselves */ - if (lseek(fd, 0L, L_SET) < 0) { + fprintf(stderr, "Stale lock on %s PID=%d... overriding.\n", + ttyname, pid); + if (lseek(fd, (off_t)0, SEEK_SET) < 0) { + perror(tbuf); (void)close(fd); - perror("lock lseek"); + fprintf(stderr, "Can't seek lock file.\n"); return(-1); } /* fall out and finish the locking process */ } pid = getpid(); - if (!put_pid (fd, pid)) { + (void)sprintf(text_pid, "%10d\n", pid); + len = strlen(text_pid); + if (write(fd, text_pid, len) != len) { (void)close(fd); (void)unlink(tbuf); perror("lock write"); @@ -103,44 +121,12 @@ uu_lock (char *ttyname) return(0); } -uu_unlock (char *ttyname) +int +uu_unlock(ttyname) + char *ttyname; { char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN]; - (void)sprintf(tbuf, _PATH_LOCKDIRNAME, ttyname); + (void)snprintf(tbuf, sizeof tbuf, _PATH_LOCKDIRNAME, ttyname); return(unlink(tbuf)); } - -static int put_pid (int fd, int pid) -{ -#if HAVE_V2_LOCKFILES - return write (fd, (char *)&pid, sizeof (pid)) == sizeof (pid); -#else - char buf [32]; - int len; - len = sprintf (buf, "%10ld\n", (long) pid); - return write (fd, buf, len) == len; -#endif -} - -static int get_pid (int fd) -{ - int bytes_read, pid; -#if HAVE_V2_LOCKFILES - bytes_read = read (fd, &pid, sizeof (pid)); - if (bytes_read != sizeof (pid)) - pid = -1; -#else - char buf [32]; - bytes_read = read (fd, buf, sizeof (buf) - 1); - if (bytes_read > 0) { - buf [bytes_read] = '\0'; - pid = strtol (buf, (char **) NULL, 10); - } - else - pid = -1; -#endif - return pid; -} - -/* end of uucplock.c */ diff --git a/usr.bin/tip/tip/value.c b/usr.bin/tip/tip/value.c index ce29a21..20817e9 100644 --- a/usr.bin/tip/tip/value.c +++ b/usr.bin/tip/tip/value.c @@ -1,3 +1,6 @@ +/* $OpenBSD: value.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */ +/* $NetBSD: value.c,v 1.6 1997/02/11 09:24:09 mrg Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,7 +35,10 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)value.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: value.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; #endif /* not lint */ #include "tip.h" @@ -45,37 +51,42 @@ static int col = 0; /* * Variable manipulation */ +void vinit() { - register value_t *p; - register char *cp; + value_t *p; + char *cp; FILE *f; - char file[256]; + char file[FILENAME_MAX]; for (p = vtable; p->v_name != NULL; p++) { if (p->v_type&ENVIRON) - if (cp = getenv(p->v_name)) + if ((cp = getenv(p->v_name))) p->v_value = cp; if (p->v_type&IREMOTE) - number(p->v_value) = *address(p->v_value); + setnumber(p->v_value, *address(p->v_value)); } /* * Read the .tiprc file in the HOME directory * for sets */ - strcpy(file, value(HOME)); - strcat(file, "/.tiprc"); - if ((f = fopen(file, "r")) != NULL) { - register char *tp; - - while (fgets(file, sizeof(file)-1, f) != NULL) { - if (vflag) - printf("set %s", file); - if (tp = rindex(file, '\n')) - *tp = '\0'; - vlex(file); + if (strlen(value(HOME)) + sizeof("/.tiprc") > sizeof(file)) { + (void)fprintf(stderr, "Home directory path too long: %s\n", + value(HOME)); + } else { + snprintf(file, sizeof file, "%s/.tiprc", value(HOME)); + if ((f = fopen(file, "r")) != NULL) { + char *tp; + + while (fgets(file, sizeof(file)-1, f) != NULL) { + if (vflag) + printf("set %s", file); + if ((tp = strrchr(file, '\n'))) + *tp = '\0'; + vlex(file); + } + fclose(f); } - fclose(f); } /* * To allow definition of exception prior to fork @@ -86,8 +97,9 @@ vinit() static int vaccess(); /*VARARGS1*/ +void vassign(p, v) - register value_t *p; + value_t *p; char *v; { @@ -102,51 +114,51 @@ vassign(p, v) return; if (!(p->v_type&(ENVIRON|INIT))) free(p->v_value); - if ((p->v_value = malloc(size(v)+1)) == NOSTR) { + if ((p->v_value = strdup(v)) == NOSTR) { printf("out of core\r\n"); return; } p->v_type &= ~(ENVIRON|INIT); - strcpy(p->v_value, v); break; case NUMBER: if (number(p->v_value) == number(v)) return; - number(p->v_value) = number(v); + setnumber(p->v_value, number(v)); break; case BOOL: if (boolean(p->v_value) == (*v != '!')) return; - boolean(p->v_value) = (*v != '!'); + setboolean(p->v_value, (*v != '!')); break; case CHAR: if (character(p->v_value) == *v) return; - character(p->v_value) = *v; + setcharacter(p->v_value, *v); } p->v_access |= CHANGED; } static void vprint(); +static void vtoken(); +void vlex(s) - register char *s; + char *s; { - register value_t *p; - static void vtoken(); + value_t *p; if (equal(s, "all")) { for (p = vtable; p->v_name; p++) if (vaccess(p->v_access, READ)) vprint(p); } else { - register char *cp; + char *cp; do { - if (cp = vinterp(s, ' ')) + if ((cp = vinterp(s, ' '))) cp++; vtoken(s); s = cp; @@ -160,15 +172,15 @@ vlex(s) static void vtoken(s) - register char *s; + char *s; { - register value_t *p; - register char *cp; + value_t *p; + char *cp; char *expand(); - if (cp = index(s, '=')) { + if ((cp = strchr(s, '='))) { *cp = '\0'; - if (p = vlookup(s)) { + if ((p = vlookup(s))) { cp++; if (p->v_type&NUMBER) vassign(p, atoi(cp)); @@ -179,7 +191,7 @@ vtoken(s) } return; } - } else if (cp = index(s, '?')) { + } else if ((cp = strchr(s, '?'))) { *cp = '\0'; if ((p = vlookup(s)) && vaccess(p->v_access, READ)) { vprint(p); @@ -200,9 +212,9 @@ vtoken(s) static void vprint(p) - register value_t *p; + value_t *p; { - register char *cp; + char *cp; extern char *interp(), *ctrl(); if (col > 0 && col < MIDDLE) @@ -231,7 +243,7 @@ vprint(p) case NUMBER: col += 6; - printf("%s=%-5d", p->v_name, number(p->v_value)); + printf("%s=%-5ld", p->v_name, number(p->v_value)); break; case CHAR: @@ -254,7 +266,7 @@ vprint(p) static int vaccess(mode, rw) - register unsigned mode, rw; + unsigned mode, rw; { if (mode & (rw<<PUBLIC)) return (1); @@ -265,9 +277,9 @@ vaccess(mode, rw) static value_t * vlookup(s) - register char *s; + char *s; { - register value_t *p; + value_t *p; for (p = vtable; p->v_name; p++) if (equal(p->v_name, s) || (p->v_abrev && equal(p->v_abrev, s))) @@ -277,10 +289,10 @@ vlookup(s) char * vinterp(s, stop) - register char *s; + char *s; char stop; { - register char *p = s, c; + char *p = s, c; int num; while ((c = *s++) && c != stop) @@ -299,7 +311,7 @@ vinterp(s, stop) if (c >= '0' && c <= '7') num = (num<<3)+(c-'0'); else { - register char *q = "n\nr\rt\tb\bf\f"; + char *q = "n\nr\rt\tb\bf\f"; for (; *q; q++) if (c == *q++) { @@ -331,12 +343,12 @@ vinterp(s, stop) /* * assign variable s with value v (for NUMBER or STRING or CHAR types) */ - +int vstring(s,v) - register char *s; - register char *v; + char *s; + char *v; { - register value_t *p; + value_t *p; char *expand(); p = vlookup(s); diff --git a/usr.bin/tip/tip/vars.c b/usr.bin/tip/tip/vars.c index 5fad05a..6131dd2 100644 --- a/usr.bin/tip/tip/vars.c +++ b/usr.bin/tip/tip/vars.c @@ -1,3 +1,6 @@ +/* $OpenBSD: vars.c,v 1.2 1996/06/26 05:40:50 deraadt Exp $ */ +/* $NetBSD: vars.c,v 1.3 1994/12/08 09:31:19 jtc Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -32,10 +35,12 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)vars.c 8.1 (Berkeley) 6/6/93"; +#endif +static char rcsid[] = "$OpenBSD: vars.c,v 1.2 1996/06/26 05:40:50 deraadt Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" #include "pathnames.h" @@ -67,10 +72,6 @@ value_t vtable[] = { "ho", (char *)&HO }, { "log", STRING|INIT, (READ|WRITE)<<ROOT, NOSTR, _PATH_ACULOG }, - { "login", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "li", (char *)&LI }, - { "logout", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "lo", (char *)&LO }, { "phones", STRING|INIT|IREMOTE, READ<<PUBLIC, NOSTR, (char *)&PH }, { "prompt", CHAR, (READ|WRITE)<<PUBLIC, |