[tor-commits] [obfsproxy/master] dummy option parsing needs to take two addresses when not in socks mode
nickm at torproject.org
nickm at torproject.org
Fri Sep 9 17:08:56 UTC 2011
commit b1832a4a236c61da0c70170d7b4a8f11cc4494a3
Author: Zack Weinberg <zackw at panix.com>
Date: Sun Jul 24 14:37:22 2011 -0700
dummy option parsing needs to take two addresses when not in socks mode
---
src/protocols/dummy.c | 27 +++++++++++++++++++--------
src/test/unittest_dummy.c | 19 +++++++++++--------
2 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/src/protocols/dummy.c b/src/protocols/dummy.c
index ae45d9c..8646889 100644
--- a/src/protocols/dummy.c
+++ b/src/protocols/dummy.c
@@ -49,7 +49,7 @@ parse_and_set_options(int n_options, const char *const *options,
{
const char* defport;
- if (n_options != 2)
+ if (n_options < 1)
return -1;
if (!strcmp(options[0], "client")) {
@@ -64,10 +64,19 @@ parse_and_set_options(int n_options, const char *const *options,
} else
return -1;
+ if (n_options != (params->mode == LSN_SOCKS_CLIENT ? 2 : 3))
+ return -1;
+
params->listen_addr = resolve_address_port(options[1], 1, 1, defport);
if (!params->listen_addr)
return -1;
+ if (params->mode != LSN_SOCKS_CLIENT) {
+ params->target_addr = resolve_address_port(options[2], 1, 0, NULL);
+ if (!params->target_addr)
+ return -1;
+ }
+
params->vtable = &dummy_vtable;
return 0;
}
@@ -78,14 +87,16 @@ parse_and_set_options(int n_options, const char *const *options,
static void
usage(void)
{
- log_warn("Great... You can't even form a dummy protocol line:\n"
- "dummy syntax:\n"
- "\tdummy dummy_opts\n"
- "\t'dummy_opts':\n"
+ log_warn("dummy syntax:\n"
+ "\tdummy <mode> <listen_address> [<target_address>]\n"
"\t\tmode ~ server|client|socks\n"
- "\t\tlisten address ~ host:port\n"
- "Example:\n"
- "\tobfsproxy dummy socks 127.0.0.1:5000");
+ "\t\tlisten_address, target_address ~ host:port\n"
+ "\ttarget_address is required for server and client mode,\n"
+ "\tand forbidden for socks mode.\n"
+ "Examples:\n"
+ "\tobfsproxy dummy socks 127.0.0.1:5000\n"
+ "\tobfsproxy dummy client 127.0.0.1:5000 192.168.1.99:11253\n"
+ "\tobfsproxy dummy server 192.168.1.99:11253 127.0.0.1:9005");
}
static void
diff --git a/src/test/unittest_dummy.c b/src/test/unittest_dummy.c
index 1739e1f..4a2316d 100644
--- a/src/test/unittest_dummy.c
+++ b/src/test/unittest_dummy.c
@@ -21,17 +21,20 @@ test_dummy_option_parsing(void *unused)
/* wrong number of options */
{ 0, 0, 1, {"dummy"} },
{ 0, 0, 2, {"dummy", "client"} },
- { 0, 0, 4, {"dummy", "client", "127.0.0.1:5552", "oops"} },
- { 0, 0, 4, {"dummy", "--frobozz", "client", "127.0.0.1:5552"} },
+ { 0, 0, 3, {"dummy", "client", "127.0.0.1:5552"} },
+ { 0, 0, 3, {"dummy", "server", "127.0.0.1:5552"} },
+ { 0, 0, 4, {"dummy", "socks", "127.0.0.1:5552", "192.168.1.99:11253"} },
/* unrecognized mode */
{ 0, 0, 3, {"dummy", "floodcontrol", "127.0.0.1:5552" } },
+ { 0, 0, 4, {"dummy", "--frobozz", "client", "127.0.0.1:5552"} },
+ { 0, 0, 4, {"dummy", "client", "--frobozz", "127.0.0.1:5552"} },
/* bad address */
- { 0, 0, 3, {"dummy", "client", "@:5552"} },
- { 0, 0, 3, {"dummy", "client", "127.0.0.1:notanumber"} },
+ { 0, 0, 3, {"dummy", "socks", "@:5552"} },
+ { 0, 0, 3, {"dummy", "socks", "127.0.0.1:notanumber"} },
/* should succeed */
- { 0, 1, 3, {"dummy", "client", "127.0.0.1:5552" } },
- { 0, 1, 3, {"dummy", "client", "127.0.0.1" } },
- { 0, 1, 3, {"dummy", "server", "127.0.0.1:5552" } },
+ { 0, 1, 4, {"dummy", "client", "127.0.0.1:5552", "192.168.1.99:11253" } },
+ { 0, 1, 4, {"dummy", "client", "127.0.0.1", "192.168.1.99:11253" } },
+ { 0, 1, 4, {"dummy", "server", "127.0.0.1:5552", "192.168.1.99:11253" } },
{ 0, 1, 3, {"dummy", "socks", "127.0.0.1:5552" } },
{ 0, 0, 0, {0} }
@@ -99,7 +102,7 @@ static const char *const options_client[] =
{"dummy", "socks", "127.0.0.1:1800"};
static const char *const options_server[] =
- {"dummy", "server", "127.0.0.1:1800"};
+ {"dummy", "server", "127.0.0.1:1800", "127.0.0.1:1801"};
static void *
setup_dummy_state(const struct testcase_t *unused)
More information about the tor-commits
mailing list