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