summaryrefslogtreecommitdiff
path: root/usr.bin/ssh
diff options
context:
space:
mode:
authorKevin Steves <stevesk@cvs.openbsd.org>2008-11-01 17:40:34 +0000
committerKevin Steves <stevesk@cvs.openbsd.org>2008-11-01 17:40:34 +0000
commitaebb4deee6aa05e00c6aef3496e80972f586286b (patch)
tree2e73c4cc4b231655a2d50453ab5032354bf13e62 /usr.bin/ssh
parentf723c9f48787cea7734d262afdc442af3bb26d38 (diff)
merge dynamic forward parsing into parse_forward(); 'i think this is OK' djm@
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r--usr.bin/ssh/clientloop.c4
-rw-r--r--usr.bin/ssh/readconf.c82
-rw-r--r--usr.bin/ssh/readconf.h4
-rw-r--r--usr.bin/ssh/ssh.c32
4 files changed, 57 insertions, 65 deletions
diff --git a/usr.bin/ssh/clientloop.c b/usr.bin/ssh/clientloop.c
index 30d88981c37..70cb20c2ea0 100644
--- a/usr.bin/ssh/clientloop.c
+++ b/usr.bin/ssh/clientloop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.c,v 1.202 2008/10/30 19:31:16 stevesk Exp $ */
+/* $OpenBSD: clientloop.c,v 1.203 2008/11/01 17:40:33 stevesk Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -833,7 +833,7 @@ process_cmdline(void)
}
channel_request_rforward_cancel(cancel_host, cancel_port);
} else {
- if (!parse_forward(&fwd, s)) {
+ if (!parse_forward(&fwd, s, 0)) {
logit("Bad forwarding specification.");
goto out;
}
diff --git a/usr.bin/ssh/readconf.c b/usr.bin/ssh/readconf.c
index 4a6ceacd8b6..8874eb62031 100644
--- a/usr.bin/ssh/readconf.c
+++ b/usr.bin/ssh/readconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: readconf.c,v 1.167 2008/06/26 11:46:31 grunk Exp $ */
+/* $OpenBSD: readconf.c,v 1.168 2008/11/01 17:40:33 stevesk Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -701,56 +701,39 @@ parse_int:
case oLocalForward:
case oRemoteForward:
+ case oDynamicForward:
arg = strdelim(&s);
if (arg == NULL || *arg == '\0')
fatal("%.200s line %d: Missing port argument.",
filename, linenum);
- arg2 = strdelim(&s);
- if (arg2 == NULL || *arg2 == '\0')
- fatal("%.200s line %d: Missing target argument.",
- filename, linenum);
- /* construct a string for parse_forward */
- snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
+ if (opcode == oLocalForward ||
+ opcode == oRemoteForward) {
+ arg2 = strdelim(&s);
+ if (arg2 == NULL || *arg2 == '\0')
+ fatal("%.200s line %d: Missing target argument.",
+ filename, linenum);
- if (parse_forward(&fwd, fwdarg) == 0)
+ /* construct a string for parse_forward */
+ snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
+ } else if (opcode == oDynamicForward) {
+ strlcpy(fwdarg, arg, sizeof(fwdarg));
+ }
+
+ if (parse_forward(&fwd, fwdarg,
+ opcode == oDynamicForward ? 1 : 0) == 0)
fatal("%.200s line %d: Bad forwarding specification.",
filename, linenum);
if (*activep) {
- if (opcode == oLocalForward)
+ if (opcode == oLocalForward ||
+ opcode == oDynamicForward)
add_local_forward(options, &fwd);
else if (opcode == oRemoteForward)
add_remote_forward(options, &fwd);
}
break;
- case oDynamicForward:
- arg = strdelim(&s);
- if (!arg || *arg == '\0')
- fatal("%.200s line %d: Missing port argument.",
- filename, linenum);
- memset(&fwd, '\0', sizeof(fwd));
- fwd.connect_host = "socks";
- fwd.listen_host = hpdelim(&arg);
- if (fwd.listen_host == NULL ||
- strlen(fwd.listen_host) >= NI_MAXHOST)
- fatal("%.200s line %d: Bad forwarding specification.",
- filename, linenum);
- if (arg) {
- fwd.listen_port = a2port(arg);
- fwd.listen_host = cleanhostname(fwd.listen_host);
- } else {
- fwd.listen_port = a2port(fwd.listen_host);
- fwd.listen_host = NULL;
- }
- if (fwd.listen_port == 0)
- fatal("%.200s line %d: Badly formatted port number.",
- filename, linenum);
- if (*activep)
- add_local_forward(options, &fwd);
- break;
-
case oClearAllForwardings:
intptr = &options->clear_forwardings;
goto parse_flag;
@@ -1214,11 +1197,14 @@ fill_default_options(Options * options)
/*
* parse_forward
* parses a string containing a port forwarding specification of the form:
+ * dynamicfwd == 0
* [listenhost:]listenport:connecthost:connectport
+ * dynamicfwd == 1
+ * [listenhost:]listenport
* returns number of arguments parsed or zero on error
*/
int
-parse_forward(Forward *fwd, const char *fwdspec)
+parse_forward(Forward *fwd, const char *fwdspec, int dynamicfwd)
{
int i;
char *p, *cp, *fwdarg[4];
@@ -1240,6 +1226,18 @@ parse_forward(Forward *fwd, const char *fwdspec)
i = 0; /* failure */
switch (i) {
+ case 1:
+ fwd->listen_host = NULL;
+ fwd->listen_port = a2port(fwdarg[0]);
+ fwd->connect_host = xstrdup("socks");
+ break;
+
+ case 2:
+ fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
+ fwd->listen_port = a2port(fwdarg[1]);
+ fwd->connect_host = xstrdup("socks");
+ break;
+
case 3:
fwd->listen_host = NULL;
fwd->listen_port = a2port(fwdarg[0]);
@@ -1259,7 +1257,17 @@ parse_forward(Forward *fwd, const char *fwdspec)
xfree(p);
- if (fwd->listen_port == 0 || fwd->connect_port == 0)
+ if (dynamicfwd) {
+ if (!(i == 1 || i == 2))
+ goto fail_free;
+ } else {
+ if (!(i == 3 || i == 4))
+ goto fail_free;
+ if (fwd->connect_port == 0)
+ goto fail_free;
+ }
+
+ if (fwd->listen_port == 0)
goto fail_free;
if (fwd->connect_host != NULL &&
diff --git a/usr.bin/ssh/readconf.h b/usr.bin/ssh/readconf.h
index 47c7aef4e04..c1387a896fa 100644
--- a/usr.bin/ssh/readconf.h
+++ b/usr.bin/ssh/readconf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: readconf.h,v 1.74 2008/06/26 11:46:31 grunk Exp $ */
+/* $OpenBSD: readconf.h,v 1.75 2008/11/01 17:40:33 stevesk Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -133,7 +133,7 @@ typedef struct {
void initialize_options(Options *);
void fill_default_options(Options *);
int read_config_file(const char *, const char *, Options *, int);
-int parse_forward(Forward *, const char *);
+int parse_forward(Forward *, const char *, int);
int
process_config_line(Options *, const char *, char *, const char *, int, int *);
diff --git a/usr.bin/ssh/ssh.c b/usr.bin/ssh/ssh.c
index eb131bc1e01..a20d156bbe7 100644
--- a/usr.bin/ssh/ssh.c
+++ b/usr.bin/ssh/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.321 2008/10/09 06:54:22 jmc Exp $ */
+/* $OpenBSD: ssh.c,v 1.322 2008/11/01 17:40:33 stevesk Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -440,7 +440,7 @@ main(int ac, char **av)
break;
case 'L':
- if (parse_forward(&fwd, optarg))
+ if (parse_forward(&fwd, optarg, 0))
add_local_forward(&options, &fwd);
else {
fprintf(stderr,
@@ -451,7 +451,7 @@ main(int ac, char **av)
break;
case 'R':
- if (parse_forward(&fwd, optarg)) {
+ if (parse_forward(&fwd, optarg, 0)) {
add_remote_forward(&options, &fwd);
} else {
fprintf(stderr,
@@ -462,30 +462,14 @@ main(int ac, char **av)
break;
case 'D':
- cp = p = xstrdup(optarg);
- memset(&fwd, '\0', sizeof(fwd));
- fwd.connect_host = "socks";
- if ((fwd.listen_host = hpdelim(&cp)) == NULL) {
- fprintf(stderr, "Bad dynamic forwarding "
- "specification '%.100s'\n", optarg);
- exit(255);
- }
- if (cp != NULL) {
- fwd.listen_port = a2port(cp);
- fwd.listen_host =
- cleanhostname(fwd.listen_host);
+ if (parse_forward(&fwd, optarg, 1)) {
+ add_local_forward(&options, &fwd);
} else {
- fwd.listen_port = a2port(fwd.listen_host);
- fwd.listen_host = NULL;
- }
-
- if (fwd.listen_port == 0) {
- fprintf(stderr, "Bad dynamic port '%s'\n",
- optarg);
+ fprintf(stderr,
+ "Bad dynamic forwarding specification "
+ "'%s'\n", optarg);
exit(255);
}
- add_local_forward(&options, &fwd);
- xfree(p);
break;
case 'C':