Home | History | Annotate | Line # | Download | only in tip
tip.h revision 1.1.1.2
      1      1.1  cgd /*
      2  1.1.1.2  jtc  * Copyright (c) 1989, 1993
      3  1.1.1.2  jtc  *	The Regents of the University of California.  All rights reserved.
      4  1.1.1.2  jtc  *
      5      1.1  cgd  *
      6      1.1  cgd  * Redistribution and use in source and binary forms, with or without
      7      1.1  cgd  * modification, are permitted provided that the following conditions
      8      1.1  cgd  * are met:
      9      1.1  cgd  * 1. Redistributions of source code must retain the above copyright
     10      1.1  cgd  *    notice, this list of conditions and the following disclaimer.
     11      1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     13      1.1  cgd  *    documentation and/or other materials provided with the distribution.
     14      1.1  cgd  * 3. All advertising materials mentioning features or use of this software
     15      1.1  cgd  *    must display the following acknowledgement:
     16      1.1  cgd  *	This product includes software developed by the University of
     17      1.1  cgd  *	California, Berkeley and its contributors.
     18      1.1  cgd  * 4. Neither the name of the University nor the names of its contributors
     19      1.1  cgd  *    may be used to endorse or promote products derived from this software
     20      1.1  cgd  *    without specific prior written permission.
     21      1.1  cgd  *
     22      1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23      1.1  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24      1.1  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25      1.1  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26      1.1  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27      1.1  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28      1.1  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29      1.1  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30      1.1  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31      1.1  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32      1.1  cgd  * SUCH DAMAGE.
     33      1.1  cgd  *
     34  1.1.1.2  jtc  *      @(#)tip.h	8.1 (Berkeley) 6/6/93
     35      1.1  cgd  */
     36      1.1  cgd 
     37      1.1  cgd /*
     38      1.1  cgd  * tip - terminal interface program
     39      1.1  cgd  */
     40      1.1  cgd 
     41      1.1  cgd #include <sys/types.h>
     42      1.1  cgd #include <machine/endian.h>
     43      1.1  cgd #include <sys/file.h>
     44      1.1  cgd #include <sys/time.h>
     45      1.1  cgd 
     46      1.1  cgd #include <sgtty.h>
     47      1.1  cgd #include <signal.h>
     48      1.1  cgd #include <stdio.h>
     49      1.1  cgd #include <stdlib.h>
     50      1.1  cgd #include <string.h>
     51      1.1  cgd #include <pwd.h>
     52      1.1  cgd #include <ctype.h>
     53      1.1  cgd #include <setjmp.h>
     54      1.1  cgd #include <unistd.h>
     55      1.1  cgd #include <errno.h>
     56      1.1  cgd 
     57      1.1  cgd /*
     58      1.1  cgd  * Remote host attributes
     59      1.1  cgd  */
     60      1.1  cgd char	*DV;			/* UNIX device(s) to open */
     61      1.1  cgd char	*EL;			/* chars marking an EOL */
     62      1.1  cgd char	*CM;			/* initial connection message */
     63      1.1  cgd char	*IE;			/* EOT to expect on input */
     64      1.1  cgd char	*OE;			/* EOT to send to complete FT */
     65      1.1  cgd char	*CU;			/* call unit if making a phone call */
     66      1.1  cgd char	*AT;			/* acu type */
     67      1.1  cgd char	*PN;			/* phone number(s) */
     68      1.1  cgd char	*DI;			/* disconnect string */
     69      1.1  cgd char	*PA;			/* parity to be generated */
     70      1.1  cgd 
     71      1.1  cgd char	*PH;			/* phone number file */
     72      1.1  cgd char	*RM;			/* remote file name */
     73      1.1  cgd char	*HO;			/* host name */
     74      1.1  cgd 
     75  1.1.1.2  jtc long	BR;			/* line speed for conversation */
     76  1.1.1.2  jtc long	FS;			/* frame size for transfers */
     77      1.1  cgd 
     78      1.1  cgd char	DU;			/* this host is dialed up */
     79      1.1  cgd char	HW;			/* this device is hardwired, see hunt.c */
     80      1.1  cgd char	*ES;			/* escape character */
     81      1.1  cgd char	*EX;			/* exceptions */
     82      1.1  cgd char	*FO;			/* force (literal next) char*/
     83      1.1  cgd char	*RC;			/* raise character */
     84      1.1  cgd char	*RE;			/* script record file */
     85      1.1  cgd char	*PR;			/* remote prompt */
     86  1.1.1.2  jtc long	DL;			/* line delay for file transfers to remote */
     87  1.1.1.2  jtc long	CL;			/* char delay for file transfers to remote */
     88  1.1.1.2  jtc long	ET;			/* echocheck timeout */
     89      1.1  cgd char	HD;			/* this host is half duplex - do local echo */
     90      1.1  cgd 
     91      1.1  cgd /*
     92      1.1  cgd  * String value table
     93      1.1  cgd  */
     94      1.1  cgd typedef
     95      1.1  cgd 	struct {
     96      1.1  cgd 		char	*v_name;	/* whose name is it */
     97      1.1  cgd 		char	v_type;		/* for interpreting set's */
     98      1.1  cgd 		char	v_access;	/* protection of touchy ones */
     99      1.1  cgd 		char	*v_abrev;	/* possible abreviation */
    100      1.1  cgd 		char	*v_value;	/* casted to a union later */
    101      1.1  cgd 	}
    102      1.1  cgd 	value_t;
    103      1.1  cgd 
    104      1.1  cgd #define STRING	01		/* string valued */
    105      1.1  cgd #define BOOL	02		/* true-false value */
    106      1.1  cgd #define NUMBER	04		/* numeric value */
    107      1.1  cgd #define CHAR	010		/* character value */
    108      1.1  cgd 
    109      1.1  cgd #define WRITE	01		/* write access to variable */
    110      1.1  cgd #define	READ	02		/* read access */
    111      1.1  cgd 
    112      1.1  cgd #define CHANGED	01		/* low bit is used to show modification */
    113      1.1  cgd #define PUBLIC	1		/* public access rights */
    114      1.1  cgd #define PRIVATE	03		/* private to definer */
    115      1.1  cgd #define ROOT	05		/* root defined */
    116      1.1  cgd 
    117      1.1  cgd #define	TRUE	1
    118      1.1  cgd #define FALSE	0
    119      1.1  cgd 
    120      1.1  cgd #define ENVIRON	020		/* initialize out of the environment */
    121      1.1  cgd #define IREMOTE	040		/* initialize out of remote structure */
    122      1.1  cgd #define INIT	0100		/* static data space used for initialization */
    123      1.1  cgd #define TMASK	017
    124      1.1  cgd 
    125      1.1  cgd /*
    126      1.1  cgd  * Definition of ACU line description
    127      1.1  cgd  */
    128      1.1  cgd typedef
    129      1.1  cgd 	struct {
    130      1.1  cgd 		char	*acu_name;
    131      1.1  cgd 		int	(*acu_dialer)();
    132      1.1  cgd 		int	(*acu_disconnect)();
    133      1.1  cgd 		int	(*acu_abort)();
    134      1.1  cgd 	}
    135      1.1  cgd 	acu_t;
    136      1.1  cgd 
    137      1.1  cgd #define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
    138      1.1  cgd 
    139      1.1  cgd /*
    140      1.1  cgd  * variable manipulation stuff --
    141      1.1  cgd  *   if we defined the value entry in value_t, then we couldn't
    142      1.1  cgd  *   initialize it in vars.c, so we cast it as needed to keep lint
    143      1.1  cgd  *   happy.
    144      1.1  cgd  */
    145      1.1  cgd typedef
    146      1.1  cgd 	union {
    147      1.1  cgd 		int	zz_number;
    148      1.1  cgd 		short	zz_boolean[2];
    149      1.1  cgd 		char	zz_character[4];
    150      1.1  cgd 		int	*zz_address;
    151      1.1  cgd 	}
    152      1.1  cgd 	zzhack;
    153      1.1  cgd 
    154      1.1  cgd #define value(v)	vtable[v].v_value
    155      1.1  cgd 
    156      1.1  cgd #define number(v)	((((zzhack *)(&(v))))->zz_number)
    157      1.1  cgd 
    158      1.1  cgd #if BYTE_ORDER == LITTLE_ENDIAN
    159      1.1  cgd #define boolean(v)	((((zzhack *)(&(v))))->zz_boolean[0])
    160      1.1  cgd #define character(v)	((((zzhack *)(&(v))))->zz_character[0])
    161      1.1  cgd #endif
    162      1.1  cgd 
    163      1.1  cgd #if BYTE_ORDER == BIG_ENDIAN
    164      1.1  cgd #define boolean(v)	((((zzhack *)(&(v))))->zz_boolean[1])
    165      1.1  cgd #define character(v)	((((zzhack *)(&(v))))->zz_character[3])
    166      1.1  cgd #endif
    167      1.1  cgd 
    168      1.1  cgd #define address(v)	((((zzhack *)(&(v))))->zz_address)
    169      1.1  cgd 
    170      1.1  cgd /*
    171      1.1  cgd  * Escape command table definitions --
    172      1.1  cgd  *   lookup in this table is performed when ``escapec'' is recognized
    173      1.1  cgd  *   at the begining of a line (as defined by the eolmarks variable).
    174      1.1  cgd */
    175      1.1  cgd 
    176      1.1  cgd typedef
    177      1.1  cgd 	struct {
    178      1.1  cgd 		char	e_char;		/* char to match on */
    179      1.1  cgd 		char	e_flags;	/* experimental, priviledged */
    180      1.1  cgd 		char	*e_help;	/* help string */
    181      1.1  cgd 		int 	(*e_func)();	/* command */
    182      1.1  cgd 	}
    183      1.1  cgd 	esctable_t;
    184      1.1  cgd 
    185      1.1  cgd #define NORM	00		/* normal protection, execute anyone */
    186      1.1  cgd #define EXP	01		/* experimental, mark it with a `*' on help */
    187      1.1  cgd #define PRIV	02		/* priviledged, root execute only */
    188      1.1  cgd 
    189      1.1  cgd extern int	vflag;		/* verbose during reading of .tiprc file */
    190      1.1  cgd extern value_t	vtable[];	/* variable table */
    191      1.1  cgd 
    192      1.1  cgd #ifndef ACULOG
    193      1.1  cgd #define logent(a, b, c, d)
    194      1.1  cgd #define loginit()
    195      1.1  cgd #endif
    196      1.1  cgd 
    197      1.1  cgd /*
    198      1.1  cgd  * Definition of indices into variable table so
    199      1.1  cgd  *  value(DEFINE) turns into a static address.
    200      1.1  cgd  */
    201      1.1  cgd 
    202      1.1  cgd #define BEAUTIFY	0
    203      1.1  cgd #define BAUDRATE	1
    204      1.1  cgd #define DIALTIMEOUT	2
    205      1.1  cgd #define EOFREAD		3
    206      1.1  cgd #define EOFWRITE	4
    207      1.1  cgd #define EOL		5
    208      1.1  cgd #define ESCAPE		6
    209      1.1  cgd #define EXCEPTIONS	7
    210      1.1  cgd #define FORCE		8
    211      1.1  cgd #define FRAMESIZE	9
    212      1.1  cgd #define HOST		10
    213      1.1  cgd #define LOG		11
    214      1.1  cgd #define PHONES		12
    215      1.1  cgd #define PROMPT		13
    216      1.1  cgd #define RAISE		14
    217      1.1  cgd #define RAISECHAR	15
    218      1.1  cgd #define RECORD		16
    219      1.1  cgd #define REMOTE		17
    220      1.1  cgd #define SCRIPT		18
    221      1.1  cgd #define TABEXPAND	19
    222      1.1  cgd #define VERBOSE		20
    223      1.1  cgd #define SHELL		21
    224      1.1  cgd #define HOME		22
    225      1.1  cgd #define ECHOCHECK	23
    226      1.1  cgd #define DISCONNECT	24
    227      1.1  cgd #define TAND		25
    228      1.1  cgd #define LDELAY		26
    229      1.1  cgd #define CDELAY		27
    230      1.1  cgd #define ETIMEOUT	28
    231      1.1  cgd #define RAWFTP		29
    232      1.1  cgd #define HALFDUPLEX	30
    233      1.1  cgd #define	LECHO		31
    234      1.1  cgd #define	PARITY		32
    235      1.1  cgd 
    236      1.1  cgd #define NOVAL	((value_t *)NULL)
    237      1.1  cgd #define NOACU	((acu_t *)NULL)
    238      1.1  cgd #define NOSTR	((char *)NULL)
    239      1.1  cgd #define NOFILE	((FILE *)NULL)
    240      1.1  cgd #define NOPWD	((struct passwd *)0)
    241      1.1  cgd 
    242      1.1  cgd struct sgttyb	arg;		/* current mode of local terminal */
    243      1.1  cgd struct sgttyb	defarg;		/* initial mode of local terminal */
    244      1.1  cgd struct tchars	tchars;		/* current state of terminal */
    245      1.1  cgd struct tchars	defchars;	/* initial state of terminal */
    246      1.1  cgd struct ltchars	ltchars;	/* current local characters of terminal */
    247      1.1  cgd struct ltchars	deflchars;	/* initial local characters of terminal */
    248      1.1  cgd 
    249      1.1  cgd FILE	*fscript;		/* FILE for scripting */
    250      1.1  cgd 
    251      1.1  cgd int	fildes[2];		/* file transfer synchronization channel */
    252      1.1  cgd int	repdes[2];		/* read process sychronization channel */
    253      1.1  cgd int	FD;			/* open file descriptor to remote host */
    254      1.1  cgd int	AC;			/* open file descriptor to dialer (v831 only) */
    255      1.1  cgd int	vflag;			/* print .tiprc initialization sequence */
    256      1.1  cgd int	sfd;			/* for ~< operation */
    257      1.1  cgd int	pid;			/* pid of tipout */
    258      1.1  cgd uid_t	uid, euid;		/* real and effective user id's */
    259      1.1  cgd gid_t	gid, egid;		/* real and effective group id's */
    260      1.1  cgd int	stop;			/* stop transfer session flag */
    261      1.1  cgd int	quit;			/* same; but on other end */
    262      1.1  cgd int	intflag;		/* recognized interrupt */
    263      1.1  cgd int	stoprompt;		/* for interrupting a prompt session */
    264      1.1  cgd int	timedout;		/* ~> transfer timedout */
    265      1.1  cgd int	cumode;			/* simulating the "cu" program */
    266      1.1  cgd 
    267      1.1  cgd char	fname[80];		/* file name buffer for ~< */
    268      1.1  cgd char	copyname[80];		/* file name buffer for ~> */
    269      1.1  cgd char	ccc;			/* synchronization character */
    270      1.1  cgd char	ch;			/* for tipout */
    271      1.1  cgd char	*uucplock;		/* name of lock file for uucp's */
    272      1.1  cgd 
    273      1.1  cgd int	odisc;				/* initial tty line discipline */
    274      1.1  cgd extern	int disc;			/* current tty discpline */
    275      1.1  cgd 
    276      1.1  cgd extern	char *ctrl();
    277      1.1  cgd extern	char *vinterp();
    278      1.1  cgd extern	char *connect();
    279