comparison cli-chansession.c @ 485:12d845ab7b5f dbclient-netcat-alike

Rework netcat-alike to be a proper mode, with -B argument.
author Matt Johnston <matt@ucc.asn.au>
date Wed, 17 Sep 2008 14:36:49 +0000
parents d4f32c3443ac
children ae600f1eef81
comparison
equal deleted inserted replaced
478:d4f32c3443ac 485:12d845ab7b5f
336 336
337 encrypt_packet(); 337 encrypt_packet();
338 TRACE(("leave send_chansess_shell_req")) 338 TRACE(("leave send_chansess_shell_req"))
339 } 339 }
340 340
341 static int cli_initchansess(struct Channel *channel) { 341 /* Shared for normal client channel and netcat-alike */
342 342 static int cli_init_stdpipe_sess(struct Channel *channel) {
343
344 channel->writefd = STDOUT_FILENO; 343 channel->writefd = STDOUT_FILENO;
345 setnonblocking(STDOUT_FILENO); 344 setnonblocking(STDOUT_FILENO);
346 345
347 channel->readfd = STDIN_FILENO; 346 channel->readfd = STDIN_FILENO;
348 setnonblocking(STDIN_FILENO); 347 setnonblocking(STDIN_FILENO);
349 348
350 channel->errfd = STDERR_FILENO; 349 channel->errfd = STDERR_FILENO;
351 setnonblocking(STDERR_FILENO); 350 setnonblocking(STDERR_FILENO);
352 351
353 channel->extrabuf = cbuf_new(opts.recv_window); 352 channel->extrabuf = cbuf_new(opts.recv_window);
353 return 0;
354 }
355
356 static int cli_initchansess(struct Channel *channel) {
357
358 cli_init_stdpipe_sess(channel);
354 359
355 if (cli_opts.wantpty) { 360 if (cli_opts.wantpty) {
356 send_chansess_pty_req(channel); 361 send_chansess_pty_req(channel);
357 } 362 }
358 363
361 if (cli_opts.wantpty) { 366 if (cli_opts.wantpty) {
362 cli_tty_setup(); 367 cli_tty_setup();
363 } 368 }
364 369
365 return 0; /* Success */ 370 return 0; /* Success */
366 371 }
367 } 372
368 373 #ifdef ENABLE_CLI_NETCAT
369 void cli_send_chansess_request() { 374
370 375 void cli_send_netcat_request() {
371 unsigned int port = 0; 376
372 unsigned char* addr = NULL; 377 const unsigned char* source_host = "127.0.0.1";
373 unsigned char* ipstring = "127.0.0.1"; 378 const int source_port = 22;
374 unsigned char* portstring = "22"; 379
375 380 const struct ChanType cli_chan_netcat = {
376 /* hack hack */
377 static const struct ChanType cli_chan_tcphack = {
378 0, /* sepfds */ 381 0, /* sepfds */
379 "direct-tcpip", 382 "direct-tcpip",
380 NULL, 383 cli_init_stdpipe_sess, /* inithandler */
381 NULL, 384 NULL,
382 NULL, 385 NULL,
383 cli_closechansess 386 cli_closechansess
384 }; 387 };
385 388
386 TRACE(("enter cli_send_chansess_request")) 389 cli_opts.wantpty = 0;
387 if (send_msg_channel_open_init(STDIN_FILENO, &cli_chan_tcphack) 390
391 if (send_msg_channel_open_init(STDIN_FILENO, &cli_chan_netcat)
388 == DROPBEAR_FAILURE) { 392 == DROPBEAR_FAILURE) {
389 dropbear_exit("Couldn't open initial channel"); 393 dropbear_exit("Couldn't open initial channel");
390 } 394 }
391 395
392 if (cli_opts.localfwds == NULL) { 396 buf_putstring(ses.writepayload, cli_opts.netcat_host,
393 dropbear_exit("You need to give a \"-L ignored:host:port\" option with this hacked up dbclient."); 397 strlen(cli_opts.netcat_host));
394 } 398 buf_putint(ses.writepayload, cli_opts.netcat_port);
395 399
396 addr = cli_opts.localfwds->connectaddr; 400 /* originator ip - localhost is accurate enough */
397 port = cli_opts.localfwds->connectport; 401 buf_putstring(ses.writepayload, source_host, strlen(source_host));
398 402 buf_putint(ses.writepayload, source_port);
399 buf_putstring(ses.writepayload, addr, strlen(addr));
400 buf_putint(ses.writepayload, port);
401
402 /* originator ip */
403 buf_putstring(ses.writepayload, ipstring, strlen(ipstring));
404 /* originator port */
405 buf_putint(ses.writepayload, atol(portstring));
406 403
407 encrypt_packet(); 404 encrypt_packet();
408 TRACE(("leave cli_send_chansess_request")) 405 TRACE(("leave cli_send_chansess_request"))
409 406 }
410 } 407 #endif
408
409 void cli_send_chansess_request() {
410
411 TRACE(("enter cli_send_chansess_request"))
412
413 if (send_msg_channel_open_init(STDIN_FILENO, &clichansess)
414 == DROPBEAR_FAILURE) {
415 dropbear_exit("Couldn't open initial channel");
416 }
417
418 /* No special channel request data */
419 encrypt_packet();
420 TRACE(("leave cli_send_chansess_request"))
421
422 }
423
411 424
412 #if 0 425 #if 0
413 while (cli_opts.localfwds != NULL) { 426 while (cli_opts.localfwds != NULL) {
414 ret = cli_localtcp(cli_opts.localfwds->listenport, 427 ret = cli_localtcp(cli_opts.localfwds->listenport,
415 cli_opts.localfwds->connectaddr, 428 cli_opts.localfwds->connectaddr,