]>
git.saurik.com Git - apple/network_cmds.git/blob - telnet.tproj/telnet.c
2 * Copyright (c) 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
34 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD: src/crypto/telnet/telnet/telnet.c,v 1.4.2.5 2002/04/13 10:59:08 markm Exp $");
41 #define __unused __attribute__((__unused__))
45 static const char sccsid
[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95";
48 #include <sys/types.h>
50 /* By the way, we need to include curses.h before telnet.h since,
51 * among other things, telnet.h #defines 'DO', which is a variable
52 * declared in curses.h.
61 #include <arpa/telnet.h>
71 #include <libtelnet/auth.h>
74 #include <libtelnet/encrypt.h>
76 #include <libtelnet/misc.h>
78 #define strip(x) ((my_want_state_is_wont(TELOPT_BINARY)) ? ((x)&0x7f) : (x))
80 static unsigned char subbuffer
[SUBBUFSIZE
],
81 *subpointer
, *subend
; /* buffer for sub-options */
82 #define SB_CLEAR() subpointer = subbuffer;
83 #define SB_TERM() { subend = subpointer; SB_CLEAR(); }
84 #define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
85 *subpointer++ = (c); \
88 #define SB_GET() ((*subpointer++)&0xff)
89 #define SB_PEEK() ((*subpointer)&0xff)
90 #define SB_EOF() (subpointer >= subend)
91 #define SB_LEN() (subend - subpointer)
93 char options
[256]; /* The combined options */
94 char do_dont_resp
[256];
95 char will_wont_resp
[256];
99 autologin
= 0, /* Autologin anyone? */
103 ISend
, /* trying to send network data in */
106 netdata
, /* Print out network data flow */
107 crlf
, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
109 SYNCHing
, /* we are in TELNET SYNCH mode */
110 flushout
, /* flush output */
111 autoflush
= 0, /* flush output when interrupting? */
112 autosynch
, /* send interrupt characters with SYNCH? */
113 localflow
, /* we handle flow control locally */
114 restartany
, /* if flow control enabled, restart on any character */
115 localchars
, /* we recognize interrupt/quit */
116 donelclchars
, /* the user has set "localchars" */
117 donebinarytoggle
, /* the user has put us in binary */
118 dontlecho
, /* do we suppress local echoing right now? */
120 doaddrlookup
= 1, /* do a reverse address lookup? */
125 char *line
; /* hack around breakage in sra.c :-( !! */
130 #ifdef KLUDGELINEMODE
135 * Telnet receiver states for fsm
144 #define TS_SB 7 /* sub-option collection */
145 #define TS_SE 8 /* looking for sub-option end */
147 static int telrcv_state
;
149 unsigned char telopt_environ
= TELOPT_NEW_ENVIRON
;
151 # define telopt_environ TELOPT_NEW_ENVIRON
160 #ifdef KLUDGELINEMODE
161 int kludgelinemode
= 1;
164 static int is_unique(char *, char **, char **);
167 * The following are some clocks used to decide how to interpret
168 * the relationship between various variables.
174 * Initialize telnet environment.
185 connected
= ISend
= localflow
= donebinarytoggle
= 0;
186 #ifdef AUTHENTICATION
188 auth_encrypt_connect(connected
);
195 /* Don't change NetTrace */
197 escape
= CONTROL(']');
198 rlogin
= _POSIX_VDISABLE
;
199 #ifdef KLUDGELINEMODE
200 echoc
= CONTROL('E');
204 telrcv_state
= TS_DATA
;
209 * These routines are in charge of sending option negotiations
212 * The basic idea is that we send the negotiation if either side
213 * is in disagreement as to what the current state should be.
217 send_do(int c
, int init
)
220 if (((do_dont_resp
[c
] == 0) && my_state_is_do(c
)) ||
221 my_want_state_is_do(c
))
223 set_my_want_state_do(c
);
228 printoption("SENT", DO
, c
);
232 send_dont(int c
, int init
)
235 if (((do_dont_resp
[c
] == 0) && my_state_is_dont(c
)) ||
236 my_want_state_is_dont(c
))
238 set_my_want_state_dont(c
);
243 printoption("SENT", DONT
, c
);
247 send_will(int c
, int init
)
250 if (((will_wont_resp
[c
] == 0) && my_state_is_will(c
)) ||
251 my_want_state_is_will(c
))
253 set_my_want_state_will(c
);
258 printoption("SENT", WILL
, c
);
262 send_wont(int c
, int init
)
265 if (((will_wont_resp
[c
] == 0) && my_state_is_wont(c
)) ||
266 my_want_state_is_wont(c
))
268 set_my_want_state_wont(c
);
273 printoption("SENT", WONT
, c
);
277 willoption(int option
)
279 int new_state_ok
= 0;
281 if (do_dont_resp
[option
]) {
282 --do_dont_resp
[option
];
283 if (do_dont_resp
[option
] && my_state_is_do(option
))
284 --do_dont_resp
[option
];
287 if ((do_dont_resp
[option
] == 0) && my_want_state_is_dont(option
)) {
294 settimer(modenegotiated
);
297 #ifdef AUTHENTICATION
298 case TELOPT_AUTHENTICATION
:
302 #endif /* ENCRYPTION */
310 * Special case for TM. If we get back a WILL,
311 * pretend we got back a WONT.
313 set_my_want_state_dont(option
);
314 set_my_state_dont(option
);
315 return; /* Never reply to TM will's/wont's */
317 case TELOPT_LINEMODE
:
323 set_my_want_state_do(option
);
325 setconnmode(0); /* possibly set new tty mode */
327 do_dont_resp
[option
]++;
328 send_dont(option
, 0);
331 set_my_state_do(option
);
333 if (option
== TELOPT_ENCRYPT
)
334 encrypt_send_support();
335 #endif /* ENCRYPTION */
339 wontoption(int option
)
341 if (do_dont_resp
[option
]) {
342 --do_dont_resp
[option
];
343 if (do_dont_resp
[option
] && my_state_is_dont(option
))
344 --do_dont_resp
[option
];
347 if ((do_dont_resp
[option
] == 0) && my_want_state_is_do(option
)) {
351 #ifdef KLUDGELINEMODE
358 settimer(modenegotiated
);
364 set_my_want_state_dont(option
);
365 set_my_state_dont(option
);
366 return; /* Never reply to TM will's/wont's */
371 set_my_want_state_dont(option
);
372 if (my_state_is_do(option
))
373 send_dont(option
, 0);
374 setconnmode(0); /* Set new tty mode */
375 } else if (option
== TELOPT_TM
) {
377 * Special case for TM.
381 set_my_want_state_dont(option
);
383 set_my_state_dont(option
);
389 int new_state_ok
= 0;
391 if (will_wont_resp
[option
]) {
392 --will_wont_resp
[option
];
393 if (will_wont_resp
[option
] && my_state_is_will(option
))
394 --will_wont_resp
[option
];
397 if (will_wont_resp
[option
] == 0) {
398 if (my_want_state_is_wont(option
)) {
404 * Special case for TM. We send a WILL, but pretend
407 send_will(option
, 0);
408 set_my_want_state_wont(TELOPT_TM
);
409 set_my_state_wont(TELOPT_TM
);
412 case TELOPT_BINARY
: /* binary mode */
413 case TELOPT_NAWS
: /* window size */
414 case TELOPT_TSPEED
: /* terminal speed */
415 case TELOPT_LFLOW
: /* local flow control */
416 case TELOPT_TTYPE
: /* terminal type option */
417 case TELOPT_SGA
: /* no big deal */
419 case TELOPT_ENCRYPT
: /* encryption variable option */
420 #endif /* ENCRYPTION */
424 case TELOPT_NEW_ENVIRON
: /* New environment variable option */
426 if (my_state_is_will(TELOPT_OLD_ENVIRON
))
427 send_wont(TELOPT_OLD_ENVIRON
, 1); /* turn off the old */
429 case TELOPT_OLD_ENVIRON
: /* Old environment variable option */
430 if (my_state_is_will(TELOPT_NEW_ENVIRON
))
431 break; /* Don't enable if new one is in use! */
433 telopt_environ
= option
;
438 #ifdef AUTHENTICATION
439 case TELOPT_AUTHENTICATION
:
445 case TELOPT_XDISPLOC
: /* X Display location */
446 if (env_getvalue("DISPLAY"))
450 case TELOPT_LINEMODE
:
451 #ifdef KLUDGELINEMODE
453 send_do(TELOPT_SGA
, 1);
455 set_my_want_state_will(TELOPT_LINEMODE
);
456 send_will(option
, 0);
457 set_my_state_will(TELOPT_LINEMODE
);
461 case TELOPT_ECHO
: /* We're never going to echo... */
467 set_my_want_state_will(option
);
468 send_will(option
, 0);
469 setconnmode(0); /* Set new tty mode */
471 will_wont_resp
[option
]++;
472 send_wont(option
, 0);
476 * Handle options that need more things done after the
477 * other side has acknowledged the option.
480 case TELOPT_LINEMODE
:
481 #ifdef KLUDGELINEMODE
483 send_do(TELOPT_SGA
, 1);
485 set_my_state_will(option
);
487 send_do(TELOPT_SGA
, 0);
492 set_my_state_will(option
);
496 dontoption(int option
)
499 if (will_wont_resp
[option
]) {
500 --will_wont_resp
[option
];
501 if (will_wont_resp
[option
] && my_state_is_wont(option
))
502 --will_wont_resp
[option
];
505 if ((will_wont_resp
[option
] == 0) && my_want_state_is_will(option
)) {
507 case TELOPT_LINEMODE
:
508 linemode
= 0; /* put us back to the default state */
511 case TELOPT_NEW_ENVIRON
:
513 * The new environ option wasn't recognized, try
516 send_will(TELOPT_OLD_ENVIRON
, 1);
517 telopt_environ
= TELOPT_OLD_ENVIRON
;
521 /* we always accept a DONT */
522 set_my_want_state_wont(option
);
523 if (my_state_is_will(option
))
524 send_wont(option
, 0);
525 setconnmode(0); /* Set new tty mode */
527 set_my_state_wont(option
);
531 * Given a buffer returned by tgetent(), this routine will turn
532 * the pipe separated list of names in the buffer into an array
533 * of pointers to null terminated names. We toss out any bad,
534 * duplicate, or verbose names (names with spaces).
537 static const char *name_unknown
= "UNKNOWN";
538 static const char *unknown
[] = { NULL
, NULL
};
541 mklist(char *buf
, char *name
)
544 char c
, *cp
, **argvp
, *cp2
, **argv
, **avt
;
547 if (strlen(name
) > 40) {
549 unknown
[0] = name_unknown
;
555 unknown
[0] = name_unknown
;
557 * Count up the number of names.
559 for (n
= 1, cp
= buf
; *cp
&& *cp
!= ':'; cp
++) {
564 * Allocate an array to put the name pointers into
566 argv
= (char **)malloc((n
+3)*sizeof(char *));
571 * Fill up the array of pointers to names.
576 for (cp
= cp2
= buf
; (c
= *cp
); cp
++) {
577 if (c
== '|' || c
== ':') {
580 * Skip entries that have spaces or are over 40
581 * characters long. If this is our environment
582 * name, then put it up front. Otherwise, as
583 * long as this is not a duplicate name (case
584 * insensitive) add it to the list.
586 if (n
|| (cp
- cp2
> 41))
588 else if (name
&& (strncasecmp(name
, cp2
, cp
-cp2
) == 0))
590 else if (is_unique(cp2
, argv
+1, argvp
))
595 * Skip multiple delimiters. Reset cp2 to
596 * the beginning of the next name. Reset n,
597 * the flag for names with spaces.
599 while ((c
= *cp
) == '|')
605 * Skip entries with spaces or non-ascii values.
606 * Convert lower case letters to upper case.
608 if ((c
== ' ') || !isascii(c
))
615 * Check for an old V6 2 character name. If the second
616 * name points to the beginning of the buffer, and is
617 * only 2 characters long, move it to the end of the array.
619 if ((argv
[1] == buf
) && (strlen(argv
[1]) == 2)) {
621 for (avt
= &argv
[1]; avt
< argvp
; avt
++)
627 * Duplicate last name, for TTYPE option, and null
628 * terminate the array. If we didn't find a match on
629 * our terminal name, put that name at the beginning.
640 for (avt
= argv
; avt
< argvp
; avt
++)
645 return((const char **)argv
);
651 is_unique(char *name
, char **as
, char **ae
)
656 n
= strlen(name
) + 1;
657 for (ap
= as
; ap
< ae
; ap
++)
658 if (strncasecmp(*ap
, name
, n
) == 0)
668 setupterm(char *tname
, int fd
, int *errp
)
670 if (tgetent(termbuf
, tname
) == 1) {
671 termbuf
[1023] = '\0';
681 #define termbuf ttytype
682 extern char ttytype
[];
685 int resettermname
= 1;
691 static const char **tnamep
= 0;
692 static const char **next
;
697 if (tnamep
&& tnamep
!= unknown
)
699 if ((tname
= env_getvalue("TERM")) &&
700 (setupterm(tname
, 1, &err
) == 0)) {
701 tnamep
= mklist(termbuf
, tname
);
703 if (tname
&& (strlen(tname
) <= 40)) {
707 unknown
[0] = name_unknown
;
719 * Look at the sub-option buffer, and try to be helpful to the other
722 * Currently we recognize:
724 * Terminal type, send request.
725 * Terminal speed (send request).
726 * Local flow control (is request).
733 unsigned char subchar
;
735 printsub('<', subbuffer
, SB_LEN()+2);
736 switch (subchar
= SB_GET()) {
738 if (my_want_state_is_wont(TELOPT_TTYPE
))
740 if (SB_EOF() || SB_GET() != TELQUAL_SEND
) {
744 unsigned char temp
[50];
747 name
= gettermname();
748 len
= strlen(name
) + 4 + 2;
749 if (len
< NETROOM()) {
750 sprintf(temp
, "%c%c%c%c%s%c%c", IAC
, SB
, TELOPT_TTYPE
,
751 TELQUAL_IS
, name
, IAC
, SE
);
752 ring_supply_data(&netoring
, temp
, len
);
753 printsub('>', &temp
[2], len
-2);
755 ExitString("No room in buffer for terminal type.\n", 1);
761 if (my_want_state_is_wont(TELOPT_TSPEED
))
765 if (SB_GET() == TELQUAL_SEND
) {
767 unsigned char temp
[50];
770 TerminalSpeeds(&ispeed
, &ospeed
);
772 sprintf((char *)temp
, "%c%c%c%c%ld,%ld%c%c", IAC
, SB
, TELOPT_TSPEED
,
773 TELQUAL_IS
, ospeed
, ispeed
, IAC
, SE
);
774 len
= strlen((char *)temp
+4) + 4; /* temp[3] is 0 ... */
776 if (len
< NETROOM()) {
777 ring_supply_data(&netoring
, temp
, len
);
778 printsub('>', temp
+2, len
- 2);
780 /*@*/ else printf("lm_will: not enough room in buffer\n");
784 if (my_want_state_is_wont(TELOPT_LFLOW
))
789 case LFLOW_RESTART_ANY
:
792 case LFLOW_RESTART_XON
:
808 case TELOPT_LINEMODE
:
809 if (my_want_state_is_wont(TELOPT_LINEMODE
))
815 lm_will(subpointer
, SB_LEN());
818 lm_wont(subpointer
, SB_LEN());
821 lm_do(subpointer
, SB_LEN());
824 lm_dont(subpointer
, SB_LEN());
827 slc(subpointer
, SB_LEN());
830 lm_mode(subpointer
, SB_LEN(), 0);
838 case TELOPT_OLD_ENVIRON
:
840 case TELOPT_NEW_ENVIRON
:
846 if (my_want_state_is_dont(subchar
))
850 if (my_want_state_is_wont(subchar
)) {
857 env_opt(subpointer
, SB_LEN());
860 case TELOPT_XDISPLOC
:
861 if (my_want_state_is_wont(TELOPT_XDISPLOC
))
865 if (SB_GET() == TELQUAL_SEND
) {
866 unsigned char temp
[50], *dp
;
869 if ((dp
= env_getvalue("DISPLAY")) == NULL
||
870 strlen(dp
) > sizeof(temp
) - 7) {
872 * Something happened, we no longer have a DISPLAY
873 * variable. Or it is too long. So, turn off the option.
875 send_wont(TELOPT_XDISPLOC
, 1);
878 snprintf(temp
, sizeof(temp
), "%c%c%c%c%s%c%c", IAC
, SB
,
879 TELOPT_XDISPLOC
, TELQUAL_IS
, dp
, IAC
, SE
);
880 len
= strlen((char *)temp
+4) + 4; /* temp[3] is 0 ... */
882 if (len
< NETROOM()) {
883 ring_supply_data(&netoring
, temp
, len
);
884 printsub('>', temp
+2, len
- 2);
886 /*@*/ else printf("lm_will: not enough room in buffer\n");
890 #ifdef AUTHENTICATION
891 case TELOPT_AUTHENTICATION
: {
898 if (my_want_state_is_dont(TELOPT_AUTHENTICATION
))
900 auth_is(subpointer
, SB_LEN());
903 if (my_want_state_is_wont(TELOPT_AUTHENTICATION
))
905 auth_send(subpointer
, SB_LEN());
908 if (my_want_state_is_wont(TELOPT_AUTHENTICATION
))
910 auth_reply(subpointer
, SB_LEN());
913 if (my_want_state_is_dont(TELOPT_AUTHENTICATION
))
915 auth_name(subpointer
, SB_LEN());
927 if (my_want_state_is_dont(TELOPT_ENCRYPT
))
929 encrypt_start(subpointer
, SB_LEN());
932 if (my_want_state_is_dont(TELOPT_ENCRYPT
))
936 case ENCRYPT_SUPPORT
:
937 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
939 encrypt_support(subpointer
, SB_LEN());
941 case ENCRYPT_REQSTART
:
942 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
944 encrypt_request_start(subpointer
, SB_LEN());
947 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
950 * We can always send an REQEND so that we cannot
951 * get stuck encrypting. We should only get this
952 * if we have been able to get in the correct mode
955 encrypt_request_end();
958 if (my_want_state_is_dont(TELOPT_ENCRYPT
))
960 encrypt_is(subpointer
, SB_LEN());
963 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
965 encrypt_reply(subpointer
, SB_LEN());
967 case ENCRYPT_ENC_KEYID
:
968 if (my_want_state_is_dont(TELOPT_ENCRYPT
))
970 encrypt_enc_keyid(subpointer
, SB_LEN());
972 case ENCRYPT_DEC_KEYID
:
973 if (my_want_state_is_wont(TELOPT_ENCRYPT
))
975 encrypt_dec_keyid(subpointer
, SB_LEN());
981 #endif /* ENCRYPTION */
987 static unsigned char str_lm
[] = { IAC
, SB
, TELOPT_LINEMODE
, 0, 0, IAC
, SE
};
990 lm_will(unsigned char *cmd
, int len
)
993 /*@*/ printf("lm_will: no command!!!\n"); /* Should not happen... */
997 case LM_FORWARDMASK
: /* We shouldn't ever get this... */
1001 if (NETROOM() > (int)sizeof(str_lm
)) {
1002 ring_supply_data(&netoring
, str_lm
, sizeof(str_lm
));
1003 printsub('>', &str_lm
[2], sizeof(str_lm
)-2);
1005 /*@*/ else printf("lm_will: not enough room in buffer\n");
1011 lm_wont(unsigned char *cmd
, int len
)
1014 /*@*/ printf("lm_wont: no command!!!\n"); /* Should not happen... */
1018 case LM_FORWARDMASK
: /* We shouldn't ever get this... */
1020 /* We are always DONT, so don't respond */
1026 lm_do(unsigned char *cmd
, int len
)
1029 /*@*/ printf("lm_do: no command!!!\n"); /* Should not happen... */
1033 case LM_FORWARDMASK
:
1037 if (NETROOM() > (int)sizeof(str_lm
)) {
1038 ring_supply_data(&netoring
, str_lm
, sizeof(str_lm
));
1039 printsub('>', &str_lm
[2], sizeof(str_lm
)-2);
1041 /*@*/ else printf("lm_do: not enough room in buffer\n");
1047 lm_dont(unsigned char *cmd
, int len
)
1050 /*@*/ printf("lm_dont: no command!!!\n"); /* Should not happen... */
1054 case LM_FORWARDMASK
:
1056 /* we are always WONT, so don't respond */
1061 static unsigned char str_lm_mode
[] = {
1062 IAC
, SB
, TELOPT_LINEMODE
, LM_MODE
, 0, IAC
, SE
1066 lm_mode(unsigned char *cmd
, int len
, int init
)
1070 if ((linemode
&MODE_MASK
&~MODE_ACK
) == *cmd
)
1074 linemode
= *cmd
&(MODE_MASK
&~MODE_ACK
);
1075 str_lm_mode
[4] = linemode
;
1077 str_lm_mode
[4] |= MODE_ACK
;
1078 if (NETROOM() > (int)sizeof(str_lm_mode
)) {
1079 ring_supply_data(&netoring
, str_lm_mode
, sizeof(str_lm_mode
));
1080 printsub('>', &str_lm_mode
[2], sizeof(str_lm_mode
)-2);
1082 /*@*/ else printf("lm_mode: not enough room in buffer\n");
1083 setconnmode(0); /* set changed mode */
1090 * Handle special character suboption of LINEMODE.
1096 char flags
; /* Current flags & level */
1097 char mylevel
; /* Maximum level & flags */
1100 #define SLC_IMPORT 0
1101 #define SLC_EXPORT 1
1102 #define SLC_RVALUE 2
1103 static int slc_mode
= SLC_EXPORT
;
1111 for (spcp
= spc_data
; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
1114 spcp
->flags
= spcp
->mylevel
= SLC_NOSUPPORT
;
1117 #define initfunc(func, flags) { \
1118 spcp = &spc_data[func]; \
1119 if ((spcp->valp = tcval(func))) { \
1120 spcp->val = *spcp->valp; \
1121 spcp->mylevel = SLC_VARIABLE|flags; \
1124 spcp->mylevel = SLC_DEFAULT; \
1128 initfunc(SLC_SYNCH
, 0);
1130 initfunc(SLC_AO
, 0);
1131 initfunc(SLC_AYT
, 0);
1133 initfunc(SLC_ABORT
, SLC_FLUSHIN
|SLC_FLUSHOUT
);
1134 initfunc(SLC_EOF
, 0);
1136 initfunc(SLC_SUSP
, SLC_FLUSHIN
);
1138 initfunc(SLC_EC
, 0);
1139 initfunc(SLC_EL
, 0);
1141 initfunc(SLC_EW
, 0);
1142 initfunc(SLC_RP
, 0);
1143 initfunc(SLC_LNEXT
, 0);
1145 initfunc(SLC_XON
, 0);
1146 initfunc(SLC_XOFF
, 0);
1148 spc_data
[SLC_XON
].mylevel
= SLC_CANTCHANGE
;
1149 spc_data
[SLC_XOFF
].mylevel
= SLC_CANTCHANGE
;
1151 initfunc(SLC_FORW1
, 0);
1153 initfunc(SLC_FORW2
, 0);
1157 initfunc(SLC_IP
, SLC_FLUSHIN
|SLC_FLUSHOUT
);
1160 if (slc_mode
== SLC_EXPORT
)
1170 printf("Special characters are %s values\n",
1171 slc_mode
== SLC_IMPORT
? "remote default" :
1172 slc_mode
== SLC_EXPORT
? "local" :
1177 slc_mode_export(void)
1179 slc_mode
= SLC_EXPORT
;
1180 if (my_state_is_will(TELOPT_LINEMODE
))
1185 slc_mode_import(int def
)
1187 slc_mode
= def
? SLC_IMPORT
: SLC_RVALUE
;
1188 if (my_state_is_will(TELOPT_LINEMODE
))
1192 unsigned char slc_import_val
[] = {
1193 IAC
, SB
, TELOPT_LINEMODE
, LM_SLC
, 0, SLC_VARIABLE
, 0, IAC
, SE
1195 unsigned char slc_import_def
[] = {
1196 IAC
, SB
, TELOPT_LINEMODE
, LM_SLC
, 0, SLC_DEFAULT
, 0, IAC
, SE
1202 if (NETROOM() > (int)sizeof(slc_import_val
)) {
1204 ring_supply_data(&netoring
, slc_import_def
, sizeof(slc_import_def
));
1205 printsub('>', &slc_import_def
[2], sizeof(slc_import_def
)-2);
1207 ring_supply_data(&netoring
, slc_import_val
, sizeof(slc_import_val
));
1208 printsub('>', &slc_import_val
[2], sizeof(slc_import_val
)-2);
1211 /*@*/ else printf("slc_import: not enough room\n");
1219 TerminalDefaultChars();
1222 for (spcp
= &spc_data
[1]; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
1223 if (spcp
->mylevel
!= SLC_NOSUPPORT
) {
1224 if (spcp
->val
== (cc_t
)(_POSIX_VDISABLE
))
1225 spcp
->flags
= SLC_NOSUPPORT
;
1227 spcp
->flags
= spcp
->mylevel
;
1229 spcp
->val
= *spcp
->valp
;
1230 slc_add_reply(spcp
- spc_data
, spcp
->flags
, spcp
->val
);
1235 setconnmode(1); /* Make sure the character values are set */
1239 slc(unsigned char *cp
, int len
)
1246 for (; len
>= 3; len
-=3, cp
+=3) {
1248 func
= cp
[SLC_FUNC
];
1252 * Client side: always ignore 0 function.
1257 if ((cp
[SLC_FLAGS
] & SLC_LEVELBITS
) != SLC_NOSUPPORT
)
1258 slc_add_reply(func
, SLC_NOSUPPORT
, 0);
1262 spcp
= &spc_data
[func
];
1264 level
= cp
[SLC_FLAGS
]&(SLC_LEVELBITS
|SLC_ACK
);
1266 if ((cp
[SLC_VALUE
] == (unsigned char)spcp
->val
) &&
1267 ((level
&SLC_LEVELBITS
) == (spcp
->flags
&SLC_LEVELBITS
))) {
1271 if (level
== (SLC_DEFAULT
|SLC_ACK
)) {
1273 * This is an error condition, the SLC_ACK
1274 * bit should never be set for the SLC_DEFAULT
1275 * level. Our best guess to recover is to
1276 * ignore the SLC_ACK bit.
1278 cp
[SLC_FLAGS
] &= ~SLC_ACK
;
1281 if (level
== ((spcp
->flags
&SLC_LEVELBITS
)|SLC_ACK
)) {
1282 spcp
->val
= (cc_t
)cp
[SLC_VALUE
];
1283 spcp
->flags
= cp
[SLC_FLAGS
]; /* include SLC_ACK */
1289 if (level
<= (spcp
->mylevel
&SLC_LEVELBITS
)) {
1290 spcp
->flags
= cp
[SLC_FLAGS
]|SLC_ACK
;
1291 spcp
->val
= (cc_t
)cp
[SLC_VALUE
];
1293 if (level
== SLC_DEFAULT
) {
1294 if ((spcp
->mylevel
&SLC_LEVELBITS
) != SLC_DEFAULT
)
1295 spcp
->flags
= spcp
->mylevel
;
1297 spcp
->flags
= SLC_NOSUPPORT
;
1299 slc_add_reply(func
, spcp
->flags
, spcp
->val
);
1303 setconnmode(1); /* set the new character values */
1312 for (spcp
= &spc_data
[1]; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
1313 if (spcp
->valp
&& spcp
->val
!= *spcp
->valp
) {
1314 spcp
->val
= *spcp
->valp
;
1315 if (spcp
->val
== (cc_t
)(_POSIX_VDISABLE
))
1316 spcp
->flags
= SLC_NOSUPPORT
;
1318 spcp
->flags
= spcp
->mylevel
;
1319 slc_add_reply(spcp
- spc_data
, spcp
->flags
, spcp
->val
);
1326 unsigned char slc_reply
[128];
1327 unsigned char *slc_replyp
;
1330 slc_start_reply(void)
1332 slc_replyp
= slc_reply
;
1333 *slc_replyp
++ = IAC
;
1335 *slc_replyp
++ = TELOPT_LINEMODE
;
1336 *slc_replyp
++ = LM_SLC
;
1340 slc_add_reply(unsigned char func
, unsigned char flags
, cc_t value
)
1342 if ((*slc_replyp
++ = func
) == IAC
)
1343 *slc_replyp
++ = IAC
;
1344 if ((*slc_replyp
++ = flags
) == IAC
)
1345 *slc_replyp
++ = IAC
;
1346 if ((*slc_replyp
++ = (unsigned char)value
) == IAC
)
1347 *slc_replyp
++ = IAC
;
1355 *slc_replyp
++ = IAC
;
1357 len
= slc_replyp
- slc_reply
;
1360 if (NETROOM() > len
) {
1361 ring_supply_data(&netoring
, slc_reply
, slc_replyp
- slc_reply
);
1362 printsub('>', &slc_reply
[2], slc_replyp
- slc_reply
- 2);
1364 /*@*/else printf("slc_end_reply: not enough room\n");
1371 int need_update
= 0;
1373 for (spcp
= &spc_data
[1]; spcp
< &spc_data
[NSLC
+1]; spcp
++) {
1374 if (!(spcp
->flags
&SLC_ACK
))
1376 spcp
->flags
&= ~SLC_ACK
;
1377 if (spcp
->valp
&& (*spcp
->valp
!= spcp
->val
)) {
1378 *spcp
->valp
= spcp
->val
;
1382 return(need_update
);
1388 * Earlier version of telnet/telnetd from the BSD code had
1389 * the definitions of VALUE and VAR reversed. To ensure
1390 * maximum interoperability, we assume that the server is
1391 * an older BSD server, until proven otherwise. The newer
1392 * BSD servers should be able to handle either definition,
1393 * so it is better to use the wrong values if we don't
1394 * know what type of server it is.
1397 int old_env_var
= OLD_ENV_VAR
;
1398 int old_env_value
= OLD_ENV_VALUE
;
1400 # define old_env_var OLD_ENV_VAR
1401 # define old_env_value OLD_ENV_VALUE
1406 env_opt(unsigned char *buf
, int len
)
1408 unsigned char *ep
= 0, *epc
= 0;
1411 switch(buf
[0]&0xff) {
1416 } else for (i
= 1; i
< len
; i
++) {
1417 switch (buf
[i
]&0xff) {
1421 if (telopt_environ
== TELOPT_OLD_ENVIRON
1423 /* Server has the same definitions */
1424 old_env_var
= OLD_ENV_VAR
;
1425 old_env_value
= OLD_ENV_VALUE
;
1431 * Although OLD_ENV_VALUE is not legal, we will
1432 * still recognize it, just in case it is an
1433 * old server that has VAR & VALUE mixed up...
1444 ep
= epc
= &buf
[i
+1];
1464 /* Ignore for now. We shouldn't get it anyway. */
1472 #define OPT_REPLY_SIZE 256
1473 unsigned char *opt_reply
;
1474 unsigned char *opt_replyp
;
1475 unsigned char *opt_replyend
;
1481 opt_reply
= (unsigned char *)realloc(opt_reply
, OPT_REPLY_SIZE
);
1483 opt_reply
= (unsigned char *)malloc(OPT_REPLY_SIZE
);
1484 if (opt_reply
== NULL
) {
1485 /*@*/ printf("env_opt_start: malloc()/realloc() failed!!!\n");
1486 opt_reply
= opt_replyp
= opt_replyend
= NULL
;
1489 opt_replyp
= opt_reply
;
1490 opt_replyend
= opt_reply
+ OPT_REPLY_SIZE
;
1491 *opt_replyp
++ = IAC
;
1493 *opt_replyp
++ = telopt_environ
;
1494 *opt_replyp
++ = TELQUAL_IS
;
1498 env_opt_start_info(void)
1502 opt_replyp
[-1] = TELQUAL_INFO
;
1506 env_opt_add(unsigned char *ep
)
1508 unsigned char *vp
, c
;
1510 if (opt_reply
== NULL
) /*XXX*/
1513 if (ep
== NULL
|| *ep
== '\0') {
1514 /* Send user defined variables first. */
1516 while ((ep
= env_default(0, 0)))
1519 /* Now add the list of well know variables. */
1521 while ((ep
= env_default(0, 1)))
1525 vp
= env_getvalue(ep
);
1526 if (opt_replyp
+ (vp
? strlen((char *)vp
) : 0) +
1527 strlen((char *)ep
) + 6 > opt_replyend
)
1530 opt_replyend
+= OPT_REPLY_SIZE
;
1531 len
= opt_replyend
- opt_reply
;
1532 opt_reply
= (unsigned char *)realloc(opt_reply
, len
);
1533 if (opt_reply
== NULL
) {
1534 /*@*/ printf("env_opt_add: realloc() failed!!!\n");
1535 opt_reply
= opt_replyp
= opt_replyend
= NULL
;
1538 opt_replyp
= opt_reply
+ len
- (opt_replyend
- opt_replyp
);
1539 opt_replyend
= opt_reply
+ len
;
1541 if (opt_welldefined(ep
))
1543 if (telopt_environ
== TELOPT_OLD_ENVIRON
)
1544 *opt_replyp
++ = old_env_var
;
1547 *opt_replyp
++ = NEW_ENV_VAR
;
1549 *opt_replyp
++ = ENV_USERVAR
;
1551 while ((c
= *ep
++)) {
1554 *opt_replyp
++ = IAC
;
1560 *opt_replyp
++ = ENV_ESC
;
1567 if (telopt_environ
== TELOPT_OLD_ENVIRON
)
1568 *opt_replyp
++ = old_env_value
;
1571 *opt_replyp
++ = NEW_ENV_VALUE
;
1579 opt_welldefined(const char *ep
)
1581 if ((strcmp(ep
, "USER") == 0) ||
1582 (strcmp(ep
, "DISPLAY") == 0) ||
1583 (strcmp(ep
, "PRINTER") == 0) ||
1584 (strcmp(ep
, "SYSTEMTYPE") == 0) ||
1585 (strcmp(ep
, "JOB") == 0) ||
1586 (strcmp(ep
, "ACCT") == 0))
1592 env_opt_end(int emptyok
)
1596 len
= opt_replyp
- opt_reply
+ 2;
1597 if (emptyok
|| len
> 6) {
1598 *opt_replyp
++ = IAC
;
1600 if (NETROOM() > len
) {
1601 ring_supply_data(&netoring
, opt_reply
, len
);
1602 printsub('>', &opt_reply
[2], len
- 2);
1604 /*@*/ else printf("slc_end_reply: not enough room\n");
1608 opt_reply
= opt_replyp
= opt_replyend
= NULL
;
1621 int returnValue
= 0;
1625 while (TTYROOM() > 2) {
1628 ring_consumed(&netiring
, count
);
1632 sbp
= netiring
.consume
;
1633 scc
= ring_full_consecutive(&netiring
);
1635 /* No more data coming in */
1640 c
= *sbp
++ & 0xff, scc
--; count
++;
1643 c
= (*decrypt_input
)(c
);
1644 #endif /* ENCRYPTION */
1646 switch (telrcv_state
) {
1649 telrcv_state
= TS_DATA
;
1651 break; /* Ignore \0 after CR */
1653 else if ((c
== '\n') && my_want_state_is_dont(TELOPT_ECHO
) && !crmod
) {
1657 /* Else, fall through */
1661 telrcv_state
= TS_IAC
;
1665 * The 'crmod' hack (see following) is needed
1666 * since we can't * set CRMOD on output only.
1667 * Machines like MULTICS like to send \r without
1668 * \n; since we must turn off CRMOD to get proper
1669 * input, the mapping is done here (sigh).
1671 if ((c
== '\r') && my_want_state_is_dont(TELOPT_BINARY
)) {
1676 c
= (*decrypt_input
)(c
);
1677 #endif /* ENCRYPTION */
1679 sbp
++, scc
--; count
++;
1682 } else if (my_want_state_is_dont(TELOPT_ECHO
) &&
1684 sbp
++, scc
--; count
++;
1689 (*decrypt_input
)(-1);
1690 #endif /* ENCRYPTION */
1698 telrcv_state
= TS_CR
;
1714 telrcv_state
= TS_WILL
;
1718 telrcv_state
= TS_WONT
;
1722 telrcv_state
= TS_DO
;
1726 telrcv_state
= TS_DONT
;
1731 * We may have missed an urgent notification,
1732 * so make sure we flush whatever is in the
1735 printoption("RCVD", IAC
, DM
);
1738 SYNCHing
= stilloob();
1744 telrcv_state
= TS_SB
;
1754 printoption("RCVD", IAC
, c
);
1757 telrcv_state
= TS_DATA
;
1761 printoption("RCVD", WILL
, c
);
1763 telrcv_state
= TS_DATA
;
1767 printoption("RCVD", WONT
, c
);
1769 telrcv_state
= TS_DATA
;
1773 printoption("RCVD", DO
, c
);
1775 if (c
== TELOPT_NAWS
) {
1777 } else if (c
== TELOPT_LFLOW
) {
1782 telrcv_state
= TS_DATA
;
1786 printoption("RCVD", DONT
, c
);
1789 setconnmode(0); /* set new tty mode (maybe) */
1790 telrcv_state
= TS_DATA
;
1795 telrcv_state
= TS_SE
;
1805 * This is an error. We only expect to get
1806 * "IAC IAC" or "IAC SE". Several things may
1807 * have happend. An IAC was not doubled, the
1808 * IAC SE was left off, or another option got
1809 * inserted into the suboption are all possibilities.
1810 * If we assume that the IAC was not doubled,
1811 * and really the IAC SE was left off, we could
1812 * get into an infinate loop here. So, instead,
1813 * we terminate the suboption, and process the
1814 * partial suboption if we can.
1821 printoption("In SUBOPTION processing, RCVD", IAC
, c
);
1822 suboption(); /* handle sub-option */
1823 telrcv_state
= TS_IAC
;
1827 telrcv_state
= TS_SB
;
1833 suboption(); /* handle sub-option */
1834 telrcv_state
= TS_DATA
;
1839 ring_consumed(&netiring
, count
);
1840 return returnValue
||count
;
1843 static int bol
= 1, local
= 0;
1851 command(0, "z\n", 2);
1862 int returnValue
= 0;
1867 while (NETROOM() > 2) {
1873 ring_consumed(&ttyiring
, count
);
1877 tbp
= ttyiring
.consume
;
1878 tcc
= ring_full_consecutive(&ttyiring
);
1883 c
= *tbp
++ & 0xff, sc
= strip(c
), tcc
--; count
++;
1884 if (rlogin
!= _POSIX_VDISABLE
) {
1893 if (sc
== '.' || c
== termEofChar
) {
1895 command(0, "close\n", 6);
1898 if (sc
== termSuspChar
) {
1900 command(0, "z\n", 2);
1904 command(0, tbp
, tcc
);
1918 if ((sc
== '\n') || (sc
== '\r'))
1920 } else if (escape
!= _POSIX_VDISABLE
&& sc
== escape
) {
1922 * Double escape is a pass through of a single escape character.
1924 if (tcc
&& strip(*tbp
) == escape
) {
1930 command(0, (char *)tbp
, tcc
);
1939 #ifdef KLUDGELINEMODE
1940 if (kludgelinemode
&& (globalmode
&MODE_EDIT
) && (sc
== echoc
)) {
1941 if (tcc
> 0 && strip(*tbp
) == echoc
) {
1942 tcc
--; tbp
++; count
++;
1944 dontlecho
= !dontlecho
;
1945 settimer(echotoggle
);
1952 if (MODE_LOCAL_CHARS(globalmode
)) {
1953 if (TerminalSpecialChars(sc
) == 0) {
1958 if (my_want_state_is_wont(TELOPT_BINARY
)) {
1962 * If we are in CRMOD mode (\r ==> \n)
1963 * on our local machine, then probably
1964 * a newline (unix) is CRLF (TELNET).
1966 if (MODE_LOCAL_CHARS(globalmode
)) {
1970 bol
= flushline
= 1;
1974 NET2ADD('\r', '\0');
1976 NET2ADD('\r', '\n');
1978 bol
= flushline
= 1;
1987 } else if (c
== IAC
) {
1994 ring_consumed(&ttyiring
, count
);
1995 return returnValue
||count
; /* Non-zero if we did anything */
2001 * Try to do something.
2003 * If we do something useful, return 1; else return 0.
2008 Scheduler(int block
)
2010 /* One wants to be a bit careful about setting returnValue
2011 * to one, since a one implies we did some useful work,
2012 * and therefore probably won't be called to block next
2015 int netin
, netout
, netex
, ttyin
, ttyout
;
2017 /* Decide which rings should be processed */
2019 netout
= ring_full_count(&netoring
) &&
2021 (my_want_state_is_wont(TELOPT_LINEMODE
)
2022 #ifdef KLUDGELINEMODE
2023 && (!kludgelinemode
|| my_want_state_is_do(TELOPT_SGA
))
2026 my_want_state_is_will(TELOPT_BINARY
));
2027 ttyout
= ring_full_count(&ttyoring
);
2029 ttyin
= ring_empty_count(&ttyiring
) && (clienteof
== 0);
2031 netin
= !ISend
&& ring_empty_count(&netiring
);
2035 /* Call to system code to process rings */
2037 returnValue
= process_rings(netin
, netout
, netex
, ttyin
, ttyout
, !block
);
2039 /* Now, look at the input rings, looking for work to do. */
2041 if (ring_full_count(&ttyiring
)) {
2042 returnValue
|= telsnd();
2045 if (ring_full_count(&netiring
)) {
2046 returnValue
|= telrcv();
2051 #ifdef AUTHENTICATION
2052 #define __unusedhere
2054 #define __unusedhere __unused
2057 * Select from tty and network...
2060 telnet(char *user __unusedhere
)
2064 #ifdef AUTHENTICATION
2067 static char local_host
[256] = { 0 };
2069 if (!local_host
[0]) {
2070 gethostname(local_host
, sizeof(local_host
));
2071 local_host
[sizeof(local_host
)-1] = 0;
2073 auth_encrypt_init(local_host
, hostname
, "TELNET", 0);
2074 auth_encrypt_user(user
);
2079 #ifdef AUTHENTICATION
2081 send_will(TELOPT_AUTHENTICATION
, 1);
2084 send_do(TELOPT_ENCRYPT
, 1);
2085 send_will(TELOPT_ENCRYPT
, 1);
2086 #endif /* ENCRYPTION */
2087 send_do(TELOPT_SGA
, 1);
2088 send_will(TELOPT_TTYPE
, 1);
2089 send_will(TELOPT_NAWS
, 1);
2090 send_will(TELOPT_TSPEED
, 1);
2091 send_will(TELOPT_LFLOW
, 1);
2092 send_will(TELOPT_LINEMODE
, 1);
2093 send_will(TELOPT_NEW_ENVIRON
, 1);
2094 send_do(TELOPT_STATUS
, 1);
2095 if (env_getvalue("DISPLAY"))
2096 send_will(TELOPT_XDISPLOC
, 1);
2098 tel_enter_binary(eight
);
2104 while ((schedValue
= Scheduler(0)) != 0) {
2105 if (schedValue
== -1) {
2111 if (Scheduler(1) == -1) {
2118 #if 0 /* XXX - this not being in is a bug */
2122 * Return the address of the next "item" in the TELNET data
2123 * stream. This will be the address of the next character if
2124 * the current address is a user data character, or it will
2125 * be the address of the character following the TELNET command
2126 * if the current address is a TELNET IAC ("I Am a Command")
2131 nextitem(char *current
)
2133 if ((*current
&0xff) != IAC
) {
2136 switch (*(current
+1)&0xff) {
2142 case SB
: /* loop forever looking for the SE */
2144 char *look
= current
+2;
2147 if ((*look
++&0xff) == IAC
) {
2148 if ((*look
++&0xff) == SE
) {
2163 * We are about to do a TELNET SYNCH operation. Clear
2164 * the path to the network.
2166 * Things are a bit tricky since we may have sent the first
2167 * byte or so of a previous TELNET command into the network.
2168 * So, we have to scan the network buffer from the beginning
2169 * until we are up to where we want to be.
2171 * A side effect of what we do, just to keep things
2172 * simple, is to clear the urgent data pointer. The principal
2173 * caller should be setting the urgent data pointer AFTER calling
2184 * These routines add various telnet commands to the data stream.
2194 (void) ttyflush(1); /* Flush/drop output */
2195 /* do printoption AFTER flush, otherwise the output gets tossed... */
2196 printoption("SENT", DO
, TELOPT_TM
);
2203 printoption("SENT", IAC
, AO
);
2213 printoption("SENT", IAC
, EL
);
2220 printoption("SENT", IAC
, EC
);
2224 dosynch(char *ch __unused
)
2226 netclear(); /* clear the path to the network */
2230 printoption("SENT", IAC
, DM
);
2234 int want_status_response
= 0;
2237 get_status(char *ch __unused
)
2239 unsigned char tmp
[16];
2242 if (my_want_state_is_dont(TELOPT_STATUS
)) {
2243 printf("Remote side does not support STATUS option\n");
2250 *cp
++ = TELOPT_STATUS
;
2251 *cp
++ = TELQUAL_SEND
;
2254 if (NETROOM() >= cp
- tmp
) {
2255 ring_supply_data(&netoring
, tmp
, cp
-tmp
);
2256 printsub('>', tmp
+2, cp
- tmp
- 2);
2258 ++want_status_response
;
2266 printoption("SENT", IAC
, IP
);
2279 NET2ADD(IAC
, BREAK
);
2280 printoption("SENT", IAC
, BREAK
);
2293 NET2ADD(IAC
, ABORT
);
2294 printoption("SENT", IAC
, ABORT
);
2308 printoption("SENT", IAC
, SUSP
);
2322 printoption("SENT", IAC
, xEOF
);
2329 printoption("SENT", IAC
, AYT
);
2333 * Send a window size update to the remote system.
2340 unsigned char tmp
[16];
2343 if (my_state_is_wont(TELOPT_NAWS
))
2346 #define PUTSHORT(cp, x) { if ((*cp++ = ((x)>>8)&0xff) == IAC) *cp++ = IAC; \
2347 if ((*cp++ = ((x))&0xff) == IAC) *cp++ = IAC; }
2349 if (TerminalWindowSize(&rows
, &cols
) == 0) { /* Failed */
2357 *cp
++ = TELOPT_NAWS
;
2362 if (NETROOM() >= cp
- tmp
) {
2363 ring_supply_data(&netoring
, tmp
, cp
-tmp
);
2364 printsub('>', tmp
+2, cp
- tmp
- 2);
2369 tel_enter_binary(int rw
)
2372 send_do(TELOPT_BINARY
, 1);
2374 send_will(TELOPT_BINARY
, 1);
2378 tel_leave_binary(int rw
)
2381 send_dont(TELOPT_BINARY
, 1);
2383 send_wont(TELOPT_BINARY
, 1);