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