starter: Restore original config in case also= is used (which reads the same values)
This commit is contained in:
+30
-20
@@ -257,12 +257,12 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
host_t *host;
|
host_t *host;
|
||||||
char *pos;
|
char *sep;
|
||||||
|
|
||||||
pos = strchr(value, '/');
|
sep = strchr(value, '/');
|
||||||
if (pos)
|
if (sep)
|
||||||
{ /* CIDR notation, address pool */
|
{ /* CIDR notation, address pool */
|
||||||
*pos = '\0';
|
*sep = '\0';
|
||||||
host = host_create_from_string(value, 0);
|
host = host_create_from_string(value, 0);
|
||||||
if (!host)
|
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);
|
host->destroy(host);
|
||||||
free(end->sourceip);
|
free(end->sourceip);
|
||||||
end->sourceip = strdupnull(value);
|
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
|
else
|
||||||
{ /* fixed srcip */
|
{ /* 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 protoent *proto;
|
||||||
struct servent *svc;
|
struct servent *svc;
|
||||||
char *pos, *port = "";
|
char *sep, *port = "", *endptr;
|
||||||
long int p;
|
long int p;
|
||||||
|
|
||||||
pos = strchr(value, '/');
|
sep = strchr(value, '/');
|
||||||
if (pos)
|
if (sep)
|
||||||
{ /* protocol/port */
|
{ /* protocol/port */
|
||||||
*pos = '\0';
|
*sep = '\0';
|
||||||
port = pos + 1;
|
port = sep + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
proto = getprotobyname(value);
|
proto = getprotobyname(value);
|
||||||
@@ -331,8 +333,8 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p = strtol(value, &pos, 0);
|
p = strtol(value, &endptr, 0);
|
||||||
if ((*value && *pos) || p < 0 || p > 0xff)
|
if ((*value && *endptr) || p < 0 || p > 0xff)
|
||||||
{
|
{
|
||||||
DBG1(DBG_APP, "# bad protocol: %s=%s", name, value);
|
DBG1(DBG_APP, "# bad protocol: %s=%s", name, value);
|
||||||
goto err;
|
goto err;
|
||||||
@@ -353,8 +355,8 @@ static void kw_end(starter_conn_t *conn, starter_end_t *end, kw_token_t token,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p = strtol(port, &pos, 0);
|
p = strtol(port, &endptr, 0);
|
||||||
if ((*port && *pos) || p < 0 || p > 0xffff)
|
if ((*port && *endptr) || p < 0 || p > 0xffff)
|
||||||
{
|
{
|
||||||
DBG1(DBG_APP, "# bad port: %s=%s", name, value);
|
DBG1(DBG_APP, "# bad port: %s=%s", name, value);
|
||||||
goto err;
|
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;
|
end->port = (u_int16_t)p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (sep)
|
||||||
|
{ /* restore the original text in case also= is used */
|
||||||
|
*sep = '/';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case KW_NATIP:
|
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)
|
static bool handle_mark(char *value, mark_t *mark)
|
||||||
{
|
{
|
||||||
char *pos, *endptr;
|
char *sep, *endptr;
|
||||||
|
|
||||||
pos = strchr(value, '/');
|
sep = strchr(value, '/');
|
||||||
if (pos)
|
if (sep)
|
||||||
{
|
{
|
||||||
*pos = '\0';
|
*sep = '\0';
|
||||||
mark->mask = strtoul(pos+1, &endptr, 0);
|
mark->mask = strtoul(sep+1, &endptr, 0);
|
||||||
if (*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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -449,6 +455,10 @@ static bool handle_mark(char *value, mark_t *mark)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (sep)
|
||||||
|
{ /* restore the original text in case also= is used */
|
||||||
|
*sep = '/';
|
||||||
|
}
|
||||||
/* apply the mask to ensure the value is in range */
|
/* apply the mask to ensure the value is in range */
|
||||||
mark->value &= mark->mask;
|
mark->value &= mark->mask;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|||||||
Reference in New Issue
Block a user