summaryrefslogtreecommitdiff
path: root/clientloop.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-03-22 03:24:32 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-03-22 03:24:32 +0000
commit5589f4b55f6f739acb8a2ff616d54e919e01dba9 (patch)
treecab1cabbbcb64b6ecf9d2f547dbd68a967a05cc8 /clientloop.c
parent58b391b1bdaaea1dc7d8e65e1d3549d16bc323f4 (diff)
- jakob@cvs.openbsd.org 2002/03/21 15:17:26
[clientloop.c ssh.1] add built-in command line for adding new port forwardings on the fly. based on a patch from brian wellington. ok markus@.
Diffstat (limited to 'clientloop.c')
-rw-r--r--clientloop.c77
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"
62RCSID("$OpenBSD: clientloop.c,v 1.96 2002/02/06 14:55:15 markus Exp $"); 62RCSID("$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 */
86extern Options options; 87extern Options options;
@@ -470,6 +471,75 @@ client_process_net_input(fd_set * readset)
470 } 471 }
471} 472}
472 473
474static void
475process_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");
536out:
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 */
474static int 544static int
475process_escapes(Buffer *bin, Buffer *bout, Buffer *berr, char *buf, int len) 545process_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\
575Supported escape sequences:\r\n\ 645Supported 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);