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 | 70a698a122a4b52e24c4db47412889d504ba4ecd (patch) | |
tree | bca14d9de2ce907f64e73b104bdb99044fdc63d9 | |
parent | d3bed4e91a49e3620bdc846e47954095f2e8a79e (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.
-rw-r--r-- | admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp index ab8e5f50..f275abea 100644 --- a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp +++ b/admin/Sources/Services/ogAdmServer/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); } |