diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2019-11-05 10:31:16 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-11-06 11:16:36 +0100 |
commit | 54ecdbbdf149990456be9b71d130c4f178a5c2ec (patch) | |
tree | 7bf5e9bd44be60f4acc53ebf65db9d5434c49194 /sources/ogAdmServer.cpp | |
parent | 64b470514bed3d5e30a85356798f7666ad2be4e3 (diff) |
#915 Validate POST /clients parameters
This patch adds og_msg_params_validate function as well as some flags that can
be used to validate parameters of a REST API request.
This patch ensures that all required parameters are sent in the request.
Diffstat (limited to 'sources/ogAdmServer.cpp')
-rw-r--r-- | sources/ogAdmServer.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp index ab8e5f5..f275abe 100644 --- a/sources/ogAdmServer.cpp +++ b/sources/ogAdmServer.cpp @@ -3289,8 +3289,17 @@ struct og_msg_params { const char *cache_size; struct og_partition partition_setup[OG_PARTITION_MAX]; struct og_sync_params sync_setup; + uint64_t flags; }; +#define OG_REST_PARAM_ADDR (1UL << 0) + +static bool og_msg_params_validate(const struct og_msg_params *params, + const uint64_t flags) +{ + return (params->flags & flags) == flags; +} + static int og_json_parse_clients(json_t *element, struct og_msg_params *params) { unsigned int i; @@ -3307,6 +3316,9 @@ static int og_json_parse_clients(json_t *element, struct og_msg_params *params) params->ips_array[params->ips_array_len++] = json_string_value(k); } + + params->flags |= OG_REST_PARAM_ADDR; + return 0; } @@ -3440,6 +3452,9 @@ static int og_cmd_post_clients(json_t *element, struct og_msg_params *params) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) + return -1; + return og_cmd_legacy_send(params, "Sondeo", CLIENTE_APAGADO); } |