1 /*        $NetBSD: externs.h,v 1.44 2018/12/14 23:40:17 christos Exp $          */
2 
3 /*
4  * Copyright (c) 1988, 1990, 1993
5  *        The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *        from: @(#)externs.h 8.3 (Berkeley) 5/30/95
32  */
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <setjmp.h>
37 #include <sys/ioctl.h>
38 #include <errno.h>
39 #include <sys/termios.h>
40 
41 #include <string.h>
42 
43 #if defined(IPSEC)
44 #include <netipsec/ipsec.h>
45 #if defined(IPSEC_POLICY_IPSEC)
46 extern char *ipsec_policy_in;
47 extern char *ipsec_policy_out;
48 #endif
49 #endif
50 
51 #ifndef   _POSIX_VDISABLE
52 # ifdef sun
53 #  include <sys/param.h>      /* pick up VDISABLE definition, mayby */
54 # endif
55 # ifdef VDISABLE
56 #  define _POSIX_VDISABLE VDISABLE
57 # else
58 #  define _POSIX_VDISABLE ((cc_t)'\377')
59 # endif
60 #endif
61 
62 #define   SUBBUFSIZE          256
63 
64 #include <sys/cdefs.h>
65 
66 extern int
67     autologin,                /* Autologin enabled */
68     skiprc,                   /* Don't process the ~/.telnetrc file */
69     eight,                    /* use eight bit mode (binary in and/or out */
70     family,                   /* address family of peer */
71     flushout,                 /* flush output */
72     connected,                /* Are we connected to the other side? */
73     globalmode,               /* Mode tty should be in */
74     telnetport,               /* Are we connected to the telnet port? */
75     localflow,                /* Flow control handled locally */
76     restartany,               /* If flow control, restart output on any character */
77     localchars,               /* we recognize interrupt/quit */
78     donelclchars,   /* the user has set "localchars" */
79     showoptions,
80     net,            /* Network file descriptor */
81     tin,            /* Terminal input file descriptor */
82     tout,           /* Terminal output file descriptor */
83     crlf,           /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
84     autoflush,                /* flush output when interrupting? */
85     autosynch,                /* send interrupt characters with SYNCH? */
86     SYNCHing,                 /* Is the stream in telnet SYNCH mode? */
87     donebinarytoggle,         /* the user has put us in binary */
88     dontlecho,                /* do we suppress local echoing right now? */
89     crmod,
90     netdata,                  /* Print out network data flow */
91     prettydump,               /* Print "netdata" output in user readable format */
92     termdata,                 /* Print out terminal data flow */
93     telnet_debug,   /* Debug level */
94     doaddrlookup,   /* do a reverse address lookup? */
95     clienteof;                /* Client received EOF */
96 
97 extern cc_t escape; /* Escape to command mode */
98 extern cc_t rlogin; /* Rlogin mode escape character */
99 #ifdef    KLUDGELINEMODE
100 extern cc_t echoc;  /* Toggle local echoing */
101 #endif
102 
103 extern char
104     *prompt;                  /* Prompt for command. */
105 
106 extern char
107     doopt[],
108     dont[],
109     will[],
110     wont[],
111     options[],                /* All the little options */
112     *hostname;                /* Who are we connected to? */
113 
114 #ifdef    ENCRYPTION
115 extern void (*encrypt_output)(unsigned char *, int);
116 extern int (*decrypt_input)(int);
117 #endif    /* ENCRYPTION */
118 
119 /*
120  * We keep track of each side of the option negotiation.
121  */
122 
123 #define   MY_STATE_WILL                 0x01
124 #define   MY_WANT_STATE_WILL  0x02
125 #define   MY_STATE_DO                   0x04
126 #define   MY_WANT_STATE_DO    0x08
127 
128 /*
129  * Macros to check the current state of things
130  */
131 
132 #define   my_state_is_do(opt)           (options[opt]&MY_STATE_DO)
133 #define   my_state_is_will(opt)                   (options[opt]&MY_STATE_WILL)
134 #define my_want_state_is_do(opt)        (options[opt]&MY_WANT_STATE_DO)
135 #define my_want_state_is_will(opt)      (options[opt]&MY_WANT_STATE_WILL)
136 
137 #define   my_state_is_dont(opt)                   (!my_state_is_do(opt))
138 #define   my_state_is_wont(opt)                   (!my_state_is_will(opt))
139 #define my_want_state_is_dont(opt)      (!my_want_state_is_do(opt))
140 #define my_want_state_is_wont(opt)      (!my_want_state_is_will(opt))
141 
142 #define   set_my_state_do(opt)                    {options[opt] |= MY_STATE_DO;}
143 #define   set_my_state_will(opt)                  {options[opt] |= MY_STATE_WILL;}
144 #define   set_my_want_state_do(opt)     {options[opt] |= MY_WANT_STATE_DO;}
145 #define   set_my_want_state_will(opt)   {options[opt] |= MY_WANT_STATE_WILL;}
146 
147 #define   set_my_state_dont(opt)                  {options[opt] &= ~MY_STATE_DO;}
148 #define   set_my_state_wont(opt)                  {options[opt] &= ~MY_STATE_WILL;}
149 #define   set_my_want_state_dont(opt)   {options[opt] &= ~MY_WANT_STATE_DO;}
150 #define   set_my_want_state_wont(opt)   {options[opt] &= ~MY_WANT_STATE_WILL;}
151 
152 /*
153  * Make everything symmetrical
154  */
155 
156 #define   HIS_STATE_WILL                          MY_STATE_DO
157 #define   HIS_WANT_STATE_WILL           MY_WANT_STATE_DO
158 #define HIS_STATE_DO                              MY_STATE_WILL
159 #define HIS_WANT_STATE_DO               MY_WANT_STATE_WILL
160 
161 #define   his_state_is_do                         my_state_is_will
162 #define   his_state_is_will             my_state_is_do
163 #define his_want_state_is_do            my_want_state_is_will
164 #define his_want_state_is_will                    my_want_state_is_do
165 
166 #define   his_state_is_dont             my_state_is_wont
167 #define   his_state_is_wont             my_state_is_dont
168 #define his_want_state_is_dont                    my_want_state_is_wont
169 #define his_want_state_is_wont                    my_want_state_is_dont
170 
171 #define   set_his_state_do              set_my_state_will
172 #define   set_his_state_will            set_my_state_do
173 #define   set_his_want_state_do                   set_my_want_state_will
174 #define   set_his_want_state_will                 set_my_want_state_do
175 
176 #define   set_his_state_dont            set_my_state_wont
177 #define   set_his_state_wont            set_my_state_dont
178 #define   set_his_want_state_dont                 set_my_want_state_wont
179 #define   set_his_want_state_wont                 set_my_want_state_dont
180 
181 
182 extern FILE
183     *NetTrace;                /* Where debugging output goes */
184 extern char
185     NetTraceFile[]; /* Name of file where debugging output goes */
186 
187 extern jmp_buf
188     toplevel;                 /* For error conditions. */
189 
190 
191 /* authenc.c */
192 int telnet_net_write(unsigned char *, int);
193 void net_encrypt(void);
194 int telnet_spin(void);
195 char *telnet_getenv(char *);
196 char *telnet_gets(char *, char *, int, int);
197 
198 /* commands.c */
199 int send_tncmd(void (*)(int, int), const char *, const char *);
200 void _setlist_init(void);
201 void set_escape_char(char *);
202 int set_mode(int);
203 int clear_mode(int);
204 int modehelp(int);
205 int suspend(int, char *[]);
206 int shell(int, char *[]);
207 int quit(int, char *[]);
208 int logout(int, char *[]);
209 int env_cmd(int, char *[]);
210 struct env_lst *env_find(const char *);
211 void env_init(void);
212 struct env_lst *env_define(const char *, char *);
213 struct env_lst *env_undefine(const char *, char *);
214 struct env_lst *env_export(const char *, char *);
215 struct env_lst *env_unexport(const char *, char *);
216 struct env_lst *env_send(const char *, char *);
217 struct env_lst *env_list(const char *, char *);
218 char *env_default(int, int );
219 char *env_getvalue(const char *);
220 void env_varval(const char *);
221 int auth_cmd(int, char *[]);
222 int ayt_status(void);
223 int encrypt_cmd(int, char *[]);
224 int tn(int, char *[]);
225 void command(int, const char *, int);
226 void cmdrc(const char *, const char *);
227 struct addrinfo;
228 
229 /* main.c */
230 void tninit(void);
231 void usage(void) __dead;
232 
233 /* network.c */
234 void init_network(void);
235 int stilloob(void);
236 void setneturg(void);
237 int netflush(void);
238 
239 /* sys_bsd.c */
240 void init_sys(void);
241 int TerminalWrite(char *, int);
242 int TerminalRead(unsigned char *, int);
243 int TerminalAutoFlush(void);
244 int TerminalSpecialChars(int);
245 void TerminalFlushOutput(void);
246 void TerminalSaveState(void);
247 cc_t *tcval(int);
248 void TerminalDefaultChars(void);
249 void TerminalNewMode(int);
250 void TerminalSpeeds(long *, long *);
251 int TerminalWindowSize(long *, long *);
252 int NetClose(int);
253 void NetSigIO(int, int);
254 void NetSetPgrp(int);
255 void sys_telnet_init(void);
256 int process_rings(int , int , int , int , int , int);
257 
258 /* telnet.c */
259 void init_telnet(void);
260 void send_do(int, int );
261 void send_dont(int, int );
262 void send_will(int, int );
263 void send_wont(int, int );
264 void willoption(int);
265 void wontoption(int);
266 char **mklist(char *, char *);
267 int is_unique(char *, char **, char **);
268 int setup_term(char *, int, int *);
269 char *gettermname(void);
270 void lm_will(unsigned char *, int);
271 void lm_wont(unsigned char *, int);
272 void lm_do(unsigned char *, int);
273 void lm_dont(unsigned char *, int);
274 void lm_mode(unsigned char *, int, int );
275 void slc_init(void);
276 void slcstate(void);
277 void slc_mode_export(int);
278 void slc_mode_import(int);
279 void slc_import(int);
280 void slc_export(void);
281 void slc(unsigned char *, int);
282 void slc_check(void);
283 void slc_start_reply(void);
284 void slc_add_reply(unsigned int, unsigned int, cc_t);
285 void slc_end_reply(void);
286 int slc_update(void);
287 void env_opt(unsigned char *, int);
288 void env_opt_start(void);
289 void env_opt_start_info(void);
290 void env_opt_add(unsigned char *);
291 int opt_welldefined(const char *);
292 void env_opt_end(int);
293 int telrcv(void);
294 int rlogin_susp(void);
295 int Scheduler(int);
296 void telnet(const char *);
297 void xmitAO(void);
298 void xmitEL(void);
299 void xmitEC(void);
300 int dosynch(const char *);
301 int get_status(const char *);
302 void intp(void);
303 void sendbrk(void);
304 void sendabort(void);
305 void sendsusp(void);
306 void sendeof(void);
307 void sendayt(void);
308 void sendnaws(void);
309 void tel_enter_binary(int);
310 void tel_leave_binary(int);
311 
312 /* terminal.c */
313 void init_terminal(void);
314 int ttyflush(int);
315 int getconnmode(void);
316 void setconnmode(int);
317 void setcommandmode(void);
318 
319 /* utilities.c */
320 void upcase(char *);
321 int SetSockOpt(int, int, int, int);
322 void SetNetTrace(const char *);
323 void Dump(int, unsigned char *, int);
324 void printoption(const char *, int, int );
325 void optionstatus(void);
326 void printsub(int, unsigned char *, int);
327 void EmptyTerminal(void);
328 void Exit(int) __attribute__((__noreturn__));
329 void ExitString(const char *, int) __attribute__((__noreturn__));
330 
331 
332 extern struct       termios new_tc;
333 
334 # define termEofChar                    new_tc.c_cc[VEOF]
335 # define termEraseChar                  new_tc.c_cc[VERASE]
336 # define termIntChar                    new_tc.c_cc[VINTR]
337 # define termKillChar                   new_tc.c_cc[VKILL]
338 # define termQuitChar                   new_tc.c_cc[VQUIT]
339 
340 #  define termSuspChar                  new_tc.c_cc[VSUSP]
341 #  define termFlushChar                 new_tc.c_cc[VDISCARD]
342 #  define termWerasChar                 new_tc.c_cc[VWERASE]
343 #  define termRprntChar                 new_tc.c_cc[VREPRINT]
344 #  define termLiteralNextChar new_tc.c_cc[VLNEXT]
345 #  define termStartChar                 new_tc.c_cc[VSTART]
346 #  define termStopChar                  new_tc.c_cc[VSTOP]
347 #  define termForw1Char                 new_tc.c_cc[VEOL]
348 #  define termForw2Char                 new_tc.c_cc[VEOL]
349 #  define termAytChar                   new_tc.c_cc[VSTATUS]
350 
351 # define termEofCharp                   &termEofChar
352 # define termEraseCharp                 &termEraseChar
353 # define termIntCharp                   &termIntChar
354 # define termKillCharp                  &termKillChar
355 # define termQuitCharp                  &termQuitChar
356 # define termSuspCharp                  &termSuspChar
357 # define termFlushCharp                 &termFlushChar
358 # define termWerasCharp                 &termWerasChar
359 # define termRprntCharp                 &termRprntChar
360 # define termLiteralNextCharp &termLiteralNextChar
361 # define termStartCharp                 &termStartChar
362 # define termStopCharp                  &termStopChar
363 # define termForw1Charp                 &termForw1Char
364 # define termForw2Charp                 &termForw2Char
365 # define termAytCharp                   &termAytChar
366