summaryrefslogtreecommitdiff
path: root/plugin/business/chaining-policy/src/chaining_policy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/business/chaining-policy/src/chaining_policy.cpp')
-rw-r--r--plugin/business/chaining-policy/src/chaining_policy.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/plugin/business/chaining-policy/src/chaining_policy.cpp b/plugin/business/chaining-policy/src/chaining_policy.cpp
index 4edfc92..87d42f2 100644
--- a/plugin/business/chaining-policy/src/chaining_policy.cpp
+++ b/plugin/business/chaining-policy/src/chaining_policy.cpp
@@ -31,23 +31,21 @@ struct chaining_policy_enforcer
static void chaining_param_new_cb(const char *table_name, const char *key, const char *table_line, void **ad, long argl, void *argp)
{
- cJSON * json_root = NULL;
- cJSON * json_subroot = NULL;
- cJSON * item = NULL;
- size_t user_region_offset = 0;
- size_t user_region_len = 0;
+ cJSON *json_root = NULL;
+ cJSON *json_subroot = NULL;
+ cJSON *item = NULL;
struct chaining_param *param = NULL;
struct chaining_policy_enforcer *enforcer = (struct chaining_policy_enforcer *)argp;
- json_root = cJSON_Parse(table_line);
+ char *json_str = strdup(table_line);
+ json_root = cJSON_Parse(json_str);
if (unlikely(!json_root))
{
TFE_LOG_ERROR(enforcer->logger, "Invalid chaining profile: %s", table_line);
goto error_out;
}
-
json_subroot = cJSON_GetObjectItem(json_root, "action_parameter");
- if (unlikely(!json_subroot))
+ if (unlikely(!json_subroot || !cJSON_IsObject(json_subroot)))
{
TFE_LOG_ERROR(enforcer->logger, "Invalid chaining rule: %s (invalid action_parameter format) %s.", key, table_line);
goto error_out;
@@ -80,6 +78,7 @@ static void chaining_param_new_cb(const char *table_name, const char *key, const
*ad = param;
TFE_LOG_INFO(enforcer->logger, "Add chaining rule: %s", key);
cJSON_Delete(json_root);
+ free(json_str);
return;
error_out:
@@ -88,6 +87,11 @@ error_out:
cJSON_Delete(json_root);
json_root = NULL;
}
+ if (json_str)
+ {
+ free(json_str);
+ json_str = NULL;
+ }
if (param)
{
free(param);
@@ -97,7 +101,7 @@ error_out:
static void chaining_param_free_cb(const char *table_name, void **ad, long argl, void *argp)
{
- char str_rule_id[UUID_STR_LEN] = {0};
+ char str_rule_id[UUID_STRING_SIZE] = {0};
struct chaining_policy_enforcer *enforcer = (struct chaining_policy_enforcer *)argp;
struct chaining_param *param = (struct chaining_param *)*ad;
if (param == NULL)
@@ -116,7 +120,7 @@ static void chaining_param_free_cb(const char *table_name, void **ad, long argl,
static void chaining_param_free(struct chaining_param *param)
{
- chaining_param_free_cb(0, (void **)&param, 0, NULL);
+ chaining_param_free_cb(NULL, (void **)&param, 0, NULL);
}
static void chaining_param_dup_cb(const char *table_name, void **to, void **from, long argl, void *argp)
@@ -167,10 +171,10 @@ void chaining_policy_enforcer_destory(struct chaining_policy_enforcer *enforcer)
}
}
-void chaining_policy_enforce(struct chaining_policy_enforcer *enforcer, struct tfe_cmsg *cmsg, uuid_t rule_id)
+void chaining_policy_enforce(struct chaining_policy_enforcer *enforcer, struct tfe_cmsg *cmsg, uuid_t *rule_id)
{
uint16_t size = 0;
- char str_rule_id[UUID_STR_LEN] = {0};
+ char str_rule_id[UUID_STRING_SIZE] = {0};
uint8_t enalbe_decrypted_traffic_steering = 0;
tfe_cmsg_get_value(cmsg, TFE_CMSG_TCP_DECRYPTED_TRAFFIC_STEERING, (unsigned char *)&enalbe_decrypted_traffic_steering, sizeof(enalbe_decrypted_traffic_steering), &size);
@@ -179,8 +183,8 @@ void chaining_policy_enforce(struct chaining_policy_enforcer *enforcer, struct t
return;
}
- uuid_unparse(rule_id, str_rule_id);
- struct chaining_param *param = (struct chaining_param *)maat_plugin_table_get_ex_data(enforcer->maat, enforcer->table_name, str_rule_id, UUID_STR_LEN-1);
+ uuid_unparse(*rule_id, str_rule_id);
+ struct chaining_param *param = (struct chaining_param *)maat_plugin_table_get_ex_data(enforcer->maat, enforcer->table_name, (const char *)rule_id, sizeof(uuid_t));
if (param == NULL)
{
TFE_LOG_INFO(enforcer->logger, "Failed to get chaining parameter of policy %s.", str_rule_id);