summaryrefslogtreecommitdiffstats
path: root/sources/ogAdmServer.cpp
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
commitec5fe704ccfe92a3dcbaf8ef15f214caa6de0357 (patch)
treed9a8be44431405f3d2b6ecaf4bf446b017256405 /sources/ogAdmServer.cpp
parent54ecdbbdf149990456be9b71d130c4f178a5c2ec (diff)
#915 Validate POST /wol REST API parameters
This patch ensures that all required parameters are sent in the request.
Diffstat (limited to 'sources/ogAdmServer.cpp')
-rw-r--r--sources/ogAdmServer.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp
index f275abe..4d61a8a 100644
--- a/sources/ogAdmServer.cpp
+++ b/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;