summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2019-11-05 10:39:05 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2019-11-06 11:16:59 +0100
commitbecce94eddbf4a20d45a501a0886f1890e303c10 (patch)
tree969e2413884c48695ce27d91c261027d58b04512
parent70a698a122a4b52e24c4db47412889d504ba4ecd (diff)
#915 Validate POST /wol REST API parameters
This patch ensures that all required parameters are sent in the request.
-rw-r--r--admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp
index f275abea..4d61a8ab 100644
--- a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp
+++ b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp
@@ -3293,6 +3293,8 @@ struct og_msg_params {
};
#define OG_REST_PARAM_ADDR (1UL << 0)
+#define OG_REST_PARAM_MAC (1UL << 1)
+#define OG_REST_PARAM_WOL_TYPE (1UL << 2)
static bool og_msg_params_validate(const struct og_msg_params *params,
const uint64_t flags)
@@ -3541,12 +3543,16 @@ static int og_json_parse_target(json_t *element, struct og_msg_params *params)
params->ips_array[params->ips_array_len] =
json_string_value(value);
+
+ params->flags |= OG_REST_PARAM_ADDR;
} else if (!strcmp(key, "mac")) {
if (json_typeof(value) != JSON_STRING)
return -1;
params->mac_array[params->ips_array_len] =
json_string_value(value);
+
+ params->flags |= OG_REST_PARAM_MAC;
}
}
@@ -3592,6 +3598,8 @@ static int og_json_parse_type(json_t *element, struct og_msg_params *params)
else if (!strcmp(type, "broadcast"))
params->wol_type = "1";
+ params->flags |= OG_REST_PARAM_WOL_TYPE;
+
return 0;
}
@@ -3615,6 +3623,11 @@ static int og_cmd_wol(json_t *element, struct og_msg_params *params)
break;
}
+ if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR |
+ OG_REST_PARAM_MAC |
+ OG_REST_PARAM_WOL_TYPE))
+ return -1;
+
if (!Levanta((char **)params->ips_array, (char **)params->mac_array,
params->ips_array_len, (char *)params->wol_type))
return -1;