From a8ce36a6a9e8bfb6f8b41ed3de0a250f91baa56a Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 13 Sep 2017 10:19:56 +0100 Subject: [PATCH] proxy/tripe-mitm.c: Allow user control over the delimiter. It turns out that `:' was a terrible choice given the syntax of IPv6 addresses. I probably knew this at the time, even. --- proxy/tripe-mitm.8.in | 17 +++++++++++++++++ proxy/tripe-mitm.c | 16 ++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/proxy/tripe-mitm.8.in b/proxy/tripe-mitm.8.in index cab0fb2b..3a91258c 100644 --- a/proxy/tripe-mitm.8.in +++ b/proxy/tripe-mitm.8.in @@ -58,6 +58,9 @@ The command line contains a sequence of directives, each of which has the form .IB command : arg \c .BR : ... +(The delimiter character can be changed using the +.B \-d +command-line option.) A list of directives can be stored in a file, one per line, and included using the .B include @@ -76,6 +79,12 @@ successfully. .B "\-u, \-\-usage" Write a usage message to standard output, and exit successfully. .TP +.BI "\-d, \-\-delimiter=" char +Use +.I char +as the delimiter to separate argument names in directives, rather than +.RB ` : '. +.TP .BI "\-k, \-\-keyring=" file Read keys from .IR file . @@ -85,6 +94,14 @@ in the current directory. .SS "Directives" A directive is ignored if it is empty, or if its first character is a .RB ` # '. +Directives consist of a name followed by zero or more arguments, +separated by a delimiter character. The default delimiter is +.RB ` : ', +but this can be overridden using the +.B \-d +option (see above); this manual uses +.RB ` : ' +consistently as the delimiter character. The following directives are recognized. .TP .BI peer: name : local-port : remote-addr : remote-port diff --git a/proxy/tripe-mitm.c b/proxy/tripe-mitm.c index ab05a882..2530f151 100644 --- a/proxy/tripe-mitm.c +++ b/proxy/tripe-mitm.c @@ -97,6 +97,7 @@ static peer peers[2]; static unsigned npeer = 0; static key_file keys; static grand *rng; +static const char *delim = ":"; #define PASS(f, buf, sz) ((f) ? (f)->func((f), (buf), (sz)) : (void)0) #define RND(i) (rng->ops->range(rng, (i))) @@ -568,11 +569,11 @@ static void parse(char *p) unsigned c = 0; const struct cmdtab *ct; - p = strtok(p, ":"); + p = strtok(p, delim); if (!p || *p == '#') return; do { v[c++] = p; - p = strtok(0, ":"); + p = strtok(0, delim); } while (p && c < AVMAX - 1); v[c] = 0; for (ct = cmdtab; ct->name; ct++) { @@ -590,7 +591,7 @@ static void version(FILE *fp) { pquis(fp, "$, TrIPE version " VERSION "\n"); } static void usage(FILE *fp) - { pquis(fp, "Usage: $ [-k KEYRING] DIRECTIVE...\n"); } + { pquis(fp, "Usage: $ [-d CHAR] [-k KEYRING] DIRECTIVE...\n"); } static void help(FILE *fp) { @@ -604,6 +605,7 @@ Options:\n\ -v, --version Show the version number.\n\ -u, --usage Show terse usage summary.\n\ \n\ +-d, --delimiter=CHAR Use CHAR rather than `:' as delimiter.\n\ -k, --keyring=FILE Fetch keys from FILE.\n\ \n\ Directives:\n\ @@ -638,14 +640,20 @@ int main(int argc, char *argv[]) { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "usage", 0, 0, 'u' }, + { "delimiter", OPTF_ARGREQ, 0, 'd' }, { "keyring", OPTF_ARGREQ, 0, 'k' }, { 0, 0, 0, 0 } }; - if ((i = mdwopt(argc, argv, "hvuk:", opt, 0, 0, 0)) < 0) break; + if ((i = mdwopt(argc, argv, "hvud:k:", opt, 0, 0, 0)) < 0) break; switch (i) { case 'h': help(stdout); exit(0); case 'v': version(stdout); exit(0); case 'u': usage(stdout); exit(0); + case 'd': + if (!optarg[0] || optarg[1]) + die(1, "delimiter must be a single character"); + delim = optarg; + break; case 'k': kfname = optarg; break; default: f |= f_bogus; break; } -- 2.11.0