374330e2 |
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
374330e2 |
3 | |
4 | #include "putty.h" |
5 | |
6 | #ifndef FALSE |
7 | #define FALSE 0 |
8 | #endif |
9 | #ifndef TRUE |
10 | #define TRUE 1 |
11 | #endif |
12 | |
32874aea |
13 | #define IAC 255 /* interpret as command: */ |
14 | #define DONT 254 /* you are not to use option */ |
15 | #define DO 253 /* please, you use option */ |
16 | #define WONT 252 /* I won't use option */ |
17 | #define WILL 251 /* I will use option */ |
18 | #define SB 250 /* interpret as subnegotiation */ |
19 | #define SE 240 /* end sub negotiation */ |
20 | |
21 | #define GA 249 /* you may reverse the line */ |
22 | #define EL 248 /* erase the current line */ |
23 | #define EC 247 /* erase the current character */ |
24 | #define AYT 246 /* are you there */ |
25 | #define AO 245 /* abort output--but let prog finish */ |
26 | #define IP 244 /* interrupt process--permanently */ |
27 | #define BREAK 243 /* break */ |
28 | #define DM 242 /* data mark--for connect. cleaning */ |
29 | #define NOP 241 /* nop */ |
30 | #define EOR 239 /* end of record (transparent mode) */ |
31 | #define ABORT 238 /* Abort process */ |
32 | #define SUSP 237 /* Suspend process */ |
33 | #define xEOF 236 /* End of file: EOF is already used... */ |
34 | |
35 | #define TELOPT_BINARY 0 /* 8-bit data path */ |
36 | #define TELOPT_ECHO 1 /* echo */ |
37 | #define TELOPT_RCP 2 /* prepare to reconnect */ |
38 | #define TELOPT_SGA 3 /* suppress go ahead */ |
39 | #define TELOPT_NAMS 4 /* approximate message size */ |
40 | #define TELOPT_STATUS 5 /* give status */ |
41 | #define TELOPT_TM 6 /* timing mark */ |
42 | #define TELOPT_RCTE 7 /* remote controlled transmission and echo */ |
43 | #define TELOPT_NAOL 8 /* negotiate about output line width */ |
44 | #define TELOPT_NAOP 9 /* negotiate about output page size */ |
45 | #define TELOPT_NAOCRD 10 /* negotiate about CR disposition */ |
46 | #define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */ |
47 | #define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */ |
48 | #define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */ |
49 | #define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */ |
50 | #define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */ |
51 | #define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */ |
52 | #define TELOPT_XASCII 17 /* extended ascic character set */ |
53 | #define TELOPT_LOGOUT 18 /* force logout */ |
54 | #define TELOPT_BM 19 /* byte macro */ |
55 | #define TELOPT_DET 20 /* data entry terminal */ |
56 | #define TELOPT_SUPDUP 21 /* supdup protocol */ |
57 | #define TELOPT_SUPDUPOUTPUT 22 /* supdup output */ |
58 | #define TELOPT_SNDLOC 23 /* send location */ |
59 | #define TELOPT_TTYPE 24 /* terminal type */ |
60 | #define TELOPT_EOR 25 /* end or record */ |
61 | #define TELOPT_TUID 26 /* TACACS user identification */ |
62 | #define TELOPT_OUTMRK 27 /* output marking */ |
63 | #define TELOPT_TTYLOC 28 /* terminal location number */ |
64 | #define TELOPT_3270REGIME 29 /* 3270 regime */ |
65 | #define TELOPT_X3PAD 30 /* X.3 PAD */ |
66 | #define TELOPT_NAWS 31 /* window size */ |
67 | #define TELOPT_TSPEED 32 /* terminal speed */ |
68 | #define TELOPT_LFLOW 33 /* remote flow control */ |
69 | #define TELOPT_LINEMODE 34 /* Linemode option */ |
70 | #define TELOPT_XDISPLOC 35 /* X Display Location */ |
71 | #define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */ |
72 | #define TELOPT_AUTHENTICATION 37 /* Authenticate */ |
73 | #define TELOPT_ENCRYPT 38 /* Encryption option */ |
74 | #define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */ |
347e5401 |
75 | #define TELOPT_TN3270E 40 /* TN3270 enhancements */ |
76 | #define TELOPT_XAUTH 41 |
77 | #define TELOPT_CHARSET 42 /* Character set */ |
78 | #define TELOPT_RSP 43 /* Remote serial port */ |
79 | #define TELOPT_COM_PORT_OPTION 44 /* Com port control */ |
80 | #define TELOPT_SLE 45 /* Suppress local echo */ |
81 | #define TELOPT_STARTTLS 46 /* Start TLS */ |
82 | #define TELOPT_KERMIT 47 /* Automatic Kermit file transfer */ |
83 | #define TELOPT_SEND_URL 48 |
84 | #define TELOPT_FORWARD_X 49 |
85 | #define TELOPT_PRAGMA_LOGON 138 |
86 | #define TELOPT_SSPI_LOGON 139 |
87 | #define TELOPT_PRAGMA_HEARTBEAT 140 |
32874aea |
88 | #define TELOPT_EXOPL 255 /* extended-options-list */ |
89 | |
90 | #define TELQUAL_IS 0 /* option is... */ |
91 | #define TELQUAL_SEND 1 /* send option */ |
92 | #define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */ |
374330e2 |
93 | #define BSD_VAR 1 |
94 | #define BSD_VALUE 0 |
95 | #define RFC_VAR 0 |
96 | #define RFC_VALUE 1 |
97 | |
98 | #define CR 13 |
99 | #define LF 10 |
100 | #define NUL 0 |
101 | |
656fa244 |
102 | #define iswritable(x) \ |
103 | ( (x) != IAC && \ |
104 | (telnet->opt_states[o_we_bin.index] == ACTIVE || (x) != CR)) |
374330e2 |
105 | |
32874aea |
106 | static char *telopt(int opt) |
107 | { |
374330e2 |
108 | #define i(x) if (opt == TELOPT_ ## x) return #x; |
32874aea |
109 | i(BINARY); |
110 | i(ECHO); |
111 | i(RCP); |
112 | i(SGA); |
113 | i(NAMS); |
114 | i(STATUS); |
115 | i(TM); |
116 | i(RCTE); |
117 | i(NAOL); |
118 | i(NAOP); |
119 | i(NAOCRD); |
120 | i(NAOHTS); |
121 | i(NAOHTD); |
122 | i(NAOFFD); |
123 | i(NAOVTS); |
124 | i(NAOVTD); |
125 | i(NAOLFD); |
126 | i(XASCII); |
127 | i(LOGOUT); |
128 | i(BM); |
129 | i(DET); |
130 | i(SUPDUP); |
131 | i(SUPDUPOUTPUT); |
132 | i(SNDLOC); |
133 | i(TTYPE); |
134 | i(EOR); |
135 | i(TUID); |
136 | i(OUTMRK); |
137 | i(TTYLOC); |
138 | i(X3PAD); |
139 | i(NAWS); |
140 | i(TSPEED); |
141 | i(LFLOW); |
142 | i(LINEMODE); |
143 | i(XDISPLOC); |
144 | i(OLD_ENVIRON); |
145 | i(AUTHENTICATION); |
146 | i(ENCRYPT); |
147 | i(NEW_ENVIRON); |
347e5401 |
148 | i(TN3270E); |
149 | i(XAUTH); |
150 | i(CHARSET); |
151 | i(RSP); |
152 | i(COM_PORT_OPTION); |
153 | i(SLE); |
154 | i(STARTTLS); |
155 | i(KERMIT); |
156 | i(SEND_URL); |
157 | i(FORWARD_X); |
158 | i(PRAGMA_LOGON); |
159 | i(SSPI_LOGON); |
160 | i(PRAGMA_HEARTBEAT); |
32874aea |
161 | i(EXOPL); |
374330e2 |
162 | #undef i |
163 | return "<unknown>"; |
164 | } |
165 | |
51470298 |
166 | static void telnet_size(void *handle, int width, int height); |
374330e2 |
167 | |
168 | struct Opt { |
169 | int send; /* what we initially send */ |
170 | int nsend; /* -ve send if requested to stop it */ |
171 | int ack, nak; /* +ve and -ve acknowledgements */ |
172 | int option; /* the option code */ |
51470298 |
173 | int index; /* index into telnet->opt_states[] */ |
374330e2 |
174 | enum { |
175 | REQUESTED, ACTIVE, INACTIVE, REALLY_INACTIVE |
51470298 |
176 | } initial_state; |
177 | }; |
178 | |
179 | enum { |
180 | OPTINDEX_NAWS, |
181 | OPTINDEX_TSPEED, |
182 | OPTINDEX_TTYPE, |
183 | OPTINDEX_OENV, |
184 | OPTINDEX_NENV, |
185 | OPTINDEX_ECHO, |
186 | OPTINDEX_WE_SGA, |
187 | OPTINDEX_THEY_SGA, |
656fa244 |
188 | OPTINDEX_WE_BIN, |
189 | OPTINDEX_THEY_BIN, |
51470298 |
190 | NUM_OPTS |
374330e2 |
191 | }; |
192 | |
51470298 |
193 | static const struct Opt o_naws = |
194 | { WILL, WONT, DO, DONT, TELOPT_NAWS, OPTINDEX_NAWS, REQUESTED }; |
195 | static const struct Opt o_tspeed = |
196 | { WILL, WONT, DO, DONT, TELOPT_TSPEED, OPTINDEX_TSPEED, REQUESTED }; |
197 | static const struct Opt o_ttype = |
198 | { WILL, WONT, DO, DONT, TELOPT_TTYPE, OPTINDEX_TTYPE, REQUESTED }; |
199 | static const struct Opt o_oenv = { WILL, WONT, DO, DONT, TELOPT_OLD_ENVIRON, |
200 | OPTINDEX_OENV, INACTIVE |
32874aea |
201 | }; |
51470298 |
202 | static const struct Opt o_nenv = { WILL, WONT, DO, DONT, TELOPT_NEW_ENVIRON, |
203 | OPTINDEX_NENV, REQUESTED |
32874aea |
204 | }; |
51470298 |
205 | static const struct Opt o_echo = |
206 | { DO, DONT, WILL, WONT, TELOPT_ECHO, OPTINDEX_ECHO, REQUESTED }; |
207 | static const struct Opt o_we_sga = |
208 | { WILL, WONT, DO, DONT, TELOPT_SGA, OPTINDEX_WE_SGA, REQUESTED }; |
209 | static const struct Opt o_they_sga = |
210 | { DO, DONT, WILL, WONT, TELOPT_SGA, OPTINDEX_THEY_SGA, REQUESTED }; |
656fa244 |
211 | static const struct Opt o_we_bin = |
212 | { WILL, WONT, DO, DONT, TELOPT_BINARY, OPTINDEX_WE_BIN, INACTIVE }; |
213 | static const struct Opt o_they_bin = |
214 | { DO, DONT, WILL, WONT, TELOPT_BINARY, OPTINDEX_THEY_BIN, INACTIVE }; |
51470298 |
215 | |
216 | static const struct Opt *const opts[] = { |
374330e2 |
217 | &o_naws, &o_tspeed, &o_ttype, &o_oenv, &o_nenv, &o_echo, |
656fa244 |
218 | &o_we_sga, &o_they_sga, &o_we_bin, &o_they_bin, NULL |
374330e2 |
219 | }; |
220 | |
51470298 |
221 | typedef struct telnet_tag { |
222 | const struct plug_function_table *fn; |
223 | /* the above field _must_ be first in the structure */ |
224 | |
225 | Socket s; |
226 | |
227 | void *frontend; |
b9d7bcad |
228 | void *ldisc; |
51470298 |
229 | int term_width, term_height; |
230 | |
231 | int opt_states[NUM_OPTS]; |
232 | |
233 | int echoing, editing; |
234 | int activated; |
235 | int bufsize; |
236 | int in_synch; |
237 | int sb_opt, sb_len; |
a1fd562d |
238 | unsigned char *sb_buf; |
51470298 |
239 | int sb_size; |
240 | |
241 | enum { |
242 | TOP_LEVEL, SEENIAC, SEENWILL, SEENWONT, SEENDO, SEENDONT, |
243 | SEENSB, SUBNEGOT, SUBNEG_IAC, SEENCR |
244 | } state; |
245 | |
86916870 |
246 | Config cfg; |
51470298 |
247 | } *Telnet; |
248 | |
5471d09a |
249 | #define TELNET_MAX_BACKLOG 4096 |
250 | |
374330e2 |
251 | #define SB_DELTA 1024 |
252 | |
51470298 |
253 | static void c_write1(Telnet telnet, int c) |
32874aea |
254 | { |
5471d09a |
255 | int backlog; |
32874aea |
256 | char cc = (char) c; |
51470298 |
257 | backlog = from_backend(telnet->frontend, 0, &cc, 1); |
258 | sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG); |
fe50e814 |
259 | } |
260 | |
a8327734 |
261 | static void log_option(Telnet telnet, char *sender, int cmd, int option) |
32874aea |
262 | { |
57356d63 |
263 | char *buf; |
24d7f854 |
264 | /* |
265 | * The strange-looking "<?""?>" below is there to avoid a |
266 | * trigraph - a double question mark followed by > maps to a |
267 | * closing brace character! |
268 | */ |
57356d63 |
269 | buf = dupprintf("%s:\t%s %s", sender, |
270 | (cmd == WILL ? "WILL" : cmd == WONT ? "WONT" : |
271 | cmd == DO ? "DO" : cmd == DONT ? "DONT" : "<?""?>"), |
272 | telopt(option)); |
a8327734 |
273 | logevent(telnet->frontend, buf); |
57356d63 |
274 | sfree(buf); |
374330e2 |
275 | } |
276 | |
51470298 |
277 | static void send_opt(Telnet telnet, int cmd, int option) |
32874aea |
278 | { |
374330e2 |
279 | unsigned char b[3]; |
280 | |
32874aea |
281 | b[0] = IAC; |
282 | b[1] = cmd; |
283 | b[2] = option; |
a1fd562d |
284 | telnet->bufsize = sk_write(telnet->s, (char *)b, 3); |
a8327734 |
285 | log_option(telnet, "client", cmd, option); |
374330e2 |
286 | } |
287 | |
51470298 |
288 | static void deactivate_option(Telnet telnet, const struct Opt *o) |
32874aea |
289 | { |
51470298 |
290 | if (telnet->opt_states[o->index] == REQUESTED || |
291 | telnet->opt_states[o->index] == ACTIVE) |
292 | send_opt(telnet, o->nsend, o->option); |
293 | telnet->opt_states[o->index] = REALLY_INACTIVE; |
374330e2 |
294 | } |
295 | |
708bbbbe |
296 | /* |
297 | * Generate side effects of enabling or disabling an option. |
298 | */ |
51470298 |
299 | static void option_side_effects(Telnet telnet, const struct Opt *o, int enabled) |
32874aea |
300 | { |
0965bee0 |
301 | if (o->option == TELOPT_ECHO && o->send == DO) |
51470298 |
302 | telnet->echoing = !enabled; |
b6c680d4 |
303 | else if (o->option == TELOPT_SGA && o->send == DO) |
51470298 |
304 | telnet->editing = !enabled; |
b9d7bcad |
305 | if (telnet->ldisc) /* cause ldisc to notice the change */ |
306 | ldisc_send(telnet->ldisc, NULL, 0, 0); |
8faa456c |
307 | |
308 | /* Ensure we get the minimum options */ |
51470298 |
309 | if (!telnet->activated) { |
310 | if (telnet->opt_states[o_echo.index] == INACTIVE) { |
311 | telnet->opt_states[o_echo.index] = REQUESTED; |
312 | send_opt(telnet, o_echo.send, o_echo.option); |
8faa456c |
313 | } |
51470298 |
314 | if (telnet->opt_states[o_we_sga.index] == INACTIVE) { |
315 | telnet->opt_states[o_we_sga.index] = REQUESTED; |
316 | send_opt(telnet, o_we_sga.send, o_we_sga.option); |
8faa456c |
317 | } |
51470298 |
318 | if (telnet->opt_states[o_they_sga.index] == INACTIVE) { |
319 | telnet->opt_states[o_they_sga.index] = REQUESTED; |
320 | send_opt(telnet, o_they_sga.send, o_they_sga.option); |
8faa456c |
321 | } |
51470298 |
322 | telnet->activated = TRUE; |
8faa456c |
323 | } |
708bbbbe |
324 | } |
325 | |
51470298 |
326 | static void activate_option(Telnet telnet, const struct Opt *o) |
32874aea |
327 | { |
374330e2 |
328 | if (o->send == WILL && o->option == TELOPT_NAWS) |
51470298 |
329 | telnet_size(telnet, telnet->term_width, telnet->term_height); |
374330e2 |
330 | if (o->send == WILL && |
331 | (o->option == TELOPT_NEW_ENVIRON || |
332 | o->option == TELOPT_OLD_ENVIRON)) { |
333 | /* |
334 | * We may only have one kind of ENVIRON going at a time. |
335 | * This is a hack, but who cares. |
336 | */ |
51470298 |
337 | deactivate_option(telnet, o->option == |
32874aea |
338 | TELOPT_NEW_ENVIRON ? &o_oenv : &o_nenv); |
374330e2 |
339 | } |
51470298 |
340 | option_side_effects(telnet, o, 1); |
374330e2 |
341 | } |
342 | |
51470298 |
343 | static void refused_option(Telnet telnet, const struct Opt *o) |
32874aea |
344 | { |
374330e2 |
345 | if (o->send == WILL && o->option == TELOPT_NEW_ENVIRON && |
51470298 |
346 | telnet->opt_states[o_oenv.index] == INACTIVE) { |
347 | send_opt(telnet, WILL, TELOPT_OLD_ENVIRON); |
348 | telnet->opt_states[o_oenv.index] = REQUESTED; |
374330e2 |
349 | } |
51470298 |
350 | option_side_effects(telnet, o, 0); |
374330e2 |
351 | } |
352 | |
51470298 |
353 | static void proc_rec_opt(Telnet telnet, int cmd, int option) |
32874aea |
354 | { |
51470298 |
355 | const struct Opt *const *o; |
374330e2 |
356 | |
a8327734 |
357 | log_option(telnet, "server", cmd, option); |
374330e2 |
358 | for (o = opts; *o; o++) { |
359 | if ((*o)->option == option && (*o)->ack == cmd) { |
51470298 |
360 | switch (telnet->opt_states[(*o)->index]) { |
374330e2 |
361 | case REQUESTED: |
51470298 |
362 | telnet->opt_states[(*o)->index] = ACTIVE; |
363 | activate_option(telnet, *o); |
374330e2 |
364 | break; |
365 | case ACTIVE: |
366 | break; |
367 | case INACTIVE: |
51470298 |
368 | telnet->opt_states[(*o)->index] = ACTIVE; |
369 | send_opt(telnet, (*o)->send, option); |
370 | activate_option(telnet, *o); |
374330e2 |
371 | break; |
372 | case REALLY_INACTIVE: |
51470298 |
373 | send_opt(telnet, (*o)->nsend, option); |
374330e2 |
374 | break; |
375 | } |
376 | return; |
377 | } else if ((*o)->option == option && (*o)->nak == cmd) { |
51470298 |
378 | switch (telnet->opt_states[(*o)->index]) { |
374330e2 |
379 | case REQUESTED: |
51470298 |
380 | telnet->opt_states[(*o)->index] = INACTIVE; |
381 | refused_option(telnet, *o); |
374330e2 |
382 | break; |
383 | case ACTIVE: |
51470298 |
384 | telnet->opt_states[(*o)->index] = INACTIVE; |
385 | send_opt(telnet, (*o)->nsend, option); |
386 | option_side_effects(telnet, *o, 0); |
374330e2 |
387 | break; |
388 | case INACTIVE: |
389 | case REALLY_INACTIVE: |
390 | break; |
391 | } |
392 | return; |
393 | } |
394 | } |
395 | /* |
396 | * If we reach here, the option was one we weren't prepared to |
397 | * cope with. So send a negative ack. |
398 | */ |
51470298 |
399 | send_opt(telnet, (cmd == WILL ? DONT : WONT), option); |
374330e2 |
400 | } |
401 | |
51470298 |
402 | static void process_subneg(Telnet telnet) |
32874aea |
403 | { |
374330e2 |
404 | unsigned char b[2048], *p, *q; |
405 | int var, value, n; |
406 | char *e; |
407 | |
51470298 |
408 | switch (telnet->sb_opt) { |
374330e2 |
409 | case TELOPT_TSPEED: |
51470298 |
410 | if (telnet->sb_len == 1 && telnet->sb_buf[0] == TELQUAL_SEND) { |
57356d63 |
411 | char *logbuf; |
32874aea |
412 | b[0] = IAC; |
413 | b[1] = SB; |
414 | b[2] = TELOPT_TSPEED; |
374330e2 |
415 | b[3] = TELQUAL_IS; |
86916870 |
416 | strcpy((char *)(b + 4), telnet->cfg.termspeed); |
417 | n = 4 + strlen(telnet->cfg.termspeed); |
32874aea |
418 | b[n] = IAC; |
419 | b[n + 1] = SE; |
a1fd562d |
420 | telnet->bufsize = sk_write(telnet->s, (char *)b, n + 2); |
a8327734 |
421 | logevent(telnet->frontend, "server:\tSB TSPEED SEND"); |
86916870 |
422 | logbuf = dupprintf("client:\tSB TSPEED IS %s", telnet->cfg.termspeed); |
a8327734 |
423 | logevent(telnet->frontend, logbuf); |
57356d63 |
424 | sfree(logbuf); |
374330e2 |
425 | } else |
a8327734 |
426 | logevent(telnet->frontend, "server:\tSB TSPEED <something weird>"); |
374330e2 |
427 | break; |
428 | case TELOPT_TTYPE: |
51470298 |
429 | if (telnet->sb_len == 1 && telnet->sb_buf[0] == TELQUAL_SEND) { |
57356d63 |
430 | char *logbuf; |
32874aea |
431 | b[0] = IAC; |
432 | b[1] = SB; |
433 | b[2] = TELOPT_TTYPE; |
374330e2 |
434 | b[3] = TELQUAL_IS; |
86916870 |
435 | for (n = 0; telnet->cfg.termtype[n]; n++) |
436 | b[n + 4] = (telnet->cfg.termtype[n] >= 'a' |
437 | && telnet->cfg.termtype[n] <= |
438 | 'z' ? telnet->cfg.termtype[n] + 'A' - |
439 | 'a' : telnet->cfg.termtype[n]); |
32874aea |
440 | b[n + 4] = IAC; |
441 | b[n + 5] = SE; |
a1fd562d |
442 | telnet->bufsize = sk_write(telnet->s, (char *)b, n + 6); |
32874aea |
443 | b[n + 4] = 0; |
a8327734 |
444 | logevent(telnet->frontend, "server:\tSB TTYPE SEND"); |
57356d63 |
445 | logbuf = dupprintf("client:\tSB TTYPE IS %s", b + 4); |
a8327734 |
446 | logevent(telnet->frontend, logbuf); |
57356d63 |
447 | sfree(logbuf); |
374330e2 |
448 | } else |
a8327734 |
449 | logevent(telnet->frontend, "server:\tSB TTYPE <something weird>\r\n"); |
374330e2 |
450 | break; |
451 | case TELOPT_OLD_ENVIRON: |
32874aea |
452 | case TELOPT_NEW_ENVIRON: |
51470298 |
453 | p = telnet->sb_buf; |
454 | q = p + telnet->sb_len; |
374330e2 |
455 | if (p < q && *p == TELQUAL_SEND) { |
57356d63 |
456 | char *logbuf; |
374330e2 |
457 | p++; |
57356d63 |
458 | logbuf = dupprintf("server:\tSB %s SEND", telopt(telnet->sb_opt)); |
a8327734 |
459 | logevent(telnet->frontend, logbuf); |
57356d63 |
460 | sfree(logbuf); |
51470298 |
461 | if (telnet->sb_opt == TELOPT_OLD_ENVIRON) { |
86916870 |
462 | if (telnet->cfg.rfc_environ) { |
374330e2 |
463 | value = RFC_VALUE; |
464 | var = RFC_VAR; |
465 | } else { |
466 | value = BSD_VALUE; |
467 | var = BSD_VAR; |
468 | } |
469 | /* |
470 | * Try to guess the sense of VAR and VALUE. |
471 | */ |
472 | while (p < q) { |
473 | if (*p == RFC_VAR) { |
474 | value = RFC_VALUE; |
475 | var = RFC_VAR; |
476 | } else if (*p == BSD_VAR) { |
477 | value = BSD_VALUE; |
478 | var = BSD_VAR; |
479 | } |
480 | p++; |
481 | } |
482 | } else { |
483 | /* |
484 | * With NEW_ENVIRON, the sense of VAR and VALUE |
485 | * isn't in doubt. |
486 | */ |
487 | value = RFC_VALUE; |
488 | var = RFC_VAR; |
489 | } |
32874aea |
490 | b[0] = IAC; |
491 | b[1] = SB; |
51470298 |
492 | b[2] = telnet->sb_opt; |
374330e2 |
493 | b[3] = TELQUAL_IS; |
494 | n = 4; |
86916870 |
495 | e = telnet->cfg.environmt; |
374330e2 |
496 | while (*e) { |
497 | b[n++] = var; |
32874aea |
498 | while (*e && *e != '\t') |
499 | b[n++] = *e++; |
500 | if (*e == '\t') |
501 | e++; |
374330e2 |
502 | b[n++] = value; |
32874aea |
503 | while (*e) |
504 | b[n++] = *e++; |
374330e2 |
505 | e++; |
506 | } |
86916870 |
507 | if (*telnet->cfg.username) { |
32874aea |
508 | b[n++] = var; |
509 | b[n++] = 'U'; |
510 | b[n++] = 'S'; |
511 | b[n++] = 'E'; |
512 | b[n++] = 'R'; |
513 | b[n++] = value; |
86916870 |
514 | e = telnet->cfg.username; |
32874aea |
515 | while (*e) |
516 | b[n++] = *e++; |
374330e2 |
517 | } |
32874aea |
518 | b[n++] = IAC; |
519 | b[n++] = SE; |
a1fd562d |
520 | telnet->bufsize = sk_write(telnet->s, (char *)b, n); |
57356d63 |
521 | logbuf = dupprintf("client:\tSB %s IS %s", telopt(telnet->sb_opt), |
522 | n == 6 ? "<nothing>" : "<stuff>"); |
a8327734 |
523 | logevent(telnet->frontend, logbuf); |
57356d63 |
524 | sfree(logbuf); |
374330e2 |
525 | } |
526 | break; |
527 | } |
528 | } |
529 | |
51470298 |
530 | static void do_telnet_read(Telnet telnet, char *buf, int len) |
32874aea |
531 | { |
374330e2 |
532 | |
533 | while (len--) { |
534 | int c = (unsigned char) *buf++; |
535 | |
51470298 |
536 | switch (telnet->state) { |
887035a5 |
537 | case TOP_LEVEL: |
374330e2 |
538 | case SEENCR: |
51470298 |
539 | if (c == NUL && telnet->state == SEENCR) |
540 | telnet->state = TOP_LEVEL; |
374330e2 |
541 | else if (c == IAC) |
51470298 |
542 | telnet->state = SEENIAC; |
374330e2 |
543 | else { |
51470298 |
544 | if (!telnet->in_synch) |
545 | c_write1(telnet, c); |
2f938b83 |
546 | |
547 | #if 1 |
548 | /* I can't get the F***ing winsock to insert the urgent IAC |
549 | * into the right position! Even with SO_OOBINLINE it gives |
550 | * it to recv too soon. And of course the DM byte (that |
551 | * arrives in the same packet!) appears several K later!! |
552 | * |
553 | * Oh well, we do get the DM in the right place so I'll |
554 | * just stop hiding on the next 0xf2 and hope for the best. |
555 | */ |
32874aea |
556 | else if (c == DM) |
51470298 |
557 | telnet->in_synch = 0; |
2f938b83 |
558 | #endif |
656fa244 |
559 | if (c == CR && telnet->opt_states[o_they_bin.index] != ACTIVE) |
51470298 |
560 | telnet->state = SEENCR; |
374330e2 |
561 | else |
51470298 |
562 | telnet->state = TOP_LEVEL; |
374330e2 |
563 | } |
564 | break; |
565 | case SEENIAC: |
32874aea |
566 | if (c == DO) |
51470298 |
567 | telnet->state = SEENDO; |
32874aea |
568 | else if (c == DONT) |
51470298 |
569 | telnet->state = SEENDONT; |
32874aea |
570 | else if (c == WILL) |
51470298 |
571 | telnet->state = SEENWILL; |
32874aea |
572 | else if (c == WONT) |
51470298 |
573 | telnet->state = SEENWONT; |
32874aea |
574 | else if (c == SB) |
51470298 |
575 | telnet->state = SEENSB; |
2f938b83 |
576 | else if (c == DM) { |
51470298 |
577 | telnet->in_synch = 0; |
578 | telnet->state = TOP_LEVEL; |
32874aea |
579 | } else { |
ded38628 |
580 | /* ignore everything else; print it if it's IAC */ |
581 | if (c == IAC) { |
51470298 |
582 | c_write1(telnet, c); |
ded38628 |
583 | } |
51470298 |
584 | telnet->state = TOP_LEVEL; |
300d41b0 |
585 | } |
374330e2 |
586 | break; |
587 | case SEENWILL: |
51470298 |
588 | proc_rec_opt(telnet, WILL, c); |
589 | telnet->state = TOP_LEVEL; |
374330e2 |
590 | break; |
591 | case SEENWONT: |
51470298 |
592 | proc_rec_opt(telnet, WONT, c); |
593 | telnet->state = TOP_LEVEL; |
374330e2 |
594 | break; |
595 | case SEENDO: |
51470298 |
596 | proc_rec_opt(telnet, DO, c); |
597 | telnet->state = TOP_LEVEL; |
374330e2 |
598 | break; |
599 | case SEENDONT: |
51470298 |
600 | proc_rec_opt(telnet, DONT, c); |
601 | telnet->state = TOP_LEVEL; |
374330e2 |
602 | break; |
603 | case SEENSB: |
51470298 |
604 | telnet->sb_opt = c; |
605 | telnet->sb_len = 0; |
606 | telnet->state = SUBNEGOT; |
374330e2 |
607 | break; |
608 | case SUBNEGOT: |
609 | if (c == IAC) |
51470298 |
610 | telnet->state = SUBNEG_IAC; |
374330e2 |
611 | else { |
32874aea |
612 | subneg_addchar: |
51470298 |
613 | if (telnet->sb_len >= telnet->sb_size) { |
a1fd562d |
614 | unsigned char *newbuf; |
51470298 |
615 | telnet->sb_size += SB_DELTA; |
616 | newbuf = (telnet->sb_buf ? |
617 | srealloc(telnet->sb_buf, telnet->sb_size) : |
618 | smalloc(telnet->sb_size)); |
374330e2 |
619 | if (newbuf) |
51470298 |
620 | telnet->sb_buf = newbuf; |
374330e2 |
621 | else |
51470298 |
622 | telnet->sb_size -= SB_DELTA; |
374330e2 |
623 | } |
51470298 |
624 | if (telnet->sb_len < telnet->sb_size) |
625 | telnet->sb_buf[telnet->sb_len++] = c; |
626 | telnet->state = SUBNEGOT; /* in case we came here by goto */ |
374330e2 |
627 | } |
628 | break; |
629 | case SUBNEG_IAC: |
630 | if (c != SE) |
631 | goto subneg_addchar; /* yes, it's a hack, I know, but... */ |
632 | else { |
51470298 |
633 | process_subneg(telnet); |
634 | telnet->state = TOP_LEVEL; |
374330e2 |
635 | } |
636 | break; |
637 | } |
638 | } |
639 | } |
640 | |
32874aea |
641 | static int telnet_closing(Plug plug, char *error_msg, int error_code, |
642 | int calling_back) |
643 | { |
51470298 |
644 | Telnet telnet = (Telnet) plug; |
645 | |
646 | if (telnet->s) { |
647 | sk_close(telnet->s); |
648 | telnet->s = NULL; |
f3ab576e |
649 | } |
7e78000d |
650 | if (error_msg) { |
32874aea |
651 | /* A socket error has occurred. */ |
a8327734 |
652 | logevent(telnet->frontend, error_msg); |
247308b5 |
653 | connection_fatal("%s", error_msg); |
32874aea |
654 | } /* Otherwise, the remote side closed the connection normally. */ |
7e78000d |
655 | return 0; |
656 | } |
657 | |
32874aea |
658 | static int telnet_receive(Plug plug, int urgent, char *data, int len) |
659 | { |
51470298 |
660 | Telnet telnet = (Telnet) plug; |
32874aea |
661 | if (urgent) |
51470298 |
662 | telnet->in_synch = TRUE; |
663 | do_telnet_read(telnet, data, len); |
8df7a775 |
664 | return 1; |
665 | } |
666 | |
3ad9d396 |
667 | static void telnet_sent(Plug plug, int bufsize) |
668 | { |
51470298 |
669 | Telnet telnet = (Telnet) plug; |
670 | telnet->bufsize = bufsize; |
3ad9d396 |
671 | } |
672 | |
374330e2 |
673 | /* |
8df7a775 |
674 | * Called to set up the Telnet connection. |
374330e2 |
675 | * |
676 | * Returns an error message, or NULL on success. |
677 | * |
6e1ebb76 |
678 | * Also places the canonical host name into `realhost'. It must be |
679 | * freed by the caller. |
374330e2 |
680 | */ |
51470298 |
681 | static char *telnet_init(void *frontend_handle, void **backend_handle, |
86916870 |
682 | Config *cfg, |
887035a5 |
683 | char *host, int port, char **realhost, int nodelay) |
32874aea |
684 | { |
51470298 |
685 | static const struct plug_function_table fn_table = { |
7e78000d |
686 | telnet_closing, |
3ad9d396 |
687 | telnet_receive, |
688 | telnet_sent |
51470298 |
689 | }; |
8df7a775 |
690 | SockAddr addr; |
691 | char *err; |
51470298 |
692 | Telnet telnet; |
693 | |
694 | telnet = smalloc(sizeof(*telnet)); |
695 | telnet->fn = &fn_table; |
86916870 |
696 | telnet->cfg = *cfg; /* STRUCTURE COPY */ |
51470298 |
697 | telnet->s = NULL; |
698 | telnet->echoing = TRUE; |
699 | telnet->editing = TRUE; |
700 | telnet->activated = FALSE; |
701 | telnet->sb_buf = NULL; |
702 | telnet->sb_size = 0; |
703 | telnet->frontend = frontend_handle; |
86916870 |
704 | telnet->term_width = telnet->cfg.width; |
705 | telnet->term_height = telnet->cfg.height; |
51470298 |
706 | telnet->state = TOP_LEVEL; |
707 | *backend_handle = telnet; |
887035a5 |
708 | |
374330e2 |
709 | /* |
710 | * Try to find host. |
711 | */ |
3ad9d396 |
712 | { |
57356d63 |
713 | char *buf; |
714 | buf = dupprintf("Looking up host \"%s\"", host); |
a8327734 |
715 | logevent(telnet->frontend, buf); |
57356d63 |
716 | sfree(buf); |
3ad9d396 |
717 | } |
e8fa8f62 |
718 | addr = name_lookup(host, port, realhost, &telnet->cfg); |
a1fd562d |
719 | if ((err = sk_addr_error(addr)) != NULL) |
8df7a775 |
720 | return err; |
374330e2 |
721 | |
722 | if (port < 0) |
723 | port = 23; /* default telnet port */ |
724 | |
725 | /* |
726 | * Open socket. |
727 | */ |
3ad9d396 |
728 | { |
57356d63 |
729 | char *buf, addrbuf[100]; |
3ad9d396 |
730 | sk_getaddr(addr, addrbuf, 100); |
57356d63 |
731 | buf = dupprintf("Connecting to %s port %d", addrbuf, port); |
a8327734 |
732 | logevent(telnet->frontend, buf); |
57356d63 |
733 | sfree(buf); |
3ad9d396 |
734 | } |
51470298 |
735 | telnet->s = new_connection(addr, *realhost, port, 0, 1, |
e8fa8f62 |
736 | nodelay, (Plug) telnet, &telnet->cfg); |
a1fd562d |
737 | if ((err = sk_socket_error(telnet->s)) != NULL) |
8df7a775 |
738 | return err; |
374330e2 |
739 | |
8df7a775 |
740 | sk_addr_free(addr); |
374330e2 |
741 | |
742 | /* |
743 | * Initialise option states. |
744 | */ |
86916870 |
745 | if (telnet->cfg.passive_telnet) { |
51470298 |
746 | const struct Opt *const *o; |
8faa456c |
747 | |
748 | for (o = opts; *o; o++) |
51470298 |
749 | telnet->opt_states[(*o)->index] = INACTIVE; |
8faa456c |
750 | } else { |
51470298 |
751 | const struct Opt *const *o; |
374330e2 |
752 | |
51470298 |
753 | for (o = opts; *o; o++) { |
754 | telnet->opt_states[(*o)->index] = (*o)->initial_state; |
755 | if (telnet->opt_states[(*o)->index] == REQUESTED) |
756 | send_opt(telnet, (*o)->send, (*o)->option); |
757 | } |
758 | telnet->activated = TRUE; |
374330e2 |
759 | } |
760 | |
374330e2 |
761 | /* |
762 | * Set up SYNCH state. |
763 | */ |
51470298 |
764 | telnet->in_synch = FALSE; |
6f34e365 |
765 | |
374330e2 |
766 | return NULL; |
767 | } |
768 | |
fabd1805 |
769 | static void telnet_free(void *handle) |
770 | { |
771 | Telnet telnet = (Telnet) handle; |
772 | |
773 | sfree(telnet->sb_buf); |
774 | if (telnet->s) |
775 | sk_close(telnet->s); |
776 | sfree(telnet); |
777 | } |
374330e2 |
778 | /* |
86916870 |
779 | * Reconfigure the Telnet backend. There's no immediate action |
780 | * necessary, in this backend: we just save the fresh config for |
781 | * any subsequent negotiations. |
782 | */ |
783 | static void telnet_reconfig(void *handle, Config *cfg) |
784 | { |
785 | Telnet telnet = (Telnet) handle; |
786 | telnet->cfg = *cfg; /* STRUCTURE COPY */ |
787 | } |
788 | |
789 | /* |
374330e2 |
790 | * Called to send data down the Telnet connection. |
791 | */ |
51470298 |
792 | static int telnet_send(void *handle, char *buf, int len) |
32874aea |
793 | { |
51470298 |
794 | Telnet telnet = (Telnet) handle; |
a1fd562d |
795 | unsigned char *p, *end; |
c85623f9 |
796 | static const unsigned char iac[2] = { IAC, IAC }; |
797 | static const unsigned char cr[2] = { CR, NUL }; |
a5f3e637 |
798 | #if 0 |
c85623f9 |
799 | static const unsigned char nl[2] = { CR, LF }; |
a5f3e637 |
800 | #endif |
374330e2 |
801 | |
51470298 |
802 | if (telnet->s == NULL) |
5471d09a |
803 | return 0; |
374330e2 |
804 | |
a1fd562d |
805 | p = (unsigned char *)buf; |
806 | end = (unsigned char *)(buf + len); |
807 | while (p < end) { |
808 | unsigned char *q = p; |
374330e2 |
809 | |
a1fd562d |
810 | while (p < end && iswritable(*p)) |
32874aea |
811 | p++; |
a1fd562d |
812 | telnet->bufsize = sk_write(telnet->s, (char *)q, p - q); |
374330e2 |
813 | |
a1fd562d |
814 | while (p < end && !iswritable(*p)) { |
51470298 |
815 | telnet->bufsize = |
a1fd562d |
816 | sk_write(telnet->s, (char *)(*p == IAC ? iac : cr), 2); |
374330e2 |
817 | p++; |
818 | } |
819 | } |
5471d09a |
820 | |
51470298 |
821 | return telnet->bufsize; |
5471d09a |
822 | } |
823 | |
824 | /* |
825 | * Called to query the current socket sendability status. |
826 | */ |
51470298 |
827 | static int telnet_sendbuffer(void *handle) |
5471d09a |
828 | { |
51470298 |
829 | Telnet telnet = (Telnet) handle; |
830 | return telnet->bufsize; |
374330e2 |
831 | } |
832 | |
833 | /* |
834 | * Called to set the size of the window from Telnet's POV. |
835 | */ |
51470298 |
836 | static void telnet_size(void *handle, int width, int height) |
32874aea |
837 | { |
51470298 |
838 | Telnet telnet = (Telnet) handle; |
ef41972c |
839 | unsigned char b[24]; |
840 | int n; |
57356d63 |
841 | char *logbuf; |
374330e2 |
842 | |
51470298 |
843 | telnet->term_width = width; |
844 | telnet->term_height = height; |
f278d6f8 |
845 | |
51470298 |
846 | if (telnet->s == NULL || telnet->opt_states[o_naws.index] != ACTIVE) |
374330e2 |
847 | return; |
ef41972c |
848 | n = 0; |
849 | b[n++] = IAC; |
850 | b[n++] = SB; |
851 | b[n++] = TELOPT_NAWS; |
852 | b[n++] = telnet->term_width >> 8; |
853 | if (b[n-1] == IAC) b[n++] = IAC; /* duplicate any IAC byte occurs */ |
854 | b[n++] = telnet->term_width & 0xFF; |
855 | if (b[n-1] == IAC) b[n++] = IAC; /* duplicate any IAC byte occurs */ |
856 | b[n++] = telnet->term_height >> 8; |
857 | if (b[n-1] == IAC) b[n++] = IAC; /* duplicate any IAC byte occurs */ |
858 | b[n++] = telnet->term_height & 0xFF; |
859 | if (b[n-1] == IAC) b[n++] = IAC; /* duplicate any IAC byte occurs */ |
860 | b[n++] = IAC; |
861 | b[n++] = SE; |
a1fd562d |
862 | telnet->bufsize = sk_write(telnet->s, (char *)b, n); |
57356d63 |
863 | logbuf = dupprintf("client:\tSB NAWS %d,%d", |
ef41972c |
864 | telnet->term_width, telnet->term_height); |
a8327734 |
865 | logevent(telnet->frontend, logbuf); |
57356d63 |
866 | sfree(logbuf); |
374330e2 |
867 | } |
868 | |
869 | /* |
870 | * Send Telnet special codes. |
871 | */ |
51470298 |
872 | static void telnet_special(void *handle, Telnet_Special code) |
32874aea |
873 | { |
51470298 |
874 | Telnet telnet = (Telnet) handle; |
374330e2 |
875 | unsigned char b[2]; |
876 | |
51470298 |
877 | if (telnet->s == NULL) |
374330e2 |
878 | return; |
879 | |
880 | b[0] = IAC; |
881 | switch (code) { |
32874aea |
882 | case TS_AYT: |
883 | b[1] = AYT; |
a1fd562d |
884 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
885 | break; |
886 | case TS_BRK: |
887 | b[1] = BREAK; |
a1fd562d |
888 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
889 | break; |
890 | case TS_EC: |
891 | b[1] = EC; |
a1fd562d |
892 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
893 | break; |
894 | case TS_EL: |
895 | b[1] = EL; |
a1fd562d |
896 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
897 | break; |
898 | case TS_GA: |
899 | b[1] = GA; |
a1fd562d |
900 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
901 | break; |
902 | case TS_NOP: |
903 | b[1] = NOP; |
a1fd562d |
904 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
905 | break; |
906 | case TS_ABORT: |
907 | b[1] = ABORT; |
a1fd562d |
908 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
909 | break; |
910 | case TS_AO: |
911 | b[1] = AO; |
a1fd562d |
912 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
913 | break; |
914 | case TS_IP: |
915 | b[1] = IP; |
a1fd562d |
916 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
917 | break; |
918 | case TS_SUSP: |
919 | b[1] = SUSP; |
a1fd562d |
920 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
921 | break; |
922 | case TS_EOR: |
923 | b[1] = EOR; |
a1fd562d |
924 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
925 | break; |
926 | case TS_EOF: |
927 | b[1] = xEOF; |
a1fd562d |
928 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
32874aea |
929 | break; |
a5f3e637 |
930 | case TS_EOL: |
6ee0cb6d |
931 | /* In BINARY mode, CR-LF becomes just CR - |
932 | * and without the NUL suffix too. */ |
656fa244 |
933 | if (telnet->opt_states[o_we_bin.index] == ACTIVE) |
6ee0cb6d |
934 | telnet->bufsize = sk_write(telnet->s, "\r", 1); |
656fa244 |
935 | else |
936 | telnet->bufsize = sk_write(telnet->s, "\r\n", 2); |
a5f3e637 |
937 | break; |
374330e2 |
938 | case TS_SYNCH: |
32874aea |
939 | b[1] = DM; |
a1fd562d |
940 | telnet->bufsize = sk_write(telnet->s, (char *)b, 1); |
941 | telnet->bufsize = sk_write_oob(telnet->s, (char *)(b + 1), 1); |
32874aea |
942 | break; |
684d367c |
943 | case TS_RECHO: |
51470298 |
944 | if (telnet->opt_states[o_echo.index] == INACTIVE || |
945 | telnet->opt_states[o_echo.index] == REALLY_INACTIVE) { |
946 | telnet->opt_states[o_echo.index] = REQUESTED; |
947 | send_opt(telnet, o_echo.send, o_echo.option); |
684d367c |
948 | } |
949 | break; |
950 | case TS_LECHO: |
51470298 |
951 | if (telnet->opt_states[o_echo.index] == ACTIVE) { |
952 | telnet->opt_states[o_echo.index] = REQUESTED; |
953 | send_opt(telnet, o_echo.nsend, o_echo.option); |
684d367c |
954 | } |
374330e2 |
955 | break; |
32874aea |
956 | case TS_PING: |
51470298 |
957 | if (telnet->opt_states[o_they_sga.index] == ACTIVE) { |
32874aea |
958 | b[1] = NOP; |
a1fd562d |
959 | telnet->bufsize = sk_write(telnet->s, (char *)b, 2); |
ec55b220 |
960 | } |
32874aea |
961 | break; |
374330e2 |
962 | } |
963 | } |
964 | |
51470298 |
965 | static Socket telnet_socket(void *handle) |
32874aea |
966 | { |
51470298 |
967 | Telnet telnet = (Telnet) handle; |
968 | return telnet->s; |
32874aea |
969 | } |
8ccc75b0 |
970 | |
51470298 |
971 | static int telnet_sendok(void *handle) |
32874aea |
972 | { |
68a49acb |
973 | /* Telnet telnet = (Telnet) handle; */ |
32874aea |
974 | return 1; |
975 | } |
4017be6d |
976 | |
51470298 |
977 | static void telnet_unthrottle(void *handle, int backlog) |
5471d09a |
978 | { |
51470298 |
979 | Telnet telnet = (Telnet) handle; |
980 | sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG); |
5471d09a |
981 | } |
982 | |
51470298 |
983 | static int telnet_ldisc(void *handle, int option) |
32874aea |
984 | { |
51470298 |
985 | Telnet telnet = (Telnet) handle; |
32874aea |
986 | if (option == LD_ECHO) |
51470298 |
987 | return telnet->echoing; |
32874aea |
988 | if (option == LD_EDIT) |
51470298 |
989 | return telnet->editing; |
0965bee0 |
990 | return FALSE; |
991 | } |
992 | |
b9d7bcad |
993 | static void telnet_provide_ldisc(void *handle, void *ldisc) |
994 | { |
995 | Telnet telnet = (Telnet) handle; |
996 | telnet->ldisc = ldisc; |
997 | } |
998 | |
a8327734 |
999 | static void telnet_provide_logctx(void *handle, void *logctx) |
1000 | { |
1001 | /* This is a stub. */ |
1002 | } |
1003 | |
51470298 |
1004 | static int telnet_exitcode(void *handle) |
d8d6c7e5 |
1005 | { |
68a49acb |
1006 | /* Telnet telnet = (Telnet) handle; */ |
d8d6c7e5 |
1007 | /* Telnet doesn't transmit exit codes back to the client */ |
1008 | return 0; |
1009 | } |
1010 | |
374330e2 |
1011 | Backend telnet_backend = { |
1012 | telnet_init, |
fabd1805 |
1013 | telnet_free, |
86916870 |
1014 | telnet_reconfig, |
374330e2 |
1015 | telnet_send, |
5471d09a |
1016 | telnet_sendbuffer, |
374330e2 |
1017 | telnet_size, |
4017be6d |
1018 | telnet_special, |
8ccc75b0 |
1019 | telnet_socket, |
d8d6c7e5 |
1020 | telnet_exitcode, |
97db3be4 |
1021 | telnet_sendok, |
0965bee0 |
1022 | telnet_ldisc, |
b9d7bcad |
1023 | telnet_provide_ldisc, |
a8327734 |
1024 | telnet_provide_logctx, |
5471d09a |
1025 | telnet_unthrottle, |
97db3be4 |
1026 | 23 |
374330e2 |
1027 | }; |