xref: /titanic_41/usr/src/head/arpa/telnet.h (revision 495db6fbcd9e8ab893e91f6f5627df6e0cec63cf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 #ifndef	_ARPA_TELNET_H
36 #define	_ARPA_TELNET_H
37 
38 #pragma ident	"%Z%%M%	%I%	%E% SMI"
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Definitions for the TELNET protocol.
46  */
47 #define	IAC	255		/* interpret as command: */
48 #define	DONT	254		/* you are not to use option */
49 #define	DO	253		/* please, you use option */
50 #define	WONT	252		/* I won't use option */
51 #define	WILL	251		/* I will use option */
52 #define	SB	250		/* interpret as subnegotiation */
53 #define	GA	249		/* you may reverse the line */
54 #define	EL	248		/* erase the current line */
55 #define	EC	247		/* erase the current character */
56 #define	AYT	246		/* are you there */
57 #define	AO	245		/* abort output--but let prog finish */
58 #define	IP	244		/* interrupt process--permanently */
59 #define	BREAK	243		/* break */
60 #define	DM	242		/* data mark--for connect. cleaning */
61 #define	NOP	241		/* nop */
62 #define	SE	240		/* end sub negotiation */
63 #define	EOR	239		/* end of record (transparent mode) */
64 #define	ABORT	238		/* Abort process */
65 #define	SUSP	237		/* Suspend process */
66 #define	xEOF	236		/* End of file: EOF is already used... */
67 
68 #define	SYNCH	242		/* for telfunc calls */
69 
70 #ifdef TELCMDS
71 char *telcmds[] = {
72 	"EOF", "SUSP", "ABORT", "EOR",
73 	"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
74 	"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0
75 };
76 #endif
77 
78 #define	TELCMD_FIRST	xEOF
79 #define	TELCMD_LAST	IAC
80 #define	TELCMD_OK(x)	((unsigned int)(x) <= TELCMD_LAST && \
81 			    (unsigned int)(x) >= TELCMD_FIRST)
82 #define	TELCMD(x)	telcmds[(x)-TELCMD_FIRST]
83 
84 /* telnet options */
85 #define	TELOPT_BINARY	0	/* 8-bit data path */
86 #define	TELOPT_ECHO	1	/* echo */
87 #define	TELOPT_RCP	2	/* prepare to reconnect */
88 #define	TELOPT_SGA	3	/* suppress go ahead */
89 #define	TELOPT_NAMS	4	/* approximate message size */
90 #define	TELOPT_STATUS	5	/* give status */
91 #define	TELOPT_TM	6	/* timing mark */
92 #define	TELOPT_RCTE	7	/* remote controlled transmission and echo */
93 #define	TELOPT_NAOL 	8	/* negotiate about output line width */
94 #define	TELOPT_NAOP 	9	/* negotiate about output page size */
95 #define	TELOPT_NAOCRD	10	/* negotiate about CR disposition */
96 #define	TELOPT_NAOHTS	11	/* negotiate about horizontal tabstops */
97 #define	TELOPT_NAOHTD	12	/* negotiate about horizontal tab disposition */
98 #define	TELOPT_NAOFFD	13	/* negotiate about formfeed disposition */
99 #define	TELOPT_NAOVTS	14	/* negotiate about vertical tab stops */
100 #define	TELOPT_NAOVTD	15	/* negotiate about vertical tab disposition */
101 #define	TELOPT_NAOLFD	16	/* negotiate about output LF disposition */
102 #define	TELOPT_XASCII	17	/* extended ascic character set */
103 #define	TELOPT_LOGOUT	18	/* force logout */
104 #define	TELOPT_BM	19	/* byte macro */
105 #define	TELOPT_DET	20	/* data entry terminal */
106 #define	TELOPT_SUPDUP	21	/* supdup protocol */
107 #define	TELOPT_SUPDUPOUTPUT 22	/* supdup output */
108 #define	TELOPT_SNDLOC	23	/* send location */
109 #define	TELOPT_TTYPE	24	/* terminal type */
110 #define	TELOPT_EOR	25	/* end or record */
111 #define	TELOPT_TUID	26	/* TACACS user identification */
112 #define	TELOPT_OUTMRK	27	/* output marking */
113 #define	TELOPT_TTYLOC	28	/* terminal location number */
114 #define	TELOPT_3270REGIME 29	/* 3270 regime */
115 #define	TELOPT_X3PAD	30	/* X.3 PAD */
116 #define	TELOPT_NAWS	31	/* window size */
117 #define	TELOPT_TSPEED	32	/* terminal speed */
118 #define	TELOPT_LFLOW	33	/* remote flow control */
119 #define	TELOPT_LINEMODE	34	/* Linemode option */
120 #define	TELOPT_XDISPLOC	35	/* X Display Location */
121 #define	TELOPT_OLD_ENVIRON 36	/* Old - Environment variables */
122 #define	TELOPT_AUTHENTICATION 37 /* Authenticate */
123 #define	TELOPT_ENCRYPT	38	/* Encryption option */
124 #define	TELOPT_NEW_ENVIRON 39	/* New - Environment variables */
125 #define	TELOPT_EXOPL	255	/* extended-options-list */
126 
127 #ifdef TELOPTS
128 #define	NTELOPTS	(1+TELOPT_NEW_ENVIRON)
129 char *telopts[NTELOPTS+1] = {
130 	"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
131 	"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
132 	"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
133 	"NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
134 	"DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
135 	"SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
136 	"TACACS UID", "OUTPUT MARKING", "TTYLOC",
137 	"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
138 	"LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
139 	"ENCRYPT", "NEW-ENVIRON",
140 	0,
141 };
142 #endif /* TELOPTS */
143 #define	TELOPT_FIRST	TELOPT_BINARY
144 #define	TELOPT_LAST	TELOPT_NEW_ENVIRON
145 #define	TELOPT_OK(x)	((unsigned int)(x) <= TELOPT_LAST)
146 #define	TELOPT(x)	telopts[(x)-TELOPT_FIRST]
147 
148 /* sub-option qualifiers */
149 #define	TELQUAL_IS	0	/* option is... */
150 #define	TELQUAL_SEND	1	/* send option */
151 #define	TELQUAL_INFO	2	/* ENVIRON: informational version of IS */
152 #define	TELQUAL_REPLY	2	/* AUTHENTICATION: client version of IS */
153 #define	TELQUAL_NAME	3	/* AUTHENTICATION: client version of IS */
154 
155 #define	LFLOW_OFF		0	/* Disable remote flow control */
156 #define	LFLOW_ON		1	/* Enable remote flow control */
157 #define	LFLOW_RESTART_ANY	2	/* Restart output on any char */
158 #define	LFLOW_RESTART_XON	3	/* Restart output only on XON */
159 
160 /*
161  * LINEMODE suboptions
162  */
163 
164 #define	LM_MODE		1
165 #define	LM_FORWARDMASK	2
166 #define	LM_SLC		3
167 
168 #define	MODE_EDIT	0x01
169 #define	MODE_TRAPSIG	0x02
170 #define	MODE_ACK	0x04
171 #define	MODE_SOFT_TAB	0x08
172 #define	MODE_LIT_ECHO	0x10
173 
174 #define	MODE_MASK	0x1f
175 
176 /* Not part of protocol, but needed to simplify things... */
177 #define	MODE_FLOW		0x0100
178 #define	MODE_ECHO		0x0200
179 #define	MODE_INBIN		0x0400
180 #define	MODE_OUTBIN		0x0800
181 #define	MODE_FORCE		0x1000
182 
183 #define	SLC_SYNCH	1
184 #define	SLC_BRK		2
185 #define	SLC_IP		3
186 #define	SLC_AO		4
187 #define	SLC_AYT		5
188 #define	SLC_EOR		6
189 #define	SLC_ABORT	7
190 #define	SLC_EOF		8
191 #define	SLC_SUSP	9
192 #define	SLC_EC		10
193 #define	SLC_EL		11
194 #define	SLC_EW		12
195 #define	SLC_RP		13
196 #define	SLC_LNEXT	14
197 #define	SLC_XON		15
198 #define	SLC_XOFF	16
199 #define	SLC_FORW1	17
200 #define	SLC_FORW2	18
201 
202 #define	NSLC		18
203 
204 /*
205  * For backwards compatability, we define SLC_NAMES to be the
206  * list of names if SLC_NAMES is not defined.
207  */
208 #define	SLC_NAMELIST	"0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
209 			"ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
210 			"LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0,
211 #ifdef	SLC_NAMES
212 char *slc_names[] = {
213 	SLC_NAMELIST
214 };
215 #else
216 extern char *slc_names[];
217 #define	SLC_NAMES SLC_NAMELIST
218 #endif
219 
220 #define	SLC_NAME_OK(x)	((unsigned int)(x) <= NSLC)
221 #define	SLC_NAME(x)	slc_names[x]
222 
223 #define	SLC_NOSUPPORT	0
224 #define	SLC_CANTCHANGE	1
225 #define	SLC_VARIABLE	2
226 #define	SLC_DEFAULT	3
227 #define	SLC_LEVELBITS	0x03
228 
229 #define	SLC_FUNC	0
230 #define	SLC_FLAGS	1
231 #define	SLC_VALUE	2
232 
233 #define	SLC_ACK		0x80
234 #define	SLC_FLUSHIN	0x40
235 #define	SLC_FLUSHOUT	0x20
236 
237 #define	OLD_ENV_VAR	1
238 #define	OLD_ENV_VALUE	0
239 #define	NEW_ENV_VAR	0
240 #define	NEW_ENV_VALUE	1
241 #define	ENV_ESC		2
242 #define	ENV_USERVAR	3
243 
244 /*
245  * AUTHENTICATION suboptions
246  */
247 #define	AUTH_REJECT	0	/* Rejected */
248 #define	AUTH_UNKNOWN	1	/* We don't know who he is, but he's okay */
249 #define	AUTH_OTHER	2	/* We know him, but not his name */
250 #define	AUTH_USER	3	/* We know his name */
251 #define	AUTH_VALID	4	/* We know him, and he needs no password */
252 
253 /*
254  * Who is authenticating who ...
255  */
256 #define	AUTH_WHO_CLIENT		0	/* Client authenticating server */
257 #define	AUTH_WHO_SERVER		1	/* Server authenticating client */
258 #define	AUTH_WHO_MASK		1
259 
260 #ifdef	AUTHWHO_STR
261 char *authwho_str[] = {
262 	"CLIENT", "SERVER" };
263 #define	AUTHWHO_NAME(x)	authwho_str[x]
264 #endif /* AUTHWHO_STR */
265 
266 /*
267  * amount of authentication done
268  */
269 #define	AUTH_HOW_ONE_WAY	0
270 #define	AUTH_HOW_MUTUAL		2
271 #define	AUTH_HOW_MASK		2
272 
273 /*
274  * should we be encrypting? (not yet formally standardized)
275  */
276 #define	AUTH_ENCRYPT_OFF	0
277 #define	AUTH_ENCRYPT_ON		4
278 #define	AUTH_ENCRYPT_MASK	4
279 
280 #define	AUTHTYPE_NULL		0
281 #define	AUTHTYPE_KERBEROS_V4	1	/* not supported */
282 #define	AUTHTYPE_KERBEROS_V5	2
283 #define	AUTHTYPE_CNT		3
284 
285 #define	OPTS_FORWARD_CREDS		0x00000002
286 #define	OPTS_FORWARDABLE_CREDS		0x00000001
287 
288 #ifdef AUTHTYPE_NAMES
289 char *authtype_names[] = {
290 	"NULL", "KERBEROS_V4", "KERBEROS_V5", 0,
291 };
292 #else
293 extern char *authtype_names[];
294 #endif /* AUTHTYPE_NAMES */
295 
296 #define	AUTHTYPE_NAME(x)	authtype_names[x]
297 #define	AUTHTYPE_NAME_OK(x)	((unsigned int)(x) < AUTHTYPE_CNT)
298 
299 #ifdef AUTHHOW_NAMES
300 char *authhow_names[] = {
301 	"ONE-WAY", "[undefined]", "MUTUAL" };
302 #endif /* AUTHHOW_NAMES */
303 
304 #define	AUTHHOW_NAME(x)		authhow_names[x]
305 
306 #define	KRB_AUTH		0	/* Authentication data follows */
307 #define	KRB_REJECT		1	/* Rejected (reason might follow) */
308 #define	KRB_ACCEPT		2	/* Accepted */
309 #define	KRB_RESPONSE		3	/* Response for mutual auth. */
310 #define	KRB_FORWARD		4	/* Forwarded credentials follow */
311 #define	KRB_FORWARD_ACCEPT	5	/* Forwarded credentials accepted */
312 #define	KRB_FORWARD_REJECT	6	/* Forwarded credentials rejected */
313 
314 #ifdef AUTHRSP_NAMES
315 char *authrsp_names[] = {
316 	"AUTH", "REJECT", "ACCEPT", "RESPONSE", "FORWARD",
317 	"FORWARD_ACCEPT", "FORWARD_REJECT" };
318 #define	AUTHRSP_NAME(x)		authrsp_names[x]
319 #endif /* AUTHRSP_NAMES */
320 
321 #define	AUTH_MODE_REQUIRE	0
322 #define	AUTH_MODE_PROMPT	1
323 #define	AUTH_MODE_WARN		2
324 #define	AUTH_MODE_REJECT	3
325 
326 
327 /*
328  * Encryption suboptions. See RFC 2946.
329  */
330 #define	ENCRYPT_IS		0	/* I pick encryption type ... */
331 #define	ENCRYPT_SUPPORT		1	/* I support encryption types ... */
332 #define	ENCRYPT_REPLY		2	/* Initial setup response */
333 #define	ENCRYPT_START		3	/* Starting encrypting output */
334 #define	ENCRYPT_END		4	/* End encrypting output */
335 #define	ENCRYPT_REQSTART	5	/* Request to start encrypting output */
336 #define	ENCRYPT_REQEND		6	/* Request to stop encrypting output */
337 #define	ENCRYPT_ENC_KEYID	7	/* Negotiate encryption key */
338 #define	ENCRYPT_DEC_KEYID	8	/* Negotiate decryption key */
339 #define	ENCRYPT_CNT		9	/* marks the maximum ENCRYPT value */
340 
341 #define	TELOPT_ENCTYPE_NULL		0
342 #define	TELOPT_ENCTYPE_DES_CFB64	1 /* 64-bit Cipher Feedback Mode */
343 #define	TELOPT_ENCTYPE_CNT		2
344 
345 #define	CFB64_IV	1
346 #define	CFB64_IV_OK	2
347 #define	CFB64_IV_BAD	3
348 
349 #define	FB64_IV		CFB64_IV
350 #define	FB64_IV_OK	CFB64_IV_OK
351 #define	FB64_IV_BAD	CFB64_IV_BAD
352 
353 #ifdef ENCRYPT_NAMES
354 char *encrypt_names[] = {
355 	"IS", "SUPPORT", "REPLY", "START", "END",
356 	"REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
357 	0,
358 };
359 
360 char *enctype_names[] = {
361 	"ANY", "DES_CFB64", 0,
362 };
363 #else
364 extern char *encrypt_names[];
365 extern char *enctype_names[];
366 #endif /* ENCRYPT_NAMES */
367 
368 #define	ENCRYPT_NAME(x)		encrypt_names[x]
369 #define	ENCTYPE_NAME(x)		enctype_names[x]
370 
371 #define	ENCRYPT_NAME_OK(x)	((unsigned int)(x) < ENCRYPT_CNT)
372 #define	ENCTYPE_NAME_OK(x)	((unsigned int)(x) < TELOPT_ENCTYPE_CNT)
373 
374 #define	SK_DES	1 /* Matched Kerberos v5 ENCTYPE_DES */
375 
376 #ifndef	DES_BLOCKSIZE
377 #define	DES_BLOCKSIZE  8
378 #endif	/* DES_BLOCKSIZE */
379 
380 #define	TELNET_MAXNUMKEYS	64
381 #define	TELNET_MAXKEYIDLEN	16
382 
383 #define	CFB 0
384 
385 #define	ENCR_STATE_FAILED	-1
386 #define	ENCR_STATE_OK		0x00
387 #define	ENCR_STATE_NO_SEND_IV	0x01
388 #define	ENCR_STATE_NO_RECV_IV	0x02
389 #define	ENCR_STATE_NO_KEYID	0x04
390 #define	ENCR_STATE_NOT_READY	0x08
391 #define	ENCR_STATE_IN_PROGRESS \
392 	(ENCR_STATE_NO_SEND_IV|ENCR_STATE_NO_RECV_IV|ENCR_STATE_NO_KEYID)
393 #define	TELNET_DIR_ENCRYPT	0
394 #define	TELNET_DIR_DECRYPT	1
395 
396 typedef unsigned char Block[DES_BLOCKSIZE];
397 typedef unsigned char *BlockT;
398 typedef struct { Block _; } Schedule[16];
399 
400 typedef struct {
401 	short		type;
402 	int		length;
403 	unsigned char	*data;
404 } Session_Key;
405 
406 typedef struct {
407 	unsigned char	need_start;
408 	unsigned char	autoflag;	/* automatically start operation */
409 	unsigned char	setup;
410 	unsigned char	type;
411 	unsigned int	state;
412 	unsigned char	keyid[TELNET_MAXNUMKEYS];
413 	int		keyidlen;
414 	Block		ivec;
415 	Block		krbdes_key;
416 } cipher_info_t;
417 
418 typedef struct {
419 	cipher_info_t encrypt;
420 	cipher_info_t decrypt;
421 } telnet_enc_data_t;
422 
423 /* A valid key has no "0" bytes */
424 #define	VALIDKEY(key)	(key[0] | key[1] | key[2] | key[3] | \
425 		key[4] | key[5] | key[6] | key[7])
426 
427 
428 #ifdef	__cplusplus
429 }
430 #endif
431 
432 #endif	/* _ARPA_TELNET_H */
433