diff options
author | markm <markm@FreeBSD.org> | 2001-12-20 14:25:46 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 2001-12-20 14:25:46 +0000 |
commit | ea00e48044b4c63ff0b00ff8afa84d9a1ac54155 (patch) | |
tree | 735e71ebf880fba90adb57f05d2821e1c63de2df /usr.bin/tip | |
parent | 3551cbb12e15475b2d7b2e33119ddd9e4f857531 (diff) | |
download | FreeBSD-src-ea00e48044b4c63ff0b00ff8afa84d9a1ac54155.zip FreeBSD-src-ea00e48044b4c63ff0b00ff8afa84d9a1ac54155.tar.gz |
Fix merge conflicts, and because this still has a zillion warnings,
protect the build with a WARNS=2.
Fix the build.
Diffstat (limited to 'usr.bin/tip')
41 files changed, 1248 insertions, 3556 deletions
diff --git a/usr.bin/tip/Makefile b/usr.bin/tip/Makefile index 721823a..532431d 100644 --- a/usr.bin/tip/Makefile +++ b/usr.bin/tip/Makefile @@ -1,3 +1,5 @@ -SUBDIR=libacu tip +# $FreeBSD$ + +SUBDIR=tip .include <bsd.subdir.mk> diff --git a/usr.bin/tip/Makefile.inc b/usr.bin/tip/Makefile.inc index 3eb8d69..265f86d 100644 --- a/usr.bin/tip/Makefile.inc +++ b/usr.bin/tip/Makefile.inc @@ -1,6 +1,3 @@ -# These are mostly just for tip, but they're more visible up here. # $FreeBSD$ -BINDIR?= /usr/bin -BINOWN?= uucp -BINGRP?= dialer -BINMODE?= 4510 + +.include "../Makefile.inc" diff --git a/usr.bin/tip/README b/usr.bin/tip/README index 12d45b2..fb9af15 100644 --- a/usr.bin/tip/README +++ b/usr.bin/tip/README @@ -1,4 +1,4 @@ -[See NEWS file for much more up-to-date information] +# $FreeBSD$ Tip can be configured in a number of ways: diff --git a/usr.bin/tip/TODO b/usr.bin/tip/TODO index 41e2d6e..6aace38 100644 --- a/usr.bin/tip/TODO +++ b/usr.bin/tip/TODO @@ -1,22 +1,4 @@ -x Fix "hangup failed" in unidialer -x Genericize tty code and/or support termios -x Fixup uucplock conventions for FreeBSD (including reference in tip man pages). -Sanity check for ttys -x Rename pathnames.h -x Qualify on USR -Use select call to merge tipin / tipout - -x Finish table-driven modem driver -x Move HAVE_USLEEP to pathhnames.h -x Add variable for login and logout scripts (connect with Perl???) -x redials / redial delay (see dial shell script) - -Add debug log capabilities for table-driven modem driver (command mode modem I/Owith timestamps). - -Use select in modem drivers. -Consolidate consh()-derived code in cmds.c -Screen-oriented command menu? -Add external file-transfer protocol implementations to command menu (rz, sz, others?) +# $FreeBSD$ 1. Rethink protection glitches on REMOTE & PHONES files (setuid/setgid??). diff --git a/usr.bin/tip/libacu/Makefile b/usr.bin/tip/libacu/Makefile deleted file mode 100644 index 77a95cd..0000000 --- a/usr.bin/tip/libacu/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -LIB= acu -CFLAGS+= -I${.CURDIR}/../tip -SRCS= acucommon.c biz22.c courier.c df.c dn11.c hayes.c \ - multitech.c t3000.c tod.c unidialer.c v3451.c v831.c ventel.c -NOPROFILE= yes - -$(OBJS): ${.CURDIR}/../tip/tipconf.h - -install: - @echo -n - -.include <bsd.lib.mk> diff --git a/usr.bin/tip/libacu/acucommon.c b/usr.bin/tip/libacu/acucommon.c deleted file mode 100644 index efb644f..0000000 --- a/usr.bin/tip/libacu/acucommon.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)acucommon.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -/* - * Routines for calling up on a Courier modem. - * Derived from Hayes driver. - */ -#include "tipconf.h" -#include "tip.h" - -#include <err.h> - -#if HAVE_SELECT -#include <sys/types.h> -#include <sys/times.h> -#include <unistd.h> - -void acu_nap (unsigned int how_long) -{ - struct timeval t; - t.tv_usec = (how_long % 1000) * 1000; - t.tv_sec = how_long / 1000; - (void) select (0, NULL, NULL, NULL, &t); -} - -#elif HAVE_USLEEP -void acu_nap (unsigned int how_long) -{ - (void) usleep (how_long * 1000); -} - -#else - -/* - * Code stolen from /usr/src/lib/libc/gen/sleep.c - */ -#define mask(s) (1<<((s)-1)) -#define setvec(vec, a) \ - vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0 - -static int ringring; - -static void acunap_napx() -{ - ringring = 1; -} - -void acu_nap (unsigned int how_long) -{ - int omask; - struct itimerval itv, oitv; - register struct itimerval *itp = &itv; - struct sigvec vec, ovec; - - timerclear(&itp->it_interval); - timerclear(&itp->it_value); - if (setitimer(ITIMER_REAL, itp, &oitv) < 0) - return; - setvec(ovec, SIG_DFL); - omask = sigblock(mask(SIGALRM)); - itp->it_value.tv_sec = how_long / 1000; - itp->it_value.tv_usec = ((how_long % 1000) * 1000); - setvec(vec, acunap_napx); - ringring = 0; - (void) sigvec(SIGALRM, &vec, &ovec); - (void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0); - while (!ringring) - sigpause(omask &~ mask(SIGALRM)); - (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0); - (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0); - (void) sigsetmask(omask); -} - -#endif /* HAVE_USLEEP */ - -void acu_hw_flow_control (hw_flow_control) -{ -#if HAVE_TERMIOS - struct termios t; - if (tcgetattr (FD, &t) == 0) { - if (hw_flow_control) - t.c_cflag |= CRTSCTS; - else - t.c_cflag &= ~CRTSCTS; - tcsetattr (FD, TCSANOW, &t); - } -#endif /* HAVE_TERMIOS */ -} - -int acu_flush () -{ -#ifdef TIOCFLUSH - int flags = 0; - return (ioctl (FD, TIOCFLUSH, &flags) == 0); /* flush any clutter */ -#elif !HAVE_TERMIOS - struct sgttyb buf; - return (ioctl (FD, TIOCGETP, &buf) == 0 && ioctl (FD, TIOCSETP, &buf) == 0); -#endif -} - -int acu_getspeed () -{ -#if HAVE_TERMIOS - struct termios term; - tcgetattr (FD, &term); - return (term.c_ospeed); -#else /* HAVE_TERMIOS */ - struct sgttyb buf; - ioctl (FD, TIOCGETP, &buf); - return (buf.sg_ospeed); -#endif -} - -int acu_setspeed (int speed) -{ - int rc = 0; -#if HAVE_TERMIOS - struct termios term; - if (tcgetattr (FD, &term) == 0) { -#ifndef _POSIX_SOURCE - cfsetspeed (&term, speed); -#else - cfsetispeed (&term, speed); - cfsetospeed (&term, speed); -#endif - if (tcsetattr (FD, TCSANOW, &term) == 0) - ++rc; - } -#else /* HAVE TERMIOS */ - struct sgttyb sb; - if (ioctl(FD, TIOCGETP, &sb) < 0) { - warn("TIOCGETP"); - } - else { - sb.sg_ispeed = sb.sg_ospeed = speed; - if (ioctl(FD, TIOCSETP, &sb) < 0) { - warn("TIOCSETP"); - } - else - ++rc; - } -#endif /* HAVE TERMIOS */ - return (rc); -} - -void acu_hupcl () -{ -#if HAVE_TERMIOS - struct termios term; - tcgetattr (FD, &term); - term.c_cflag |= HUPCL; - tcsetattr (FD, TCSANOW, &term); -#elif defined(TIOCHPCL) - ioctl(FD, TIOCHPCL, 0); -#endif -} - -/* end of acucommon.c */ diff --git a/usr.bin/tip/libacu/acucommon.h b/usr.bin/tip/libacu/acucommon.h deleted file mode 100644 index 50d28cd..0000000 --- a/usr.bin/tip/libacu/acucommon.h +++ /dev/null @@ -1,6 +0,0 @@ -void acu_nap (unsigned int how_long); -void acu_hw_flow_control (int hw_flow_control); -int acu_flush (); -void acu_hupcl (); -int acu_setspeed (int speed); -/* end of acucommon.h */ diff --git a/usr.bin/tip/libacu/biz22.c b/usr.bin/tip/libacu/biz22.c index 63fb11c..2794ba7 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. @@ -31,11 +34,16 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint +#if 0 static char sccsid[] = "@(#)biz22.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: biz22.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; +#endif #endif /* not lint */ -#include "tipconf.h" #include "tip.h" #define DISCONNECT_CMD "\20\04" /* disconnection string */ @@ -44,6 +52,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 +64,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 +77,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 +97,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 +111,7 @@ biz_dialer(num, mod) return (connected); } +int biz22w_dialer(num, acu) char *num, *acu; { @@ -110,6 +119,7 @@ biz22w_dialer(num, acu) return (biz_dialer(num, "W")); } +int biz22f_dialer(num, acu) char *num, *acu; { @@ -117,15 +127,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 +152,7 @@ sigALRM() static int cmd(s) - register char *s; + char *s; { sig_t f; char c; @@ -164,7 +174,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..44b8a62 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. @@ -31,11 +34,16 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint +#if 0 static char sccsid[] = "@(#)biz31.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: biz31.c,v 1.6 2001/10/24 18:38:58 millert Exp $"; +#endif #endif /* not lint */ -#include "tipconf.h" #include "tip.h" #define MAXRETRY 3 /* sync up retry count */ @@ -54,7 +62,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 +90,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 +127,7 @@ biz31_disconnect() write(FD, DISCONNECT_CMD, 4); sleep(2); - ioctl(FD, TIOCFLUSH); + tcflush(FD, TCIOFLUSH); } biz31_abort() @@ -130,7 +138,7 @@ biz31_abort() static int echo(s) - register char *s; + char *s; { char c; @@ -162,7 +170,7 @@ sigALRM() static int detect(s) - register char *s; + char *s; { sig_t f; char c; @@ -187,7 +195,7 @@ detect(s) static int flush(s) - register char *s; + char *s; { sig_t f; char c; @@ -222,12 +230,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 df19573..67c7529 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. @@ -31,20 +34,23 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#if 0 +static char sccsid[] = "@(#)courier.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: courier.c,v 1.9 2001/10/24 18:38:58 millert Exp $"; #endif +#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> -#include <unistd.h> #define MAXRETRY 5 @@ -52,30 +58,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); @@ -86,7 +97,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; @@ -98,9 +109,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); } @@ -110,6 +121,7 @@ badsynch: return (connected); } +void cour_disconnect() { /* first hang up the modem*/ @@ -120,6 +132,7 @@ cour_disconnect() close(FD); } +void cour_abort() { cour_write(FD, "\r", 1); /* send anything to abort the call */ @@ -136,8 +149,8 @@ sigALRM() static int cour_swallow(match) - register char *match; - { + char *match; +{ sig_t f; char c; @@ -224,8 +237,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))) @@ -241,9 +258,7 @@ again: putchar(c); #endif } -error1: printf("%s\r\n", dialer_buf); -error: signal(SIGALRM, f); return (0); } @@ -260,7 +275,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); @@ -271,8 +286,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); } /* @@ -294,6 +309,7 @@ coursync() return (0); } +static void cour_write(fd, cp, n) int fd; char *cp; @@ -301,13 +317,13 @@ int n; { #ifdef notdef if (boolean(value(VERBOSE))) - write(STDOUT_FILENO, cp, n); + write(1, cp, n); #endif - acu_flush (); + tcdrain(fd); cour_nap(); for ( ; n-- ; cp++) { write(fd, cp, 1); - acu_flush (); + tcdrain(fd); cour_nap(); } } @@ -324,13 +340,18 @@ cour_verbose_read() return; if (read(FD, buf, n) != n) return; - write(STDOUT_FILENO, buf, n); + write(1, buf, n); } #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..1c8ee30 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. @@ -31,20 +34,26 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint +#if 0 static char sccsid[] = "@(#)df.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: df.c,v 1.5 2001/10/24 18:38:58 millert Exp $"; +#endif #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 +61,7 @@ df02_dialer(num, acu) return (df_dialer(num, acu, 0)); } +int df03_dialer(num, acu) char *num, *acu; { @@ -59,16 +69,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 +94,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 +107,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 6a2fc3e..ea78cce 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. @@ -29,32 +32,35 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint +#if 0 static char sccsid[] = "@(#)dn11.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: dn11.c,v 1.5 2001/11/19 19:02:16 mpech Exp $"; +#endif #endif /* not lint */ /* * Routines for dialing up on DN-11 */ -#include "tipconf.h" #include "tip.h" -#include <errno.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; { - 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..."); @@ -98,18 +104,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) ; @@ -133,6 +130,7 @@ alarmtr() * Insurance, for some reason we don't seem to be * hanging up... */ +void dn_disconnect() { @@ -142,6 +140,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 dcce6a5..8210fbf 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. @@ -31,8 +34,14 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint +#if 0 static char sccsid[] = "@(#)hayes.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: hayes.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; +#endif #endif /* not lint */ /* @@ -48,19 +57,21 @@ static char sccsid[] = "@(#)hayes.c 8.1 (Berkeley) 6/6/93"; * before modem is hung up, removal of the DTR signal * has no effect (except that it prevents the modem from * recognizing commands). - * (by Helge Skrivervik, Calma Company, Sunnyvale, CA. 1984) + * (by Helge Skrivervik, Calma Company, Sunnyvale, CA. 1984) */ /* * TODO: * It is probably not a good idea to switch the modem * state between 'verbose' and terse (status messages). - * This should be kicked out and we should use verbose + * This should be kicked out and we should use verbose * 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 +87,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 +104,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 +131,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 +145,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 +158,10 @@ hay_disconnect() goodbye(); } +void hay_abort() { - char c; - write(FD, "\r", 1); /* send anything to abort the call */ hay_disconnect(); } @@ -162,7 +177,7 @@ sigALRM() static char gobble(match) - register char *match; + char *match; { char c; sig_t f; @@ -196,8 +211,9 @@ gobble(match) return (status); } +static void error_rep(c) - register char c; + char c; { printf("\n\r"); switch (c) { @@ -209,23 +225,23 @@ error_rep(c) case '1': printf("CONNECT"); break; - + case '2': printf("RING"); break; - + case '3': printf("NO CARRIER"); break; - + case '4': printf("ERROR in input"); break; - + case '5': printf("CONNECT 1200"); break; - + default: printf("Unknown Modem error: %c (0x%x)", c, c); } @@ -236,16 +252,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 +290,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 +308,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/multitech.c b/usr.bin/tip/libacu/multitech.c deleted file mode 100644 index 2c3b2d9..0000000 --- a/usr.bin/tip/libacu/multitech.c +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright (c) 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif - -/* - * Routines for calling up on a Courier modem. - * Derived from Hayes driver. - */ -#include "tipconf.h" -#include "tip.h" -#include "acucommon.h" - -#include <stdio.h> -#include <unistd.h> - -/* #define DEBUG */ -#define MAXRETRY 5 -/* - Configuration -*/ -static CONST char *dial_command = "ATDT"; -static CONST char *hangup_command = "ATH\r"; -static CONST char *echo_off_command = "ATE0\r"; -static CONST char *reset_command = "\rATZ\r"; -static CONST char *init_string = "AT$BA0$SB38400&E1&E4&E13&E15Q0V1X4E0S0=0\r"; -static CONST char *escape_sequence = "+++"; /* return to command escape sequence */ -static CONST int lock_baud = 1; -static CONST unsigned int intercharacter_delay = 20; -static CONST unsigned int intercommand_delay = 250; -static CONST unsigned int escape_guard_time = 250; -static CONST unsigned int reset_delay = 2000; - -/* - Forward declarations -*/ -void multitech_write (int fd, CONST char *cp, int n); -void multitech_write_str (int fd, CONST char *cp); -void multitech_disconnect (); -void acu_nap (unsigned int how_long); -static void sigALRM (); -static int multitechsync (); -static int multitech_swallow (register char *match); - -/* - Global vars -*/ -static int timeout = 0; -static int connected = 0; -static jmp_buf timeoutbuf, intbuf; - -int multitech_dialer (register char *num, char *acu) -{ - register char *cp; -#if ACULOG - char line [80]; -#endif - static int multitech_connect(), multitech_swallow(); - - if (lock_baud) - { - int i; - if ((i = speed(number(value(BAUDRATE)))) == 0) - return 0; - ttysetup (i); - } - - if (boolean(value(VERBOSE))) - printf("Using \"%s\"\n", acu); - - acu_hupcl (); - - /* - * Get in synch. - */ - if (!multitechsync()) { -badsynch: - printf("can't synchronize with multitech\n"); -#if ACULOG - logent(value(HOST), num, "multitech", "can't synch up"); -#endif - return (0); - } - acu_nap (intercommand_delay); - - multitech_write_str (FD, echo_off_command); /* turn off echoing */ - - sleep(1); - -#ifdef DEBUG - if (boolean(value(VERBOSE))) - multitech_verbose_read(); -#endif - - acu_flush (); - - acu_nap (intercommand_delay); - multitech_write_str (FD, init_string); - - if (!multitech_swallow ("\r\nOK\r\n")) - goto badsynch; - - fflush (stdout); - - acu_nap (intercommand_delay); - multitech_write_str (FD, dial_command); - - for (cp = num; *cp; cp++) - if (*cp == '=') - *cp = ','; - - multitech_write_str (FD, num); - - multitech_write_str (FD, "\r"); - - connected = multitech_connect(); - -#if ACULOG - if (timeout) { - sprintf(line, "%d second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "multitech", line); - } -#endif - if (timeout) - multitech_disconnect (); - return (connected); -} - -void multitech_disconnect () -{ - int okay, retries; - for (retries = okay = 0; retries < 3 && !okay; retries++) - { - /* first hang up the modem*/ - ioctl (FD, TIOCCDTR, 0); - acu_nap (escape_guard_time); - ioctl (FD, TIOCSDTR, 0); - acu_nap (escape_guard_time); - /* - * If not strapped for DTR control, try to get command mode. - */ - acu_nap (escape_guard_time); - multitech_write_str (FD, escape_sequence); - acu_nap (escape_guard_time); - multitech_write_str (FD, hangup_command); - okay = multitech_swallow ("\r\nOK\r\n"); - } - if (!okay) - { - #if ACULOG - logent(value(HOST), "", "multitech", "can't hang up modem"); - #endif - if (boolean(value(VERBOSE))) - printf("hang up failed\n"); - } - close (FD); -} - -void multitech_abort () -{ - multitech_write_str (FD, "\r"); /* send anything to abort the call */ - multitech_disconnect (); -} - -static void sigALRM () -{ - (void) printf("\07timeout waiting for reply\n"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int multitech_swallow (register char *match) - { - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - do { - if (*match =='\0') { - signal(SIGALRM, f); - return (1); - } - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - return (0); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - c &= 0177; -#ifdef DEBUG - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } while (c == *match++); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - fflush (stdout); -#endif - signal(SIGALRM, SIG_DFL); - return (0); -} - -static struct baud_msg { - char *msg; - int baud; -} baud_msg[] = { - "", B300, - " 1200", B1200, - " 2400", B2400, - " 9600", B9600, - " 9600/ARQ", B9600, - 0, 0, -}; - -static int multitech_connect () -{ - char c; - int nc, nl, n; - char dialer_buf[64]; - struct baud_msg *bm; - sig_t f; - - if (multitech_swallow("\r\n") == 0) - return (0); - f = signal(SIGALRM, sigALRM); -again: - nc = 0; nl = sizeof(dialer_buf)-1; - bzero(dialer_buf, sizeof(dialer_buf)); - timeout = 0; - for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) { - if (setjmp(timeoutbuf)) - break; - alarm(number(value(DIALTIMEOUT))); - n = read(FD, &c, 1); - alarm(0); - if (n <= 0) - break; - c &= 0x7f; - if (c == '\r') { - if (multitech_swallow("\n") == 0) - break; - if (!dialer_buf[0]) - goto again; - if (strcmp(dialer_buf, "RINGING") == 0 && - boolean(value(VERBOSE))) { -#ifdef DEBUG - printf("%s\r\n", dialer_buf); -#endif - goto again; - } - if (strncmp(dialer_buf, "CONNECT", - sizeof("CONNECT")-1) != 0) - break; - if (lock_baud) { - signal(SIGALRM, f); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - printf("%s\r\n", dialer_buf); -#endif - return (1); - } - for (bm = baud_msg ; bm->msg ; bm++) - if (strcmp(bm->msg, dialer_buf+sizeof("CONNECT")-1) == 0) { - if (!acu_setspeed (bm->baud)) - goto error; - signal(SIGALRM, f); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - printf("%s\r\n", dialer_buf); -#endif - return (1); - } - break; - } - dialer_buf[nc] = c; - } -error1: - printf("%s\r\n", dialer_buf); -error: - signal(SIGALRM, f); - return (0); -} - -/* - * This convoluted piece of code attempts to get - * the multitech in sync. - */ -static int multitechsync () -{ - int already = 0; - int len; - char buf[40]; - - while (already++ < MAXRETRY) { - acu_nap (intercommand_delay); - ioctl (FD, TIOCFLUSH, 0); /* flush any clutter */ - multitech_write_str (FD, reset_command); /* reset modem */ - bzero(buf, sizeof(buf)); - acu_nap (reset_delay); - ioctl (FD, FIONREAD, &len); - if (len) { - len = read(FD, buf, sizeof(buf)); -#ifdef DEBUG - buf [len] = '\0'; - printf("multitechsync: (\"%s\")\n\r", buf); -#endif - if (index(buf, '0') || - (index(buf, 'O') && index(buf, 'K'))) - return(1); - } - /* - * If not strapped for DTR control, - * try to get command mode. - */ - acu_nap (escape_guard_time); - multitech_write_str (FD, escape_sequence); - acu_nap (escape_guard_time); - multitech_write_str (FD, hangup_command); - /* - * Toggle DTR to force anyone off that might have left - * the modem connected. - */ - acu_nap (escape_guard_time); - ioctl (FD, TIOCCDTR, 0); - acu_nap (escape_guard_time); - ioctl (FD, TIOCSDTR, 0); - } - acu_nap (intercommand_delay); - multitech_write_str (FD, reset_command); - return (0); -} - -void multitech_write_str (int fd, const char *cp) -{ -#ifdef DEBUG - printf ("multitech: sending %s\n", cp); -#endif - multitech_write (fd, cp, strlen (cp)); -} - -void multitech_write (int fd, const char *cp, int n) -{ - acu_flush (); - acu_nap (intercharacter_delay); - for ( ; n-- ; cp++) { - write (fd, cp, 1); - acu_flush (); - acu_nap (intercharacter_delay); - } -} - -#ifdef DEBUG -multitech_verbose_read() -{ - int n = 0; - char buf[BUFSIZ]; - - if (ioctl(FD, FIONREAD, &n) < 0) - return; - if (n <= 0) - return; - if (read(FD, buf, n) != n) - return; - write(STDOUT_FILENO, buf, n); -} -#endif - -/* end of multitech.c */ diff --git a/usr.bin/tip/libacu/t3000.c b/usr.bin/tip/libacu/t3000.c index b8caafe..627aae9 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. @@ -31,20 +34,24 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#if 0 +static char sccsid[] = "@(#)t3000.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $"; #endif +#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> -#include <unistd.h> #define MAXRETRY 5 @@ -52,29 +59,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); @@ -85,7 +96,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; @@ -97,9 +108,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); } @@ -109,6 +120,7 @@ badsynch: return (connected); } +void t3000_disconnect() { /* first hang up the modem*/ @@ -119,6 +131,7 @@ t3000_disconnect() close(FD); } +void t3000_abort() { t3000_write(FD, "\r", 1); /* send anything to abort the call */ @@ -135,8 +148,8 @@ sigALRM() static int t3000_swallow(match) - register char *match; - { + char *match; +{ sig_t f; char c; @@ -237,8 +250,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))) @@ -254,9 +271,7 @@ again: putchar(c); #endif } -error1: printf("%s\r\n", dialer_buf); -error: signal(SIGALRM, f); return (0); } @@ -273,7 +288,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); @@ -287,8 +302,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); } /* @@ -310,6 +325,7 @@ if (len == 0) len = 1; return (0); } +static int t3000_write(fd, cp, n) int fd; char *cp; @@ -317,13 +333,13 @@ int n; { #ifdef notdef if (boolean(value(VERBOSE))) - write(STDOUT_FILENO, cp, n); + write(1, cp, n); #endif - acu_flush (); + tcdrain(fd); t3000_nap(); for ( ; n-- ; cp++) { write(fd, cp, 1); - acu_flush (); + tcdrain(fd); t3000_nap(); } } @@ -340,13 +356,18 @@ t3000_verbose_read() return; if (read(FD, buf, n) != n) return; - write(STDOUT_FILENO, buf, n); + write(1, buf, n); } #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/tod.c b/usr.bin/tip/libacu/tod.c deleted file mode 100644 index f585063..0000000 --- a/usr.bin/tip/libacu/tod.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * tod.c -- time of day pseudo-class implementation - * - * Copyright (c) 1995 John H. Poplett - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice immediately at the beginning of the file, without modification, - * this list of conditions, and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Absolutely no warranty of function or purpose is made by the author - * John H. Poplett. - * 4. This work was done expressly for inclusion into FreeBSD. Other use - * is allowed if this notation is included. - * 5. Modifications may be freely made to this file if the above conditions - * are met. - * - */ - -#include <sys/types.h> -#include <sys/time.h> - -#include <assert.h> -#include <stdio.h> - -#include "tod.h" - -#define USP 1000000 - -int tod_cmp (const struct timeval *a, const struct timeval *b) -{ - int rc; - assert (a->tv_usec <= USP); - assert (b->tv_usec <= USP); - rc = a->tv_sec - b->tv_sec; - if (rc == 0) - rc = a->tv_usec - b->tv_usec; - return rc; -} - -/* - TOD < command -*/ -int tod_lt (const struct timeval *a, const struct timeval *b) -{ - return tod_cmp (a, b) < 0; -} - -int tod_gt (const struct timeval *a, const struct timeval *b) -{ - return tod_cmp (a, b) > 0; -} - -int tod_lte (const struct timeval *a, const struct timeval *b) -{ - return tod_cmp (a, b) <= 0; -} - -int tod_gte (const struct timeval *a, const struct timeval *b) -{ - return tod_cmp (a, b) >= 0; -} - -int tod_eq (const struct timeval *a, const struct timeval *b) -{ - return tod_cmp (a, b) == 0; -} - -/* - TOD += command -*/ -void tod_addto (struct timeval *a, const struct timeval *b) -{ - a->tv_usec += b->tv_usec; - a->tv_sec += b->tv_sec + a->tv_usec / USP; - a->tv_usec %= USP; -} - -/* - TOD -= command -*/ -void tod_subfrom (struct timeval *a, struct timeval b) -{ - assert (a->tv_usec <= USP); - assert (b.tv_usec <= USP); - if (b.tv_usec > a->tv_usec) - { - a->tv_usec += USP; - a->tv_sec -= 1; - } - a->tv_usec -= b.tv_usec; - a->tv_sec -= b.tv_sec; -} - -void tod_gettime (struct timeval *tp) -{ - gettimeofday (tp, NULL); - tp->tv_sec += tp->tv_usec / USP; - tp->tv_usec %= USP; -} - -/* end of tod.c */ diff --git a/usr.bin/tip/libacu/tod.h b/usr.bin/tip/libacu/tod.h deleted file mode 100644 index d772230..0000000 --- a/usr.bin/tip/libacu/tod.h +++ /dev/null @@ -1,9 +0,0 @@ -int tod_cmp (const struct timeval *a, const struct timeval *b); -int tod_lt (const struct timeval *a, const struct timeval *b) ; -int tod_gt (const struct timeval *a, const struct timeval *b); -int tod_lte (const struct timeval *a, const struct timeval *b); -int tod_gte (const struct timeval *a, const struct timeval *b); -int tod_eq (const struct timeval *a, const struct timeval *b); -void tod_addto (struct timeval *a, const struct timeval *b); -void tod_subfrom (struct timeval *a, struct timeval b); -void tod_gettime (struct timeval *tp); diff --git a/usr.bin/tip/libacu/unidialer.c b/usr.bin/tip/libacu/unidialer.c deleted file mode 100644 index 6fcec2f..0000000 --- a/usr.bin/tip/libacu/unidialer.c +++ /dev/null @@ -1,806 +0,0 @@ -/* - * Copyright (c) 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)unidialer.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -/* - * Generalized routines for calling up on a Hayes AT command set based modem. - * Control variables are pulled out of a modem caps-style database to - * configure the driver for a particular modem. - */ -#include "tipconf.h" -#include "tip.h" -#include "pathnames.h" - -#include <sys/times.h> -#include <assert.h> -#include <err.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include "acucommon.h" -#include "tod.h" - -/* #define DEBUG */ -#define MAXRETRY 5 - -typedef enum -{ - mpt_notype, mpt_string, mpt_number, mpt_boolean -} modem_parm_type_t; - -typedef struct { - modem_parm_type_t modem_parm_type; - const char *name; - union { - char **string; - unsigned int *number; - } value; - union { - char *string; - unsigned int number; - } default_value; -} modem_parm_t; - -/* - Configuration -*/ -static char modem_name [80]; -static char *dial_command; -static char *hangup_command; -static char *echo_off_command; -static char *reset_command; -static char *init_string; -static char *escape_sequence; -static int hw_flow_control; -static int lock_baud; -static unsigned int intercharacter_delay; -static unsigned int intercommand_delay; -static unsigned int escape_guard_time; -static unsigned int reset_delay; - -static int unidialer_dialer (register char *num, char *acu); -static void unidialer_disconnect (); -static void unidialer_abort (); - -static acu_t unidialer = -{ - modem_name, - unidialer_dialer, - unidialer_disconnect, - unidialer_abort -}; - -/* - Table of parameters kept in modem database -*/ -modem_parm_t modem_parms [] = { - { mpt_string, "dial_command", &dial_command, "ATDT%s\r" }, - { mpt_string, "hangup_command", &hangup_command, "ATH\r", }, - { mpt_string, "echo_off_command", &echo_off_command, "ATE0\r" }, - { mpt_string, "reset_command", &reset_command, "ATZ\r" }, - { mpt_string, "init_string", &init_string, "AT&F\r", }, - { mpt_string, "escape_sequence", &escape_sequence, "+++" }, - { mpt_boolean, "hw_flow_control", (char **)&hw_flow_control, NULL }, - { mpt_boolean, "lock_baud", (char **)&lock_baud, NULL }, - { mpt_number, "intercharacter_delay", (char **)&intercharacter_delay, (char *)50 }, - { mpt_number, "intercommand_delay", (char **)&intercommand_delay, (char *)300 }, - { mpt_number, "escape_guard_time", (char **)&escape_guard_time, (char *)300 }, - { mpt_number, "reset_delay", (char **)&reset_delay, (char *)3000 }, - { mpt_notype, NULL, NULL, NULL } -}; - -/* - Forward declarations -*/ -static void unidialer_verbose_read (); -static void unidialer_modem_cmd (int fd, CONST char *cmd); -static void unidialer_write (int fd, CONST char *cp, int n); -static void unidialer_write_str (int fd, CONST char *cp); -static void unidialer_disconnect (); -static void sigALRM (); -static int unidialersync (); -static int unidialer_swallow (register char *match); - -/* - Global vars -*/ -static int timeout = 0; -static int connected = 0; -static jmp_buf timeoutbuf, intbuf; - -#define cgetflag(f) (cgetcap(bp, f, ':') != NULL) - -#ifdef DEBUG - -#define print_str(x) printf (#x " = %s\n", x) -#define print_num(x) printf (#x " = %d\n", x) - -void dumpmodemparms (char *modem) -{ - printf ("modem parms for %s\n", modem); - print_str (dial_command); - print_str (hangup_command); - print_str (echo_off_command); - print_str (reset_command); - print_str (init_string); - print_str (escape_sequence); - print_num (lock_baud); - print_num (intercharacter_delay); - print_num (intercommand_delay); - print_num (escape_guard_time); - print_num (reset_delay); - printf ("\n"); -} -#endif - -static int getmodemparms (const char *modem) -{ - char *bp, *db_array [3], *modempath; - int ndx, stat; - modem_parm_t *mpp; - - modempath = getenv ("MODEMS"); - - ndx = 0; - - if (modempath != NULL) - db_array [ndx++] = modempath; - - db_array [ndx++] = _PATH_MODEMS; - db_array [ndx] = NULL; - - if ((stat = cgetent (&bp, db_array, (char *)modem)) < 0) { - switch (stat) { - case -1: - warnx ("unknown modem %s", modem); - break; - case -2: - warnx ("can't open modem description file"); - break; - case -3: - warnx ("possible reference loop in modem description file"); - break; - } - return 0; - } - for (mpp = modem_parms; mpp->name; mpp++) - { - switch (mpp->modem_parm_type) - { - case mpt_string: - if (cgetstr (bp, (char *)mpp->name, mpp->value.string) == -1) - *mpp->value.string = mpp->default_value.string; - break; - - case mpt_number: - { - long l; - if (cgetnum (bp, (char *)mpp->name, &l) == -1) - *mpp->value.number = mpp->default_value.number; - else - *mpp->value.number = (unsigned int)l; - } - break; - - case mpt_boolean: - *mpp->value.number = cgetflag ((char *)mpp->name); - break; - } - } - strncpy (modem_name, modem, sizeof (modem_name) - 1); - modem_name [sizeof (modem_name) - 1] = '\0'; - return 1; -} - -/* -*/ -acu_t* unidialer_getmodem (const char *modem_name) -{ - acu_t* rc = NOACU; - if (getmodemparms (modem_name)) - rc = &unidialer; - return rc; -} - -static int unidialer_modem_ready () -{ -#ifdef TIOCMGET - int state; - ioctl (FD, TIOCMGET, &state); - return (state & TIOCM_DSR) ? 1 : 0; -#else - return (1); -#endif -} - -static int unidialer_waitfor_modem_ready (int ms) -{ -#ifdef TIOCMGET - int count; - for (count = 0; count < ms; count += 100) - { - if (unidialer_modem_ready ()) - { -#ifdef DEBUG - printf ("unidialer_waitfor_modem_ready: modem ready.\n"); -#endif - break; - } - acu_nap (100); - } - return (count < ms); -#else - acu_nap (250); - return (1); -#endif -} - -int unidialer_tty_clocal (int flag) -{ -#if HAVE_TERMIOS - struct termios t; - tcgetattr (FD, &t); - if (flag) - t.c_cflag |= CLOCAL; - else - t.c_cflag &= ~CLOCAL; - tcsetattr (FD, TCSANOW, &t); -#elif defined(TIOCMSET) - int state; - /* - Don't have CLOCAL so raise CD in software to - get the same effect. - */ - ioctl (FD, TIOCMGET, &state); - if (flag) - state |= TIOCM_CD; - else - state &= ~TIOCM_CD; - ioctl (FD, TIOCMSET, &state); -#endif -} - -int unidialer_get_modem_response (char *buf, int bufsz, int response_timeout) -{ - sig_t f; - char c, *p = buf, *lid = buf + bufsz - 1; - int state; - - assert (bufsz > 0); - - f = signal (SIGALRM, sigALRM); - - timeout = 0; - - if (setjmp (timeoutbuf)) { - signal (SIGALRM, f); - *p = '\0'; -#ifdef DEBUG - printf ("get_response: timeout buf=%s, state=%d\n", buf, state); -#endif - return (0); - } - - ualarm (response_timeout * 1000, 0); - - state = 0; - - while (1) - { - switch (state) - { - case 0: - if (read (FD, &c, 1) == 1) - { - if (c == '\r') - { - ++state; - } - else - { -#ifdef DEBUG - printf ("get_response: unexpected char %s.\n", ctrl (c)); -#endif - } - } - break; - - case 1: - if (read (FD, &c, 1) == 1) - { - if (c == '\n') - { -#ifdef DEBUG - printf ("get_response: <CRLF> encountered.\n", buf); -#endif - ++state; - } - else - { - state = 0; -#ifdef DEBUG - printf ("get_response: unexpected char %s.\n", ctrl (c)); -#endif - } - } - break; - - case 2: - if (read (FD, &c, 1) == 1) - { - if (c == '\r') - ++state; - else if (c >= ' ' && p < lid) - *p++ = c; - } - break; - - case 3: - if (read (FD, &c, 1) == 1) - { - if (c == '\n') - { - signal (SIGALRM, f); - /* ualarm (0, 0); */ - alarm (0); - *p = '\0'; -#ifdef DEBUG - printf ("get_response: %s\n", buf); -#endif - return (1); - } - else - { - state = 0; - p = buf; - } - } - break; - } - } -} - -int unidialer_get_okay (int ms) -{ - int okay; - char buf [BUFSIZ]; - okay = unidialer_get_modem_response (buf, sizeof (buf), ms) && - strcmp (buf, "OK") == 0; - return okay; -} - -static int unidialer_dialer (register char *num, char *acu) -{ - register char *cp; - char dial_string [80]; -#if ACULOG - char line [80]; -#endif - static int unidialer_connect(), unidialer_swallow(); - - #ifdef DEBUG - dumpmodemparms (modem_name); - #endif - - if (lock_baud) { - int i; - if ((i = speed(number(value(BAUDRATE)))) == 0) - return 0; - ttysetup (i); - } - - if (boolean(value(VERBOSE))) - printf("Using \"%s\"\n", acu); - - acu_hupcl (); - - /* - * Get in synch. - */ - if (!unidialersync()) { -badsynch: - printf("tip: can't synchronize with %s\n", modem_name); -#if ACULOG - logent(value(HOST), num, modem_name, "can't synch up"); -#endif - return (0); - } - - unidialer_modem_cmd (FD, echo_off_command); /* turn off echoing */ - - sleep(1); - -#ifdef DEBUG - if (boolean(value(VERBOSE))) - unidialer_verbose_read(); -#endif - - acu_flush (); /* flush any clutter */ - - unidialer_modem_cmd (FD, init_string); - - if (!unidialer_get_okay (reset_delay)) - goto badsynch; - - fflush (stdout); - - for (cp = num; *cp; cp++) - if (*cp == '=') - *cp = ','; - - (void) sprintf (dial_string, dial_command, num); - - unidialer_modem_cmd (FD, dial_string); - - connected = unidialer_connect (); - - if (connected && hw_flow_control) { - acu_hw_flow_control (hw_flow_control); - } - -#if ACULOG - if (timeout) { - sprintf(line, "%d second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, modem_name, line); - } -#endif - - if (timeout) - unidialer_disconnect (); - - return (connected); -} - -static void unidialer_disconnect () -{ - int okay, retries; - - acu_flush (); /* flush any clutter */ - - unidialer_tty_clocal (TRUE); - - /* first hang up the modem*/ - ioctl (FD, TIOCCDTR, 0); - acu_nap (250); - ioctl (FD, TIOCSDTR, 0); - - /* - * If AT&D2, then dropping DTR *should* just hangup the modem. But - * some modems reset anyway; also, the modem may be programmed to reset - * anyway with AT&D3. Play it safe and wait for the full reset time before - * proceeding. - */ - acu_nap (reset_delay); - - if (!unidialer_waitfor_modem_ready (reset_delay)) - { -#ifdef DEBUG - printf ("unidialer_disconnect: warning CTS low.\r\n"); -#endif - } - - /* - * If not strapped for DTR control, try to get command mode. - */ - for (retries = okay = 0; retries < MAXRETRY && !okay; retries++) - { - int timeout_value; - /* flush any clutter */ - if (!acu_flush ()) - { -#ifdef DEBUG - printf ("unidialer_disconnect: warning flush failed.\r\n"); -#endif - } - timeout_value = escape_guard_time; - timeout_value += (timeout_value * retries / MAXRETRY); - acu_nap (timeout_value); - acu_flush (); /* flush any clutter */ - unidialer_modem_cmd (FD, escape_sequence); - acu_nap (timeout_value); - unidialer_modem_cmd (FD, hangup_command); - okay = unidialer_get_okay (reset_delay); - } - if (!okay) - { - #if ACULOG - logent(value(HOST), "", modem_name, "can't hang up modem"); - #endif - if (boolean(value(VERBOSE))) - printf("hang up failed\n"); - } - (void) acu_flush (); - close (FD); -} - -static void unidialer_abort () -{ - unidialer_write_str (FD, "\r"); /* send anything to abort the call */ - unidialer_disconnect (); -} - -static void sigALRM () -{ - (void) printf("\07timeout waiting for reply\n"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int unidialer_swallow (register char *match) -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - - timeout = 0; - - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - return (0); - } - - alarm(number(value(DIALTIMEOUT))); - - do { - if (*match =='\0') { - signal(SIGALRM, f); - alarm (0); - return (1); - } - do { - read (FD, &c, 1); - } while (c == '\0'); - c &= 0177; -#ifdef DEBUG - if (boolean(value(VERBOSE))) - { - /* putchar(c); */ - printf (ctrl (c)); - } -#endif - } while (c == *match++); - signal(SIGALRM, SIG_DFL); - alarm(0); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - fflush (stdout); -#endif - return (0); -} - -static struct baud_msg { - char *msg; - int baud; -} baud_msg[] = { - "", B300, - " 1200", B1200, - " 2400", B2400, - " 9600", B9600, - " 9600/ARQ", B9600, - 0, 0, -}; - -static int unidialer_connect () -{ - char c; - int nc, nl, n; - char dialer_buf[64]; - struct baud_msg *bm; - sig_t f; - - if (unidialer_swallow("\r\n") == 0) - return (0); - f = signal(SIGALRM, sigALRM); -again: - nc = 0; nl = sizeof(dialer_buf)-1; - bzero(dialer_buf, sizeof(dialer_buf)); - timeout = 0; - for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) { - if (setjmp(timeoutbuf)) - break; - alarm(number(value(DIALTIMEOUT))); - n = read(FD, &c, 1); - alarm(0); - if (n <= 0) - break; - c &= 0x7f; - if (c == '\r') { - if (unidialer_swallow("\n") == 0) - break; - if (!dialer_buf[0]) - goto again; - if (strcmp(dialer_buf, "RINGING") == 0 && - boolean(value(VERBOSE))) { -#ifdef DEBUG - printf("%s\r\n", dialer_buf); -#endif - goto again; - } - if (strncmp(dialer_buf, "CONNECT", - sizeof("CONNECT")-1) != 0) - break; - if (lock_baud) { - signal(SIGALRM, f); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - printf("%s\r\n", dialer_buf); -#endif - return (1); - } - for (bm = baud_msg ; bm->msg ; bm++) - if (strcmp(bm->msg, dialer_buf+sizeof("CONNECT")-1) == 0) { - if (!acu_setspeed (bm->baud)) - goto error; - signal(SIGALRM, f); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - printf("%s\r\n", dialer_buf); -#endif - return (1); - } - break; - } - dialer_buf[nc] = c; - } -error1: - printf("%s\r\n", dialer_buf); -error: - signal(SIGALRM, f); - return (0); -} - -/* - * This convoluted piece of code attempts to get - * the unidialer in sync. - */ -static int unidialersync () -{ - int already = 0; - int len; - char buf[40]; - - while (already++ < MAXRETRY) { - acu_nap (intercommand_delay); - acu_flush (); /* flush any clutter */ - unidialer_write_str (FD, reset_command); /* reset modem */ - bzero(buf, sizeof(buf)); - acu_nap (reset_delay); - ioctl (FD, FIONREAD, &len); - if (len) { - len = read(FD, buf, sizeof(buf)); -#ifdef DEBUG - buf [len] = '\0'; - printf("unidialersync (%s): (\"%s\")\n\r", modem_name, buf); -#endif - if (index(buf, '0') || - (index(buf, 'O') && index(buf, 'K'))) - return(1); - } - /* - * If not strapped for DTR control, - * try to get command mode. - */ - acu_nap (escape_guard_time); - unidialer_write_str (FD, escape_sequence); - acu_nap (escape_guard_time); - unidialer_write_str (FD, hangup_command); - /* - * Toggle DTR to force anyone off that might have left - * the modem connected. - */ - acu_nap (escape_guard_time); - ioctl (FD, TIOCCDTR, 0); - acu_nap (1000); - ioctl (FD, TIOCSDTR, 0); - } - acu_nap (intercommand_delay); - unidialer_write_str (FD, reset_command); - return (0); -} - -/* - Send commands to modem; impose delay between commands. -*/ -static void unidialer_modem_cmd (int fd, const char *cmd) -{ - static struct timeval oldt = { 0, 0 }; - struct timeval newt; - tod_gettime (&newt); - if (tod_lt (&newt, &oldt)) - { - unsigned int naptime; - tod_subfrom (&oldt, newt); - naptime = oldt.tv_sec * 1000 + oldt.tv_usec / 1000; - if (naptime > intercommand_delay) - { -#ifdef DEBUG - printf ("unidialer_modem_cmd: suspicious naptime (%u ms)\r\n", naptime); -#endif - naptime = intercommand_delay; - } -#ifdef DEBUG - printf ("unidialer_modem_cmd: delaying %u ms\r\n", naptime); -#endif - acu_nap (naptime); - } - unidialer_write_str (fd, cmd); - tod_gettime (&oldt); - newt.tv_sec = 0; - newt.tv_usec = intercommand_delay; - tod_addto (&oldt, &newt); -} - -static void unidialer_write_str (int fd, const char *cp) -{ -#ifdef DEBUG - printf ("unidialer (%s): sending %s\n", modem_name, cp); -#endif - unidialer_write (fd, cp, strlen (cp)); -} - -static void unidialer_write (int fd, const char *cp, int n) -{ - acu_nap (intercharacter_delay); - for ( ; n-- ; cp++) { - write (fd, cp, 1); - acu_nap (intercharacter_delay); - } -} - -#ifdef DEBUG -static void unidialer_verbose_read() -{ - int n = 0; - char buf[BUFSIZ]; - - if (ioctl(FD, FIONREAD, &n) < 0) - return; - if (n <= 0) - return; - if (read(FD, buf, n) != n) - return; - write(STDOUT_FILENO, buf, n); -} -#endif - -/* end of unidialer.c */ diff --git a/usr.bin/tip/libacu/v3451.c b/usr.bin/tip/libacu/v3451.c index a98c4d4..df850a5 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. @@ -31,31 +34,36 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint +#if 0 static char sccsid[] = "@(#)v3451.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: v3451.c,v 1.6 2001/10/24 18:38:58 millert Exp $"; +#endif #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 +74,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 +110,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 +121,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 +146,7 @@ v3451_abort() static void vawrite(cp, delay) - register char *cp; + char *cp; int delay; { @@ -143,15 +154,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 +203,6 @@ static int notin(sh, lg) char *sh, *lg; { - static int prefix(); for (; *lg; lg++) if (prefix(sh, lg)) @@ -202,11 +210,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 e02121c..5a6268e 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. @@ -29,33 +32,38 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint +#if 0 static char sccsid[] = "@(#)v831.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: v831.c,v 1.6 2001/11/19 19:02:16 mpech Exp $"; +#endif #endif /* not lint */ /* * Routines for dialing up on Vadic 831 */ -#include "tipconf.h" #include "tip.h" -#include <errno.h> +#include <termios.h> -int v831_abort(); +void v831_abort(); static void alarmtr(); +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..."); @@ -104,9 +112,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) ; @@ -128,20 +133,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() { @@ -152,7 +164,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); @@ -180,13 +192,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 @@ -201,28 +213,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); @@ -257,10 +254,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 08f2be5..c3b87ae 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. @@ -31,21 +34,23 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)ventel.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: ventel.c,v 1.7 2001/11/19 19:02:16 mpech Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #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 <err.h> +#include <termios.h> +#include <sys/ioctl.h> #define MAXRETRY 5 @@ -53,6 +58,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 @@ -60,25 +68,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); @@ -86,7 +94,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); @@ -97,10 +107,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); } @@ -110,10 +120,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) { @@ -130,12 +140,14 @@ ven_dialer(num, acu) return (connected); } +void ven_disconnect() { close(FD); } +void ven_abort() { @@ -145,7 +157,7 @@ ven_abort() static void echo(s) - register char *s; + char *s; { char c; @@ -177,10 +189,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; @@ -240,7 +252,7 @@ vensync(fd) write(fd, "\r", 1); sleep(2); if (ioctl(fd, FIONREAD, (caddr_t)&nread) < 0) { - warn("ioctl"); + perror("tip: ioctl"); continue; } while (nread > 0) { diff --git a/usr.bin/tip/tip/Makefile b/usr.bin/tip/tip/Makefile index ec0ba0f..253892c 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 $ # $FreeBSD$ # # Files are: @@ -7,29 +7,46 @@ # mode 6?? # /var/log/aculog ACU accounting file, owned by ${OWNER} and # mode 6?? {if ACULOG defined} - -.if exists(${.OBJDIR}/../libacu) -LIBACU=${.OBJDIR}/../libacu/libacu.a -.else -LIBACU=${.CURDIR}/../libacu/libacu.a -.endif +# 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 -DPADD= ${LIBACU} ${LIBUTIL} -LDADD= ${LIBACU} -lutil LINKS= ${BINDIR}/tip ${BINDIR}/cu -MAN= tip.1 modems.5 MLINKS= tip.1 cu.1 +CFLAGS+=-I${.CURDIR} \ + -DDEFBR=9600 -DDEFFS=BUFSIZ -DACULOG -DPRISTINE -DCONNECT \ + -DV831 -DVENTEL -DHAYES -DCOURIER -DT3000 +WARNS?= 0 +.PATH: ${.CURDIR}/../libacu SRCS= acu.c acutab.c cmds.c cmdtab.c cu.c hunt.c log.c partab.c \ - remote.c tip.c tipout.c value.c vars.c - -BINDIR?= /usr/bin -BINOWN= uucp -BINGRP= dialer -#BINMODE?= 4510 + 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 -# XXX: there is some concern that `tip' in its current state shouldn't run -# SUID. If it believed it should, the mode above may still no be proper. +# -- 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 # Dirty, rotten hack. This can be removed when we are confident that there # is no cu(1) with the schg-bit set. diff --git a/usr.bin/tip/tip/acu.c b/usr.bin/tip/tip/acu.c index 3ee0381..b13d7c9 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. @@ -31,25 +34,22 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)acu.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: acu.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #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(); -static acu_t *acutype(); +static void acuabort __P((int)); +static acu_t *acutype __P((char *)); static jmp_buf jmpbuf; /* * Establish connection for tip @@ -67,17 +67,17 @@ static jmp_buf jmpbuf; * for a single host acting as a rotary (in the order * found in the file). */ -char * +const 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) - xpwrite(FD, CM, size(CM)); + parwrite(FD, CM, size(CM)); logent(value(HOST), "", DV, "call completed"); return (NOSTR); } @@ -93,7 +93,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 @@ -105,20 +105,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) - xpwrite(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 { @@ -127,45 +126,41 @@ 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 ((conflag = (*acu->acu_dialer)(phnum, CU))) { - fclose(fd); - if (CM != NOSTR) - xpwrite(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 (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; + + 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 @@ -180,13 +175,14 @@ disconnect(reason) logent(value(HOST), "", acu->acu_name, "call terminated"); if (boolean(value(VERBOSE))) printf("\r\ndisconnecting..."); - } else + } else logent(value(HOST), "", acu->acu_name, reason); (*acu->acu_disconnect)(); } static void acuabort(s) + int s; { signal(s, SIG_IGN); longjmp(jmpbuf, 1); @@ -194,18 +190,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 2d38c7d..33601c2 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. @@ -31,43 +34,18 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)acutab.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: acutab.c,v 1.2 1996/06/26 05:40:41 deraadt Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" -extern int df02_dialer(), df03_dialer(), - biz31f_dialer(), - biz31w_dialer(), - biz22f_dialer(), - 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(); - acu_t acutable[] = { #if BIZ1031 "biz31f", biz31f_dialer, biz31_disconnect, biz31_abort, @@ -86,29 +64,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 28b03ef..a5fe28e 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. @@ -31,24 +34,20 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: cmds.c,v 1.13 2001/10/24 18:38:58 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" #include "pathnames.h" -#include <sys/types.h> -#include <sys/wait.h> -#include <err.h> -#include <libutil.h> -#include <stdio.h> -#include <unistd.h> +#include <vis.h> /* * tip @@ -63,69 +62,8 @@ char *sep[] = { "second", "minute", "hour" }; static char *argv[10]; /* argument vector for take and put */ void timeout(); /* timeout function called on alarm */ -static void stopsnd(); /* SIGINT handler during file transfers */ -static void intcopy(); /* interrupt routine for file transfers */ - -void suspend __P((char)); -void genbrk __P((void)); -void variable __P((void)); -void finish __P((void)); -void tipabort __P((char *)); -void chdirectory __P((void)); -void shell __P((void)); -void cu_put __P((char)); -void sendfile __P((char)); -void pipefile __P((void)); -void cu_take __P((char)); -void getfl __P((char)); - -static int anyof __P((char *, char *)); -static void tandem __P((char *)); -static void prtime __P((char *, time_t)); -static int args __P((char *, char **, int)); -static void execute __P((char *)); -static void send __P((char)); -static void transmit __P((FILE *, char *, char *)); -static void transfer __P((char *, int, char *)); -static void xfer __P((char *, int, char *)); - -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 -} +void stopsnd(); /* SIGINT handler during file transfers */ +void intcopy(); /* interrupt routine for file transfers */ /* * FTP - remote ==> local @@ -136,7 +74,7 @@ getfl(c) char c; { char buf[256], *cp, *expand(); - + putchar(c); /* * get the UNIX receiving file's name @@ -148,7 +86,7 @@ getfl(c) printf("\r\n%s: cannot creat\r\n", copyname); return; } - + /* * collect parameters */ @@ -171,7 +109,8 @@ cu_take(cc) if (prompt("[take] ", copyname, sizeof(copyname))) return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || argc > 2) { + if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || + argc > 2) { printf("usage: <take> from [to]\r\n"); return; } @@ -182,143 +121,50 @@ cu_take(cc) printf("\r\n%s: cannot create\r\n", argv[1]); return; } - (void)snprintf(line, sizeof(line), "cat %s ; echo \"\" ; echo ___tip_end_of_file_marker___", argv[0]); - xfer(line, fd, "\n___tip_end_of_file_marker___\n"); + (void)snprintf(line, sizeof(line), "cat %s;echo \01", argv[0]); + transfer(line, fd, "\01"); } -static jmp_buf intbuf; - -static void -xfer(buf, fd, eofchars) - char *buf, *eofchars; -{ - int ct; - char c, *match; - int cnt, eof, v; - time_t start; - sig_t f; - char r; - FILE *ff; - - v = boolean(value(VERBOSE)); - - if ((ff = fdopen (fd, "w")) == NULL) { - warn("file open"); - return; - } - if ((cnt = number(value(FRAMESIZE))) != BUFSIZ) - if (setvbuf(ff, NULL, _IOFBF, cnt) != 0) { - warn("file allocation"); - (void)fclose(ff); - return; - } - - xpwrite(FD, buf, size(buf)); - quit = 0; - kill(pid, SIGIOT); - read(repdes[0], (char *)&ccc, 1); /* Wait until read process stops */ - - /* - * finish command - */ - r = '\r'; - xpwrite(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); -} +static jmp_buf intbuf; /* * Bulk transfer routine -- * used by getfl(), cu_take(), and pipefile() */ -static void +void transfer(buf, fd, eofchars) char *buf, *eofchars; + int fd; { - register int ct; - char c; - register int cnt, eof, v; + int ct; + char c, buffer[BUFSIZ]; + 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) { - warn("file open"); - return; - } - if ((cnt = number(value(FRAMESIZE))) != BUFSIZ) - if (setvbuf(ff, NULL, _IOFBF, cnt) != 0) { - warn("file allocation"); - (void)fclose(ff); - return; - } - - xpwrite(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 */ - + /* * finish command */ r = '\r'; - xpwrite(FD, &r, 1); + parwrite(FD, &r, 1); do - read(FD, &c, 1); - while ((c&0177) != '\n'); - usedefchars (); + read(FD, &c, 1); + 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)) @@ -327,16 +173,28 @@ 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); } /* @@ -374,7 +232,7 @@ pipefile() ; } } else { - register int f; + int f; dup2(pdes[0], 0); close(pdes[0]); @@ -426,16 +284,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() */ -static void +void transmit(fd, eofchars, command) FILE *fd; char *eofchars, *command; @@ -448,7 +305,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++) @@ -456,7 +313,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 */ } } @@ -498,7 +355,7 @@ transmit(fd, eofchars, command) printf("\r%d", ++lcount); if (boolean(value(ECHOCHECK))) { timedout = 0; - alarm(number(value(ETIMEOUT))); + alarm((long)value(ETIMEOUT)); do { /* wait for prompt */ read(FD, (char *)&c, 1); if (timedout || stop) { @@ -507,25 +364,28 @@ 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; 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); } /* @@ -543,7 +403,8 @@ cu_put(cc) if (prompt("[put] ", copyname, sizeof(copyname))) return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || argc > 2) { + if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || + argc > 2) { printf("usage: <put> from [to]\r\n"); return; } @@ -555,57 +416,47 @@ cu_put(cc) return; } if (boolean(value(ECHOCHECK))) - snprintf(line, sizeof(line), "cat>%s\r", argv[1]); + (void)snprintf(line, sizeof(line), "cat>%s\r", argv[1]); else - snprintf(line, sizeof(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); } - -static int -nap(msec) - int msec; /* milliseconds */ -{ - if (usleep(msec*1000) != 0) { - fprintf ( stderr, "warning: ldelay or cdelay interrupted, " - "delay time cut short: %s\n", - strerror(errno) ); - } - - return 0; -} - - /* * FTP - send single character * wait for echo & handle timeout */ -static void +void send(c) - char c; + int c; { char cc; int retry = 0; cc = c; - xpwrite(FD, &cc, 1); + parwrite(FD, &cc, 1); +#ifdef notdef if (number(value(CDELAY)) > 0 && c != '\r') nap(number(value(CDELAY))); +#endif if (!boolean(value(ECHOCHECK))) { +#ifdef notdef if (number(value(LDELAY)) > 0 && c == '\r') nap(number(value(LDELAY))); +#endif return; } tryagain: timedout = 0; - alarm(number(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; - xpwrite(FD, &null, 1); /* poke it */ + parwrite(FD, &null, 1); /* poke it */ goto tryagain; } } @@ -626,7 +477,7 @@ pipeout(c) { char buf[256]; int cpid, status, p; - time_t start; + time_t start = time(NULL); putchar(c); if (prompt("Local command? ", buf, sizeof(buf))) @@ -634,7 +485,7 @@ pipeout(c) 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 @@ -643,11 +494,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++) @@ -661,27 +512,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... @@ -693,47 +550,24 @@ 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 - */ -int -consh(c) -{ - char buf[256]; - putchar(c); - if (prompt("Local command? ", buf, sizeof(buf))) - return; - tiplink (buf, TL_SIGNAL_TIPOUT | TL_VERBOSE); - return 0; + write(fildes[1], (char *)&ccc, 1); + tcsetattr(0, TCSAFLUSH, &term); + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); } #endif @@ -760,12 +594,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, (char *)0); + execl(value(SHELL), cp, (char *)NULL); printf("\r\ncan't execl!\r\n"); exit(1); } @@ -802,7 +636,7 @@ void chdirectory() { char dirname[PATH_MAX]; - register char *cp = dirname; + char *cp = dirname; if (prompt("[cd] ", dirname, sizeof(dirname))) { if (stoprompt) @@ -833,17 +667,13 @@ tipabort(msg) 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 @@ -854,30 +684,30 @@ intcopy() longjmp(intbuf, 1); } -static void +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, (char *)0); + execl(value(SHELL), cp, "-c", s, (char *)NULL); } -static int +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; - while (*p && n < num) { + do { while (*p && (*p == ' ' || *p == '\t')) p++; start = p; @@ -889,16 +719,17 @@ args(buf, a, num) parg++, n++; if (*p) *p++ = '\0'; - } + } while (*p && n < num); + return(n); } -static void +void prtime(s, a) char *s; time_t a; { - register i; + int i; int nums[3]; for (i = 0; i < 3; i++) { @@ -907,7 +738,7 @@ prtime(s, a) } printf("%s", s); while (--i >= 0) - if (nums[i] || (i == 0 && nums[1] == 0 && nums[2] == 0)) + if (nums[i] || i == 0 && nums[1] == 0 && nums[2] == 0) printf("%d %s%c ", nums[i], sep[i], nums[i] == 1 ? '\0' : 's'); printf("\r\n!\r\n"); @@ -953,44 +784,69 @@ variable() } if (vtable[PARITY].v_access&CHANGED) { vtable[PARITY].v_access &= ~CHANGED; - setparity(value(PARITY)); + setparity(NOSTR); } } +void +listvariables() +{ + value_t *p; + char *buf; + char charbuf[5]; /* for vis(3), 4 chars for encoding, plus nul */ + + 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) { + buf = malloc(4*strlen(p->v_value) + 1); + if (buf == NULL) { + fprintf(stderr, "Unable to malloc()\n"); + abort(); + } + strvis(buf, p->v_value, VIS_WHITE); + printf(" %s", buf); + free(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(charbuf, character(p->v_value), VIS_WHITE, 0); + printf(" %s\r\n", charbuf); + break; + } + } +} + /* * Turn tandem mode on or off for remote tty. */ -static void +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); } /* @@ -1028,19 +884,19 @@ expand(name) { static char xname[BUFSIZ]; char cmdbuf[BUFSIZ]; - register int pid, l; - register char *cp, *Shell; - int s, pivec[2] /*, (*sigint)()*/; + int pid, l; + char *cp, *Shell; + int s, pivec[2]; if (!anyof(name, "~{[*?$`'\"\\")) return(name); /* sigint = signal(SIGINT, SIG_IGN); */ if (pipe(pivec) < 0) { - warn("pipe"); + perror("pipe"); /* signal(SIGINT, sigint) */ return(name); } - snprintf(cmdbuf, sizeof(cmdbuf), "echo %s", name); + (void)snprintf(cmdbuf, sizeof(cmdbuf), "echo %s", name); if ((pid = vfork()) == 0) { Shell = value(SHELL); if (Shell == NOSTR) @@ -1051,11 +907,11 @@ expand(name) close(pivec[1]); close(2); shell_uid(); - execl(Shell, Shell, "-c", cmdbuf, (char *)0); + execl(Shell, Shell, "-c", cmdbuf, (char *)NULL); _exit(1); } if (pid == -1) { - warn("fork"); + perror("fork"); close(pivec[0]); close(pivec[1]); return(NOSTR); @@ -1071,7 +927,7 @@ expand(name) return(NOSTR); } if (l < 0) { - warn("read"); + perror("read"); return(NOSTR); } if (l == 0) { @@ -1092,12 +948,11 @@ expand(name) /* * Are any of the characters in the two strings the same? */ - -static int +int anyof(s1, s2) - register char *s1, *s2; + char *s1, *s2; { - register int c; + int c; while ((c = *s1++)) if (any(c, s2)) diff --git a/usr.bin/tip/tip/cmdtab.c b/usr.bin/tip/tip/cmdtab.c index 3ad19e8..562fa74 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. @@ -31,20 +34,21 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.3 2001/09/09 17:58:41 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" extern int shell(), getfl(), sendfile(), chdirectory(); -extern int finish(), help(), pipefile(), pipeout(), variable(); -extern int cu_take(), cu_put(), dollar(), genbrk(), suspend(); +extern int finish(), help(), pipefile(), pipeout(), consh(), variable(); +extern int cu_take(), cu_put(), dollar(), genbrk(), suspend(), listvariables(); esctable_t etable[] = { { '!', NORM, "shell", shell }, @@ -54,7 +58,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 }, @@ -63,6 +67,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 2b3b2ed..b2d7e86 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. @@ -31,76 +34,104 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: cu.c,v 1.10 2001/09/26 06:07:28 pvalchev Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #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); @@ -110,7 +141,7 @@ cumain(argc, argv) * The "cu" host name is used to define the * attributes of the generic dialer. */ - (void)snprintf(sbuf, sizeof(sbuf), "cu%d", BR); + (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR); if ((i = hunt(sbuf)) == 0) { printf("all ports busy\n"); exit(3); @@ -125,7 +156,7 @@ cumain(argc, argv) user_uid(); vinit(); setparity("none"); - boolean(value(VERBOSE)) = 0; + setboolean(value(VERBOSE), FALSE); if (HW) ttysetup(speed(BR)); if (connect()) { @@ -137,4 +168,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/dial.sh b/usr.bin/tip/tip/dial.sh deleted file mode 100755 index ed30da5..0000000 --- a/usr.bin/tip/tip/dial.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -# -# @(#)dial.sh -- dialup remote using tip -# - -#set -x - -if [ $# -lt 1 ] ; then - echo "$0: not enough arguments" 1>&2 - exit 1 -fi - -x=0 - -while ! tip $* && test $x -lt 3 -do - sleep 5 - x=$(($x+1)) -done - -exit 0 diff --git a/usr.bin/tip/tip/hunt.c b/usr.bin/tip/tip/hunt.c index 90f7a61..7396466 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. @@ -31,22 +34,19 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)hunt.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: hunt.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ -#include <sys/types.h> -#include <err.h> -#include <libutil.h> -#include "tipconf.h" #include "tip.h" extern char *getremote(); -extern char *rindex(); static jmp_buf deadline; static int deadfl; @@ -58,23 +58,24 @@ dead() longjmp(deadline, 1); } -int +long hunt(name) char *name; { - register char *cp; + char *cp; sig_t f; - int res; f = signal(SIGALRM, dead); while ((cp = getremote(name))) { deadfl = 0; - uucplock = rindex(cp, '/')+1; - if ((res = uu_lock(uucplock)) != UU_LOCK_OK) { - if (res != UU_LOCK_INUSE) - fprintf(stderr, "uu_lock: %s\n", uu_lockerr(res)); + uucplock = strrchr(cp, '/'); + if (uucplock == NULL) + uucplock = cp; + else + uucplock++; + + if (uu_lock(uucplock) < 0) continue; - } /* * Straight through call units, such as the BIZCOMP, * VADIC and the DF, must indicate they're hardwired in @@ -86,33 +87,27 @@ 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) { - warn("%s", cp); + perror(cp); 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 20004e8..2385810 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. @@ -31,28 +34,28 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: log.c,v 1.5 2001/09/09 19:30:49 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" -#include <err.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 *group; + const char *num, *acu, *message; { char *user, *timestamp; struct passwd *pwd; @@ -61,20 +64,21 @@ logent(group, num, acu, message) if (flog == NULL) return; if (flock(fileno(flog), LOCK_EX) < 0) { - warn("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, diff --git a/usr.bin/tip/tip/partab.c b/usr.bin/tip/tip/partab.c index 94b2ab1..bfdb17d 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. @@ -31,18 +34,20 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)partab.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: partab.c,v 1.3 1997/04/02 01:47:02 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #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 0f9a15b..c885ea7 100644 --- a/usr.bin/tip/tip/pathnames.h +++ b/usr.bin/tip/tip/pathnames.h @@ -1,3 +1,7 @@ +/* $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 $ */ +/* $FreeBSD$ */ + /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -35,24 +39,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 _PATH_UUCPLOCK "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/remcap.c b/usr.bin/tip/tip/remcap.c deleted file mode 100644 index 5a0e791..0000000 --- a/usr.bin/tip/tip/remcap.c +++ /dev/null @@ -1,428 +0,0 @@ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif - -/* - * remcap - routines for dealing with the remote host data base - * - * derived from termcap - */ -#include <sys/types.h> -#include <fcntl.h> -#include <ctype.h> -#include <stdlib.h> -#include <unistd.h> -#include "pathnames.h" - -#ifndef BUFSIZ -#define BUFSIZ 1024 -#endif -#define MAXHOP 32 /* max number of tc= indirections */ - -#define tgetent rgetent -#define tnchktc rnchktc -#define tnamatch rnamatch -#define tgetnum rgetnum -#define tgetflag rgetflag -#define tgetstr rgetstr -#define E_TERMCAP RM = _PATH_REMOTE -#define V_TERMCAP "REMOTE" -#define V_TERM "HOST" - -char *RM; - -/* - * termcap - routines for dealing with the terminal capability data base - * - * BUG: Should use a "last" pointer in tbuf, so that searching - * for capabilities alphabetically would not be a n**2/2 - * process when large numbers of capabilities are given. - * Note: If we add a last pointer now we will screw up the - * tc capability. We really should compile termcap. - * - * Essentially all the work here is scanning and decoding escapes - * in string capabilities. We don't use stdio because the editor - * doesn't, and because living w/o it is not hard. - */ - -static char *tbuf; -static int hopcount; /* detect infinite loops in termcap, init 0 */ -static char *tskip(); -char *tgetstr(); -static char *tdecode(); -static char *remotefile; - -/* - * Get an entry for terminal name in buffer bp, - * from the termcap file. Parse is very rudimentary; - * we just notice escaped newlines. - */ -tgetent(bp, name) - char *bp, *name; -{ - char lbuf[BUFSIZ], *cp, *p; - int rc1, rc2; - - remotefile = cp = getenv(V_TERMCAP); - if (cp == (char *)0 || strcmp(cp, _PATH_REMOTE) == 0) { - remotefile = cp = _PATH_REMOTE; - return (getent(bp, name, cp)); - } else { - if ((rc1 = getent(bp, name, cp)) != 1) - *bp = '\0'; - remotefile = cp = _PATH_REMOTE; - rc2 = getent(lbuf, name, cp); - if (rc1 != 1 && rc2 != 1) - return (rc2); - if (rc2 == 1) { - p = lbuf; - if (rc1 == 1) - while (*p++ != ':') - ; - if (strlen(bp) + strlen(p) > BUFSIZ) { - write(STDERR_FILENO, "Remcap entry too long\n", 23); - return (-1); - } - strcat(bp, p); - } - tbuf = bp; - return (1); - } -} - -getent(bp, name, cp) - char *bp, *name, *cp; -{ - register int c; - register int i = 0, cnt = 0; - char ibuf[BUFSIZ], *cp2; - int tf; - - tbuf = bp; - tf = 0; - /* - * TERMCAP can have one of two things in it. It can be the - * name of a file to use instead of /etc/termcap. In this - * case it better start with a "/". Or it can be an entry to - * use so we don't have to read the file. In this case it - * has to already have the newlines crunched out. - */ - if (cp && *cp) { - if (*cp!='/') { - cp2 = getenv(V_TERM); - if (cp2 == (char *)0 || strcmp(name,cp2) == 0) { - strcpy(bp,cp); - return (tnchktc()); - } else - tf = open(E_TERMCAP, O_RDONLY); - } else - tf = open(RM = cp, O_RDONLY); - } - if (tf == 0) - tf = open(E_TERMCAP, O_RDONLY); - if (tf < 0) - return (-1); - for (;;) { - cp = bp; - for (;;) { - if (i == cnt) { - cnt = read(tf, ibuf, BUFSIZ); - if (cnt <= 0) { - close(tf); - return (0); - } - i = 0; - } - c = ibuf[i++]; - if (c == '\n') { - if (cp > bp && cp[-1] == '\\') { - cp--; - continue; - } - break; - } - if (cp >= bp+BUFSIZ) { - write(STDERR_FILENO, "Remcap entry too long\n", 23); - break; - } else - *cp++ = c; - } - *cp = 0; - - /* - * The real work for the match. - */ - if (tnamatch(name)) { - close(tf); - return (tnchktc()); - } - } -} - -/* - * tnchktc: check the last entry, see if it's tc=xxx. If so, - * recursively find xxx and append that entry (minus the names) - * to take the place of the tc=xxx entry. This allows termcap - * entries to say "like an HP2621 but doesn't turn on the labels". - * Note that this works because of the left to right scan. - */ -tnchktc() -{ - register char *p, *q; - char tcname[16]; /* name of similar terminal */ - char tcbuf[BUFSIZ]; - char *holdtbuf = tbuf; - int l; - char *cp; - - p = tbuf + strlen(tbuf) - 2; /* before the last colon */ - while (*--p != ':') - if (p<tbuf) { - write(STDERR_FILENO, "Bad remcap entry\n", 18); - return (0); - } - p++; - /* p now points to beginning of last field */ - if (p[0] != 't' || p[1] != 'c') - return (1); - strcpy(tcname, p+3); - q = tcname; - while (*q && *q != ':') - q++; - *q = 0; - if (++hopcount > MAXHOP) { - write(STDERR_FILENO, "Infinite tc= loop\n", 18); - return (0); - } - if (getent(tcbuf, tcname, remotefile) != 1) { - if (strcmp(remotefile, _PATH_REMOTE) == 0) - return (0); - else if (getent(tcbuf, tcname, _PATH_REMOTE) != 1) - return (0); - } - for (q = tcbuf; *q++ != ':'; ) - ; - l = p - holdtbuf + strlen(q); - if (l > BUFSIZ) { - write(STDERR_FILENO, "Remcap entry too long\n", 23); - q[BUFSIZ - (p-holdtbuf)] = 0; - } - strcpy(p, q); - tbuf = holdtbuf; - return (1); -} - -/* - * Tnamatch deals with name matching. The first field of the termcap - * entry is a sequence of names separated by |'s, so we compare - * against each such name. The normal : terminator after the last - * name (before the first field) stops us. - */ -tnamatch(np) - char *np; -{ - register char *Np, *Bp; - - Bp = tbuf; - if (*Bp == '#') - return (0); - for (;;) { - for (Np = np; *Np && *Bp == *Np; Bp++, Np++) - continue; - if (*Np == 0 && (*Bp == '|' || *Bp == ':' || *Bp == 0)) - return (1); - while (*Bp && *Bp != ':' && *Bp != '|') - Bp++; - if (*Bp == 0 || *Bp == ':') - return (0); - Bp++; - } -} - -/* - * Skip to the next field. Notice that this is very dumb, not - * knowing about \: escapes or any such. If necessary, :'s can be put - * into the termcap file in octal. - */ -static char * -tskip(bp) - register char *bp; -{ - - while (*bp && *bp != ':') - bp++; - if (*bp == ':') - bp++; - return (bp); -} - -/* - * Return the (numeric) option id. - * Numeric options look like - * li#80 - * i.e. the option string is separated from the numeric value by - * a # character. If the option is not found we return -1. - * Note that we handle octal numbers beginning with 0. - */ -tgetnum(id) - char *id; -{ - register int i, base; - register char *bp = tbuf; - - for (;;) { - bp = tskip(bp); - if (*bp == 0) - return (-1); - if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1]) - continue; - if (*bp == '@') - return (-1); - if (*bp != '#') - continue; - bp++; - base = 10; - if (*bp == '0') - base = 8; - i = 0; - while (isdigit(*bp)) - i *= base, i += *bp++ - '0'; - return (i); - } -} - -/* - * Handle a flag option. - * Flag options are given "naked", i.e. followed by a : or the end - * of the buffer. Return 1 if we find the option, or 0 if it is - * not given. - */ -tgetflag(id) - char *id; -{ - register char *bp = tbuf; - - for (;;) { - bp = tskip(bp); - if (!*bp) - return (0); - if (*bp++ == id[0] && *bp != 0 && *bp++ == id[1]) { - if (!*bp || *bp == ':') - return (1); - else if (*bp == '@') - return (0); - } - } -} - -/* - * Get a string valued option. - * These are given as - * cl=^Z - * Much decoding is done on the strings, and the strings are - * placed in area, which is a ref parameter which is updated. - * No checking on area overflow. - */ -char * -tgetstr(id, area) - char *id, **area; -{ - register char *bp = tbuf; - - for (;;) { - bp = tskip(bp); - if (!*bp) - return (0); - if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1]) - continue; - if (*bp == '@') - return (0); - if (*bp != '=') - continue; - bp++; - return (tdecode(bp, area)); - } -} - -/* - * Tdecode does the grung work to decode the - * string capability escapes. - */ -static char * -tdecode(str, area) - register char *str; - char **area; -{ - register char *cp; - register int c; - register char *dp; - int i; - - cp = *area; - while ((c = *str++) && c != ':') { - switch (c) { - - case '^': - c = *str++ & 037; - break; - - case '\\': - dp = "E\033^^\\\\::n\nr\rt\tb\bf\f"; - c = *str++; -nextc: - if (*dp++ == c) { - c = *dp++; - break; - } - dp++; - if (*dp) - goto nextc; - if (isdigit(c)) { - c -= '0', i = 2; - do - c <<= 3, c |= *str++ - '0'; - while (--i && isdigit(*str)); - } - break; - } - *cp++ = c; - } - *cp++ = 0; - str = *area; - *area = cp; - return (str); -} diff --git a/usr.bin/tip/tip/remote.c b/usr.bin/tip/tip/remote.c index 2bc9343..1a5d560 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. @@ -32,8 +35,11 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint -static const char copyright[] = +static char copyright[] = "@(#) Copyright (c) 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ @@ -41,19 +47,15 @@ static const char copyright[] = #ifndef lint #if 0 static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: remote.c,v 1.10 2001/10/24 18:38:58 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ -#include <sys/syslimits.h> -#include <err.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 @@ -61,65 +63,29 @@ static const char rcsid[] = */ 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) -static void getremcap __P((char *)); - -/* - 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; - } - return (-1); -} - 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); @@ -127,10 +93,11 @@ getremcap(host) db_array[1] = rempath; db_array[2] = _PATH_REMOTE; } + } if ((stat = cgetent(&bp, db_array, host)) < 0) { if (DV || - (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) { + host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) { CU = DV; HO = host; HW = 1; @@ -142,13 +109,17 @@ getremcap(host) } switch(stat) { case -1: - warnx("unknown host %s", host); + fprintf(stderr, "%s: unknown host %s\n", __progname, + host); break; case -2: - warnx("can't open host description file"); + fprintf(stderr, + "%s: can't open host description file\n", + __progname); break; case -3: - warnx("possible reference loop in host description file"); + fprintf(stderr, + "%s: possible reference loop in host description file\n", __progname); break; } exit(3); @@ -175,6 +146,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"); @@ -185,58 +160,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) @@ -261,13 +213,15 @@ 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) - errx(3, "no host specified"); + if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { + fprintf(stderr, "%s: no host specified\n", __progname); + exit(3); + } getremcap(host); next = DV; lookedup++; @@ -278,7 +232,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.c b/usr.bin/tip/tip/tip.c index 1f910e5..98e8424 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. @@ -31,8 +34,11 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint -static const char copyright[] = +static char copyright[] = "@(#) Copyright (c) 1983, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ @@ -40,91 +46,61 @@ static const char copyright[] = #ifndef lint #if 0 static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: tip.c,v 1.15 2001/10/24 18:38:58 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #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 <err.h> -#include <errno.h> -#include <sys/types.h> -#include <libutil.h> -#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 killchild(); void cleanup(); -void tipdone(); -char *sname(); char PNbuf[256]; /* This limits the size of a number */ -static void usage __P((void)); -void setparity __P((char *)); -void xpwrite __P((int, char *, int)); -char escape __P((void)); -void tipin __P((void)); -int prompt __P((char *, char *, size_t)); -void unraw __P((void)); -void shell_uid __P((void)); -void daemon_uid __P((void)); -void user_uid __P((void)); -int speed __P((int)); - 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) - usage(); - if (!isatty(0)) - errx(1, "must be interactive"); + if (argc > 4) { + fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n"); + exit(1); + } + if (!isatty(0)) { + fprintf(stderr, "%s: must be interactive\n", __progname); + exit(1); + } for (; argc > 1; argv++, argc--) { if (argv[1][0] != '-') @@ -135,13 +111,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: - warnx("%s, unknown option", argv[1]); + fprintf(stderr, "%s: %s, unknown option\n", __progname, + argv[1]); break; } } @@ -155,9 +136,12 @@ main(argc, argv) * Copy the number then stomp on the original (in case the number * is private, we don't want 'ps' or 'w' to find it). */ - if (strlen(system) > sizeof(PNbuf) - 1) - errx(1, "phone number too long (max = %d bytes)", sizeof PNbuf - 1); - strncpy(PNbuf, system, sizeof(PNbuf) - 1); + if (strlen(system) > 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; @@ -169,7 +153,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"); @@ -184,29 +167,31 @@ 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 */ + setparity("none"); /* set the parity table */ if ((i = speed(number(value(BAUDRATE)))) == 0) { - printf("tip: bad baud rate %d\n", number(value(BAUDRATE))); + 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) @@ -221,39 +206,34 @@ notnumber: } if (!HW) ttysetup(i); -/* cucommon:*/ +cucommon: /* * From here down the code is shared with * 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); @@ -267,32 +247,12 @@ notnumber: * 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())) tipin(); else tipout(); /*NOTREACHED*/ -} - -static void -usage() -{ - fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n"); - exit(1); -} - -void -killchild() -{ - if (pid != 0) { - kill(pid, SIGTERM); - pid = 0; - } + exit(0); } void @@ -301,18 +261,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 @@ -335,6 +288,7 @@ user_uid() void daemon_uid() { + if (uidswapped) { seteuid(euid); uidswapped = 0; @@ -352,17 +306,9 @@ 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); } @@ -372,15 +318,7 @@ raw () 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; @@ -393,10 +331,11 @@ static jmp_buf promptbuf; 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; @@ -405,7 +344,7 @@ prompt(s, p, sz) unraw(); printf("%s", s); if (setjmp(promptbuf) == 0) - while ((*p = getchar()) != EOF && *p != '\n' && --sz > 0) + while ((c = getchar()) != EOF && (*p = c) != '\n' && --sz > 0) p++; *p = '\0'; @@ -434,11 +373,8 @@ intprompt() void tipin() { - int i; char gch, bol = 1; - atexit(killchild); - /* * Kinda klugey here... * check for scripting being turned on from the .tiprc file, @@ -452,32 +388,27 @@ tipin() } while (1) { - i = getchar(); - if (i == EOF) - break; - gch = i&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; - xpwrite(FD, &gch, 1); + parwrite(FD, &gch, 1); if (boolean(value(HALFDUPLEX))) printf("\r\n"); continue; - } else if (!cumode && gch == character(value(FORCE))) { - i = getchar(); - if (i == EOF) - break; - gch = i & 0177; - } + } else if (!cumode && gch == character(value(FORCE))) + gch = getchar()&STRIP_PAR; bol = any(gch, value(EOL)); if (boolean(value(RAISE)) && islower(gch)) gch = toupper(gch); - xpwrite(FD, &gch, 1); + parwrite(FD, &gch, 1); if (boolean(value(HALFDUPLEX))) printf("%c", gch); } @@ -489,18 +420,14 @@ extern esctable_t etable[]; * Escape handler -- * called on recognition of ``escapec'' at the beginning of a line */ -char +int escape() { - register char gch; - register esctable_t *p; + char gch; + esctable_t *p; char c = character(value(ESCAPE)); - int i; - i = getchar(); - if (i == EOF) - return 0; - gch = (i&0177); + gch = (getchar()&STRIP_PAR); for (p = etable; p->e_char; p++) if (p->e_char == gch) { if ((p->e_flags&PRIV) && uid) @@ -511,7 +438,7 @@ escape() } /* ESCAPE ESCAPE forces ESCAPE */ if (c != gch) - xpwrite(FD, &c, 1); + parwrite(FD, &c, 1); return (gch); } @@ -519,22 +446,20 @@ 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; } int -any(c, p) - register char c, *p; +any(cc, p) + int cc; + char *p; { + char c = cc; while (p && *p) if (*p++ == c) return (1); @@ -543,9 +468,9 @@ any(c, p) int size(s) - register char *s; + char *s; { - register int i = 0; + int i = 0; while (s && *s++) i++; @@ -554,10 +479,10 @@ 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++)) { for (q = "\nn\rr\tt\ff\033E\bb"; *q; q++) @@ -602,7 +527,7 @@ void help(c) char c; { - register esctable_t *p; + esctable_t *p; printf("%c\r\n", c); for (p = etable; p->e_char; p++) { @@ -618,53 +543,29 @@ 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. @@ -672,13 +573,13 @@ static int bits8; * with the right parity and output it. */ void -xpwrite(fd, buf, n) +parwrite(fd, buf, n) int fd; char *buf; - register int n; + int n; { - register int i; - register char *bp; + int i; + char *bp; bp = buf; if (bits8 == 0) @@ -689,9 +590,8 @@ xpwrite(fd, buf, n) if (write(fd, buf, n) < 0) { if (errno == EIO) tipabort("Lost carrier."); - if (errno == ENODEV) - tipabort("tty not available."); - tipabort("Something wrong..."); + /* this is questionable */ + perror("write"); } } @@ -702,9 +602,9 @@ 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; @@ -728,5 +628,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 9aa69c2..1e9832c 100644 --- a/usr.bin/tip/tip/tip.h +++ b/usr.bin/tip/tip/tip.h @@ -1,3 +1,7 @@ +/* $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 $ */ +/* $FreeBSD$ */ + /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -32,8 +36,6 @@ * SUCH DAMAGE. * * @(#)tip.h 8.1 (Berkeley) 6/6/93 - * - * $FreeBSD$ */ /* @@ -41,19 +43,12 @@ */ #include <sys/types.h> -#include <machine/endian.h> #include <sys/file.h> #include <sys/time.h> -#include <limits.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 <sys/wait.h> +#include <sys/ioctl.h> +#include <termios.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -63,6 +58,7 @@ #include <setjmp.h> #include <unistd.h> #include <errno.h> +#include <limits.h> /* * Remote host attributes @@ -82,14 +78,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*/ @@ -99,7 +92,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 @@ -140,10 +134,10 @@ typedef */ typedef struct { - char *acu_name; - int (*acu_dialer)(); - void (*acu_disconnect)(); - void (*acu_abort)(); + const char *acu_name; + int (*acu_dialer) __P((char *, char *)); + void (*acu_disconnect) __P((void)); + void (*acu_abort) __P((void)); } acu_t; @@ -155,30 +149,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 -- @@ -190,8 +172,8 @@ typedef struct { char e_char; /* char to match on */ char e_flags; /* experimental, priviledged */ - char *e_help; /* help string */ - int (*e_func)(); /* command */ + const char *e_help; /* help string */ + int (*e_func) __P((char)); /* command */ } esctable_t; @@ -200,13 +182,12 @@ 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() -#else -void logent __P((char *, char *, char *, char*)); #endif /* @@ -214,65 +195,49 @@ void logent __P((char *, char *, char *, char*)); * 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) -#ifdef NOFILE -#undef NOFILE -#endif #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 */ @@ -281,6 +246,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 */ @@ -291,6 +257,8 @@ 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[PATH_MAX]; /* file name buffer for ~< */ char copyname[PATH_MAX]; /* file name buffer for ~> */ @@ -298,35 +266,67 @@ 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 */ - -extern char *ctrl(); -extern char *vinterp(); -extern char *connect(); -extern int size __P((char *)); -extern int any __P((char, char *)); -extern void setscript __P((void)); -extern void tipout __P((void)); -extern void vinit __P((void)); -extern void loginit __P((void)); -extern int hunt __P((char *)); -extern int vstring __P((char *, char *)); -extern void setparity __P((char *)); -extern void vlex __P((char *)); -extern void daemon_uid __P((void)); -extern void disconnect __P((char *)); -extern void shell_uid __P((void)); -extern void unraw __P((void)); -extern void xpwrite __P((int, char *, int)); -extern int prompt __P((char *, char *, size_t)); -extern int consh __P((int)); -extern void 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 */ +int odisc; /* initial tty line discipline */ +extern int disc; /* current tty discpline */ + +extern char *__progname; /* program name */ + +extern char *ctrl __P((char)); +extern char *vinterp __P((char *, char)); +extern const char *connect __P((void)); + +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, const char *num, const char *acu, const 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)); + +int biz31f_dialer __P((char *, char *)); +void biz31f_disconnect __P((void)); +void biz31f_abort __P((void)); +int ven_dialer __P((char *, char *)); +void ven_disconnect __P((void)); +void ven_abort __P((void)); +int hay_dialer __P((char *, char *)); +void hay_disconnect __P((void)); +void hay_abort __P((void)); +int cour_dialer __P((char *, char *)); +void cour_disconnect __P((void)); +void cour_abort __P((void)); +int t3000_dialer __P((char *, char *)); +void t3000_disconnect __P((void)); +void t3000_abort __P((void)); +int v831_dialer __P((char *, char *)); +void v831_disconnect __P((void)); +void v831_abort __P((void)); diff --git a/usr.bin/tip/tip/tipconf.h b/usr.bin/tip/tip/tipconf.h deleted file mode 100644 index f21be62..0000000 --- a/usr.bin/tip/tip/tipconf.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tipconf.h 8.1 (Berkeley) 3/25/95 - */ - -#ifndef tipconf_h_included -#define tipconf_h_included - -/* - Define constness -*/ -#define CONST const - -/* - Specify default bit rate for connections -*/ -#define DEFBR 1200 - -/* - Default frame size for file transfer buffering of writes - on local side -*/ -#ifndef BUFSIZ -#define DEFFS 1024 -#else -#define DEFFS BUFSIZ -#endif - -/* - Enable logging of ACU use -*/ -#define ACULOG 1 - -/* - Strip phone #s from ACU log file -*/ -#define PRISTINE 1 - -/* - Enable command to "connect" remote with local process -*/ -#define CONNECT 1 - -/* - Specify style of UUCP lock files -*/ -#define HAVE_V2_LOCKFILES 0 -#define HAVE_HDB_LOCKFILES 1 - -/* - System has a millisecond based sleep function -*/ -#define HAVE_USLEEP 0 - -/* - System has select -*/ -#define HAVE_SELECT 1 - -/* - System has termios tty interface -*/ -#define HAVE_TERMIOS 1 - -/* - Include configurable modem driver -*/ -#define UNIDIALER 1 - -/* - Specify builtin modem drivers to include -*/ -#define BIZ1031 0 -#define BIZ1022 0 -#define COURIER 0 -#define DF02 0 -#define DF03 0 -#define DN11 0 -#define HAYES 0 -#define MULTITECH 0 -#define T3000 0 -#define V3451 0 -#define V831 0 -#define VENTEL 0 - -/* - Include cu interface so that, when tip is linked to cu and then - invoked as cu, it behaves like cu. -*/ -#define INCLUDE_CU_INTERFACE 0 - -#endif - -/* end of tipconf.h */ diff --git a/usr.bin/tip/tip/tipout.c b/usr.bin/tip/tip/tipout.c index ac40ec7..e8e380e 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. @@ -31,17 +34,17 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)tipout.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: tipout.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ #include "tip.h" -#include <errno.h> -#include <unistd.h> /* * tip * @@ -72,7 +75,7 @@ void intEMT() { char c, line[256]; - register char *pline = line; + char *pline = line; char reply; read(fildes[0], &c, 1); @@ -84,14 +87,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); @@ -111,7 +114,7 @@ void intSYS() { - boolean(value(BEAUTIFY)) = !boolean(value(BEAUTIFY)); + setboolean(value(BEAUTIFY), !boolean(value(BEAUTIFY))); longjmp(sigbuf, 1); } @@ -122,9 +125,9 @@ void tipout() { char buf[BUFSIZ]; - register char *cp; - register int cnt; - int omask; + char *cp; + int cnt; + sigset_t mask, omask; signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); @@ -134,35 +137,30 @@ 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) { - if (getppid() != 1) - kill(getppid(),SIGUSR1); - sigblock(sigmask(SIGTERM)); - intTERM(); - /*NOTREACHED*/ - } else if (cnt < 0) { - if (getppid() != 1) - kill(getppid(),SIGUSR1); - sigblock(sigmask(SIGTERM)); + sigemptyset(&mask); + sigaddset(&mask, SIGTERM); + sigprocmask(SIG_BLOCK, &mask, NULL); intTERM(); /*NOTREACHED*/ } 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; - if (write(STDOUT_FILENO, buf, cnt) < 0) - exit(1); + *cp &= STRIP_PAR; + write(1, buf, cnt); if (boolean(value(SCRIPT)) && fscript != NULL) { if (!boolean(value(BEAUTIFY))) { fwrite(buf, 1, cnt, fscript); diff --git a/usr.bin/tip/tip/uucplock.c b/usr.bin/tip/tip/uucplock.c index 858ed01..8431288 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. @@ -29,39 +32,45 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint +#if 0 static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: uucplock.c,v 1.6 1998/07/13 02:11:44 millert Exp $"; +#endif #endif /* not lint */ #include <sys/types.h> #include <sys/file.h> -#include <sys/dir.h> +#include <sys/dirent.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) { /* @@ -70,14 +79,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 ((pid = 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 */ @@ -87,15 +101,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"); @@ -105,44 +124,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 0c103c8..59ff91d 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. @@ -31,12 +34,14 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)value.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: value.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ #include "tip.h" @@ -44,10 +49,6 @@ static const char rcsid[] = #define MIDDLE 35 static value_t *vlookup(); -int vstring __P((char *, char *)); -void vlex __P((char *)); -void vassign __P((value_t *, char *)); - static int col = 0; /* @@ -56,38 +57,39 @@ static int col = 0; 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))) p->v_value = cp; if (p->v_type&IREMOTE) - if (p->v_type&STRING) - p->v_value = *(char **) address(p->v_value); - else - 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 @@ -100,7 +102,7 @@ static int vaccess(); /*VARARGS1*/ void vassign(p, v) - register value_t *p; + value_t *p; char *v; { @@ -115,49 +117,48 @@ 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, ' '))) @@ -174,18 +175,18 @@ 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))) { cp++; if (p->v_type&NUMBER) - vassign(p, (char *) atoi(cp)); + vassign(p, atoi(cp)); else { if (strcmp(s, "record") == 0) cp = expand(cp); @@ -193,7 +194,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); @@ -214,9 +215,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) @@ -245,7 +246,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: @@ -268,7 +269,7 @@ vprint(p) static int vaccess(mode, rw) - register unsigned mode, rw; + unsigned mode, rw; { if (mode & (rw<<PUBLIC)) return (1); @@ -279,9 +280,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))) @@ -291,10 +292,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) @@ -313,7 +314,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++) { @@ -345,20 +346,19 @@ 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); + p = vlookup(s); if (p == 0) return (1); if (p->v_type&NUMBER) - vassign(p, (char *) atoi(v)); + vassign(p, atoi(v)); else { if (strcmp(s, "record") == 0) v = expand(v); diff --git a/usr.bin/tip/tip/vars.c b/usr.bin/tip/tip/vars.c index 6aba499..5c2ceb5 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. @@ -31,15 +34,16 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #ifndef lint #if 0 static char sccsid[] = "@(#)vars.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "$OpenBSD: vars.c,v 1.2 1996/06/26 05:40:50 deraadt Exp $"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" #include "pathnames.h" @@ -71,10 +75,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, @@ -117,5 +117,5 @@ value_t vtable[] = { "le", (char *)FALSE }, { "parity", STRING|INIT|IREMOTE, (READ|WRITE)<<PUBLIC, "par", (char *)&PA }, - { NOSTR, 0, 0, NOSTR, NOSTR } + { NOSTR, NULL, NULL, NOSTR, NOSTR } }; |