xref: /titanic_51/usr/src/cmd/tip/tip.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 /*
6  * Copyright (c) 1983 Regents of the University of California.
7  * All rights reserved.  The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 #pragma ident	"%Z%%M%	%I%	%E% SMI"
12 
13 /*
14  * tip - terminal interface program
15  */
16 
17 #include <sys/types.h>
18 #ifdef USG
19 #include <fcntl.h>	/* for O_RDWR, etc. */
20 #include <unistd.h>	/* for R_OK, etc. */
21 #else
22 #include <sys/file.h>
23 #endif
24 
25 #include <sys/termios.h>
26 #include <sys/filio.h>	/* XXX - for FIONREAD only */
27 #include <signal.h>
28 #include <stdio.h>
29 #include <pwd.h>
30 #include <ctype.h>
31 #include <setjmp.h>
32 #include <errno.h>
33 #include <string.h>
34 #include <time.h>
35 #include <sys/isa_defs.h>	/* for ENDIAN defines */
36 
37 #define	_CTRL(c)	(c&037)
38 
39 #ifdef USG
40 #define	signal(_sig_, _hdlr_)	sigset((_sig_), (_hdlr_))
41 #endif
42 typedef	void (*sig_handler_t)();	/* works on BSD and SV */
43 
44 /*
45  * Remote host attributes
46  */
47 char	*DV;			/* UNIX device(s) to open */
48 char	*EL;			/* chars marking an EOL */
49 char	*CM;			/* initial connection message */
50 char	*IE;			/* EOT to expect on input */
51 char	*OE;			/* EOT to send to complete FT */
52 char	*CU;			/* call unit if making a phone call */
53 char	*AT;			/* acu type */
54 char	*PN;			/* phone number(s) */
55 char	*DI;			/* disconnect string */
56 char	*PA;			/* parity to be generated */
57 
58 char	*PH;			/* phone number file */
59 char	*RM;			/* remote file name */
60 char	*HO;			/* host name */
61 
62 int	BR;			/* line speed for conversation */
63 int	FS;			/* frame size for transfers */
64 
65 signed char	DU;		/* this host is dialed up */
66 char	HW;			/* this device is hardwired, see hunt.c */
67 char	*ES;			/* escape character */
68 char	*EX;			/* exceptions */
69 char	*FO;			/* force (literal next) char */
70 char	*RC;			/* raise character */
71 char	*RE;			/* script record file */
72 char	*PR;			/* remote prompt */
73 int	DL;			/* line delay for file transfers to remote */
74 int	CL;			/* char delay for file transfers to remote */
75 int	ET;			/* echocheck timeout */
76 int	DB;			/* dialback - ignore hangup */
77 
78 /*
79  * String value table
80  */
81 typedef
82 	struct {
83 		char	*v_name;	/* whose name is it */
84 		char	v_type;		/* for interpreting set's */
85 		char	v_access;	/* protection of touchy ones */
86 		char	*v_abrev;	/* possible abreviation */
87 		char	*v_value;	/* casted to a union later */
88 	}
89 	value_t;
90 
91 #define	STRING	01		/* string valued */
92 #define	BOOL	02		/* true-false value */
93 #define	NUMBER	04		/* numeric value */
94 #define	CHAR	010		/* character value */
95 
96 #define	WRITE	01		/* write access to variable */
97 #define	READ	02		/* read access */
98 
99 #define	CHANGED	01		/* low bit is used to show modification */
100 #define	PUBLIC	1		/* public access rights */
101 #define	PRIVATE	03		/* private to definer */
102 #define	ROOT	05		/* root defined */
103 
104 #define	TRUE	1
105 #define	FALSE	0
106 
107 #define	ENVIRON	020		/* initialize out of the environment */
108 #define	IREMOTE	040		/* initialize out of remote structure */
109 #define	INIT	0100		/* static data space used for initialization */
110 #define	TMASK	017
111 
112 /*
113  * Definition of ACU line description
114  */
115 typedef
116 	struct {
117 		char	*acu_name;
118 		int	(*acu_dialer)();
119 		int	(*acu_disconnect)();
120 		int	(*acu_abort)();
121 	}
122 	acu_t;
123 
124 #define	equal(a, b)	(strcmp(a, b) == 0)	/* A nice function to compare */
125 
126 /*
127  * variable manipulation stuff --
128  *   if we defined the value entry in value_t, then we couldn't
129  *   initialize it in vars.c, so we cast it as needed to keep lint
130  *   happy.
131  */
132 typedef
133 	union {
134 		int	zz_number;
135 		int	*zz_address;
136 #if defined(_LITTLE_ENDIAN)
137 		short	zz_boolean;
138 		char	zz_character;
139 #endif
140 #if defined(_BIG_ENDIAN)
141 		int	zz_boolean;
142 		int	zz_character;
143 #endif
144 	}
145 	zzhack;
146 
147 #define	value(v)	vtable[v].v_value
148 
149 #define	boolean(v)	((((zzhack *)(&(v))))->zz_boolean)
150 #define	number(v)	((((zzhack *)(&(v))))->zz_number)
151 #define	character(v)	((((zzhack *)(&(v))))->zz_character)
152 #define	address(v)	((((zzhack *)(&(v))))->zz_address)
153 
154 /*
155  * Escape command table definitions --
156  *   lookup in this table is performed when ``escapec'' is recognized
157  *   at the begining of a line (as defined by the eolmarks variable).
158  */
159 
160 typedef
161 	struct {
162 		char	e_char;		/* char to match on */
163 		char	e_flags;	/* experimental, priviledged */
164 		char	*e_help;	/* help string */
165 		int 	(*e_func)();	/* command */
166 	}
167 	esctable_t;
168 
169 #define	NORM	00		/* normal protection, execute anyone */
170 #define	EXP	01		/* experimental, mark it with a `*' on help */
171 #define	PRIV	02		/* priviledged, root execute only */
172 
173 extern int	vflag;		/* verbose during reading of .tiprc file */
174 extern value_t	vtable[];	/* variable table */
175 extern int	noparity;
176 
177 
178 #ifndef ACULOG
179 #define	logent(a, b, c, d)
180 #define	loginit()
181 #endif
182 
183 /*
184  * Definition of indices into variable table so
185  *  value(DEFINE) turns into a static address.
186  */
187 
188 #define	BEAUTIFY	0
189 #define	BAUDRATE	1
190 #define	DIALTIMEOUT	2
191 #define	EOFREAD		3
192 #define	EOFWRITE	4
193 #define	EOL		5
194 #define	ESCAPE		6
195 #define	EXCEPTIONS	7
196 #define	FORCE		8
197 #define	FRAMESIZE	9
198 #define	HOST		10
199 #define	LOG		11
200 #define	PHONES		12
201 #define	PROMPT		13
202 #define	RAISE		14
203 #define	RAISECHAR	15
204 #define	RECORD		16
205 #define	REMOTE		17
206 #define	SCRIPT		18
207 #define	TABEXPAND	19
208 #define	VERBOSE		20
209 #define	SHELL		21
210 #define	HOME		22
211 #define	ECHOCHECK	23
212 #define	DISCONNECT	24
213 #define	TAND		25
214 #define	LDELAY		26
215 #define	CDELAY		27
216 #define	ETIMEOUT	28
217 #define	RAWFTP		29
218 #define	HALFDUPLEX	30
219 #define	LECHO		31
220 #define	PARITY		32
221 #define	HARDWAREFLOW	33
222 
223 #define	NOVAL	((value_t *)NULL)
224 #define	NOACU	((acu_t *)NULL)
225 #define	NOSTR	((char *)NULL)
226 #define	NOFILE	((FILE *)NULL)
227 #define	NOPWD	((struct passwd *)0)
228 
229 struct termios	arg;		/* current mode of local terminal */
230 struct termios	defarg;		/* initial mode of local terminal */
231 
232 FILE	*fscript;		/* FILE for scripting */
233 FILE	*phfd;			/* FILE for PHONES file */
234 
235 int	fildes[2];		/* file transfer synchronization channel */
236 int	repdes[2];		/* read process sychronization channel */
237 int	FD;			/* open file descriptor to remote host */
238 int	AC;			/* open file descriptor to dialer (v831 only) */
239 int	vflag;			/* print .tiprc initialization sequence */
240 int	sfd;			/* for ~< operation */
241 int	pid;			/* pid of tipout */
242 int	uid, euid;		/* real and effective user id's */
243 int	gid, egid;		/* real and effective group id's */
244 int	stoprompt;		/* for interrupting a prompt session */
245 int	timedout;		/* ~> transfer timedout */
246 int	cumode;			/* simulating the "cu" program */
247 
248 char	fname[80];		/* file name buffer for ~< */
249 char	copyname[80];		/* file name buffer for ~> */
250 char	ccc;			/* synchronization character */
251 char	ch;			/* for tipout */
252 char	*uucplock;		/* name of lock file for uucp's */
253 extern int trusted_device;
254 
255 extern	char *ctrl();
256 extern	char *ctime();
257 extern	struct passwd *getpwuid();
258 extern	char *getlogin();
259 extern	char *vinterp();
260 extern	char *getenv();
261 extern	char *malloc();
262 extern	char *connect();
263