diff options
| author | fengweihao <[email protected]> | 2020-04-16 15:07:27 +0800 |
|---|---|---|
| committer | fengweihao <[email protected]> | 2020-04-16 15:07:27 +0800 |
| commit | 633005fa246c79187e487332c9047cd017853c74 (patch) | |
| tree | 214706d22611a38bc2a2592ae481b3880b6e35de | |
| parent | eba8d6797a91b5b30f3a5ffe5c4e63bff74fc741 (diff) | |
TSG-1274 Minitor规则多命中修改v2.1.2-20200506
| -rw-r--r-- | scan/src/pangu_http.cpp | 98 |
1 files changed, 15 insertions, 83 deletions
diff --git a/scan/src/pangu_http.cpp b/scan/src/pangu_http.cpp index cbceaea..e664f0f 100644 --- a/scan/src/pangu_http.cpp +++ b/scan/src/pangu_http.cpp @@ -130,95 +130,21 @@ static enum pangu_action decide_ctrl_action(const struct Maat_rule_t * hit_rules struct Maat_rule_t monit_rule[n_hit]; enum pangu_action prior_action = PG_ACTION_NONE; - - for (i = 0; i < n_hit; i++) - { - unsigned char __expand_action = (unsigned char) hit_rules[i].action; - enum pangu_action __action = (enum pangu_action) __expand_action; - - if (__action == PG_ACTION_MONIT) - { - memcpy(monit_rule + n_monit, hit_rules + i, sizeof(struct Maat_rule_t)); - n_monit++; - } - else - { - continue; - } - } - - exist_enforce_num = *n_enforce; - if (prior_action == PG_ACTION_MONIT) - { - *n_enforce += n_monit; - } - else - { - *n_enforce += n_monit + 1; - } - - *enforce_rules = (struct Maat_rule_t *) realloc(*enforce_rules, sizeof(struct Maat_rule_t) * (*n_enforce)); - if (prior_action == PG_ACTION_MONIT) - { - memcpy(*enforce_rules + exist_enforce_num, monit_rule, n_monit * sizeof(struct Maat_rule_t)); - } - else - { - memmove(*enforce_rules+1, *enforce_rules, exist_enforce_num*sizeof(struct Maat_rule_t)); - memcpy(*enforce_rules, prior_rule, sizeof(struct Maat_rule_t)); - memcpy(*enforce_rules + exist_enforce_num + 1, monit_rule, n_monit * sizeof(struct Maat_rule_t)); - } - - return prior_action; -} - -#if 0 -static enum pangu_action decide_ctrl_action(const struct Maat_rule_t * hit_rules, size_t n_hit, - struct Maat_rule_t ** enforce_rules, size_t * n_enforce) -{ - size_t n_monit = 0, exist_enforce_num = 0, i = 0; - const struct Maat_rule_t * prior_rule = hit_rules; - struct Maat_rule_t monit_rule[n_hit]; - enum pangu_action prior_action = PG_ACTION_NONE; - for (i = 0; i < n_hit; i++) { unsigned char __expand_action = (unsigned char) hit_rules[i].action; enum pangu_action __action = (enum pangu_action) __expand_action; - if (__action == PG_ACTION_MONIT) { memcpy(monit_rule + n_monit, hit_rules + i, sizeof(struct Maat_rule_t)); n_monit++; - } - if (action_cmp(__action, prior_action) > 0) - { - prior_rule = hit_rules + i; - prior_action = __action; - } - else if (action_cmp(__action, prior_action) == 0) - { - if (hit_rules[i].config_id > prior_rule->config_id) - { - prior_rule = hit_rules + i; - } - } - else - { - continue; + break; } } + i = (i == 0) ? 1 : 0; - if (prior_action == PG_ACTION_WHITELIST) - { - if(*n_enforce==0) - { - *enforce_rules=ALLOC(struct Maat_rule_t, 1); - } - *enforce_rules[0]=*prior_rule; - *n_enforce=1; - return PG_ACTION_WHITELIST; - } + prior_action = (enum pangu_action)hit_rules[i].action; + prior_rule = hit_rules + i; exist_enforce_num = *n_enforce; if (prior_action == PG_ACTION_MONIT) @@ -244,7 +170,6 @@ static enum pangu_action decide_ctrl_action(const struct Maat_rule_t * hit_rules return prior_action; } -#endif void get_scan_status(struct verify_policy_query_obj *query_obj, cJSON *attributes, cJSON *data_obj, void *pme) { @@ -283,7 +208,8 @@ void get_scan_status(struct verify_policy_query_obj *query_obj, cJSON *attribute static int http_hit_policy_list(Maat_feather_t maat, size_t hit_cnt, cJSON *data_obj, void *pme) { - size_t i=0, ret = 0; + bool succeeded = false; + size_t rules=0, i=0, ret=0; struct pangu_http_ctx * ctx = (struct pangu_http_ctx *) pme; @@ -309,11 +235,17 @@ static int http_hit_policy_list(Maat_feather_t maat, size_t hit_cnt, cJSON *data policy_obj=cJSON_CreateObject(); cJSON_AddNumberToObject(policy_obj, "policyId",ctx->result[i].config_id); cJSON_AddStringToObject(policy_obj, "policyName", ""); - if (ctx->enforce_rules[0].config_id == ctx->result[i].config_id) + + for (rules = 0; rules < ctx->n_enforce; rules++) { - cJSON_AddBoolToObject(policy_obj, "isExecutePolicy", true); + if (ctx->enforce_rules[rules].config_id == ctx->result[i].config_id) + { + cJSON_AddBoolToObject(policy_obj, "isExecutePolicy", true); + succeeded = true; + } + } - else + if (succeeded == false) { cJSON_AddBoolToObject(policy_obj, "isExecutePolicy", false); } |
