Home | History | Annotate | Line # | Download | only in telnet
externs.h revision 1.39
      1 /*	$NetBSD: externs.h,v 1.39 2018/12/13 04:49:19 maya 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     In3270,		/* Are we in 3270 mode? */
     75     telnetport,		/* Are we connected to the telnet port? */
     76     localflow,		/* Flow control handled locally */
     77     restartany,		/* If flow control, restart output on any character */
     78     localchars,		/* we recognize interrupt/quit */
     79     donelclchars,	/* the user has set "localchars" */
     80     showoptions,
     81     net,		/* Network file descriptor */
     82     tin,		/* Terminal input file descriptor */
     83     tout,		/* Terminal output file descriptor */
     84     crlf,		/* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
     85     autoflush,		/* flush output when interrupting? */
     86     autosynch,		/* send interrupt characters with SYNCH? */
     87     SYNCHing,		/* Is the stream in telnet SYNCH mode? */
     88     donebinarytoggle,	/* the user has put us in binary */
     89     dontlecho,		/* do we suppress local echoing right now? */
     90     crmod,
     91     netdata,		/* Print out network data flow */
     92     prettydump,		/* Print "netdata" output in user readable format */
     93     termdata,		/* Print out terminal data flow */
     94     telnet_debug,	/* Debug level */
     95     doaddrlookup,	/* do a reverse address lookup? */
     96     clienteof;		/* Client received EOF */
     97 
     98 extern cc_t escape;	/* Escape to command mode */
     99 extern cc_t rlogin;	/* Rlogin mode escape character */
    100 #ifdef	KLUDGELINEMODE
    101 extern cc_t echoc;	/* Toggle local echoing */
    102 #endif
    103 
    104 extern char
    105     *prompt;		/* Prompt for command. */
    106 
    107 extern char
    108     doopt[],
    109     dont[],
    110     will[],
    111     wont[],
    112     options[],		/* All the little options */
    113     *hostname;		/* Who are we connected to? */
    114 
    115 #ifdef	ENCRYPTION
    116 extern void (*encrypt_output)(unsigned char *, int);
    117 extern int (*decrypt_input)(int);
    118 #endif	/* ENCRYPTION */
    119 
    120 /*
    121  * We keep track of each side of the option negotiation.
    122  */
    123 
    124 #define	MY_STATE_WILL		0x01
    125 #define	MY_WANT_STATE_WILL	0x02
    126 #define	MY_STATE_DO		0x04
    127 #define	MY_WANT_STATE_DO	0x08
    128 
    129 /*
    130  * Macros to check the current state of things
    131  */
    132 
    133 #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
    134 #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
    135 #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
    136 #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
    137 
    138 #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
    139 #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
    140 #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
    141 #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
    142 
    143 #define	set_my_state_do(opt)		{options[opt] |= MY_STATE_DO;}
    144 #define	set_my_state_will(opt)		{options[opt] |= MY_STATE_WILL;}
    145 #define	set_my_want_state_do(opt)	{options[opt] |= MY_WANT_STATE_DO;}
    146 #define	set_my_want_state_will(opt)	{options[opt] |= MY_WANT_STATE_WILL;}
    147 
    148 #define	set_my_state_dont(opt)		{options[opt] &= ~MY_STATE_DO;}
    149 #define	set_my_state_wont(opt)		{options[opt] &= ~MY_STATE_WILL;}
    150 #define	set_my_want_state_dont(opt)	{options[opt] &= ~MY_WANT_STATE_DO;}
    151 #define	set_my_want_state_wont(opt)	{options[opt] &= ~MY_WANT_STATE_WILL;}
    152 
    153 /*
    154  * Make everything symmetrical
    155  */
    156 
    157 #define	HIS_STATE_WILL			MY_STATE_DO
    158 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
    159 #define HIS_STATE_DO			MY_STATE_WILL
    160 #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
    161 
    162 #define	his_state_is_do			my_state_is_will
    163 #define	his_state_is_will		my_state_is_do
    164 #define his_want_state_is_do		my_want_state_is_will
    165 #define his_want_state_is_will		my_want_state_is_do
    166 
    167 #define	his_state_is_dont		my_state_is_wont
    168 #define	his_state_is_wont		my_state_is_dont
    169 #define his_want_state_is_dont		my_want_state_is_wont
    170 #define his_want_state_is_wont		my_want_state_is_dont
    171 
    172 #define	set_his_state_do		set_my_state_will
    173 #define	set_his_state_will		set_my_state_do
    174 #define	set_his_want_state_do		set_my_want_state_will
    175 #define	set_his_want_state_will		set_my_want_state_do
    176 
    177 #define	set_his_state_dont		set_my_state_wont
    178 #define	set_his_state_wont		set_my_state_dont
    179 #define	set_his_want_state_dont		set_my_want_state_wont
    180 #define	set_his_want_state_wont		set_my_want_state_dont
    181 
    182 
    183 extern FILE
    184     *NetTrace;		/* Where debugging output goes */
    185 extern char
    186     NetTraceFile[];	/* Name of file where debugging output goes */
    187 
    188 extern jmp_buf
    189     toplevel;		/* For error conditions. */
    190 
    191 
    192 /* authenc.c */
    193 int telnet_net_write(unsigned char *, int);
    194 void net_encrypt(void);
    195 int telnet_spin(void);
    196 char *telnet_getenv(char *);
    197 char *telnet_gets(char *, char *, int, int);
    198 
    199 /* commands.c */
    200 int send_tncmd(void (*)(int, int), const char *, char *);
    201 void _setlist_init(void);
    202 void set_escape_char(char *);
    203 int set_mode(int);
    204 int clear_mode(int);
    205 int modehelp(int);
    206 int suspend(int, char *[]);
    207 int shell(int, char *[]);
    208 int quit(int, char *[]);
    209 int logout(int, char *[]);
    210 int env_cmd(int, char *[]);
    211 struct env_lst *env_find(const unsigned char *);
    212 void env_init(void);
    213 struct env_lst *env_define(const unsigned char *, unsigned char *);
    214 struct env_lst *env_undefine(const unsigned char *, unsigned char *);
    215 struct env_lst *env_export(const unsigned char *, unsigned char *);
    216 struct env_lst *env_unexport(const unsigned char *, unsigned char *);
    217 struct env_lst *env_send(const unsigned char *, unsigned char *);
    218 struct env_lst *env_list(const unsigned char *, unsigned char *);
    219 unsigned char *env_default(int, int );
    220 unsigned char *env_getvalue(const unsigned char *);
    221 void env_varval(const unsigned char *);
    222 int auth_cmd(int, char *[]);
    223 int ayt_status(void);
    224 int encrypt_cmd(int, char *[]);
    225 int tn(int, char *[]);
    226 void command(int, const char *, int);
    227 void cmdrc(const char *, const char *);
    228 struct addrinfo;
    229 
    230 /* main.c */
    231 void tninit(void);
    232 void usage(void) __dead;
    233 
    234 /* network.c */
    235 void init_network(void);
    236 int stilloob(void);
    237 void setneturg(void);
    238 int netflush(void);
    239 
    240 /* sys_bsd.c */
    241 void init_sys(void);
    242 int TerminalWrite(char *, int);
    243 int TerminalRead(unsigned char *, int);
    244 int TerminalAutoFlush(void);
    245 int TerminalSpecialChars(int);
    246 void TerminalFlushOutput(void);
    247 void TerminalSaveState(void);
    248 cc_t *tcval(int);
    249 void TerminalDefaultChars(void);
    250 void TerminalRestoreState(void);
    251 void TerminalNewMode(int);
    252 void TerminalSpeeds(long *, long *);
    253 int TerminalWindowSize(long *, long *);
    254 int NetClose(int);
    255 void NetNonblockingIO(int, int);
    256 void NetSigIO(int, int);
    257 void NetSetPgrp(int);
    258 void sys_telnet_init(void);
    259 int process_rings(int , int , int , int , int , int);
    260 
    261 /* telnet.c */
    262 void init_telnet(void);
    263 void send_do(int, int );
    264 void send_dont(int, int );
    265 void send_will(int, int );
    266 void send_wont(int, int );
    267 void willoption(int);
    268 void wontoption(int);
    269 char **mklist(char *, char *);
    270 int is_unique(char *, char **, char **);
    271 int setup_term(char *, int, int *);
    272 char *gettermname(void);
    273 void lm_will(unsigned char *, int);
    274 void lm_wont(unsigned char *, int);
    275 void lm_do(unsigned char *, int);
    276 void lm_dont(unsigned char *, int);
    277 void lm_mode(unsigned char *, int, int );
    278 void slc_init(void);
    279 void slcstate(void);
    280 void slc_mode_export(int);
    281 void slc_mode_import(int);
    282 void slc_import(int);
    283 void slc_export(void);
    284 void slc(unsigned char *, int);
    285 void slc_check(void);
    286 void slc_start_reply(void);
    287 void slc_add_reply(unsigned int, unsigned int, cc_t);
    288 void slc_end_reply(void);
    289 int slc_update(void);
    290 void env_opt(unsigned char *, int);
    291 void env_opt_start(void);
    292 void env_opt_start_info(void);
    293 void env_opt_add(unsigned char *);
    294 int opt_welldefined(const char *);
    295 void env_opt_end(int);
    296 int telrcv(void);
    297 int rlogin_susp(void);
    298 int Scheduler(int);
    299 void telnet(const char *);
    300 void xmitAO(void);
    301 void xmitEL(void);
    302 void xmitEC(void);
    303 int dosynch(char *);
    304 int get_status(char *);
    305 void intp(void);
    306 void sendbrk(void);
    307 void sendabort(void);
    308 void sendsusp(void);
    309 void sendeof(void);
    310 void sendayt(void);
    311 void sendnaws(void);
    312 void tel_enter_binary(int);
    313 void tel_leave_binary(int);
    314 
    315 /* terminal.c */
    316 void init_terminal(void);
    317 int ttyflush(int);
    318 int getconnmode(void);
    319 void setconnmode(int);
    320 void setcommandmode(void);
    321 
    322 /* utilities.c */
    323 void upcase(char *);
    324 int SetSockOpt(int, int, int, int);
    325 void SetNetTrace(char *);
    326 void Dump(int, unsigned char *, int);
    327 void printoption(const char *, int, int );
    328 void optionstatus(void);
    329 void printsub(int, unsigned char *, int);
    330 void EmptyTerminal(void);
    331 void SetForExit(void);
    332 void Exit(int) __attribute__((__noreturn__));
    333 void ExitString(const char *, int) __attribute__((__noreturn__));
    334 
    335 
    336 extern struct	termios new_tc;
    337 
    338 # define termEofChar		new_tc.c_cc[VEOF]
    339 # define termEraseChar		new_tc.c_cc[VERASE]
    340 # define termIntChar		new_tc.c_cc[VINTR]
    341 # define termKillChar		new_tc.c_cc[VKILL]
    342 # define termQuitChar		new_tc.c_cc[VQUIT]
    343 
    344 #  define termSuspChar		new_tc.c_cc[VSUSP]
    345 #  define termFlushChar		new_tc.c_cc[VDISCARD]
    346 #  define termWerasChar		new_tc.c_cc[VWERASE]
    347 #  define termRprntChar		new_tc.c_cc[VREPRINT]
    348 #  define termLiteralNextChar	new_tc.c_cc[VLNEXT]
    349 #  define termStartChar		new_tc.c_cc[VSTART]
    350 #  define termStopChar		new_tc.c_cc[VSTOP]
    351 #  define termForw1Char		new_tc.c_cc[VEOL]
    352 #  define termForw2Char		new_tc.c_cc[VEOL]
    353 #  define termAytChar		new_tc.c_cc[VSTATUS]
    354 
    355 # define termEofCharp		&termEofChar
    356 # define termEraseCharp		&termEraseChar
    357 # define termIntCharp		&termIntChar
    358 # define termKillCharp		&termKillChar
    359 # define termQuitCharp		&termQuitChar
    360 # define termSuspCharp		&termSuspChar
    361 # define termFlushCharp		&termFlushChar
    362 # define termWerasCharp		&termWerasChar
    363 # define termRprntCharp		&termRprntChar
    364 # define termLiteralNextCharp	&termLiteralNextChar
    365 # define termStartCharp		&termStartChar
    366 # define termStopCharp		&termStopChar
    367 # define termForw1Charp		&termForw1Char
    368 # define termForw2Charp		&termForw2Char
    369 # define termAytCharp		&termAytChar
    370