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