mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Fix make test
This commit is contained in:
@@ -932,152 +932,6 @@ static const char *update_rule_action(cmd_parms *cmd, directory_config *dcfg,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *update_rule_target(cmd_parms *cmd, directory_config *dcfg,
|
||||
msre_ruleset *rset, const char *p1, const char *p2, const char *p3)
|
||||
{
|
||||
msre_var **targets = NULL;
|
||||
msre_rule *rule = NULL;
|
||||
msre_ruleset *ruleset = NULL;
|
||||
const char *curr_targets = NULL;
|
||||
char *my_error_msg = NULL;
|
||||
char *p = NULL, *savedptr = NULL;
|
||||
char *target_list = NULL, *replace = NULL;
|
||||
int is_negated = 0, is_counting = 0;
|
||||
int name_len = 0, value_len = 0;
|
||||
char *name = NULL, *value = NULL;
|
||||
char *opt = NULL, *param = NULL;
|
||||
int i, rc, match = 0;
|
||||
int offset = 0;
|
||||
|
||||
if(p1 == NULL || p2 == NULL || (dcfg == NULL && rset == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(dcfg != NULL)
|
||||
ruleset = dcfg->ruleset;
|
||||
else if (rset != NULL)
|
||||
ruleset = rset;
|
||||
|
||||
/* Get the ruleset if one exists */
|
||||
if ((ruleset == NULL)||(ruleset == NOT_SET_P)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rule = msre_ruleset_fetch_rule(ruleset, p1, offset);
|
||||
if (rule == NULL) {
|
||||
if (cmd != NULL) {
|
||||
ap_log_perror(APLOG_MARK, APLOG_STARTUP|APLOG_NOERRNO, 0, cmd->pool,
|
||||
"Update rule id=\"%s\" with targets \"%s\" failed: Rule not found.", p1, p2);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
target_list = strdup(p2);
|
||||
if(target_list == NULL)
|
||||
return NULL;
|
||||
|
||||
if(p3 != NULL) {
|
||||
replace = strdup(p3);
|
||||
if(replace == NULL) {
|
||||
free(target_list);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(replace != NULL) {
|
||||
|
||||
opt = strchr(replace,'!');
|
||||
|
||||
if(opt != NULL) {
|
||||
*opt = '\0';
|
||||
opt++;
|
||||
param = opt;
|
||||
is_negated = 1;
|
||||
} else if ((opt = strchr(replace,'&')) != NULL) {
|
||||
*opt = '\0';
|
||||
opt++;
|
||||
param = opt;
|
||||
is_counting = 1;
|
||||
} else {
|
||||
param = replace;
|
||||
}
|
||||
|
||||
opt = strchr(param,':');
|
||||
|
||||
if(opt != NULL) {
|
||||
name = apr_strtok(param,":",&value);
|
||||
if(strchr(value,':') != NULL) {
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
name = param;
|
||||
}
|
||||
|
||||
name_len = strlen(name);
|
||||
|
||||
if(value != NULL)
|
||||
value_len = strlen(value);
|
||||
|
||||
targets = (msre_var **)rule->targets->elts;
|
||||
// TODO need a good way to remove the element from array, maybe change array by tables or rings
|
||||
for (i = 0; i < rule->targets->nelts; i++) {
|
||||
if((strncasecmp(targets[i]->name,name,name_len) == 0) &&
|
||||
(targets[i]->is_negated == is_negated) &&
|
||||
(targets[i]->is_counting == is_counting)) {
|
||||
|
||||
if(value != NULL && targets[i]->param != NULL) {
|
||||
if(strncasecmp(targets[i]->param,value,value_len) == 0) {
|
||||
memset(targets[i]->name,0,strlen(targets[i]->name));
|
||||
memset(targets[i]->param,0,strlen(targets[i]->param));
|
||||
match = 1;
|
||||
}
|
||||
} else if (value == NULL && targets[i]->param == NULL){
|
||||
memset(targets[i]->name,0,strlen(targets[i]->name));
|
||||
match = 1;
|
||||
} else
|
||||
continue;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p = apr_strtok(target_list, ",", &savedptr);
|
||||
|
||||
while(p != NULL) {
|
||||
|
||||
if(replace != NULL) {
|
||||
if(match == 1) {
|
||||
rc = msre_parse_targets(ruleset, p, rule->targets, &my_error_msg);
|
||||
if (rc < 0) {
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
|
||||
rc = msre_parse_targets(ruleset, p, rule->targets, &my_error_msg);
|
||||
if (rc < 0) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
p = apr_strtok(NULL,",",&savedptr);
|
||||
}
|
||||
|
||||
curr_targets = msre_generate_target_string(ruleset->mp, rule);
|
||||
|
||||
rule->unparsed = msre_rule_generate_unparsed(ruleset->mp, rule, curr_targets, NULL, NULL);
|
||||
|
||||
end:
|
||||
if(target_list != NULL)
|
||||
free(target_list);
|
||||
if(replace != NULL)
|
||||
free(replace);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* -- Configuration directives -- */
|
||||
|
||||
static const char *cmd_action(cmd_parms *cmd, void *_dcfg, const char *p1)
|
||||
|
Reference in New Issue
Block a user