diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2019-11-05 10:47:10 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-11-06 11:24:24 +0100 |
commit | 8901505bb541a68b441a8925c6b1598128344f87 (patch) | |
tree | 942549cbb8fb19f5482b5f3eed9e5b3de6f3bb9c /sources | |
parent | 61059e1b2e66bf64098adac7f47e771739d48038 (diff) |
#915 Validate POST /session REST API parameters
This patch ensures that all required parameters are sent in the request.
Diffstat (limited to 'sources')
-rw-r--r-- | sources/ogAdmServer.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp index 5d17480..cf06df5 100644 --- a/sources/ogAdmServer.cpp +++ b/sources/ogAdmServer.cpp @@ -3296,6 +3296,8 @@ struct og_msg_params { #define OG_REST_PARAM_MAC (1UL << 1) #define OG_REST_PARAM_WOL_TYPE (1UL << 2) #define OG_REST_PARAM_RUN_CMD (1UL << 3) +#define OG_REST_PARAM_DISK (1UL << 4) +#define OG_REST_PARAM_PARTITION (1UL << 5) static bool og_msg_params_validate(const struct og_msg_params *params, const uint64_t flags) @@ -3803,17 +3805,25 @@ static int og_cmd_session(json_t *element, struct og_msg_params *params) return -1; json_object_foreach(element, key, value) { - if (!strcmp(key, "clients")) + if (!strcmp(key, "clients")) { err = og_json_parse_clients(value, params); - else if (!strcmp(key, "disk")) + } else if (!strcmp(key, "disk")) { err = og_json_parse_string(value, ¶ms->disk); - else if (!strcmp(key, "partition")) + params->flags |= OG_REST_PARAM_DISK; + } else if (!strcmp(key, "partition")) { err = og_json_parse_string(value, ¶ms->partition); + params->flags |= OG_REST_PARAM_PARTITION; + } if (err < 0) return err; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_PARTITION)) + return -1; + for (i = 0; i < params->ips_array_len; i++) { snprintf(iph + strlen(iph), sizeof(iph), "%s;", params->ips_array[i]); |