version 1.167, 2008/06/26 11:46:31 |
version 1.168, 2008/11/01 17:40:33 |
|
|
|
|
case oLocalForward: |
case oLocalForward: |
case oRemoteForward: |
case oRemoteForward: |
|
case oDynamicForward: |
arg = strdelim(&s); |
arg = strdelim(&s); |
if (arg == NULL || *arg == '\0') |
if (arg == NULL || *arg == '\0') |
fatal("%.200s line %d: Missing port argument.", |
fatal("%.200s line %d: Missing port argument.", |
filename, linenum); |
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 */ |
if (opcode == oLocalForward || |
snprintf(fwdarg, sizeof(fwdarg), "%s:%s", arg, arg2); |
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.", |
fatal("%.200s line %d: Bad forwarding specification.", |
filename, linenum); |
filename, linenum); |
|
|
if (*activep) { |
if (*activep) { |
if (opcode == oLocalForward) |
if (opcode == oLocalForward || |
|
opcode == oDynamicForward) |
add_local_forward(options, &fwd); |
add_local_forward(options, &fwd); |
else if (opcode == oRemoteForward) |
else if (opcode == oRemoteForward) |
add_remote_forward(options, &fwd); |
add_remote_forward(options, &fwd); |
} |
} |
break; |
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: |
case oClearAllForwardings: |
intptr = &options->clear_forwardings; |
intptr = &options->clear_forwardings; |
goto parse_flag; |
goto parse_flag; |
|
|
/* |
/* |
* parse_forward |
* parse_forward |
* parses a string containing a port forwarding specification of the form: |
* parses a string containing a port forwarding specification of the form: |
|
* dynamicfwd == 0 |
* [listenhost:]listenport:connecthost:connectport |
* [listenhost:]listenport:connecthost:connectport |
|
* dynamicfwd == 1 |
|
* [listenhost:]listenport |
* returns number of arguments parsed or zero on error |
* returns number of arguments parsed or zero on error |
*/ |
*/ |
int |
int |
parse_forward(Forward *fwd, const char *fwdspec) |
parse_forward(Forward *fwd, const char *fwdspec, int dynamicfwd) |
{ |
{ |
int i; |
int i; |
char *p, *cp, *fwdarg[4]; |
char *p, *cp, *fwdarg[4]; |
|
|
i = 0; /* failure */ |
i = 0; /* failure */ |
|
|
switch (i) { |
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: |
case 3: |
fwd->listen_host = NULL; |
fwd->listen_host = NULL; |
fwd->listen_port = a2port(fwdarg[0]); |
fwd->listen_port = a2port(fwdarg[0]); |
|
|
|
|
xfree(p); |
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; |
goto fail_free; |
|
|
if (fwd->connect_host != NULL && |
if (fwd->connect_host != NULL && |