Home | History | Annotate | Line # | Download | only in telnetd
defs.h revision 1.4
      1 /*
      2  * Copyright (c) 1989, 1993
      3  *	The Regents of the University of California.  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  *	from: @(#)defs.h	8.1 (Berkeley) 6/4/93
     34  *	$Id: defs.h,v 1.4 1994/02/25 03:20:46 cgd Exp $
     35  */
     36 
     37 /*
     38  * Telnet server defines
     39  */
     40 #include <sys/types.h>
     41 #include <sys/param.h>
     42 
     43 #ifndef	BSD
     44 # define	BSD 43
     45 #endif
     46 
     47 #if	defined(CRAY) && !defined(LINEMODE)
     48 # define SYSV_TERMIO
     49 # define LINEMODE
     50 # define KLUDGELINEMODE
     51 # define DIAGNOSTICS
     52 # if defined(UNICOS50) && !defined(UNICOS5)
     53 #  define UNICOS5
     54 # endif
     55 # if !defined(UNICOS5)
     56 #  define BFTPDAEMON
     57 #  define HAS_IP_TOS
     58 # endif
     59 #endif /* CRAY */
     60 #if defined(UNICOS5) && !defined(NO_SETSID)
     61 # define NO_SETSID
     62 #endif
     63 
     64 #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
     65 #define TELOPTS
     66 #define TELCMDS
     67 #define	SLC_NAMES
     68 #endif
     69 
     70 #if	defined(SYSV_TERMIO) && !defined(USE_TERMIO)
     71 # define	USE_TERMIO
     72 #endif
     73 
     74 #include <sys/socket.h>
     75 #ifndef	CRAY
     76 #include <sys/wait.h>
     77 #endif	/* CRAY */
     78 #include <fcntl.h>
     79 #include <sys/file.h>
     80 #include <sys/stat.h>
     81 #include <sys/time.h>
     82 #ifndef	FILIO_H
     83 #include <sys/ioctl.h>
     84 #else
     85 #include <sys/filio.h>
     86 #endif
     87 
     88 #include <netinet/in.h>
     89 
     90 #include <arpa/telnet.h>
     91 
     92 #include <stdio.h>
     93 #ifdef	__STDC__
     94 #include <stdlib.h>
     95 #endif
     96 #include <signal.h>
     97 #include <errno.h>
     98 #include <netdb.h>
     99 #include <syslog.h>
    100 #ifndef	LOG_DAEMON
    101 #define	LOG_DAEMON	0
    102 #endif
    103 #ifndef	LOG_ODELAY
    104 #define	LOG_ODELAY	0
    105 #endif
    106 #include <ctype.h>
    107 #ifndef NO_STRING_H
    108 #include <string.h>
    109 #else
    110 #include <strings.h>
    111 #endif
    112 
    113 #ifndef	USE_TERMIO
    114 #include <sgtty.h>
    115 #else
    116 # ifdef	SYSV_TERMIO
    117 # include <termio.h>
    118 # else
    119 # include <termios.h>
    120 # endif
    121 #endif
    122 #if !defined(USE_TERMIO) || defined(NO_CC_T)
    123 typedef unsigned char cc_t;
    124 #endif
    125 
    126 #ifdef	__STDC__
    127 #include <unistd.h>
    128 #endif
    129 
    130 #ifndef _POSIX_VDISABLE
    131 # ifdef VDISABLE
    132 #  define _POSIX_VDISABLE VDISABLE
    133 # else
    134 #  define _POSIX_VDISABLE ((unsigned char)'\377')
    135 # endif
    136 #endif
    137 
    138 
    139 #ifdef	CRAY
    140 # ifdef	CRAY1
    141 # include <sys/pty.h>
    142 #  ifndef FD_ZERO
    143 # include <sys/select.h>
    144 #  endif /* FD_ZERO */
    145 # endif	/* CRAY1 */
    146 
    147 #include <memory.h>
    148 #endif	/* CRAY */
    149 
    150 #ifdef __hpux
    151 #include <sys/ptyio.h>
    152 #endif
    153 
    154 #if	!defined(TIOCSCTTY) && defined(TCSETCTTY)
    155 # define	TIOCSCTTY TCSETCTTY
    156 #endif
    157 
    158 #ifndef	FD_SET
    159 #ifndef	HAVE_fd_set
    160 typedef struct fd_set { int fds_bits[1]; } fd_set;
    161 #endif
    162 
    163 #define	FD_SET(n, p)	((p)->fds_bits[0] |= (1<<(n)))
    164 #define	FD_CLR(n, p)	((p)->fds_bits[0] &= ~(1<<(n)))
    165 #define	FD_ISSET(n, p)	((p)->fds_bits[0] & (1<<(n)))
    166 #define FD_ZERO(p)	((p)->fds_bits[0] = 0)
    167 #endif	/* FD_SET */
    168 
    169 /*
    170  * I/O data buffers defines
    171  */
    172 #define	NETSLOP	64
    173 #ifdef CRAY
    174 #undef BUFSIZ
    175 #define BUFSIZ  2048
    176 #endif
    177 
    178 #define	NIACCUM(c)	{   *netip++ = c; \
    179 			    ncc++; \
    180 			}
    181 
    182 /* clock manipulations */
    183 #define	settimer(x)	(clocks.x = ++clocks.system)
    184 #define	sequenceIs(x,y)	(clocks.x < clocks.y)
    185 
    186 /*
    187  * Linemode support states, in decreasing order of importance
    188  */
    189 #define REAL_LINEMODE	0x04
    190 #define KLUDGE_OK	0x03
    191 #define	NO_AUTOKLUDGE	0x02
    192 #define KLUDGE_LINEMODE	0x01
    193 #define NO_LINEMODE	0x00
    194 
    195 /*
    196  * Structures of information for each special character function.
    197  */
    198 typedef struct {
    199 	unsigned char	flag;		/* the flags for this function */
    200 	cc_t		val;		/* the value of the special character */
    201 } slcent, *Slcent;
    202 
    203 typedef struct {
    204 	slcent		defset;		/* the default settings */
    205 	slcent		current;	/* the current settings */
    206 	cc_t		*sptr;		/* a pointer to the char in */
    207 					/* system data structures */
    208 } slcfun, *Slcfun;
    209 
    210 #ifdef DIAGNOSTICS
    211 /*
    212  * Diagnostics capabilities
    213  */
    214 #define	TD_REPORT	0x01	/* Report operations to client */
    215 #define TD_EXERCISE	0x02	/* Exercise client's implementation */
    216 #define TD_NETDATA	0x04	/* Display received data stream */
    217 #define TD_PTYDATA	0x08	/* Display data passed to pty */
    218 #define	TD_OPTIONS	0x10	/* Report just telnet options */
    219 #endif /* DIAGNOSTICS */
    220 
    221 /*
    222  * We keep track of each side of the option negotiation.
    223  */
    224 
    225 #define	MY_STATE_WILL		0x01
    226 #define	MY_WANT_STATE_WILL	0x02
    227 #define	MY_STATE_DO		0x04
    228 #define	MY_WANT_STATE_DO	0x08
    229 
    230 /*
    231  * Macros to check the current state of things
    232  */
    233 
    234 #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
    235 #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
    236 #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
    237 #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
    238 
    239 #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
    240 #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
    241 #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
    242 #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
    243 
    244 #define	set_my_state_do(opt)		(options[opt] |= MY_STATE_DO)
    245 #define	set_my_state_will(opt)		(options[opt] |= MY_STATE_WILL)
    246 #define	set_my_want_state_do(opt)	(options[opt] |= MY_WANT_STATE_DO)
    247 #define	set_my_want_state_will(opt)	(options[opt] |= MY_WANT_STATE_WILL)
    248 
    249 #define	set_my_state_dont(opt)		(options[opt] &= ~MY_STATE_DO)
    250 #define	set_my_state_wont(opt)		(options[opt] &= ~MY_STATE_WILL)
    251 #define	set_my_want_state_dont(opt)	(options[opt] &= ~MY_WANT_STATE_DO)
    252 #define	set_my_want_state_wont(opt)	(options[opt] &= ~MY_WANT_STATE_WILL)
    253 
    254 /*
    255  * Tricky code here.  What we want to know is if the MY_STATE_WILL
    256  * and MY_WANT_STATE_WILL bits have the same value.  Since the two
    257  * bits are adjacent, a little arithmatic will show that by adding
    258  * in the lower bit, the upper bit will be set if the two bits were
    259  * different, and clear if they were the same.
    260  */
    261 #define my_will_wont_is_changing(opt) \
    262 			((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
    263 
    264 #define my_do_dont_is_changing(opt) \
    265 			((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
    266 
    267 /*
    268  * Make everything symetrical
    269  */
    270 
    271 #define	HIS_STATE_WILL			MY_STATE_DO
    272 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
    273 #define HIS_STATE_DO			MY_STATE_WILL
    274 #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
    275 
    276 #define	his_state_is_do			my_state_is_will
    277 #define	his_state_is_will		my_state_is_do
    278 #define his_want_state_is_do		my_want_state_is_will
    279 #define his_want_state_is_will		my_want_state_is_do
    280 
    281 #define	his_state_is_dont		my_state_is_wont
    282 #define	his_state_is_wont		my_state_is_dont
    283 #define his_want_state_is_dont		my_want_state_is_wont
    284 #define his_want_state_is_wont		my_want_state_is_dont
    285 
    286 #define	set_his_state_do		set_my_state_will
    287 #define	set_his_state_will		set_my_state_do
    288 #define	set_his_want_state_do		set_my_want_state_will
    289 #define	set_his_want_state_will		set_my_want_state_do
    290 
    291 #define	set_his_state_dont		set_my_state_wont
    292 #define	set_his_state_wont		set_my_state_dont
    293 #define	set_his_want_state_dont		set_my_want_state_wont
    294 #define	set_his_want_state_wont		set_my_want_state_dont
    295 
    296 #define his_will_wont_is_changing	my_do_dont_is_changing
    297 #define his_do_dont_is_changing		my_will_wont_is_changing
    298