diff --git a/tip/GNUmakefile b/tip/GNUmakefile index 55e40bf22492f954bf5d318536356589c8d18410..242dcb0a32da3b42b0783bc256c282f8980c43e3 100644 --- a/tip/GNUmakefile +++ b/tip/GNUmakefile @@ -1,18 +1,16 @@ -CC = gcc -g +CC = gcc -g -O2 -# for BSD -#CFLAGS = -O -#LIBS= -lutil +OBJS = cmds.o cmdtab.o hunt.o partab.o \ + remote.o tip.o value.o vars.o getcap.o -# for Linux -CFLAGS = -O -DLINUX -LIBS= -ldb +# +# If HAVE_UUCPLOCK is defined you need -lutil for BSD +# +LIBS= -OBJS = acu.o acutab.o cmds.o cmdtab.o cu.o hunt.o log.o partab.o \ - remote.o tip.o tipout.o value.o vars.o getcap.o -DESTDIR = /usr/site +DESTDIR = /usr/testbed -all: tip +all: tip.static # tip tip: $(OBJS) $(CC) -o tip $(OBJS) $(LIBS) @@ -20,8 +18,11 @@ tip: $(OBJS) tip.static: $(OBJS) $(CC) -static -o tip.static $(OBJS) $(LIBS) -install: - install -s -c tip $(DESTDIR)/bin/tip +$(OBJS): tipconf.h tip.h + +install: all +# install -s -c tip $(DESTDIR)/bin/tip + install -s -c tip.static $(DESTDIR)/bin/ntip clean: rm -f $(OBJS) tip tip.static diff --git a/tip/acu.c b/tip/acu.c deleted file mode 100644 index 865b6fad8403a0da484aab9d4a9789c590dbfd51..0000000000000000000000000000000000000000 --- a/tip/acu.c +++ /dev/null @@ -1,211 +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 -#if 0 -static char sccsid[] = "@(#)acu.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$Id: acu.c,v 1.1 2000-12-22 18:48:46 mike Exp $"; -#endif /* not lint */ - -#include "tipconf.h" -#include "tip.h" - -#if UNIDIALER -acu_t* unidialer_getmodem (const char *modem_name); -#endif - -static acu_t *acu = NOACU; -static int conflag; -static void acuabort(); -static acu_t *acutype(); -static jmp_buf jmpbuf; -/* - * Establish connection for tip - * - * If DU is true, we should dial an ACU whose type is AT. - * The phone numbers are in PN, and the call unit is in CU. - * - * If the PN is an '@', then we consult the PHONES file for - * the phone numbers. This file is /etc/phones, unless overriden - * by an exported shell variable. - * - * The data base files must be in the format: - * host-name[ \t]*phone-number - * with the possibility of multiple phone numbers - * for a single host acting as a rotary (in the order - * found in the file). - */ -char * -connect() -{ - register char *cp = PN; - char *phnum, string[256]; - FILE *fd; - int tried = 0; - - if (!DU) { /* regular connect message */ - if (CM != NOSTR) - xpwrite(FD, CM, size(CM)); - logent(value(HOST), "", DV, "call completed"); - return (NOSTR); - } - /* - * @ =>'s use data base in PHONES environment variable - * otherwise, use /etc/phones - */ - signal(SIGINT, acuabort); - signal(SIGQUIT, acuabort); - if (setjmp(jmpbuf)) { - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - printf("\ncall aborted\n"); - logent(value(HOST), "", "", "call aborted"); - if (acu != NOACU) { - boolean(value(VERBOSE)) = FALSE; - if (conflag) - disconnect(NOSTR); - else - (*acu->acu_abort)(); - } - return ("interrupt"); - } - if ((acu = acutype(AT)) == NOACU) - return ("unknown ACU type"); - if (*cp != '@') { - while (*cp) { - for (phnum = cp; *cp && *cp != ','; cp++) - ; - if (*cp) - *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"); - tried++; - } - } else { - if ((fd = fopen(PH, "r")) == NOFILE) { - printf("%s: ", PH); - 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++ = '\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"); - tried++; - } - fclose(fd); - } - if (!tried) - logent(value(HOST), "", acu->acu_name, "missing phone number"); - else - (*acu->acu_abort)(); - return (tried ? "call failed" : "missing phone number"); -} - -void -disconnect(reason) - char *reason; -{ - if (!conflag) { - logent(value(HOST), "", DV, "call terminated"); - return; - } - if (reason == NOSTR) { - logent(value(HOST), "", acu->acu_name, "call terminated"); - if (boolean(value(VERBOSE))) - printf("\r\ndisconnecting..."); - } else - logent(value(HOST), "", acu->acu_name, reason); - (*acu->acu_disconnect)(); -} - -static void -acuabort(s) -{ - signal(s, SIG_IGN); - longjmp(jmpbuf, 1); -} - -static acu_t * -acutype(s) - register char *s; -{ - register 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/tip/acutab.c b/tip/acutab.c deleted file mode 100644 index 0c1c41af72f1dead212643226ff45c8c2af2143d..0000000000000000000000000000000000000000 --- a/tip/acutab.c +++ /dev/null @@ -1,118 +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 -#if 0 -static char sccsid[] = "@(#)acutab.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$Id: acutab.c,v 1.1 2000-12-22 18:48:46 mike Exp $"; -#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, - "biz31w", biz31w_dialer, biz31_disconnect, biz31_abort, -#endif -#if BIZ1022 - "biz22f", biz22f_dialer, biz22_disconnect, biz22_abort, - "biz22w", biz22w_dialer, biz22_disconnect, biz22_abort, -#endif -#if DF02 - "df02", df02_dialer, df_disconnect, df_abort, -#endif -#if DF03 - "df03", df03_dialer, df_disconnect, df_abort, -#endif -#if DN11 - "dn11", dn_dialer, dn_disconnect, dn_abort, -#endif -#if VENTEL - "ventel",ven_dialer, ven_disconnect, ven_abort, -#endif -#if HAYES - "hayes",hay_dialer, hay_disconnect, hay_abort, -#endif -#if COURIER - "courier",cour_dialer, cour_disconnect, cour_abort, -#endif -#if MULTITECH - "multitech",multitech_dialer, multitech_disconnect, multitech_abort, -#endif -#if T3000 - "t3000",t3000_dialer, t3000_disconnect, t3000_abort, -#endif -#if V3451 -#if !V831 - "vadic",v3451_dialer, v3451_disconnect, v3451_abort, -#endif - "v3451",v3451_dialer, v3451_disconnect, v3451_abort, -#endif -#if V831 -#if !V3451 - "vadic",v831_dialer, v831_disconnect, v831_abort, -#endif - "v831",v831_dialer, v831_disconnect, v831_abort, -#endif - 0, 0, 0, 0 -}; - diff --git a/tip/cmds.c b/tip/cmds.c index 2ad298b1ab183bd45e3c701c10a5a3c3c24c031b..74573ed1889f2cc7fd19de52c194b6163b991bca 100644 --- a/tip/cmds.c +++ b/tip/cmds.c @@ -36,10 +36,9 @@ static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: cmds.c,v 1.1 2000-12-22 18:48:46 mike Exp $"; + "$Id: cmds.c,v 1.2 2000-12-27 00:49:33 mike Exp $"; #endif /* not lint */ -#include "tipconf.h" #include "tip.h" #include "pathnames.h" @@ -50,7 +49,6 @@ static const char rcsid[] = #include <libutil.h> #endif #include <stdio.h> -#include <unistd.h> /* * tip @@ -58,15 +56,9 @@ static const char rcsid[] = * miscellaneous commands */ -int quant[] = { 60, 60, 24 }; - -char null = '\0'; -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)); @@ -75,46 +67,11 @@ 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 () @@ -133,483 +90,6 @@ flush_remote () #endif } -/* - * FTP - remote ==> local - * get a file from the remote host - */ -void -getfl(c) - char c; -{ - char buf[256], *cp, *expand(); - - putchar(c); - /* - * get the UNIX receiving file's name - */ - if (prompt("Local file name? ", copyname, sizeof(copyname))) - return; - cp = expand(copyname); - if ((sfd = creat(cp, 0666)) < 0) { - printf("\r\n%s: cannot creat\r\n", copyname); - return; - } - - /* - * collect parameters - */ - if (prompt("List command for remote system? ", buf, sizeof(buf))) { - unlink(copyname); - return; - } - transfer(buf, sfd, value(EOFREAD)); -} - -/* - * Cu-like take command - */ -void -cu_take(cc) - char cc; -{ - int fd, argc; - char line[BUFSIZ], *expand(), *cp; - - if (prompt("[take] ", copyname, sizeof(copyname))) - return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || argc > 2) { - printf("usage: <take> from [to]\r\n"); - return; - } - if (argc == 1) - argv[1] = argv[0]; - cp = expand(argv[1]); - if ((fd = creat(cp, 0666)) < 0) { - 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"); -} - -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); -} - -/* - * Bulk transfer routine -- - * used by getfl(), cu_take(), and pipefile() - */ -static void -transfer(buf, fd, eofchars) - char *buf, *eofchars; -{ - register int ct; - char c; - register int cnt, eof, v; - time_t start; - sig_t f; - char r; - FILE *ff; - - v = boolean(value(VERBOSE)); - - if ((ff = fdopen (fd, "w")) == NULL) { - 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); - for (ct = 0; !quit;) { - eof = read(FD, &c, 1) <= 0; - c &= 0177; - if (quit) - continue; - if (eof || any(c, eofchars)) - break; - if (c == 0) - continue; /* ignore nulls */ - if (c == '\r') - continue; - if (c == '\n' && v) - 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); -} - -/* - * FTP - remote ==> local process - * send remote input to local process via pipe - */ -void -pipefile() -{ - int cpid, pdes[2]; - char buf[256]; - int status, p; - - if (prompt("Local command? ", buf, sizeof(buf))) - return; - - if (pipe(pdes)) { - printf("can't establish pipe\r\n"); - return; - } - - if ((cpid = fork()) < 0) { - printf("can't fork!\r\n"); - return; - } else if (cpid) { - if (prompt("List command for remote system? ", buf, sizeof(buf))) { - close(pdes[0]), close(pdes[1]); - kill (cpid, SIGKILL); - } else { - close(pdes[0]); - signal(SIGPIPE, intcopy); - transfer(buf, pdes[1], value(EOFREAD)); - signal(SIGPIPE, SIG_DFL); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } - } else { - register int f; - - dup2(pdes[0], 0); - close(pdes[0]); - for (f = 3; f < 20; f++) - close(f); - execute(buf); - printf("can't execl!\r\n"); - exit(0); - } -} - -/* - * Interrupt service routine for FTP - */ -void -stopsnd() -{ - - stop = 1; - signal(SIGINT, SIG_IGN); -} - -/* - * FTP - local ==> remote - * send local file to remote host - * terminate transmission with pseudo EOF sequence - */ -void -sendfile(cc) - char cc; -{ - FILE *fd; - char *fnamex; - char *expand(); - - putchar(cc); - /* - * get file name - */ - if (prompt("Local file name? ", fname, sizeof(fname))) - return; - - /* - * look up file - */ - fnamex = expand(fname); - if ((fd = fopen(fnamex, "r")) == NULL) { - printf("%s: cannot open\r\n", fname); - return; - } - transmit(fd, value(EOFWRITE), NULL); - if (!boolean(value(ECHOCHECK))) { - flush_remote (); - } -} - -/* - * Bulk transfer routine to remote host -- - * used by sendfile() and cu_put() - */ -static void -transmit(fd, eofchars, command) - FILE *fd; - char *eofchars, *command; -{ - char *pc, lastc; - int c, ccount, lcount; - time_t start_t, stop_t; - sig_t f; - - kill(pid, SIGIOT); /* put TIPOUT into a wait state */ - stop = 0; - f = signal(SIGINT, stopsnd); - usedefchars (); - read(repdes[0], (char *)&ccc, 1); - if (command != NULL) { - for (pc = command; *pc; pc++) - send(*pc); - if (boolean(value(ECHOCHECK))) - read(FD, (char *)&c, 1); /* trailing \n */ - else { - flush_remote (); - sleep(5); /* wait for remote stty to take effect */ - } - } - lcount = 0; - lastc = '\0'; - start_t = time(0); - while (1) { - ccount = 0; - do { - c = getc(fd); - if (stop) - goto out; - if (c == EOF) - goto out; - if (c == 0177 && !boolean(value(RAWFTP))) - continue; - lastc = c; - if (c < 040) { - if (c == '\n') { - if (!boolean(value(RAWFTP))) - c = '\r'; - } - else if (c == '\t') { - if (!boolean(value(RAWFTP))) { - if (boolean(value(TABEXPAND))) { - send(' '); - while ((++ccount % 8) != 0) - send(' '); - continue; - } - } - } else - if (!boolean(value(RAWFTP))) - continue; - } - send(c); - } while (c != '\r' && !boolean(value(RAWFTP))); - if (boolean(value(VERBOSE))) - printf("\r%d", ++lcount); - if (boolean(value(ECHOCHECK))) { - timedout = 0; - alarm(number(value(ETIMEOUT))); - do { /* wait for prompt */ - read(FD, (char *)&c, 1); - if (timedout || stop) { - if (timedout) - printf("\r\ntimed out at eol\r\n"); - alarm(0); - goto out; - } - } while ((c&0177) != character(value(PROMPT))); - alarm(0); - } - } -out: - if (lastc != '\n' && !boolean(value(RAWFTP))) - send('\r'); - for (pc = eofchars; pc && *pc; pc++) - send(*pc); - stop_t = time(0); - fclose(fd); - signal(SIGINT, f); - 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 (); -} - -/* - * Cu-like put command - */ -void -cu_put(cc) - char cc; -{ - FILE *fd; - char line[BUFSIZ]; - int argc; - char *expand(); - char *copynamex; - - if (prompt("[put] ", copyname, sizeof(copyname))) - return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || argc > 2) { - printf("usage: <put> from [to]\r\n"); - return; - } - if (argc == 1) - argv[1] = argv[0]; - copynamex = expand(argv[0]); - if ((fd = fopen(copynamex, "r")) == NULL) { - printf("%s: cannot open\r\n", copynamex); - return; - } - if (boolean(value(ECHOCHECK))) - snprintf(line, sizeof(line), "cat>%s\r", argv[1]); - else - snprintf(line, sizeof(line), "stty -echo;cat>%s;stty echo\r", argv[1]); - transmit(fd, "\04", line); -} - - -static void -nap(msec) - int msec; /* milliseconds */ -{ - usleep(msec*1000); -} - - -/* - * FTP - send single character - * wait for echo & handle timeout - */ -static void -send(c) - char c; -{ - char cc; - int retry = 0; - - cc = c; - xpwrite(FD, &cc, 1); - if (number(value(CDELAY)) > 0 && c != '\r') - nap(number(value(CDELAY))); - if (!boolean(value(ECHOCHECK))) { - if (number(value(LDELAY)) > 0 && c == '\r') - nap(number(value(LDELAY))); - return; - } -tryagain: - timedout = 0; - alarm(number(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 */ - goto tryagain; - } -} - void timeout() { @@ -617,126 +97,6 @@ timeout() timedout = 1; } -/* - * Stolen from consh() -- puts a remote file on the output of a local command. - * Identical to consh() except for where stdout goes. - */ -void -pipeout(c) -{ - char buf[256]; - int cpid, status, p; - time_t start; - - 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); - usedefchars (); - read(repdes[0], (char *)&ccc, 1); - /* - * Set up file descriptors in the child and - * let it go... - */ - if ((cpid = fork()) < 0) - printf("can't fork!\r\n"); - else if (cpid) { - start = time(0); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } else { - register int i; - - dup2(FD, 1); - for (i = 3; i < 20; i++) - close(i); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - execute(buf); - printf("can't find `%s'\r\n", buf); - exit(0); - } - if (boolean(value(VERBOSE))) - prtime("away for ", time(0)-start); - write(fildes[1], (char *)&ccc, 1); - usetchars (); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); -} - -#if CONNECT - -int -tiplink (char *cmd, unsigned int flags) -{ - 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); - } - - /* - * Set up file descriptors in the child and - * let it go... - */ - if ((cpid = fork()) < 0) - printf("can't fork!\r\n"); - else if (cpid) { - start = time(0); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } else { - register int fd; - - dup2(FD, 0); - dup2(3, 1); - for (fd = 3; fd < 20; fd++) - close (fd); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - execute (cmd); - printf("can't find `%s'\r\n", cmd); - exit(0); - } - - if (flags & TL_VERBOSE && 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; -} -#endif - /* * Escape to local shell */ @@ -772,26 +132,24 @@ shell() } /* - * TIPIN portion of scripting - * initiate the conversation with TIPOUT + * Turn on/off scripting */ void setscript() { - char c; - /* - * enable TIPOUT side for dialogue - */ - kill(pid, SIGEMT); - if (boolean(value(SCRIPT))) - write(fildes[1], value(RECORD), size(value(RECORD))); - write(fildes[1], "\n", 1); - /* - * wait for TIPOUT to finish - */ - read(repdes[0], &c, 1); - if (c == 'n') - printf("can't create %s\r\n", value(RECORD)); + char *line = value(RECORD); + + if (boolean(value(SCRIPT))) { + if ((fscript = fopen(line, "a")) == NULL) { + printf("can't create %s\r\n", value(RECORD)); + boolean(value(SCRIPT)) = FALSE; + } + } else { + if (fscript != NULL) { + fclose(fscript); + fscript = NULL; + } + } } /* @@ -819,13 +177,13 @@ tipabort(msg) char *msg; { - kill(pid, SIGTERM); - disconnect(msg); if (msg != NOSTR) printf("\r\n%s", msg); printf("\r\n[EOT]\r\n"); daemon_uid(); +#if HAVE_UUCPLOCK (void)uu_unlock(uucplock); +#endif unraw(); exit(0); } @@ -833,25 +191,7 @@ tipabort(msg) void finish() { - char *abortmsg = NOSTR, *dismsg; - - if (LO != NOSTR && tiplink (LO, TL_SIGNAL_TIPOUT) != 0) { - abortmsg = "logout failed"; - } - - if ((dismsg = value(DISCONNECT)) != NOSTR) { - write(FD, dismsg, strlen(dismsg)); - sleep (2); - } - tipabort(abortmsg); -} - -void -intcopy() -{ - raw(); - quit = 1; - longjmp(intbuf, 1); + tipabort(NOSTR); } static void @@ -893,26 +233,6 @@ args(buf, a, num) return(n); } -static void -prtime(s, a) - char *s; - time_t a; -{ - register i; - int nums[3]; - - for (i = 0; i < 3; i++) { - nums[i] = (int)(a % quant[i]); - a /= quant[i]; - } - printf("%s", s); - while (--i >= 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"); -} - void variable() { @@ -921,10 +241,8 @@ variable() if (prompt("[set] ", buf, sizeof(buf))) return; vlex(buf); - if (vtable[BEAUTIFY].v_access&CHANGED) { + if (vtable[BEAUTIFY].v_access&CHANGED) vtable[BEAUTIFY].v_access &= ~CHANGED; - kill(pid, SIGSYS); - } if (vtable[SCRIPT].v_access&CHANGED) { vtable[SCRIPT].v_access &= ~CHANGED; setscript(); diff --git a/tip/cmdtab.c b/tip/cmdtab.c index 5997ffffd426471ef3a63b369f56b6dfe786a4ea..b7b974e338edf5a0b7d975c4b1189d6355b4574f 100644 --- a/tip/cmdtab.c +++ b/tip/cmdtab.c @@ -36,27 +36,17 @@ static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: cmdtab.c,v 1.1 2000-12-22 18:48:47 mike Exp $"; + "$Id: cmdtab.c,v 1.2 2000-12-27 00:49:33 mike Exp $"; #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 shell(), chdirectory(); +extern int finish(), help(), variable(); +extern dollar(), genbrk(), suspend(); esctable_t etable[] = { { '!', NORM, "shell", shell }, - { '<', NORM, "receive file from remote host", getfl }, - { '>', NORM, "send file to remote host", sendfile }, - { 't', NORM, "take file from remote UNIX", cu_take }, - { 'p', NORM, "put file to remote UNIX", cu_put }, - { '|', NORM, "pipe remote file", pipefile }, - { '$', NORM, "pipe local command to remote host", pipeout }, -#if CONNECT - { 'C', NORM, "connect program to remote host",consh }, -#endif { 'c', NORM, "change directory", chdirectory }, { '.', NORM, "exit from tip", finish }, {CTRL('d'),NORM,"exit from tip", finish }, diff --git a/tip/cu.c b/tip/cu.c deleted file mode 100644 index cc6c1637d9f21155c2782c640f48e82281de7fbc..0000000000000000000000000000000000000000 --- a/tip/cu.c +++ /dev/null @@ -1,140 +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 -#if 0 -static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$Id: cu.c,v 1.1 2000-12-22 18:48:47 mike Exp $"; -#endif /* not lint */ - -#include "tipconf.h" -#include "tip.h" - -void cleanup(); - -#if INCLUDE_CU_INTERFACE - -/* - * Botch the interface to look like cu's - */ -cumain(argc, argv) - char *argv[]; -{ - register int i; - static char sbuf[12]; - - if (argc < 2) { - printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n"); - exit(8); - } - 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; - - case 'a': - CU = argv[2]; ++argv; --argc; - break; - - case 's': - if (argc < 3 || speed(atoi(argv[2])) == 0) { - fprintf(stderr, "cu: unsupported speed %s\n", - argv[2]); - exit(3); - } - BR = atoi(argv[2]); ++argv; --argc; - break; - - case 'l': - DV = argv[2]; ++argv; --argc; - 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]; - if (DV) - DV[strlen(DV)-1] = argv[1][1]; - break; - - default: - printf("Bad flag %s", argv[1]); - break; - } - } - signal(SIGINT, cleanup); - signal(SIGQUIT, cleanup); - signal(SIGHUP, cleanup); - signal(SIGTERM, cleanup); - - /* - * The "cu" host name is used to define the - * attributes of the generic dialer. - */ - (void)snprintf(sbuf, sizeof(sbuf), "cu%d", BR); - if ((i = hunt(sbuf)) == 0) { - printf("all ports busy\n"); - exit(3); - } - if (i == -1) { - printf("link down\n"); - (void)uu_unlock(uucplock); - exit(3); - } - setbuf(stdout, NULL); - loginit(); - user_uid(); - vinit(); - setparity("none"); - boolean(value(VERBOSE)) = 0; - if (HW) - ttysetup(speed(BR)); - if (connect()) { - printf("Connect failed\n"); - daemon_uid(); - (void)uu_unlock(uucplock); - exit(1); - } - if (!HW) - ttysetup(speed(BR)); -} -#endif /* INCLUDE_CU_INTERFACE */ diff --git a/tip/getcap.c b/tip/getcap.c index dda084fb2e76a238fdc22ffc8f377578ac4590f5..64d03c1898c0a31f327612b8325ab45188c3e972 100644 --- a/tip/getcap.c +++ b/tip/getcap.c @@ -38,6 +38,8 @@ static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; #endif /* LIBC_SCCS and not lint */ +#include "tipconf.h" + #include <sys/types.h> #include <ctype.h> diff --git a/tip/hunt.c b/tip/hunt.c index df2a1c12fc05003278d17a8b3fce0f92cc050240..fd998dd25587403819fc03a77b7352a647fa9214 100644 --- a/tip/hunt.c +++ b/tip/hunt.c @@ -36,16 +36,17 @@ static char sccsid[] = "@(#)hunt.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: hunt.c,v 1.1 2000-12-22 18:48:47 mike Exp $"; + "$Id: hunt.c,v 1.2 2000-12-27 00:49:34 mike Exp $"; #endif /* not lint */ +#include "tip.h" + #include <sys/types.h> #include <err.h> #ifndef LINUX #include <libutil.h> #endif -#include "tipconf.h" -#include "tip.h" + extern char *getremote(); extern char *rindex(); @@ -71,12 +72,14 @@ hunt(name) f = signal(SIGALRM, dead); while ((cp = getremote(name))) { deadfl = 0; +#if HAVE_UUCPLOCK 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)); continue; } +#endif /* * Straight through call units, such as the BIZCOMP, * VADIC and the DF, must indicate they're hardwired in @@ -89,6 +92,8 @@ hunt(name) if (setjmp(deadline) == 0) { alarm(10); FD = open(cp, O_RDWR); + if (FD >= 0) + ioctl(FD, TIOCEXCL, 0); } alarm(0); if (FD < 0) { @@ -96,14 +101,12 @@ hunt(name) deadfl = 1; } if (!deadfl) { - ioctl(FD, TIOCEXCL, 0); #if HAVE_TERMIOS - { - struct termios t; - if (tcgetattr(FD, &t) == 0) { - t.c_cflag |= HUPCL; - (void)tcsetattr(FD, TCSANOW, &t); - } + struct termios t; + + if (tcgetattr(FD, &t) == 0) { + t.c_cflag |= HUPCL; + (void)tcsetattr(FD, TCSANOW, &t); } #else /* HAVE_TERMIOS */ #ifdef TIOCHPCL @@ -113,7 +116,9 @@ hunt(name) signal(SIGALRM, SIG_DFL); return ((int)cp); } +#if HAVE_UUCPLOCK (void)uu_unlock(uucplock); +#endif } signal(SIGALRM, f); return (deadfl ? -1 : (int)cp); diff --git a/tip/log.c b/tip/log.c deleted file mode 100644 index 65b25ceb336fc678bec3899e3d199974eccf5dc8..0000000000000000000000000000000000000000 --- a/tip/log.c +++ /dev/null @@ -1,94 +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 -#if 0 -static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$Id: log.c,v 1.1 2000-12-22 18:48:48 mike Exp $"; -#endif /* not lint */ - -#include "tipconf.h" -#include "tip.h" -#include <err.h> - -#if ACULOG -static FILE *flog = NULL; - -/* - * Log file maintenance routines - */ - -void -logent(group, num, acu, message) - char *group, *num, *acu, *message; -{ - char *user, *timestamp; - struct passwd *pwd; - time_t t; - - if (flog == NULL) - return; - if (flock(fileno(flog), LOCK_EX) < 0) { - warn("flock"); - return; - } - 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 - "", -#else - num, -#endif - acu, message); - (void) fflush(flog); - (void) flock(fileno(flog), LOCK_UN); -} - -void -loginit() -{ - flog = fopen(value(LOG), "a"); - if (flog == NULL) - fprintf(stderr, "can't open log file %s.\r\n", value(LOG)); -} -#endif diff --git a/tip/modems.5 b/tip/modems.5 deleted file mode 100644 index 7fd347433cc02bba62881d7981a0f30dc6c3ead7..0000000000000000000000000000000000000000 --- a/tip/modems.5 +++ /dev/null @@ -1,141 +0,0 @@ -.\" Copyright (c) 1983, 1991, 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. -.\" -.\" @(#)modems.5 3/24/95 -.\" -.Dd March 24, 1995 -.Dt MODEMS 5 -.Os BSD 4.4 -.Sh NAME -.Nm modems -.Nd modem configuration data base -.Sh DESCRIPTION -The modems known by -.Xr tip 1 -and their attributes are stored in an -.Tn ASCII -file which -is structured somewhat like the -.Xr termcap 5 -file. Each line in the file provides a description for a single -.Em modem . -Fields are separated by a colon (``:''). -Lines ending in a \e character with an immediately following newline are -continued on the next line. -.Pp -The first entry is the name(s) of the modem. If there is more -than one name for a modem, the names are separated by vertical bars. -After the name of the modem comes the fields of the description. A -field name followed by an `=' sign indicates a string value follows. A field -name followed by a `#' sign indicates a following numeric value. -.Pp -When -.Xr tip 1 -is invoked, an entry for a remote system is looked up in the -.Pa /etc/remote -database. -If the entry includes an "ACU" type capability (abbreviated at), -.Xr tip 1 -looks up the specified modem in -.Pa /etc/modems. -If a modem entry is found, -the corresponding capabilities determine how -.Xr tip 1 -programs the modem when connecting to and disconnecting from the -remote system. -.Sh CAPABILITIES -Capabilities are either strings (str), numbers (num), or boolean -flags (bool). A string capability is specified by -.Em capability Ns Ar = Ns Em value ; -for example, ``reset_command=ATZ\\r''. A numeric capability is specified by -.Em capability Ns Ar # Ns Em value ; -for example, ``intercharacter_delay#50''. A boolean capability is specified -by simply listing the capability. -.Bl -tag -width intercharacter_delay indent -.It Cm \&dial_command -(str) -AT command used to dial remote system (typically, "ATDT") -.It Cm \&echo_off_command -(str) -AT command to turn off command echo. -.It Cm \&escape_guard_time -(num) -The delay, expressed in milliseconds, used to frame return-to-command -escape sequences. -.It Cm \&escape_sequence -(str) -The return-to-command escape sequence. -.It Cm \&hangup_command -(str) -AT command used to hangup modem. -.It Cm \&hw_flow_control -(bool) -Enable hardware (RTS/CTS) flow control between computer and modem (DTE/DCE). -.It Cm \&init_string -(str) -AT command used to initialize modem before dialing. -.It Cm \&intercharacter_delay -(num) -Delay value, expressed in milliseconds, between characters when sending commands -to the modem. -.It Cm \&intercommand_delay -(num) -Minimum delay value, expressed in milliseconds, to impose between commands -issued to the modem. -.It Cm \&lock_baud -(bool) -Use a fixed bit rate between the computer and the modem (DTE / DCE). The -bit rate is specified in -.Pa /etc/remote. -.It Cm \&reset_command -(str) -AT command to reset the modem. -.It Cm \&reset_delay -(num) -The time, expressed in milliseconds, required by the modem to complete -a reset and return to a ready condition. -.Sh FILES -.Bl -tag -width /etc/modems -compact -.It Pa /etc/modems -The -.Nm modems -configuration database file -resides in -.Pa /etc . -.El -.Sh SEE ALSO -.Xr tip 1 , -.Xr remote 5 -.Sh HISTORY -The -.Nm -file format appeared in -.Bx 4.4 . diff --git a/tip/tip.1 b/tip/ntip.1 similarity index 73% rename from tip/tip.1 rename to tip/ntip.1 index 687fda9886670f9238b6764e7605eb0b9c10a925..8735a1bfd65c37cd2bc4ea49b5471ef85b2a0f1a 100644 --- a/tip/tip.1 +++ b/tip/ntip.1 @@ -31,32 +31,94 @@ .\" .\" @(#)tip.1 8.4 (Berkeley) 4/18/94 .\" -.Dd April 18, 1994 -.Dt TIP 1 +.Dd December 26, 2000 +.Dt NTIP 1 .Os BSD 4 .Sh NAME -.Nm tip -.Nd connect to a remote system +.Nm ntip +.Nd connect to a directly-connected remote system .Sh SYNOPSIS -.Nm tip +.Nm ntip +.Op Fl c +.Op Fl r .Op Fl v .Fl Ns Ns Ar speed .Ar system\-name -.Nm tip -.Op Fl v -.Fl Ns Ns Ar speed -.Ar phone\-number .Sh DESCRIPTION -.Nm Tip -establish a full-duplex connection to another machine, +.Nm Ntip +establishes a full-duplex connection to another machine, giving the appearance of being logged in directly on the remote cpu. It goes without saying that you must have a login on the machine (or equivalent) to which you wish to connect. .Pp +.Nm Ntip +differs from the traditional +.Nm tip +in a number of ways: +.Bl -enum +.It +It does not support calling a remote system, +all auto-dialing code has been removed. +.It +All the cheezy file transfer support has been removed. +.It +Most of the tilde escapes have been removed. Mostly these were the file +trasfer related ones. See below for what remains. +.It +.Nm Ntip +ignores 90% of the +.Xr remote 5 +capabilities. You can set the baud rate (br) and the device (dv). +Period. +.It +All of +.Nm tips +variables are still present, but most don't do anything. +It is left as an exercise to the interested user to differentiate. +.It +By default, it operates in ``raw'' mode instead of the usual ``cbreak'' mode. +This means that all input processing (if any) is performed by the remote system. +Raw mode also disables ``raisechar'' and ``force'' variable interpretation. +Yes, you can actually run emacs on an +.Nm ntip +line (modulo the '~' thing). +.It +.Nm Tip +is the poster-child for fork-without-exec, +creating separate reader and writer processes executing ``the same code.'' +.Nm Ntip +is a child of convenience and consists of a single process using +.Xr select 2 . +.It +.Nm Ntip +no longer uses +.Xr uucp 1 +style locking. +It relies on the TIOCEXCL ioctl (see +.Xr tty 4 ) +to provide ``reasonably mutually exclusive'' access. +While it is still technically possible that two parties could open the +same line and both get ``exclusive'' access to it, +we consider this to be the source of amusing anecdotes rather than a bug. +.El +.Pp Available Option: .Bl -tag -width indent +.It Fl c +Force +.Nm ntip +to use ``cbreak'' +(``(c)onventional'', ``(c)razy'', ``(c)an't run emacs'') +mode. +.It Fl r +Force +.Nm ntip +to use ``raw'' +(``(r)ocks!'', ``(r)ulz!'', ``(r)ighteous'') +mode. .It Fl v Set verbose mode. +Whatever the hell that is. .El .Pp Typed characters are normally transmitted directly to the remote @@ -76,63 +138,6 @@ implies change to your home directory). .It Ic \&~! Escape to a shell (exiting the shell will return you to tip). -.It Ic \&~> -Copy file from local to remote. -.Nm Tip -prompts for the name of a local file to transmit. -.It Ic \&~< -Copy file from remote to local. -.Nm Tip -prompts first for the name of the file to be sent, then for -a command to be executed on the remote machine. -.It Ic \&~p Ar from Op Ar to -Send a file to a remote -.Ux -host. The put command causes the remote -.Ux -system to run the command string ``cat > 'to''', while -.Nm tip -sends it the ``from'' -file. If the ``to'' file isn't specified the ``from'' file name is used. -This command is actually a -.Ux -specific version of the ``~>'' command. -.It Ic \&~t Ar from Op Ar to -Take a file from a remote -.Ux -host. -As in the put command the ``to'' file -defaults to the ``from'' file name if it isn't specified. -The remote host -executes the command string ``cat 'from';echo ^A'' to send the file to -.Nm tip . -.It Ic \&~| -Pipe the output from a remote command to a local -.Ux -process. -The command string sent to the local -.Ux -system is processed by the shell. -.It Ic \&~$ -Pipe the output from a local -.Ux -process to the remote host. -The command string sent to the local -.Ux -system is processed by the shell. -.It Ic \&~C -Fork a child process on the local system to perform special protocols -such as \s-1XMODEM\s+1. The child program will be run with the following -somewhat unusual arrangement of file descriptors: -.nf -.in +1i -0 <-> local tty in -1 <-> local tty out -2 <-> local tty out -3 <-> remote tty in -4 <-> remote tty out -.in -1i -.fi .It Ic \&~# Send a .Dv BREAK @@ -148,20 +153,20 @@ characters. Set a variable (see the discussion below). .It Ic \&~^Z Stop -.Nm tip +.Nm ntip (only available with job control). .It Ic \&~^Y Stop only the ``local side'' of -.Nm tip +.Nm ntip (only available with job control); the ``remote side'' of -.Nm tip , +.Nm ntip , the side that displays output from the remote host, is left running. .It Ic \&~? Get a summary of the tilde escapes .El .Pp -.Nm Tip +.Nm Ntip uses the file .Pa /etc/remote to find how to reach a particular @@ -176,56 +181,18 @@ to be used may be specified on the command line, e.g. .Ql "tip -300 mds" . .Pp When -.Nm tip -establishes a connection it sends out a -connection message to the remote system; the default value, if any, -is defined in -.Pa /etc/remote -(see -.Xr remote 5 ) . -.Pp -When -.Nm tip -prompts for an argument (e.g. during setup of -a file transfer) the line typed may be edited with the standard +.Nm ntip +prompts for an argument (e.g. while setting a variable) +the line typed may be edited with the standard erase and kill characters. A null line in response to a prompt, or an interrupt, will abort the dialogue and return you to the remote machine. .Pp -.Nm Tip +.Nm Ntip guards against multiple users connecting to a remote system -by opening modems and terminal lines with exclusive access, -and by honoring the locking protocol used by -.Xr uucico 8 . -.Pp -During file transfers -.Nm tip -provides a running count of the number of lines transferred. -When using the ~> and ~< commands, the ``eofread'' and ``eofwrite'' -variables are used to recognize end-of-file when reading, and -specify end-of-file when writing (see below). File transfers -normally depend on tandem mode for flow control. If the remote -system does not support tandem mode, ``echocheck'' may be set -to indicate -.Nm tip -should synchronize with the remote system on the echo of each -transmitted character. -.Pp -When -.Nm tip -must dial a phone number to connect to a system it will print -various messages indicating its actions. -.Nm Tip -supports modems that use the AT command set. -.Nm Tip -uses the file -.Pa /etc/modems -to find out how to operate with a particular -modem; refer to -.Xr modems 5 -for a full description. +by opening terminal lines with exclusive access. .Ss VARIABLES -.Nm Tip +.Nm Ntip maintains a set of .Ar variables which control its operation. @@ -254,7 +221,7 @@ Variables may be initialized at run time by placing set commands in one's home directory). The .Fl v option causes -.Nm tip +.Nm ntip to display the sets as they are made. Certain common variables have abbreviations. The following is a list of common variables, @@ -286,7 +253,7 @@ a ~> file transfer command; abbreviated .Ar eofw . .It Ar eol (str) The set of characters which indicate an end-of-line. -.Nm Tip +.Nm Ntip will recognize escape characters only after an end-of-line. .It Ar escape (char) The command prefix (escape) character; abbreviated @@ -333,7 +300,7 @@ default value is .Ar off . When this mode is enabled, all lower case letters will be mapped to upper case by -.Nm tip +.Nm ntip for transmission to the remote machine. .It Ar raisechar (char) The input character used to toggle upper case mapping mode; @@ -354,7 +321,7 @@ When .Ar script is .Li true , -.Nm tip +.Nm ntip will record everything transmitted by the remote machine in the script record file specified in .Ar record . @@ -380,13 +347,13 @@ Each tab is expanded to 8 spaces. default is .Ar true . When verbose mode is enabled, -.Nm tip +.Nm ntip prints messages while dialing, shows the current number of lines transferred during a file transfer operations, and more. .El .Sh ENVIRONMENT -.Nm Tip +.Nm Ntip uses the following environment variables: .Bl -tag -width Fl .It Ev SHELL @@ -399,44 +366,35 @@ value is taken from the environment. Check for a default host if none specified. .El .Pp -The variables +The variable .Ev ${REMOTE} -and -.Ev ${PHONES} -are also exported. +is also exported. .Sh FILES -.Bl -tag -width /var/spool/lock/LCK..* -compact -.It Pa /etc/modems -Global modem configuration data base. +.Bl -tag -width /etc/remote -compact .It Pa /etc/remote Global system descriptions. -.It Pa /etc/phones -Global phone number data base. .It ${REMOTE} Private system descriptions. -.It ${PHONES} -Private phone numbers. .It ~/.tiprc Initialization file. .It Pa tip.record Record file. -.It /var/log/aculog -Line access log. -.It Pa /var/spool/lock/LCK..* -Lock file to avoid conflicts with -.Xr uucp . .El .Sh DIAGNOSTICS Diagnostics are, hopefully, self explanatory. .Sh SEE ALSO -.Xr cu 1 , -.Xr phones 5 , +.Xr tip 1 , .Xr remote 5 .Sh HISTORY The .Nm tip -appeared command in +command appeared command in .Bx 4.2 . +The +.Nm ntip +command was an act of desperation on the part of its author. .Sh BUGS The full set of variables is undocumented and should, probably, be pared down. +.Nm Tip +and all of its bastard spawn should be eliminated from the face of the earth. diff --git a/tip/remote.c b/tip/remote.c index 0eba8545252bcb78f016113207d41c0cad011052..ee5911f46171f47a5a126947c90b4f3e35696e66 100644 --- a/tip/remote.c +++ b/tip/remote.c @@ -43,9 +43,12 @@ static const char copyright[] = static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: remote.c,v 1.1 2000-12-22 18:48:48 mike Exp $"; + "$Id: remote.c,v 1.2 2000-12-27 00:49:35 mike Exp $"; #endif /* not lint */ +#include "tip.h" +#include "pathnames.h" + #ifndef LINUX #include <sys/syslimits.h> #endif @@ -53,10 +56,6 @@ static const char rcsid[] = #include <stdio.h> #include <stdlib.h> -#include "tipconf.h" -#include "tip.h" -#include "pathnames.h" - /* * Attributes to be gleened from remote host description * data base. @@ -73,8 +72,6 @@ static char *capstrings[] = { static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; -char *cgetcap __P((char *, char *, int)); - #define cgetflag(f) (cgetcap(bp, f, ':') != NULL) static void getremcap __P((char *)); diff --git a/tip/tip.c b/tip/tip.c index 00bc079b7e9633ca38394ff9f26681b92c583bb2..24afe2b22f21ce74b247e3bedfbe407826c7fd6e 100644 --- a/tip/tip.c +++ b/tip/tip.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: tip.c,v 1.1 2000-12-22 18:48:49 mike Exp $"; + "$Id: tip.c,v 1.2 2000-12-27 00:49:35 mike Exp $"; #endif /* not lint */ /* @@ -57,15 +57,15 @@ void ttysetup (int speed); * cu phone-number [-s speed] [-l line] [-a acu] */ +#include "tip.h" +#include "pathnames.h" + #include <err.h> #include <errno.h> #include <sys/types.h> #ifndef LINUX #include <libutil.h> #endif -#include "tipconf.h" -#include "tip.h" -#include "pathnames.h" /* * Baud rate mapping table @@ -110,16 +110,18 @@ int disc = OTTYDISC; /* tip normally runs this way */ void intprompt(); void timeout(); -void cleanup(); void tipdone(); char *sname(); char PNbuf[256]; /* This limits the size of a number */ +int rflag = 1; + static void usage __P((void)); void setparity __P((char *)); void xpwrite __P((int, char *, int)); -char escape __P((void)); -void tipin __P((void)); +void tipio __P((void)); +void tipinfunc __P((char *, int)); +void tipoutfunc __P((char *, int)); int prompt __P((char *, char *, size_t)); void unraw __P((void)); void shell_uid __P((void)); @@ -141,19 +143,13 @@ main(argc, argv) uid = getuid(); euid = geteuid(); -#if INCLUDE_CU_INTERFACE - if (equal(sname(argv[0]), "cu")) { - cumode = 1; - cumain(argc, argv); - goto cucommon; - } -#endif /* INCLUDE_CU_INTERFACE */ - if (argc > 4) usage(); if (!isatty(0)) errx(1, "must be interactive"); + STDIN = 0; + for (; argc > 1; argv++, argc--) { if (argv[1][0] != '-') system = argv[1]; @@ -163,6 +159,13 @@ main(argc, argv) vflag++; break; + case 'c': + rflag = 0; + break; + case 'r': + rflag = 1; + 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]); @@ -174,38 +177,25 @@ main(argc, argv) } } - if (system == NOSTR) - goto notnumber; - if (isalpha(*system)) - goto notnumber; - /* - * System name is really a phone number... - * 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); - for (p = system; *p; p++) - *p = '\0'; - PN = PNbuf; - (void)snprintf(sbuf, sizeof(sbuf), "tip%ld", BR); - system = sbuf; - -notnumber: - (void)signal(SIGINT, cleanup); - (void)signal(SIGQUIT, cleanup); - (void)signal(SIGHUP, cleanup); - (void)signal(SIGTERM, cleanup); + (void)signal(SIGINT, tipdone); + (void)signal(SIGQUIT, tipdone); + (void)signal(SIGHUP, tipdone); + (void)signal(SIGTERM, tipdone); (void)signal(SIGUSR1, tipdone); + /* reset the tty on screw ups */ + (void)signal(SIGBUS, tipdone); + (void)signal(SIGSEGV, tipdone); + if ((i = hunt(system)) == 0) { printf("all ports busy\n"); exit(3); } if (i == -1) { - printf("link down\n"); + printf("%s: busy\n", system); +#if HAVE_UUCPLOCK (void)uu_unlock(uucplock); +#endif exit(3); } setbuf(stdout, NULL); @@ -221,7 +211,9 @@ notnumber: setparity("even"); /* set the parity table */ if ((i = speed(number(value(BAUDRATE)))) == 0) { printf("tip: bad baud rate %d\n", number(value(BAUDRATE))); +#if HAVE_UUCPLOCK (void)uu_unlock(uucplock); +#endif exit(3); } @@ -241,15 +233,7 @@ notnumber: */ if (HW) ttysetup(i); - if ((p = connect())) { - printf("\07%s\n[EOT]\n", p); - daemon_uid(); - (void)uu_unlock(uucplock); - exit(1); - } - if (!HW) - ttysetup(i); -/* cucommon:*/ + /* * From here down the code is shared with * the "cu" version of tip. @@ -258,27 +242,40 @@ notnumber: #if HAVE_TERMIOS tcgetattr (0, &otermios); ctermios = otermios; + if (rflag) { + ctermios.c_iflag = (IGNBRK|IGNPAR); + ctermios.c_lflag = 0; + ctermios.c_cflag = (CLOCAL|CREAD|CS8); + ctermios.c_cc[VMIN] = 1; + ctermios.c_cc[VTIME] = 5; + ctermios.c_oflag = 0; + } else { #ifndef _POSIX_SOURCE - ctermios.c_iflag = (IMAXBEL|IXANY|ISTRIP|IXON|BRKINT); - ctermios.c_lflag = (PENDIN|IEXTEN|ISIG|ECHOCTL|ECHOE|ECHOKE); + 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); + 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[VDISCARD] = - ctermios.c_cc[VLNEXT] = -1; + ctermios.c_cflag = (CLOCAL|HUPCL|CREAD|CS8); + ctermios.c_cc[VINTR] = ctermios.c_cc[VQUIT] = _POSIX_VDISABLE; + ctermios.c_cc[VSUSP] = ctermios.c_cc[VDISCARD] = + ctermios.c_cc[VLNEXT] = _POSIX_VDISABLE; #ifdef VDSUSP - ctermios.c_cc[VDSUSP] = -1; + ctermios.c_cc[VDSUSP] = _POSIX_VDISABLE; #endif + } #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; + if (rflag) + arg.sg_flags = RAW; + else + arg.sg_flags = CBREAK; + arg.sg_flags |= PASS8 | ANYP; tchars = defchars; tchars.t_intrc = tchars.t_quitc = -1; ltchars = deflchars; @@ -287,7 +284,6 @@ notnumber: #endif /* HAVE_TERMIOS */ raw(); - pipe(fildes); pipe(repdes); (void)signal(SIGALRM, timeout); /* @@ -295,18 +291,14 @@ notnumber: * connection established (hardwired or dialup) * line conditioned (baud rate, mode, etc.) * internal data structures (variables) - * so, fork one process for local side and one for remote. + * so, fire up! */ - printf(cumode ? "Connected\r\n" : "\07connected\r\n"); - - if (LI != NOSTR && tiplink (LI, 0) != 0) { - tipabort ("login failed"); - } - - if ((pid = fork())) - tipin(); + if (rflag) + printf("\07connected (raw mode)\r\n"); else - tipout(); + printf("\07connected\r\n"); + + tipio(); /*NOTREACHED*/ } @@ -318,23 +310,22 @@ usage() } void -cleanup() +tipdone(sig) + int sig; { - - daemon_uid(); - (void)uu_unlock(uucplock); -#if !HAVE_TERMIOS - if (odisc) - ioctl(0, TIOCSETD, (char *)&odisc); -#endif - exit(0); + switch (sig) { + case SIGHUP: + tipabort("Hangup."); + break; + case SIGTERM: + tipabort("Killed."); + break; + default: + printf("\r\nSignal %d", sig); + tipabort(NOSTR); + } } -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 @@ -370,21 +361,27 @@ shell_uid() seteuid(uid); } +static int inrawmode; + /* * put the controlling keyboard into raw mode */ void -raw () +raw() { + if (inrawmode) + return; + #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 */ + + inrawmode = 1; } @@ -394,15 +391,19 @@ raw () void unraw() { + if (!inrawmode) + return; + #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 */ + + inrawmode = 0; } static jmp_buf promptbuf; @@ -427,7 +428,7 @@ prompt(s, p, sz) unraw(); printf("%s", s); if (setjmp(promptbuf) == 0) - while ((*p = getchar()) != EOF && *p != '\n' && --sz > 0) + while ((*p = tipgetchar()) != '\n' && --sz > 0) p++; *p = '\0'; @@ -451,35 +452,123 @@ intprompt() } /* - * ****TIPIN TIPIN**** + * ****TIPIO TIPIO**** + * + * Replace two process reader/writer with select-based single process + * reader and writer. */ void -tipin() +tipio() { - int i; - char gch, bol = 1; + fd_set sfds, fds; + int n, i, cc; + char buf[4096]; /* - * Kinda klugey here... - * check for scripting being turned on from the .tiprc file, - * but be careful about just using setscript(), as we may - * send a SIGEMT before tipout has a chance to set up catching - * it; so wait a second, then setscript() + * Check for scripting being turned on from the .tiprc file. */ - if (boolean(value(SCRIPT))) { - sleep(1); + if (boolean(value(SCRIPT))) setscript(); + + n = STDIN; + if (n < FD) + n = FD; + n++; + FD_ZERO(&sfds); + FD_SET(STDIN, &sfds); + FD_SET(FD, &sfds); + for (;;) { + fds = sfds; + i = select(n, &fds, NULL, NULL, NULL); + if (i <= 0) + tipabort("select failed"); + + /* + * Check for user input first. + * It is lower volume and possibly more important (^C) + */ + if (FD_ISSET(STDIN, &fds)) { + cc = read(STDIN, buf, sizeof(buf)); + if (cc < 0) + tipabort("stdin read failed"); + if (cc == 0) + finish(); + tipinfunc(buf, cc); + } + + if (FD_ISSET(FD, &fds)) { + cc = read(FD, buf, sizeof(buf)); + if (cc < 0) + tipabort("device read failed"); + if (cc == 0) + tipabort("device read EOF"); + + tipoutfunc(buf, cc); + } } +} - while (1) { - i = tipgetchar(); - if (i == EOF) - break; - gch = i&0177; - if ((gch == character(value(ESCAPE))) && bol) { - if (!(gch = escape())) +void +tipinfunc(buf, nchar) + char *buf; + int nchar; +{ + int i; + char gch; + char escc = character(value(ESCAPE)); + char forcec = character(value(FORCE)); + static int bol = 1; + static int inescape = 0; + static int inforce = 0; + + for (i = 0; i < nchar; i++) { + gch = buf[i] & 0177; + if (inescape || (gch == escc && bol)) { + esctable_t *p; + + /* + * Read the next char if not already in an escape. + * If there is no next char note that we are in an + * escape and exit. + */ + if (!inescape && ++i == nchar) { + inescape = 1; + break; + } + gch = buf[i] & 0177; + inescape = 0; + + for (p = etable; p->e_char; p++) + if (p->e_char == gch) + break; + + /* + * If this is a legit escape command, process it. + * Otherwise, for an unrecognized sequence (which + * includes ESCAPE ESCAPE), we just send the escaped + * char with no further interpretation. + */ + if (p->e_char) { + if ((p->e_flags&PRIV) && uid) + continue; + printf("%s", ctrl(escc)); + (*p->e_func)(gch); continue; - } else if (!cumode && gch == character(value(RAISECHAR))) { + } + } else if (inforce || gch == forcec) { + /* + * Same story, different character... + * Read the next char if not already in a force. + * If there is no next char note that we are forcing + * and exit. + */ + if (!inforce && ++i == nchar) { + inforce = 1; + break; + } + gch = buf[i] & 0177; + inforce = 0; + } else if (gch == character(value(RAISECHAR))) { boolean(value(RAISE)) = !boolean(value(RAISE)); continue; } else if (gch == '\r') { @@ -488,11 +577,6 @@ tipin() if (boolean(value(HALFDUPLEX))) printf("\r\n"); continue; - } else if (!cumode && gch == character(value(FORCE))) { - i = tipgetchar(); - if (i == EOF) - break; - gch = i & 0177; } bol = any(gch, value(EOL)); if (boolean(value(RAISE)) && islower(gch)) @@ -503,36 +587,28 @@ tipin() } } -extern esctable_t etable[]; - -/* - * Escape handler -- - * called on recognition of ``escapec'' at the beginning of a line - */ -char -escape() +void +tipoutfunc(buf, nchar) + char *buf; + int nchar; { - register char gch; - register esctable_t *p; - char c = character(value(ESCAPE)); - int i; + char *cp; - i = tipgetchar(); - if (i == EOF) - return 0; - gch = (i&0177); - for (p = etable; p->e_char; p++) - if (p->e_char == gch) { - if ((p->e_flags&PRIV) && uid) - continue; - printf("%s", ctrl(c)); - (*p->e_func)(gch); - return (0); - } - /* ESCAPE ESCAPE forces ESCAPE */ - if (c != gch) - xpwrite(FD, &c, 1); - return (gch); + for (cp = buf; cp < buf + nchar; cp++) + *cp &= 0177; + write(1, buf, nchar); + + if (boolean(value(SCRIPT)) && fscript != NULL) { + if (boolean(value(BEAUTIFY))) { + char *excepts = value(EXCEPTIONS); + + for (cp = buf; cp < buf + nchar; cp++) + if ((*cp >= ' ' && *cp <= '~') || + any(*cp, excepts)) + putc(*cp, fscript); + } else + fwrite(buf, 1, nchar, fscript); + } } int @@ -652,16 +728,14 @@ ttysetup (int speed) #if HAVE_TERMIOS struct termios termios; tcgetattr (FD, &termios); + termios.c_iflag = (IGNBRK|IGNPAR); 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_iflag |= IXOFF; + termios.c_lflag = 0; termios.c_cflag = (CLOCAL|HUPCL|CREAD|CS8); + termios.c_cc[VMIN] = 1; + termios.c_cc[VTIME] = 5; + termios.c_oflag = 0; cfsetispeed(&termios, speed); cfsetospeed(&termios, speed); tcsetattr (FD, TCSANOW, &termios); @@ -709,6 +783,7 @@ xpwrite(fd, buf, n) { register int i; register char *bp; + extern int errno; bp = buf; if (bits8 == 0) @@ -769,9 +844,8 @@ tipgetchar() { char gch; - gch = getchar(); - if (gch == EOF && feof(stdin)) + if (read(STDIN, &gch, 1) != 1) finish(); + return gch; } - diff --git a/tip/tip.h b/tip/tip.h index 67f539426efbef1d869e8a734495abb56162c196..142633ceb1ad9c663d15e89f8ff590decf5605a5 100644 --- a/tip/tip.h +++ b/tip/tip.h @@ -38,18 +38,16 @@ * tip - terminal interface program */ +#include "tipconf.h" + #ifdef LINUX /* signals */ #define SIGEMT SIGUSR1 #define SIGSYS SIGUSR2 -/* uucp stuff */ -#define uu_lock(x) (0) -#define uu_unlock(x) (0) -#define UU_LOCK_OK 0 -#define UU_LOCK_INUSE 1 +#define HAVE_UUCPLOCK 0 +#define HAVE_TERMIOS 1 -#define HAVE_TERMIOS 1 /* XXX */ #endif #include <sys/types.h> @@ -153,18 +151,6 @@ typedef #define INIT 0100 /* static data space used for initialization */ #define TMASK 017 -/* - * Definition of ACU line description - */ -typedef - struct { - char *acu_name; - int (*acu_dialer)(); - void (*acu_disconnect)(); - void (*acu_abort)(); - } - acu_t; - #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */ /* @@ -219,13 +205,10 @@ typedef extern int vflag; /* verbose during reading of .tiprc file */ extern value_t vtable[]; /* variable table */ +extern esctable_t etable[]; -#if !ACULOG #define logent(a, b, c, d) #define loginit() -#else -void logent __P((char *, char *, char *, char*)); -#endif /* * Definition of indices into variable table so @@ -272,7 +255,6 @@ void logent __P((char *, char *, char *, char*)); #define LECHO 33 #define PARITY 34 #define NOVAL ((value_t *)NULL) -#define NOACU ((acu_t *)NULL) #define NOSTR ((char *)NULL) #ifdef NOFILE #undef NOFILE @@ -294,13 +276,11 @@ struct ltchars deflchars; /* initial local characters of terminal */ FILE *fscript; /* FILE for scripting */ -int fildes[2]; /* file transfer synchronization channel */ -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 STDIN; /* stdin file descriptor */ int vflag; /* print .tiprc initialization sequence */ +int rflag; /* use raw mode instead of cbreak */ int sfd; /* for ~< operation */ -int pid; /* pid of tipout */ uid_t uid, euid; /* real and effective user id's */ gid_t gid, egid; /* real and effective group id's */ int stop; /* stop transfer session flag */ @@ -308,20 +288,20 @@ int quit; /* same; but on other end */ int intflag; /* recognized interrupt */ int stoprompt; /* for interrupting a prompt session */ int timedout; /* ~> transfer timedout */ -int cumode; /* simulating the "cu" program */ char fname[PATH_MAX]; /* file name buffer for ~< */ char copyname[PATH_MAX]; /* file name buffer for ~> */ char ccc; /* synchronization character */ char ch; /* for tipout */ +#if HAVE_UUCPLOCK char *uucplock; /* name of lock file for uucp's */ +#endif 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)); @@ -333,18 +313,12 @@ 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 */ diff --git a/tip/tipconf.h b/tip/tipconf.h index a0890b8f71f6c79b318662abccad635baf9d1b40..52c264100b04e5a293fc604cc7b4f0733a742ec2 100644 --- a/tip/tipconf.h +++ b/tip/tipconf.h @@ -44,7 +44,7 @@ /* Specify default bit rate for connections */ -#define DEFBR 1200 +#define DEFBR 9600 /* Default frame size for file transfer buffering of writes @@ -57,68 +57,29 @@ #endif /* - Enable logging of ACU use + Enable use of UUCP lockfiles. + Otherwise relies on using the exclusive use ioctl. This opens up + a minor race since setting exclusive use is not atomic with opening + the device, but we live with it. */ -#define ACULOG 1 - -/* - Strip phone #s from ACU log file -*/ -#define PRISTINE 1 - -/* - Enable command to "connect" remote with local process -*/ -#define CONNECT 1 +#define HAVE_UUCPLOCK 0 /* Specify style of UUCP lock files + (only matters if UUCPLOCK is defined non-zero) */ #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 0 - -/* - 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 +#ifdef __linux__ +#define LINUX #endif /* end of tipconf.h */ diff --git a/tip/tipout.c b/tip/tipout.c deleted file mode 100644 index 6a77903250ec27c41833e5481d16e5482650ebdb..0000000000000000000000000000000000000000 --- a/tip/tipout.c +++ /dev/null @@ -1,175 +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 -#if 0 -static char sccsid[] = "@(#)tipout.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$Id: tipout.c,v 1.1 2000-12-22 18:48:49 mike Exp $"; -#endif /* not lint */ - -#include "tip.h" -#include <errno.h> -/* - * tip - * - * lower fork of tip -- handles passive side - * reading from the remote host - */ - -static jmp_buf sigbuf; - -/* - * TIPOUT wait state routine -- - * sent by TIPIN when it wants to posses the remote host - */ -void -intIOT() -{ - - write(repdes[1],&ccc,1); - read(fildes[0], &ccc,1); - longjmp(sigbuf, 1); -} - -/* - * Scripting command interpreter -- - * accepts script file name over the pipe and acts accordingly - */ -void -intEMT() -{ - char c, line[256]; - register char *pline = line; - char reply; - - read(fildes[0], &c, 1); - while (c != '\n' && pline - line < sizeof(line)) { - *pline++ = c; - read(fildes[0], &c, 1); - } - *pline = '\0'; - if (boolean(value(SCRIPT)) && fscript != NULL) - fclose(fscript); - if (pline == line) { - boolean(value(SCRIPT)) = FALSE; - reply = 'y'; - } else { - if ((fscript = fopen(line, "a")) == NULL) - reply = 'n'; - else { - reply = 'y'; - boolean(value(SCRIPT)) = TRUE; - } - } - write(repdes[1], &reply, 1); - longjmp(sigbuf, 1); -} - -void -intTERM() -{ - - if (boolean(value(SCRIPT)) && fscript != NULL) - fclose(fscript); - exit(0); -} - -void -intSYS() -{ - - boolean(value(BEAUTIFY)) = !boolean(value(BEAUTIFY)); - longjmp(sigbuf, 1); -} - -/* - * ****TIPOUT TIPOUT**** - */ -void -tipout() -{ - char buf[BUFSIZ]; - register char *cp; - register int cnt; - int omask; - - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - signal(SIGEMT, intEMT); /* attention from TIPIN */ - signal(SIGTERM, intTERM); /* time to go signal */ - signal(SIGIOT, intIOT); /* scripting going on signal */ - signal(SIGHUP, intTERM); /* for dial-ups */ - signal(SIGSYS, intSYS); /* beautify toggle */ - (void) setjmp(sigbuf); - for (omask = 0;; sigsetmask(omask)) { - 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)); - intTERM(); - /*NOTREACHED*/ - } - continue; - } -#define ALLSIGS sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS) - omask = sigblock(ALLSIGS); - for (cp = buf; cp < buf + cnt; cp++) - *cp &= 0177; - write(1, buf, cnt); - if (boolean(value(SCRIPT)) && fscript != NULL) { - if (!boolean(value(BEAUTIFY))) { - fwrite(buf, 1, cnt, fscript); - continue; - } - for (cp = buf; cp < buf + cnt; cp++) - if ((*cp >= ' ' && *cp <= '~') || - any(*cp, value(EXCEPTIONS))) - putc(*cp, fscript); - } - } -} diff --git a/tip/value.c b/tip/value.c index 7faa1039d88ddf52aac42f6b38a557deec05ce75..1b3ccd251fbfa1aeac35fcf7822aebe9ce4ab5e9 100644 --- a/tip/value.c +++ b/tip/value.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)value.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: value.c,v 1.1 2000-12-22 18:48:50 mike Exp $"; + "$Id: value.c,v 1.2 2000-12-27 00:49:36 mike Exp $"; #endif /* not lint */ #include "tip.h" @@ -93,6 +93,17 @@ vinit() * To allow definition of exception prior to fork */ vtable[EXCEPTIONS].v_access &= ~(WRITE<<PUBLIC); + + /* + * Disable most magic keys in raw mode + */ + if (rflag) { + character(value(RAISECHAR)) = 0; + character(value(FORCE)) = 0; + if (value(PARITY) == NOSTR || + !equal(value(PARITY), "none")) + value(PARITY) = "none"; + } } static int vaccess(); @@ -236,11 +247,12 @@ vprint(p) case STRING: printf("%s=", p->v_name); col++; - if (p->v_value) { + if (p->v_value) cp = interp(p->v_value, NULL); - col += size(cp); - printf("%s", cp); - } + else + cp = "<NULL>"; + col += size(cp); + printf("%s", cp); break; case NUMBER: @@ -251,11 +263,12 @@ vprint(p) case CHAR: printf("%s=", p->v_name); col++; - if (p->v_value) { + if (p->v_value) cp = ctrl(character(p->v_value)); - col += size(cp); - printf("%s", cp); - } + else + cp = "<NULL>"; + col += size(cp); + printf("%s", cp); break; } if (col >= MIDDLE) {