summaryrefslogtreecommitdiff
path: root/readconf.c
diff options
context:
space:
mode:
Diffstat (limited to 'readconf.c')
-rw-r--r--readconf.c82
1 files changed, 45 insertions, 37 deletions
diff --git a/readconf.c b/readconf.c
index 73f6eb361..27be8df68 100644
--- a/readconf.c
+++ b/readconf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: readconf.c,v 1.167 2008/06/26 11:46:31 grunk Exp $ */ 1/* $OpenBSD: readconf.c,v 1.168 2008/11/01 17:40:33 stevesk Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -706,56 +706,39 @@ parse_int:
706 706
707 case oLocalForward: 707 case oLocalForward:
708 case oRemoteForward: 708 case oRemoteForward:
709 case oDynamicForward:
709 arg = strdelim(&s); 710 arg = strdelim(&s);
710 if (arg == NULL || *arg == '\0') 711 if (arg == NULL || *arg == '\0')
711 fatal("%.200s line %d: Missing port argument.", 712 fatal("%.200s line %d: Missing port argument.",
712 filename, linenum); 713 filename, linenum);
713 arg2 = strdelim(&s);
714 if (arg2 == NULL || *arg2 == '\0')
715 fatal("%.200s line %d: Missing target argument.",
716 filename, linenum);
717 714
718 /* construct a string for parse_forward */ 715 if (opcode == oLocalForward ||
719 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2); 716 opcode == oRemoteForward) {
717 arg2 = strdelim(&s);
718 if (arg2 == NULL || *arg2 == '\0')
719 fatal("%.200s line %d: Missing target argument.",
720 filename, linenum);
720 721
721 if (parse_forward(&fwd, fwdarg) == 0) 722 /* construct a string for parse_forward */
723 snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2);
724 } else if (opcode == oDynamicForward) {
725 strlcpy(fwdarg, arg, sizeof(fwdarg));
726 }
727
728 if (parse_forward(&fwd, fwdarg,
729 opcode == oDynamicForward ? 1 : 0) == 0)
722 fatal("%.200s line %d: Bad forwarding specification.", 730 fatal("%.200s line %d: Bad forwarding specification.",
723 filename, linenum); 731 filename, linenum);
724 732
725 if (*activep) { 733 if (*activep) {
726 if (opcode == oLocalForward) 734 if (opcode == oLocalForward ||
735 opcode == oDynamicForward)
727 add_local_forward(options, &fwd); 736 add_local_forward(options, &fwd);
728 else if (opcode == oRemoteForward) 737 else if (opcode == oRemoteForward)
729 add_remote_forward(options, &fwd); 738 add_remote_forward(options, &fwd);
730 } 739 }
731 break; 740 break;
732 741
733 case oDynamicForward:
734 arg = strdelim(&s);
735 if (!arg || *arg == '\0')
736 fatal("%.200s line %d: Missing port argument.",
737 filename, linenum);
738 memset(&fwd, '\0', sizeof(fwd));
739 fwd.connect_host = "socks";
740 fwd.listen_host = hpdelim(&arg);
741 if (fwd.listen_host == NULL ||
742 strlen(fwd.listen_host) >= NI_MAXHOST)
743 fatal("%.200s line %d: Bad forwarding specification.",
744 filename, linenum);
745 if (arg) {
746 fwd.listen_port = a2port(arg);
747 fwd.listen_host = cleanhostname(fwd.listen_host);
748 } else {
749 fwd.listen_port = a2port(fwd.listen_host);
750 fwd.listen_host = NULL;
751 }
752 if (fwd.listen_port == 0)
753 fatal("%.200s line %d: Badly formatted port number.",
754 filename, linenum);
755 if (*activep)
756 add_local_forward(options, &fwd);
757 break;
758
759 case oClearAllForwardings: 742 case oClearAllForwardings:
760 intptr = &options->clear_forwardings; 743 intptr = &options->clear_forwardings;
761 goto parse_flag; 744 goto parse_flag;
@@ -1219,11 +1202,14 @@ fill_default_options(Options * options)
1219/* 1202/*
1220 * parse_forward 1203 * parse_forward
1221 * parses a string containing a port forwarding specification of the form: 1204 * parses a string containing a port forwarding specification of the form:
1205 * dynamicfwd == 0
1222 * [listenhost:]listenport:connecthost:connectport 1206 * [listenhost:]listenport:connecthost:connectport
1207 * dynamicfwd == 1
1208 * [listenhost:]listenport
1223 * returns number of arguments parsed or zero on error 1209 * returns number of arguments parsed or zero on error
1224 */ 1210 */
1225int 1211int
1226parse_forward(Forward *fwd, const char *fwdspec) 1212parse_forward(Forward *fwd, const char *fwdspec, int dynamicfwd)
1227{ 1213{
1228 int i; 1214 int i;
1229 char *p, *cp, *fwdarg[4]; 1215 char *p, *cp, *fwdarg[4];
@@ -1245,6 +1231,18 @@ parse_forward(Forward *fwd, const char *fwdspec)
1245 i = 0; /* failure */ 1231 i = 0; /* failure */
1246 1232
1247 switch (i) { 1233 switch (i) {
1234 case 1:
1235 fwd->listen_host = NULL;
1236 fwd->listen_port = a2port(fwdarg[0]);
1237 fwd->connect_host = xstrdup("socks");
1238 break;
1239
1240 case 2:
1241 fwd->listen_host = xstrdup(cleanhostname(fwdarg[0]));
1242 fwd->listen_port = a2port(fwdarg[1]);
1243 fwd->connect_host = xstrdup("socks");
1244 break;
1245
1248 case 3: 1246 case 3:
1249 fwd->listen_host = NULL; 1247 fwd->listen_host = NULL;
1250 fwd->listen_port = a2port(fwdarg[0]); 1248 fwd->listen_port = a2port(fwdarg[0]);
@@ -1264,7 +1262,17 @@ parse_forward(Forward *fwd, const char *fwdspec)
1264 1262
1265 xfree(p); 1263 xfree(p);
1266 1264
1267 if (fwd->listen_port == 0 || fwd->connect_port == 0) 1265 if (dynamicfwd) {
1266 if (!(i == 1 || i == 2))
1267 goto fail_free;
1268 } else {
1269 if (!(i == 3 || i == 4))
1270 goto fail_free;
1271 if (fwd->connect_port == 0)
1272 goto fail_free;
1273 }
1274
1275 if (fwd->listen_port == 0)
1268 goto fail_free; 1276 goto fail_free;
1269 1277
1270 if (fwd->connect_host != NULL && 1278 if (fwd->connect_host != NULL &&