Home | History | Annotate | Line # | Download | only in tip
      1 /*	$NetBSD: tip.h,v 1.37 2022/05/22 11:27:37 andvar Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1989, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. Neither the name of the University nor the names of its contributors
     17  *    may be used to endorse or promote products derived from this software
     18  *    without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  * SUCH DAMAGE.
     31  *
     32  *      @(#)tip.h	8.1 (Berkeley) 6/6/93
     33  */
     34 
     35 /*
     36  * tip - terminal interface program
     37  */
     38 
     39 #include <sys/param.h>
     40 #include <sys/ioctl.h>
     41 #include <sys/time.h>
     42 #include <sys/wait.h>
     43 #include <machine/endian.h>
     44 
     45 #include <err.h>
     46 #include <fcntl.h>
     47 #include <errno.h>
     48 #include <dirent.h>
     49 #include <pwd.h>
     50 #include <setjmp.h>
     51 #include <signal.h>
     52 #include <stdio.h>
     53 #include <stdlib.h>
     54 #include <string.h>
     55 #include <termios.h>
     56 #include <time.h>
     57 #include <unistd.h>
     58 
     59 /*
     60  * Remote host attributes
     61  */
     62 extern char	*DV;			/* UNIX device(s) to open */
     63 extern char	*EL;			/* chars marking an EOL */
     64 extern char	*CM;			/* initial connection message */
     65 extern char	*IE;			/* EOT to expect on input */
     66 extern char	*OE;			/* EOT to send to complete FT */
     67 extern char	*CU;			/* call unit if making a phone call */
     68 extern char	*AT;			/* acu type */
     69 extern char	*PN;			/* phone number(s) */
     70 extern char	*DI;			/* disconnect string */
     71 extern char	*PA;			/* parity to be generated */
     72 
     73 extern char	*PH;			/* phone number file */
     74 extern char	*RM;			/* remote file name */
     75 extern char	*HO;			/* host name */
     76 
     77 extern long	BR;			/* line speed for conversation */
     78 extern long	FS;			/* frame size for transfers */
     79 
     80 extern long	DU;			/* this host is dialed up */
     81 extern long	HW;			/* this device is hardwired, see hunt.c */
     82 extern char	*ES;			/* escape character */
     83 extern char	*EX;			/* exceptions */
     84 extern char	*FO;			/* force (literal next) char*/
     85 extern char	*RC;			/* raise character */
     86 extern char	*RE;			/* script record file */
     87 extern char	*PR;			/* remote prompt */
     88 extern long	DL;			/* line delay for file transfers to remote */
     89 extern long	CL;			/* char delay for file transfers to remote */
     90 extern long	ET;			/* echocheck timeout */
     91 extern long	HD;			/* this host is half duplex - do local echo */
     92 extern char	DC;			/* this host is directly connected. */
     93 
     94 /*
     95  * String value table
     96  */
     97 typedef
     98 	struct {
     99 		const char *v_name;	/* whose name is it */
    100 		uint8_t v_type;		/* for interpreting set's */
    101 		uint8_t v_access;	/* protection of touchy ones */
    102 		const char *v_abrev;	/* possible abbreviation */
    103 		void *v_value;		/* casted to a union later */
    104 				/*
    105 				 * XXX:	this assumes that the storage space
    106 				 *	of a pointer >= that of a long
    107 				 */
    108 	}
    109 	value_t;
    110 
    111 #define STRING	01		/* string valued */
    112 #define BOOL	02		/* true-false value */
    113 #define NUMBER	04		/* numeric value */
    114 #define CHAR	010		/* character value */
    115 
    116 #define WRITE	01		/* write access to variable */
    117 #define	READ	02		/* read access */
    118 
    119 #define CHANGED	01		/* low bit is used to show modification */
    120 #define PUBLIC	1		/* public access rights */
    121 #define PRIVATE	03		/* private to definer */
    122 #define ROOT	05		/* root defined */
    123 
    124 #define	TRUE	1
    125 #define FALSE	0
    126 
    127 #define ENVIRON	020		/* initialize out of the environment */
    128 #define IREMOTE	040		/* initialize out of remote structure */
    129 #define INIT	0100		/* static data space used for initialization */
    130 #define TMASK	017
    131 
    132 /*
    133  * Definition of ACU line description
    134  */
    135 typedef
    136 	struct {
    137 		const char *acu_name;
    138 		int	(*acu_dialer)(char *, char *);
    139 		void	(*acu_disconnect)(void);
    140 		void	(*acu_abort)(void);
    141 	}
    142 	acu_t;
    143 
    144 /*
    145  * variable manipulation stuff --
    146  *   if we defined the value entry in value_t, then we couldn't
    147  *   initialize it in vars.c, so we cast it as needed to keep lint
    148  *   happy.
    149  */
    150 
    151 #define value(v)	vtable[v].v_value
    152 
    153 #define	number(v)	((int)(intptr_t)(v))
    154 #define	boolean(v)	((short)(intptr_t)(v))
    155 #define	character(v)	((char)(intptr_t)(v))
    156 #define	address(v)	((long *)(intptr_t)(v))
    157 
    158 #define	setnumber(v,n)		do { (v) = (char *)(intptr_t)(n); } while (0)
    159 #define	setboolean(v,n)		do { (v) = (char *)(intptr_t)(n); } while (0)
    160 #define	setcharacter(v,n)	do { (v) = (char *)(intptr_t)(n); } while (0)
    161 #define	setaddress(v,n)		do { (v) = (char *)(intptr_t)(n); } while (0)
    162 
    163 /*
    164  * Escape command table definitions --
    165  *   lookup in this table is performed when ``escapec'' is recognized
    166  *   at the beginning of a line (as defined by the eolmarks variable).
    167 */
    168 
    169 typedef
    170 	struct {
    171 		char	e_char;			/* char to match on */
    172 		char	e_flags;		/* experimental, privileged */
    173 		const char *e_help;		/* help string */
    174 		void 	(*e_func)(char);	/* command */
    175 	}
    176 	esctable_t;
    177 
    178 #define NORM	00		/* normal protection, execute anyone */
    179 #define EXP	01		/* experimental, mark it with a `*' on help */
    180 #define PRIV	02		/* privileged, root execute only */
    181 
    182 extern int	vflag;		/* verbose during reading of .tiprc file */
    183 extern value_t	vtable[];	/* variable table */
    184 
    185 /*
    186  * Definition of indices into variable table so
    187  *  value(DEFINE) turns into a static address.
    188  *
    189  * XXX: keep in sync with vtable[] in vars.c
    190  */
    191 
    192 #define BEAUTIFY	0
    193 #define BAUDRATE	1
    194 #define DIALTIMEOUT	2
    195 #define EOFREAD		3
    196 #define EOFWRITE	4
    197 #define EOL		5
    198 #define ESCAPE		6
    199 #define EXCEPTIONS	7
    200 #define FORCE		8
    201 #define FRAMESIZE	9
    202 #define HOST		10
    203 #define PHONES		11
    204 #define PROMPT		12
    205 #define RAISE		13
    206 #define RAISECHAR	14
    207 #define RECORD		15
    208 #define REMOTE		16
    209 #define SCRIPT		17
    210 #define TABEXPAND	18
    211 #define VERBOSE		19
    212 #define SHELL		20
    213 #define HOME		21
    214 #define ECHOCHECK	22
    215 #define DISCONNECT	23
    216 #define TAND		24
    217 #define LDELAY		25
    218 #define CDELAY		26
    219 #define ETIMEOUT	27
    220 #define RAWFTP		28
    221 #define HALFDUPLEX	29
    222 #define	LECHO		30
    223 #define	PARITY		31
    224 #define	HARDWAREFLOW	32
    225 
    226 extern struct termios	term;		/* current mode of terminal */
    227 extern struct termios	defterm;	/* initial mode of terminal */
    228 extern struct termios	defchars;	/* current mode with initial chars */
    229 
    230 extern FILE	*fscript;		/* FILE for scripting */
    231 
    232 extern int	attndes[2];		/* coprocess wakeup channel */
    233 extern int	fildes[2];		/* file transfer synchronization channel */
    234 extern int	repdes[2];		/* read process synchronization channel */
    235 extern int	FD;			/* open file descriptor to remote host */
    236 #ifndef __lint__  /* not used by hayes.c, but used by some other dialers */
    237 extern int	AC;			/* open file descriptor to dialer (v831 only) */
    238 #endif /*__lint__*/
    239 extern int	sfd;			/* for ~< operation */
    240 extern int	pid;			/* pid of tipout */
    241 extern uid_t	uid, euid;		/* real and effective user id's */
    242 extern gid_t	gid, egid;		/* real and effective group id's */
    243 extern int	stop;			/* stop transfer session flag */
    244 extern int	quit;			/* same; but on other end */
    245 extern int	stoprompt;		/* for interrupting a prompt session */
    246 extern int	timedout;		/* ~> transfer timedout */
    247 extern int	cumode;			/* simulating the "cu" program */
    248 extern int	bits8;			/* terminal is in 8-bit mode */
    249 #define STRIP_PAR	(bits8 ? 0377 : 0177)
    250 
    251 extern char	fname[80];		/* file name buffer for ~< */
    252 extern char	copyname[80];		/* file name buffer for ~> */
    253 extern char	ccc;			/* synchronization character */
    254 
    255 extern int	odisc;			/* initial tty line discipline */
    256 
    257 extern acu_t		acutable[];
    258 extern esctable_t	etable[];
    259 extern unsigned char	evenpartab[];
    260 
    261 void	alrmtimeout(int);
    262 int	any(char, const char *);
    263 void	chdirectory(char);
    264 void	cleanup(int) __dead;
    265 const char   *tip_connect(void);
    266 void	consh(char);
    267 char   *ctrl(char);
    268 void	cumain(int, char **);
    269 void	cu_put(char);
    270 void	cu_take(char);
    271 void	disconnect(const char *);
    272 char   *expand(char *);
    273 void	finish(char) __dead;
    274 void	genbrk(char);
    275 void	getfl(char);
    276 char   *getremote(char *);
    277 void	hardwareflow(const char *);
    278 void	help(char);
    279 int	hunt(char *);
    280 char   *interp(const char *);
    281 void	pipefile(char);
    282 void	pipeout(char);
    283 int	prompt(const char *, char *, size_t);
    284 void	xpwrite(int, char *, size_t);
    285 void	raw(void);
    286 void	sendchar(char);
    287 void	sendfile(char);
    288 void	setparity(const char *);
    289 void	setscript(void);
    290 void	shell(char);
    291 void	suspend(char);
    292 void	tandem(const char *);
    293 void	tipabort(const char *) __dead;
    294 void	tipout(void) __dead;
    295 int	ttysetup(speed_t);
    296 void	unraw(void);
    297 void	variable(char);
    298 void	vinit(void);
    299 char   *vinterp(char *, char);
    300 void	vlex(char *);
    301 int	vstring(const char *, char *);
    302 
    303 void	biz22_abort(void);
    304 void	biz22_disconnect(void);
    305 int	biz22f_dialer(char *, char *);
    306 int	biz22w_dialer(char *, char *);
    307 void	biz31_abort(void);
    308 void	biz31_disconnect(void);
    309 int	biz31f_dialer(char *, char *);
    310 int	biz31w_dialer(char *, char *);
    311 void	cour_abort(void);
    312 int	cour_dialer(char *, char *);
    313 void	cour_disconnect(void);
    314 int	df02_dialer(char *, char *);
    315 int	df03_dialer(char *, char *);
    316 void	df_abort(void);
    317 void	df_disconnect(void);
    318 void	dn_abort(void);
    319 int	dn_dialer(char *, char *);
    320 void	dn_disconnect(void);
    321 void	hay_abort(void);
    322 int	hay_dialer(char *, char *);
    323 void	hay_disconnect(void);
    324 void	t3000_abort(void);
    325 int	t3000_dialer(char *, char *);
    326 void	t3000_disconnect(void);
    327 void	v3451_abort(void);
    328 int	v3451_dialer(char *, char *);
    329 void	v3451_disconnect(void);
    330 void	v831_abort(void);
    331 int	v831_dialer(char *, char *);
    332 void	v831_disconnect(void);
    333 void	ven_abort(void);
    334 int	ven_dialer(char *, char *);
    335 void	ven_disconnect(void);
    336