Mercurial > dropbear
comparison cli-chansession.c @ 579:8c737cd7c1af
merge of '48fdaa8706d1acda35e9d564adc9a1fbc96c18c8'
and '658fd03abd21e0da7c4c89b9fff9dc693c72daae'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 27 Feb 2010 11:53:18 +0000 |
parents | fad3eb63b907 |
children | 6b9d12477953 |
comparison
equal
deleted
inserted
replaced
577:69e98c45db7c | 579:8c737cd7c1af |
---|---|
31 #include "channel.h" | 31 #include "channel.h" |
32 #include "ssh.h" | 32 #include "ssh.h" |
33 #include "runopts.h" | 33 #include "runopts.h" |
34 #include "termcodes.h" | 34 #include "termcodes.h" |
35 #include "chansession.h" | 35 #include "chansession.h" |
36 #include "agentfwd.h" | |
36 | 37 |
37 static void cli_closechansess(struct Channel *channel); | 38 static void cli_closechansess(struct Channel *channel); |
38 static int cli_initchansess(struct Channel *channel); | 39 static int cli_initchansess(struct Channel *channel); |
39 static void cli_chansessreq(struct Channel *channel); | 40 static void cli_chansessreq(struct Channel *channel); |
40 | |
41 static void start_channel_request(struct Channel *channel, unsigned char *type); | |
42 | 41 |
43 static void send_chansess_pty_req(struct Channel *channel); | 42 static void send_chansess_pty_req(struct Channel *channel); |
44 static void send_chansess_shell_req(struct Channel *channel); | 43 static void send_chansess_shell_req(struct Channel *channel); |
45 | 44 |
46 static void cli_tty_setup(); | 45 static void cli_tty_setup(); |
90 | 89 |
91 cli_tty_cleanup(); /* Restore tty modes etc */ | 90 cli_tty_cleanup(); /* Restore tty modes etc */ |
92 | 91 |
93 } | 92 } |
94 | 93 |
95 static void start_channel_request(struct Channel *channel, | 94 void cli_start_send_channel_request(struct Channel *channel, |
96 unsigned char *type) { | 95 unsigned char *type) { |
97 | 96 |
98 CHECKCLEARTOWRITE(); | 97 CHECKCLEARTOWRITE(); |
99 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_REQUEST); | 98 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_REQUEST); |
100 buf_putint(ses.writepayload, channel->remotechan); | 99 buf_putint(ses.writepayload, channel->remotechan); |
285 | 284 |
286 unsigned char* term = NULL; | 285 unsigned char* term = NULL; |
287 | 286 |
288 TRACE(("enter send_chansess_pty_req")) | 287 TRACE(("enter send_chansess_pty_req")) |
289 | 288 |
290 start_channel_request(channel, "pty-req"); | 289 cli_start_send_channel_request(channel, "pty-req"); |
291 | 290 |
292 /* Don't want replies */ | 291 /* Don't want replies */ |
293 buf_putbyte(ses.writepayload, 0); | 292 buf_putbyte(ses.writepayload, 0); |
294 | 293 |
295 /* Get the terminal */ | 294 /* Get the terminal */ |
328 } | 327 } |
329 } else { | 328 } else { |
330 reqtype = "shell"; | 329 reqtype = "shell"; |
331 } | 330 } |
332 | 331 |
333 start_channel_request(channel, reqtype); | 332 cli_start_send_channel_request(channel, reqtype); |
334 | 333 |
335 /* XXX TODO */ | 334 /* XXX TODO */ |
336 buf_putbyte(ses.writepayload, 0); /* Don't want replies */ | 335 buf_putbyte(ses.writepayload, 0); /* Don't want replies */ |
337 if (cli_opts.cmd) { | 336 if (cli_opts.cmd) { |
338 buf_putstring(ses.writepayload, cli_opts.cmd, strlen(cli_opts.cmd)); | 337 buf_putstring(ses.writepayload, cli_opts.cmd, strlen(cli_opts.cmd)); |
359 | 358 |
360 static int cli_initchansess(struct Channel *channel) { | 359 static int cli_initchansess(struct Channel *channel) { |
361 | 360 |
362 cli_init_stdpipe_sess(channel); | 361 cli_init_stdpipe_sess(channel); |
363 | 362 |
363 #ifdef ENABLE_CLI_AGENTFWD | |
364 if (cli_opts.agent_fwd) { | |
365 cli_setup_agent(channel); | |
366 } | |
367 #endif | |
368 | |
364 if (cli_opts.wantpty) { | 369 if (cli_opts.wantpty) { |
365 send_chansess_pty_req(channel); | 370 send_chansess_pty_req(channel); |
366 } | 371 } |
367 | 372 |
368 send_chansess_shell_req(channel); | 373 send_chansess_shell_req(channel); |
374 return 0; /* Success */ | 379 return 0; /* Success */ |
375 } | 380 } |
376 | 381 |
377 #ifdef ENABLE_CLI_NETCAT | 382 #ifdef ENABLE_CLI_NETCAT |
378 | 383 |
384 const struct ChanType cli_chan_netcat = { | |
385 0, /* sepfds */ | |
386 "direct-tcpip", | |
387 cli_init_stdpipe_sess, /* inithandler */ | |
388 NULL, | |
389 NULL, | |
390 cli_closechansess | |
391 }; | |
392 | |
379 void cli_send_netcat_request() { | 393 void cli_send_netcat_request() { |
380 | 394 |
381 const unsigned char* source_host = "127.0.0.1"; | 395 const unsigned char* source_host = "127.0.0.1"; |
382 const int source_port = 22; | 396 const int source_port = 22; |
383 | |
384 const struct ChanType cli_chan_netcat = { | |
385 0, /* sepfds */ | |
386 "direct-tcpip", | |
387 cli_init_stdpipe_sess, /* inithandler */ | |
388 NULL, | |
389 NULL, | |
390 cli_closechansess | |
391 }; | |
392 | 397 |
393 cli_opts.wantpty = 0; | 398 cli_opts.wantpty = 0; |
394 | 399 |
395 if (send_msg_channel_open_init(STDIN_FILENO, &cli_chan_netcat) | 400 if (send_msg_channel_open_init(STDIN_FILENO, &cli_chan_netcat) |
396 == DROPBEAR_FAILURE) { | 401 == DROPBEAR_FAILURE) { |
422 /* No special channel request data */ | 427 /* No special channel request data */ |
423 encrypt_packet(); | 428 encrypt_packet(); |
424 TRACE(("leave cli_send_chansess_request")) | 429 TRACE(("leave cli_send_chansess_request")) |
425 | 430 |
426 } | 431 } |
427 | |
428 | |
429 #if 0 | |
430 while (cli_opts.localfwds != NULL) { | |
431 ret = cli_localtcp(cli_opts.localfwds->listenport, | |
432 cli_opts.localfwds->connectaddr, | |
433 cli_opts.localfwds->connectport); | |
434 if (ret == DROPBEAR_FAILURE) { | |
435 dropbear_log(LOG_WARNING, "Failed local port forward %d:%s:%d", | |
436 cli_opts.localfwds->listenport, | |
437 cli_opts.localfwds->connectaddr, | |
438 cli_opts.localfwds->connectport); | |
439 #endif |