xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.bin/telnet/externs.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * Copyright 1994-2002 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1988, 1990, 1993
8  *	The Regents of the University of California.  All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)externs.h	8.1 (Berkeley) 6/6/93
39  */
40 
41 #ifndef _EXTERNS_H
42 #define	_EXTERNS_H
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 #include <libintl.h>
49 #include <stdio.h>
50 #include <setjmp.h>
51 #include <sys/filio.h>
52 #ifdef	USE_TERMIO
53 #include <sys/termios.h>
54 #define	termio termios
55 #endif
56 #if defined(NO_CC_T) || !defined(USE_TERMIO)
57 #if !defined(USE_TERMIO)
58 typedef char cc_t;
59 #else
60 typedef unsigned char cc_t;
61 #endif
62 #endif
63 
64 #include "auth.h"
65 #include "encrypt.h"
66 #include <profile/prof_int.h>
67 
68 extern profile_options_boolean	config_file_options[];
69 #define	forwardable_flag_set	config_file_options[0].found
70 #define	forward_flag_set	config_file_options[1].found
71 #define	encrypt_flag_set	config_file_options[2].found
72 #define	autologin_set		config_file_options[3].found
73 
74 #include <string.h>
75 
76 #ifndef	_POSIX_VDISABLE
77 #include <sys/param.h>	/* pick up VDISABLE definition, mayby */
78 #ifdef VDISABLE
79 #define	_POSIX_VDISABLE VDISABLE
80 #else
81 #define	_POSIX_VDISABLE ((cc_t)'\377')
82 #endif
83 #endif
84 
85 #include <wait.h>
86 #include <stdlib.h>
87 #include <unistd.h>
88 
89 
90 #define	SUBBUFSIZE	256
91 
92 extern int autologin;	/* Autologin enabled */
93 extern int skiprc;	/* Don't process the ~/.telnetrc file */
94 extern int eight;	/* use eight bit mode (binary in and/or out */
95 extern int flushout;	/* flush output */
96 extern int connected;	/* Are we connected to the other side? */
97 extern int globalmode;	/* Mode tty should be in */
98 extern int telnetport;	/* Are we connected to the telnet port? */
99 extern int localflow;	/* Flow control handled locally */
100 extern int restartany;	/* If flow control, restart output on any character */
101 extern int localchars;	/* we recognize interrupt/quit */
102 extern int donelclchars; /* the user has set "localchars" */
103 extern int showoptions;
104 extern int net;		/* Network file descriptor */
105 extern int tout;	/* Terminal output file descriptor */
106 extern int crlf;	/* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
107 extern int autoflush;	/* flush output when interrupting? */
108 extern int autosynch;	/* send interrupt characters with SYNCH? */
109 extern int SYNCHing;	/* Is the stream in telnet SYNCH mode? */
110 extern int donebinarytoggle;	/* the user has put us in binary */
111 extern int dontlecho;	/* do we suppress local echoing right now? */
112 extern int crmod;
113 extern int netdata;	/* Print out network data flow */
114 extern int prettydump;	/* Print "netdata" output in user readable format */
115 extern int termdata;	/* Print out terminal data flow */
116 extern int eof_pending;	/* Received EOF in line mode, need to send IAC-xEOF */
117 extern int debug;	/* Debug level */
118 
119 
120 extern int krb5auth_flag;
121 extern char *RemoteHostName;
122 extern char *UserNameRequested;
123 extern int forwardable_flag;
124 extern int forward_flag;
125 extern boolean_t wantencryption;	/* User has requested encryption */
126 extern int encrypt_flag;		/* for reading config file for Krb5 */
127 
128 extern boolean_t Ambiguous(void *);
129 extern boolean_t intr_happened;	/* for interrupt handling */
130 extern boolean_t intr_waiting;
131 
132 extern cc_t escape;	/* Escape to command mode */
133 extern cc_t rlogin;	/* Rlogin mode escape character */
134 extern boolean_t escape_valid;
135 #ifdef	KLUDGELINEMODE
136 extern cc_t echoc;	/* Toggle local echoing */
137 #endif
138 
139 extern char *prompt;	/* Prompt for command. */
140 
141 extern char doopt[];
142 extern char dont[];
143 extern char will[];
144 extern char wont[];
145 extern char options[];	/* All the little options */
146 extern char *hostname;	/* Who are we connected to? */
147 extern void (*encrypt_output) (unsigned char *, int);
148 extern int (*decrypt_input) (int);
149 
150 /*
151  * We keep track of each side of the option negotiation.
152  */
153 
154 #define	MY_STATE_WILL		0x01
155 #define	MY_WANT_STATE_WILL	0x02
156 #define	MY_STATE_DO		0x04
157 #define	MY_WANT_STATE_DO	0x08
158 
159 /*
160  * Macros to check the current state of things
161  */
162 
163 #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
164 #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
165 #define	my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
166 #define	my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
167 
168 #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
169 #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
170 #define	my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
171 #define	my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
172 
173 #define	set_my_state_do(opt)		{options[opt] |= MY_STATE_DO; }
174 #define	set_my_state_will(opt)		{options[opt] |= MY_STATE_WILL; }
175 #define	set_my_want_state_do(opt)	{options[opt] |= MY_WANT_STATE_DO; }
176 #define	set_my_want_state_will(opt)	{options[opt] |= MY_WANT_STATE_WILL; }
177 
178 #define	set_my_state_dont(opt)		{options[opt] &= ~MY_STATE_DO; }
179 #define	set_my_state_wont(opt)		{options[opt] &= ~MY_STATE_WILL; }
180 #define	set_my_want_state_dont(opt)	{options[opt] &= ~MY_WANT_STATE_DO; }
181 #define	set_my_want_state_wont(opt)	{options[opt] &= ~MY_WANT_STATE_WILL; }
182 
183 /*
184  * Make everything symetrical
185  */
186 
187 #define	HIS_STATE_WILL			MY_STATE_DO
188 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
189 #define	HIS_STATE_DO			MY_STATE_WILL
190 #define	HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
191 
192 #define	his_state_is_do			my_state_is_will
193 #define	his_state_is_will		my_state_is_do
194 #define	his_want_state_is_do		my_want_state_is_will
195 #define	his_want_state_is_will		my_want_state_is_do
196 
197 #define	his_state_is_dont		my_state_is_wont
198 #define	his_state_is_wont		my_state_is_dont
199 #define	his_want_state_is_dont		my_want_state_is_wont
200 #define	his_want_state_is_wont		my_want_state_is_dont
201 
202 #define	set_his_state_do		set_my_state_will
203 #define	set_his_state_will		set_my_state_do
204 #define	set_his_want_state_do		set_my_want_state_will
205 #define	set_his_want_state_will		set_my_want_state_do
206 
207 #define	set_his_state_dont		set_my_state_wont
208 #define	set_his_state_wont		set_my_state_dont
209 #define	set_his_want_state_dont		set_my_want_state_wont
210 #define	set_his_want_state_wont		set_my_want_state_dont
211 
212 
213 extern FILE *NetTrace;		/* Where debugging output goes */
214 				/* Name of file where debugging output goes */
215 extern unsigned char NetTraceFile[];
216 extern void SetNetTrace(char *); /* Function to change where debugging goes */
217 
218 extern jmp_buf peerdied;
219 extern jmp_buf toplevel;	/* For error conditions. */
220 
221 extern char *AllocStringBuffer(char **, unsigned int *, unsigned int);
222 extern void ExitString(char *, int);
223 extern void Exit(int);
224 extern void command(int, char *, int);
225 extern void Dump(int, unsigned char *, int);
226 extern char *GetAndAppendString(char **, unsigned int *, char *, FILE *);
227 extern char *GetString(char **, unsigned int *, FILE *);
228 extern void init_network(void);
229 extern void init_terminal(void);
230 extern void init_sys(void);
231 extern void optionstatus(void);
232 extern void printoption(char *, int, int);
233 extern void printsub(int, unsigned char *, int);
234 extern void sendnaws(void);
235 extern void setconnmode(int);
236 extern void setcommandmode(void);
237 extern void setneturg(void);
238 extern void sys_telnet_init(void);
239 extern void telnet(char *);
240 extern void tel_enter_binary(int);
241 extern void tel_leave_binary(int);
242 extern void TerminalDefaultChars(void);
243 extern void TerminalFlushOutput(void);
244 extern void TerminalNewMode(int);
245 extern void TerminalSaveState(void);
246 extern void TerminalSpeeds(int *, int *);
247 extern void upcase(char *);
248 
249 extern void xmitEL(void);
250 extern void xmitEC(void);
251 extern void intp(void);
252 extern void sendabort(void);
253 extern void sendsusp(void);
254 extern void set_escape_char(char *);
255 extern void fatal_tty_error(char *);
256 
257 extern void send_do(int, int);
258 extern void send_dont(int, int);
259 extern void send_will(int, int);
260 extern void send_wont(int, int);
261 
262 extern void lm_mode(unsigned char *, int, int);
263 
264 extern void slcstate(void);
265 extern void slc_mode_export(void);
266 extern void slc_mode_import(int);
267 extern void slc_check(void);
268 
269 extern void env_opt_start_info(void);
270 extern void env_opt_add(unsigned char *);
271 extern void env_opt_end(int);
272 
273 extern char **genget(char *, char **, int);
274 extern unsigned char *env_default(int, int);
275 extern unsigned char *env_getvalue(unsigned char *);
276 
277 extern int env_init(void);
278 extern int get_status(void);
279 extern int init_telnet(void);
280 extern int isprefix(register char *, register char *);
281 extern int netflush(void);
282 extern int opt_welldefined(char *);
283 extern int process_rings(int, int, int, int, int, int);
284 extern int quit(void);
285 extern int rlogin_susp(void);
286 extern int Scheduler(int);
287 extern int SetSockOpt(int, int, int, int);
288 extern int stilloob(void);
289 extern int telrcv(void);
290 extern int TerminalWindowSize(unsigned short *, unsigned short *);
291 extern int TerminalWrite(char *, int);
292 extern int TerminalSpecialChars(int);
293 extern int tn(int, char **);
294 extern int tninit(void);
295 extern int ttyflush(int);
296 extern int getconnmode(void);
297 extern int xmitAO(void);
298 extern int sendbrk(void);
299 extern int dosynch(void);
300 
301 extern cc_t *tcval(int);
302 
303 extern void	auth_encrypt_init(char *, char *, char *);
304 extern void	auth_encrypt_user(char *);
305 extern int	net_write(unsigned char *, int len);
306 extern void	net_encrypt(void);
307 extern void	telnet_spin(void);
308 extern void	printd(unsigned char *, int);
309 
310 #ifndef	USE_TERMIO
311 
312 extern struct	tchars ntc;
313 extern struct	ltchars nltc;
314 extern struct	sgttyb nttyb;
315 
316 #define	termEofChar		ntc.t_eofc
317 #define	termEraseChar		nttyb.sg_erase
318 #define	termFlushChar		nltc.t_flushc
319 #define	termIntChar		ntc.t_intrc
320 #define	termKillChar		nttyb.sg_kill
321 #define	termLiteralNextChar	nltc.t_lnextc
322 #define	termQuitChar		ntc.t_quitc
323 #define	termSuspChar		nltc.t_suspc
324 #define	termRprntChar		nltc.t_rprntc
325 #define	termWerasChar		nltc.t_werasc
326 #define	termStartChar		ntc.t_startc
327 #define	termStopChar		ntc.t_stopc
328 #define	termForw1Char		ntc.t_brkc
329 extern cc_t termForw2Char;
330 extern cc_t termAytChar;
331 
332 #define	termEofCharp		(cc_t *)&ntc.t_eofc
333 #define	termEraseCharp		(cc_t *)&nttyb.sg_erase
334 #define	termFlushCharp		(cc_t *)&nltc.t_flushc
335 #define	termIntCharp		(cc_t *)&ntc.t_intrc
336 #define	termKillCharp		(cc_t *)&nttyb.sg_kill
337 #define	termLiteralNextCharp	(cc_t *)&nltc.t_lnextc
338 #define	termQuitCharp		(cc_t *)&ntc.t_quitc
339 #define	termSuspCharp		(cc_t *)&nltc.t_suspc
340 #define	termRprntCharp		(cc_t *)&nltc.t_rprntc
341 #define	termWerasCharp		(cc_t *)&nltc.t_werasc
342 #define	termStartCharp		(cc_t *)&ntc.t_startc
343 #define	termStopCharp		(cc_t *)&ntc.t_stopc
344 #define	termForw1Charp		(cc_t *)&ntc.t_brkc
345 #define	termForw2Charp		(cc_t *)&termForw2Char
346 #define	termAytCharp		(cc_t *)&termAytChar
347 
348 #else
349 
350 extern struct	termio new_tc;
351 
352 #define	termEofChar		new_tc.c_cc[VEOF]
353 #define	termEraseChar		new_tc.c_cc[VERASE]
354 #define	termIntChar		new_tc.c_cc[VINTR]
355 #define	termKillChar		new_tc.c_cc[VKILL]
356 #define	termQuitChar		new_tc.c_cc[VQUIT]
357 
358 #define	termSuspChar		new_tc.c_cc[VSUSP]
359 #define	termFlushChar		new_tc.c_cc[VDISCARD]
360 #define	termWerasChar		new_tc.c_cc[VWERASE]
361 #define	termRprntChar		new_tc.c_cc[VREPRINT]
362 #define	termLiteralNextChar	new_tc.c_cc[VLNEXT]
363 #define	termStartChar		new_tc.c_cc[VSTART]
364 #define	termStopChar		new_tc.c_cc[VSTOP]
365 #define	termForw1Char		new_tc.c_cc[VEOL]
366 #define	termForw2Char		new_tc.c_cc[VEOL]
367 extern cc_t termAytChar;
368 
369 #define	termEofCharp		&termEofChar
370 #define	termEraseCharp		&termEraseChar
371 #define	termIntCharp		&termIntChar
372 #define	termKillCharp		&termKillChar
373 #define	termQuitCharp		&termQuitChar
374 #define	termSuspCharp		&termSuspChar
375 #define	termFlushCharp		&termFlushChar
376 #define	termWerasCharp		&termWerasChar
377 #define	termRprntCharp		&termRprntChar
378 #define	termLiteralNextCharp	&termLiteralNextChar
379 #define	termStartCharp		&termStartChar
380 #define	termStopCharp		&termStopChar
381 #define	termForw1Charp		&termForw1Char
382 #define	termForw2Charp		&termForw2Char
383 #define	termAytCharp		&termAytChar
384 #endif
385 
386 
387 /* Ring buffer structures which are shared */
388 
389 #include "ring.h"
390 
391 extern Ring netoring;
392 extern Ring netiring;
393 extern Ring ttyoring;
394 extern Ring ttyiring;
395 
396 #ifdef	__cplusplus
397 }
398 #endif
399 
400 #endif	/* _EXTERNS_H */
401