diff options
Diffstat (limited to 'clientloop.c')
-rw-r--r-- | clientloop.c | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/clientloop.c b/clientloop.c index 65a6682a6..7259959ee 100644 --- a/clientloop.c +++ b/clientloop.c | |||
@@ -59,7 +59,7 @@ | |||
59 | */ | 59 | */ |
60 | 60 | ||
61 | #include "includes.h" | 61 | #include "includes.h" |
62 | RCSID("$OpenBSD: clientloop.c,v 1.96 2002/02/06 14:55:15 markus Exp $"); | 62 | RCSID("$OpenBSD: clientloop.c,v 1.97 2002/03/21 15:17:26 jakob Exp $"); |
63 | 63 | ||
64 | #include "ssh.h" | 64 | #include "ssh.h" |
65 | #include "ssh1.h" | 65 | #include "ssh1.h" |
@@ -81,6 +81,7 @@ RCSID("$OpenBSD: clientloop.c,v 1.96 2002/02/06 14:55:15 markus Exp $"); | |||
81 | #include "atomicio.h" | 81 | #include "atomicio.h" |
82 | #include "sshtty.h" | 82 | #include "sshtty.h" |
83 | #include "misc.h" | 83 | #include "misc.h" |
84 | #include "readpass.h" | ||
84 | 85 | ||
85 | /* import options */ | 86 | /* import options */ |
86 | extern Options options; | 87 | extern Options options; |
@@ -470,6 +471,75 @@ client_process_net_input(fd_set * readset) | |||
470 | } | 471 | } |
471 | } | 472 | } |
472 | 473 | ||
474 | static void | ||
475 | process_cmdline(Buffer *bin, Buffer *bout, Buffer *berr) | ||
476 | { | ||
477 | char string[1024]; | ||
478 | void (*handler)(int); | ||
479 | char *s, *cmd; | ||
480 | u_short fwd_port, fwd_host_port; | ||
481 | char buf[1024], sfwd_port[6], sfwd_host_port[6]; | ||
482 | int local = 0; | ||
483 | int n; | ||
484 | |||
485 | leave_raw_mode(); | ||
486 | handler = signal(SIGINT, SIG_IGN); | ||
487 | s = read_passphrase("\r\nssh> ", RP_ECHO); | ||
488 | if (s == NULL) | ||
489 | goto out; | ||
490 | cmd = s; | ||
491 | |||
492 | while (*s && isspace(*s)) | ||
493 | s++; | ||
494 | |||
495 | if (*s == 0) | ||
496 | goto out; | ||
497 | |||
498 | if (strlen(s) < 2 || s[0] != '-' || !(s[1] == 'L' || s[1] == 'R')) { | ||
499 | log("Invalid command"); | ||
500 | goto out; | ||
501 | } | ||
502 | if (s[1] == 'L') | ||
503 | local = 1; | ||
504 | if (!local && !compat20) { | ||
505 | log("Not supported for SSH protocol version 1"); | ||
506 | goto out; | ||
507 | } | ||
508 | |||
509 | s += 2; | ||
510 | while (*s && isspace(*s)) | ||
511 | s++; | ||
512 | |||
513 | if (sscanf(s, "%5[0-9]:%255[^:]:%5[0-9]", | ||
514 | sfwd_port, buf, sfwd_host_port) != 3 && | ||
515 | sscanf(s, "%5[0-9]/%255[^/]/%5[0-9]", | ||
516 | sfwd_port, buf, sfwd_host_port) != 3) { | ||
517 | log("Bad forwarding specification"); | ||
518 | goto out; | ||
519 | } | ||
520 | if ((fwd_port = a2port(sfwd_port)) == 0 || | ||
521 | (fwd_host_port = a2port(sfwd_host_port)) == 0) { | ||
522 | log("Bad forwarding port(s)"); | ||
523 | goto out; | ||
524 | } | ||
525 | if (local) { | ||
526 | n = channel_setup_local_fwd_listener(fwd_port, buf, | ||
527 | fwd_host_port, options.gateway_ports); | ||
528 | if (n <= 0) { | ||
529 | log("Port forwarding failed"); | ||
530 | goto out; | ||
531 | } | ||
532 | } else | ||
533 | channel_request_remote_forwarding(fwd_port, buf, | ||
534 | fwd_host_port); | ||
535 | log("Forwarding port"); | ||
536 | out: | ||
537 | signal(SIGINT, handler); | ||
538 | enter_raw_mode(); | ||
539 | if (cmd) | ||
540 | xfree(cmd); | ||
541 | } | ||
542 | |||
473 | /* process the characters one by one */ | 543 | /* process the characters one by one */ |
474 | static int | 544 | static int |
475 | process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len) | 545 | process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len) |
@@ -574,6 +644,7 @@ process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len) | |||
574 | "%c?\r\n\ | 644 | "%c?\r\n\ |
575 | Supported escape sequences:\r\n\ | 645 | Supported escape sequences:\r\n\ |
576 | ~. - terminate connection\r\n\ | 646 | ~. - terminate connection\r\n\ |
647 | ~C - open a command line\r\n\ | ||
577 | ~R - Request rekey (SSH protocol 2 only)\r\n\ | 648 | ~R - Request rekey (SSH protocol 2 only)\r\n\ |
578 | ~^Z - suspend ssh\r\n\ | 649 | ~^Z - suspend ssh\r\n\ |
579 | ~# - list forwarded connections\r\n\ | 650 | ~# - list forwarded connections\r\n\ |
@@ -593,6 +664,10 @@ Supported escape sequences:\r\n\ | |||
593 | xfree(s); | 664 | xfree(s); |
594 | continue; | 665 | continue; |
595 | 666 | ||
667 | case 'C': | ||
668 | process_cmdline(bin, bout, berr); | ||
669 | continue; | ||
670 | |||
596 | default: | 671 | default: |
597 | if (ch != escape_char) { | 672 | if (ch != escape_char) { |
598 | buffer_put_char(bin, escape_char); | 673 | buffer_put_char(bin, escape_char); |