summaryrefslogtreecommitdiff
path: root/clientloop.c
diff options
context:
space:
mode:
Diffstat (limited to 'clientloop.c')
-rw-r--r--clientloop.c84
1 files changed, 59 insertions, 25 deletions
diff --git a/clientloop.c b/clientloop.c
index 9cbc1b0ce..ce627e8b8 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.120 2004/05/20 10:58:05 dtucker Exp $"); 62RCSID("$OpenBSD: clientloop.c,v 1.121 2004/05/21 11:33:11 djm Exp $");
63 63
64#include "ssh.h" 64#include "ssh.h"
65#include "ssh1.h" 65#include "ssh1.h"
@@ -506,6 +506,7 @@ process_cmdline(void)
506 char *s, *cmd; 506 char *s, *cmd;
507 u_short fwd_port, fwd_host_port; 507 u_short fwd_port, fwd_host_port;
508 char buf[1024], sfwd_port[6], sfwd_host_port[6]; 508 char buf[1024], sfwd_port[6], sfwd_host_port[6];
509 int delete = 0;
509 int local = 0; 510 int local = 0;
510 511
511 leave_raw_mode(); 512 leave_raw_mode();
@@ -515,44 +516,77 @@ process_cmdline(void)
515 goto out; 516 goto out;
516 while (*s && isspace(*s)) 517 while (*s && isspace(*s))
517 s++; 518 s++;
519 if (*s == '-')
520 s++; /* Skip cmdline '-', if any */
518 if (*s == '\0') 521 if (*s == '\0')
519 goto out; 522 goto out;
520 if (strlen(s) < 2 || s[0] != '-' || !(s[1] == 'L' || s[1] == 'R')) { 523
524 if (*s == '?') {
525 logit("Commands:");
526 logit(" -Lport:host:hostport Request local forward");
527 logit(" -Rport:host:hostport Request remote forward");
528 logit(" -KRhostport Cancel remote forward");
529 goto out;
530 }
531
532 if (*s == 'K') {
533 delete = 1;
534 s++;
535 }
536 if (*s != 'L' && *s != 'R') {
521 logit("Invalid command."); 537 logit("Invalid command.");
522 goto out; 538 goto out;
523 } 539 }
524 if (s[1] == 'L') 540 if (*s == 'L')
525 local = 1; 541 local = 1;
526 if (!local && !compat20) { 542 if (local && delete) {
543 logit("Not supported.");
544 goto out;
545 }
546 if ((!local || delete) && !compat20) {
527 logit("Not supported for SSH protocol version 1."); 547 logit("Not supported for SSH protocol version 1.");
528 goto out; 548 goto out;
529 } 549 }
530 s += 2; 550
551 s++;
531 while (*s && isspace(*s)) 552 while (*s && isspace(*s))
532 s++; 553 s++;
533 554
534 if (sscanf(s, "%5[0-9]:%255[^:]:%5[0-9]", 555 if (delete) {
535 sfwd_port, buf, sfwd_host_port) != 3 && 556 if (sscanf(s, "%5[0-9]", sfwd_host_port) != 1) {
536 sscanf(s, "%5[0-9]/%255[^/]/%5[0-9]", 557 logit("Bad forwarding specification.");
537 sfwd_port, buf, sfwd_host_port) != 3) { 558 goto out;
538 logit("Bad forwarding specification."); 559 }
539 goto out; 560 if ((fwd_host_port = a2port(sfwd_host_port)) == 0) {
540 } 561 logit("Bad forwarding port(s).");
541 if ((fwd_port = a2port(sfwd_port)) == 0 || 562 goto out;
542 (fwd_host_port = a2port(sfwd_host_port)) == 0) { 563 }
543 logit("Bad forwarding port(s)."); 564 channel_request_rforward_cancel(fwd_host_port);
544 goto out; 565 } else {
545 } 566 if (sscanf(s, "%5[0-9]:%255[^:]:%5[0-9]",
546 if (local) { 567 sfwd_port, buf, sfwd_host_port) != 3 &&
547 if (channel_setup_local_fwd_listener(fwd_port, buf, 568 sscanf(s, "%5[0-9]/%255[^/]/%5[0-9]",
548 fwd_host_port, options.gateway_ports) < 0) { 569 sfwd_port, buf, sfwd_host_port) != 3) {
549 logit("Port forwarding failed."); 570 logit("Bad forwarding specification.");
550 goto out; 571 goto out;
551 } 572 }
552 } else 573 if ((fwd_port = a2port(sfwd_port)) == 0 ||
553 channel_request_remote_forwarding(fwd_port, buf, 574 (fwd_host_port = a2port(sfwd_host_port)) == 0) {
554 fwd_host_port); 575 logit("Bad forwarding port(s).");
555 logit("Forwarding port."); 576 goto out;
577 }
578 if (local) {
579 if (channel_setup_local_fwd_listener(fwd_port, buf,
580 fwd_host_port, options.gateway_ports) < 0) {
581 logit("Port forwarding failed.");
582 goto out;
583 }
584 } else
585 channel_request_remote_forwarding(fwd_port, buf,
586 fwd_host_port);
587 logit("Forwarding port.");
588 }
589
556out: 590out:
557 signal(SIGINT, handler); 591 signal(SIGINT, handler);
558 enter_raw_mode(); 592 enter_raw_mode();