tip.h revision 1.16 1 /* $NetBSD: tip.h,v 1.16 2004/04/23 22:11:44 christos 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 <ctype.h>
46 #include <err.h>
47 #include <fcntl.h>
48 #include <errno.h>
49 #include <libgen.h>
50 #include <dirent.h>
51 #include <pwd.h>
52 #include <setjmp.h>
53 #include <signal.h>
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #include <termios.h>
58 #include <time.h>
59 #include <unistd.h>
60
61 /*
62 * Remote host attributes
63 */
64 char *DV; /* UNIX device(s) to open */
65 char *EL; /* chars marking an EOL */
66 char *CM; /* initial connection message */
67 char *IE; /* EOT to expect on input */
68 char *OE; /* EOT to send to complete FT */
69 char *CU; /* call unit if making a phone call */
70 char *AT; /* acu type */
71 char *PN; /* phone number(s) */
72 char *DI; /* disconnect string */
73 char *PA; /* parity to be generated */
74
75 char *PH; /* phone number file */
76 char *RM; /* remote file name */
77 char *HO; /* host name */
78
79 long BR; /* line speed for conversation */
80 long FS; /* frame size for transfers */
81
82 int DU; /* this host is dialed up */
83 int HW; /* this device is hardwired, see hunt.c */
84 char *ES; /* escape character */
85 char *EX; /* exceptions */
86 char *FO; /* force (literal next) char*/
87 char *RC; /* raise character */
88 char *RE; /* script record file */
89 char *PR; /* remote prompt */
90 long DL; /* line delay for file transfers to remote */
91 long CL; /* char delay for file transfers to remote */
92 long ET; /* echocheck timeout */
93 int HD; /* this host is half duplex - do local echo */
94 char DC; /* this host is directly connected. */
95
96 /*
97 * String value table
98 */
99 typedef
100 struct {
101 const char *v_name; /* whose name is it */
102 char v_type; /* for interpreting set's */
103 char v_access; /* protection of touchy ones */
104 const char *v_abrev; /* possible abreviation */
105 char *v_value; /* casted to a union later */
106 /*
107 * XXX: this assumes that the storage space
108 * of a pointer >= that of a long
109 */
110 }
111 value_t;
112
113 #define STRING 01 /* string valued */
114 #define BOOL 02 /* true-false value */
115 #define NUMBER 04 /* numeric value */
116 #define CHAR 010 /* character value */
117
118 #define WRITE 01 /* write access to variable */
119 #define READ 02 /* read access */
120
121 #define CHANGED 01 /* low bit is used to show modification */
122 #define PUBLIC 1 /* public access rights */
123 #define PRIVATE 03 /* private to definer */
124 #define ROOT 05 /* root defined */
125
126 #define TRUE 1
127 #define FALSE 0
128
129 #define ENVIRON 020 /* initialize out of the environment */
130 #define IREMOTE 040 /* initialize out of remote structure */
131 #define INIT 0100 /* static data space used for initialization */
132 #define TMASK 017
133
134 /*
135 * Definition of ACU line description
136 */
137 typedef
138 struct {
139 const char *acu_name;
140 int (*acu_dialer) __P((char *, char *));
141 void (*acu_disconnect) __P((void));
142 void (*acu_abort) __P((void));
143 }
144 acu_t;
145
146 #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */
147
148 /*
149 * variable manipulation stuff --
150 * if we defined the value entry in value_t, then we couldn't
151 * initialize it in vars.c, so we cast it as needed to keep lint
152 * happy.
153 */
154
155 #define value(v) vtable[v].v_value
156
157 #define number(v) ((long)(v))
158 #define boolean(v) ((short)(long)(v))
159 #define character(v) ((char)(long)(v))
160 #define address(v) ((long *)(v))
161
162 #define setnumber(v,n) do { (v) = (char *)(long)(n); } while (0)
163 #define setboolean(v,n) do { (v) = (char *)(long)(n); } while (0)
164 #define setcharacter(v,n) do { (v) = (char *)(long)(n); } while (0)
165 #define setaddress(v,n) do { (v) = (char *)(n); } while (0)
166
167 /*
168 * Escape command table definitions --
169 * lookup in this table is performed when ``escapec'' is recognized
170 * at the begining of a line (as defined by the eolmarks variable).
171 */
172
173 typedef
174 struct {
175 char e_char; /* char to match on */
176 char e_flags; /* experimental, privileged */
177 const char *e_help; /* help string */
178 void (*e_func) __P((char)); /* command */
179 }
180 esctable_t;
181
182 #define NORM 00 /* normal protection, execute anyone */
183 #define EXP 01 /* experimental, mark it with a `*' on help */
184 #define PRIV 02 /* privileged, root execute only */
185
186 extern int vflag; /* verbose during reading of .tiprc file */
187 extern value_t vtable[]; /* variable table */
188
189 #ifndef ACULOG
190 #define logent(a, b, c, d)
191 #define loginit()
192 #endif
193
194 /*
195 * Definition of indices into variable table so
196 * value(DEFINE) turns into a static address.
197 *
198 * XXX: keep in sync with vtable[] in vars.c
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 struct termios term; /* current mode of terminal */
236 struct termios defterm; /* initial mode of terminal */
237 struct termios defchars; /* current mode with initial chars */
238
239 FILE *fscript; /* FILE for scripting */
240
241 int fildes[2]; /* file transfer synchronization channel */
242 int repdes[2]; /* read process synchronization channel */
243 int FD; /* open file descriptor to remote host */
244 int AC; /* open file descriptor to dialer (v831 only) */
245 int vflag; /* print .tiprc initialization sequence */
246 int sfd; /* for ~< operation */
247 int pid; /* pid of tipout */
248 uid_t uid, euid; /* real and effective user id's */
249 gid_t gid, egid; /* real and effective group id's */
250 int stop; /* stop transfer session flag */
251 int quit; /* same; but on other end */
252 int intflag; /* recognized interrupt */
253 int stoprompt; /* for interrupting a prompt session */
254 int timedout; /* ~> transfer timedout */
255 int cumode; /* simulating the "cu" program */
256 int bits8; /* terminal is is 8-bit mode */
257 #define STRIP_PAR (bits8 ? 0377 : 0177)
258
259 char fname[80]; /* file name buffer for ~< */
260 char copyname[80]; /* file name buffer for ~> */
261 char ccc; /* synchronization character */
262 char ch; /* for tipout */
263 char *uucplock; /* name of lock file for uucp's */
264
265 int odisc; /* initial tty line discipline */
266 extern int disc; /* current tty discpline */
267
268 extern acu_t acutable[];
269 extern esctable_t etable[];
270 extern unsigned char evenpartab[];
271
272 void alrmtimeout __P((int));
273 int any __P((char, const char *));
274 void chdirectory __P((char));
275 void cleanup __P((int));
276 const char *connect __P((void));
277 void consh __P((char));
278 char *ctrl __P((char));
279 int cumain __P((int, char **));
280 void cu_put __P((char));
281 void cu_take __P((char));
282 void daemon_uid __P((void));
283 void disconnect __P((const char *));
284 char *expand __P((char *));
285 void finish __P((char));
286 void genbrk __P((char));
287 void getfl __P((char));
288 char *getremote __P((char *));
289 void help __P((char));
290 int hunt __P((char *));
291 char *interp __P((const char *));
292 void logent __P((const char *, const char *, const char *, const char *));
293 void loginit __P((void));
294 void pipefile __P((char));
295 void pipeout __P((char));
296 int prompt __P((const char *, char *, size_t));
297 void xpwrite __P((int, char *, int));
298 void raw __P((void));
299 void send __P((char));
300 void sendfile __P((char));
301 void setparity __P((const char *));
302 void setscript __P((void));
303 void shell __P((char));
304 void shell_uid __P((void));
305 int speed __P((int));
306 void suspend __P((char));
307 void tandem __P((const char *));
308 void tipabort __P((const char *));
309 void tipout __P((void));
310 void ttysetup __P((int));
311 void unraw __P((void));
312 void user_uid __P((void));
313 int uu_lock __P((char *));
314 int uu_unlock __P((char *));
315 void variable __P((char));
316 void vinit __P((void));
317 char *vinterp __P((char *, char));
318 void vlex __P((char *));
319 int vstring __P((const char *, char *));
320
321 void biz22_abort __P((void));
322 void biz22_disconnect __P((void));
323 int biz22f_dialer __P((char *, char *));
324 int biz22w_dialer __P((char *, char *));
325 void biz31_abort __P((void));
326 void biz31_disconnect __P((void));
327 int biz31f_dialer __P((char *, char *));
328 int biz31w_dialer __P((char *, char *));
329 void cour_abort __P((void));
330 int cour_dialer __P((char *, char *));
331 void cour_disconnect __P((void));
332 int df02_dialer __P((char *, char *));
333 int df03_dialer __P((char *, char *));
334 void df_abort __P((void));
335 void df_disconnect __P((void));
336 void dn_abort __P((void));
337 int dn_dialer __P((char *, char *));
338 void dn_disconnect __P((void));
339 void hay_abort __P((void));
340 int hay_dialer __P((char *, char *));
341 void hay_disconnect __P((void));
342 void t3000_abort __P((void));
343 int t3000_dialer __P((char *, char *));
344 void t3000_disconnect __P((void));
345 void v3451_abort __P((void));
346 int v3451_dialer __P((char *, char *));
347 void v3451_disconnect __P((void));
348 void v831_abort __P((void));
349 int v831_dialer __P((char *, char *));
350 void v831_disconnect __P((void));
351 void ven_abort __P((void));
352 int ven_dialer __P((char *, char *));
353 void ven_disconnect __P((void));
354