diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-08-16 16:45:11 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2012-08-16 16:45:11 +0200 |
commit | 21d839204129d64b90c673e3fc93e96b7b9bf33d (patch) | |
tree | 540eaa86b91566d93e32c12b3f4b46fceeca14f1 /src | |
parent | 31a0e24b0fa13ee4e2bfc1dc7abece290ff7be14 (diff) | |
download | strongswan-21d839204129d64b90c673e3fc93e96b7b9bf33d.tar.bz2 strongswan-21d839204129d64b90c673e3fc93e96b7b9bf33d.tar.xz |
starter: Restore original config in case also= is used (which reads the same values)
Diffstat (limited to 'src')
-rw-r--r-- | src/starter/confread.c | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/src/starter/confread.c b/src/starter/confread.c index cd011afa4..642fc551b 100644 --- a/src/starter/confread.c +++ b/src/starter/confread.c @@ -257,12 +257,12 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token, else { host_t *host; - char *pos; + char *sep; - pos = strchr(value, '/'); - if (pos) + sep = strchr(value, '/'); + if (sep) { /* CIDR notation, address pool */ - *pos = '\0'; + *sep = '\0'; host = host_create_from_string(value, 0); if (!host) { @@ -272,7 +272,9 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token, host->destroy(host); free(end->sourceip); end->sourceip = strdupnull(value); - end->sourceip_mask = atoi(pos + 1); + end->sourceip_mask = atoi(sep + 1); + /* restore the original text in case also= is used */ + *sep = '/'; } else { /* fixed srcip */ @@ -314,14 +316,14 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token, { struct protoent *proto; struct servent *svc; - char *pos, *port = ""; + char *sep, *port = "", *endptr; long int p; - pos = strchr(value, '/'); - if (pos) + sep = strchr(value, '/'); + if (sep) { /* protocol/port */ - *pos = '\0'; - port = pos + 1; + *sep = '\0'; + port = sep + 1; } proto = getprotobyname(value); @@ -331,8 +333,8 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token, } else { - p = strtol(value, &pos, 0); - if ((*value && *pos) || p < 0 || p > 0xff) + p = strtol(value, &endptr, 0); + if ((*value && *endptr) || p < 0 || p > 0xff) { DBG1(DBG_APP, "# bad protocol: %s=%s", name, value); goto err; @@ -353,8 +355,8 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token, } else { - p = strtol(port, &pos, 0); - if ((*port && *pos) || p < 0 || p > 0xffff) + p = strtol(port, &endptr, 0); + if ((*port && *endptr) || p < 0 || p > 0xffff) { DBG1(DBG_APP, "# bad port: %s=%s", name, value); goto err; @@ -362,6 +364,10 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token, end->port = (u_int16_t)p; } } + if (sep) + { /* restore the original text in case also= is used */ + *sep = '/'; + } break; } case KW_NATIP: @@ -419,16 +425,16 @@ static void handle_firewall(const char *label, starter_end_t *end, static bool handle_mark(char *value, mark_t *mark) { - char *pos, *endptr; + char *sep, *endptr; - pos = strchr(value, '/'); - if (pos) + sep = strchr(value, '/'); + if (sep) { - *pos = '\0'; - mark->mask = strtoul(pos+1, &endptr, 0); + *sep = '\0'; + mark->mask = strtoul(sep+1, &endptr, 0); if (*endptr != '\0') { - DBG1(DBG_APP, "# invalid mark mask: %s", pos+1); + DBG1(DBG_APP, "# invalid mark mask: %s", sep+1); return FALSE; } } @@ -449,6 +455,10 @@ static bool handle_mark(char *value, mark_t *mark) return FALSE; } } + if (sep) + { /* restore the original text in case also= is used */ + *sep = '/'; + } /* apply the mask to ensure the value is in range */ mark->value &= mark->mask; return TRUE; |