修改insert读取位置方式
修改插入脚本位置判断
This commit is contained in:
@@ -98,6 +98,7 @@ struct manipulate_profile
|
||||
char *profile_name;
|
||||
char *profile_msg;
|
||||
char *profile_type;
|
||||
char *profile_position;
|
||||
ctemplate::Template * tpl;
|
||||
pthread_mutex_t lock;
|
||||
};
|
||||
@@ -640,6 +641,7 @@ void ma_profile_table_new_cb(int table_id, const char* key, const char* table_li
|
||||
TFE_LOG_ERROR(g_pangu_rt->local_logger, "Policy table parse config failed: %s", table_line);
|
||||
return;
|
||||
}
|
||||
|
||||
struct manipulate_profile* ply_profile=ALLOC(struct manipulate_profile, 1);
|
||||
memset(ply_profile, 0, sizeof(struct manipulate_profile));
|
||||
|
||||
@@ -667,6 +669,47 @@ void ma_profile_table_new_cb(int table_id, const char* key, const char* table_li
|
||||
return;
|
||||
}
|
||||
|
||||
void ma_insert_profile_table_new_cb(int table_id, const char* key, const char* table_line, MAAT_PLUGIN_EX_DATA* ad, long argl, void* argp)
|
||||
{
|
||||
int ret=0, profile_id=0, is_valid=0;
|
||||
char profile_name[128]={0}, formate[128]={0};
|
||||
char profile_path[TFE_PATH_MAX]={0},profile_position[TFE_PATH_MAX]={0};
|
||||
|
||||
ret=sscanf(table_line, "%d\t%s\t%s\t%s\t%s\t%d", &profile_id, profile_name, formate, profile_path, profile_position, &is_valid);
|
||||
if(ret!=6)
|
||||
{
|
||||
TFE_LOG_ERROR(g_pangu_rt->local_logger, "Policy table parse config failed: %s", table_line);
|
||||
return;
|
||||
}
|
||||
struct manipulate_profile* ply_profile=ALLOC(struct manipulate_profile, 1);
|
||||
memset(ply_profile, 0, sizeof(struct manipulate_profile));
|
||||
|
||||
ply_profile->profile_id=profile_id;
|
||||
ply_profile->ref_cnt=1;
|
||||
pthread_mutex_init(&(ply_profile->lock), NULL);
|
||||
|
||||
if(strcasecmp(formate, "template") == 0)
|
||||
{
|
||||
ply_profile->tpl = ctemplate::Template::GetTemplate(profile_path, ctemplate::DO_NOT_STRIP);
|
||||
}else
|
||||
{
|
||||
ply_profile->profile_msg = execute_read_file(profile_path, &ply_profile->msg_len);
|
||||
if (ply_profile->profile_msg == NULL)
|
||||
{
|
||||
TFE_LOG_ERROR(g_pangu_rt->local_logger, "Read file failed %d:%s:%s", profile_id, profile_name, profile_path);
|
||||
}
|
||||
}
|
||||
ply_profile->profile_name=tfe_strdup(profile_name);
|
||||
ply_profile->profile_type=tfe_strdup(formate);
|
||||
ply_profile->profile_position=tfe_strdup(profile_position);
|
||||
|
||||
TFE_LOG_INFO(g_pangu_rt->local_logger, "Policy table add success %d", profile_id);
|
||||
|
||||
*ad = ply_profile;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void ma_hijack_profile_table_new_cb(int table_id, const char* key, const char* table_line, MAAT_PLUGIN_EX_DATA* ad, long argl, void* argp)
|
||||
{
|
||||
int ret=0, profile_id=0, is_valid=0;
|
||||
@@ -714,6 +757,8 @@ void ma_profile_table_free_cb(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl,
|
||||
FREE(&ply_obj->profile_type);
|
||||
FREE(&ply_obj->profile_msg);
|
||||
FREE(&ply_obj->profile_name);
|
||||
if (ply_obj->profile_position)
|
||||
FREE(&ply_obj->profile_position);
|
||||
FREE(&ply_obj);
|
||||
*ad=NULL;
|
||||
return;
|
||||
@@ -778,7 +823,6 @@ int maat_table_ex_init(int profile_idx,
|
||||
int pangu_policy_init(const char* profile_path, const char* static_section, const char* dynamic_section)
|
||||
{
|
||||
int ret = 0;
|
||||
int profile_table_idx = 0;
|
||||
|
||||
g_pangu_rt->maat = create_maat_feather("static", profile_path, static_section, g_pangu_rt->thread_num, g_pangu_rt->local_logger);
|
||||
if (!g_pangu_rt->maat)
|
||||
@@ -834,16 +878,22 @@ int pangu_policy_init(const char* profile_path, const char* static_section, cons
|
||||
}
|
||||
|
||||
|
||||
for (profile_table_idx = 0; profile_table_idx <=POLICY_PROFILE_TABLE_INSERT; profile_table_idx++)
|
||||
ret = maat_table_ex_init(POLICY_PROFLIE_TABLE_REJECT,
|
||||
ma_profile_table_new_cb,
|
||||
ma_profile_table_free_cb,
|
||||
ma_profile_table_dup_cb);
|
||||
if(ret<0)
|
||||
{
|
||||
ret = maat_table_ex_init(profile_table_idx,
|
||||
ma_profile_table_new_cb,
|
||||
ma_profile_table_free_cb,
|
||||
ma_profile_table_dup_cb);
|
||||
if(ret<0)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
ret = maat_table_ex_init(POLICY_PROFILE_TABLE_INSERT,
|
||||
ma_insert_profile_table_new_cb,
|
||||
ma_profile_table_free_cb,
|
||||
ma_profile_table_dup_cb);
|
||||
if(ret<0)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
ret = maat_table_ex_init(POLICY_PROFILE_TABLE_HIJACK,
|
||||
@@ -1413,7 +1463,7 @@ void http_replace(const struct tfe_stream * stream, const struct tfe_http_sessio
|
||||
rewrite_buff = NULL;
|
||||
rewrite_sz = 0;
|
||||
|
||||
if (tfe_http_in_response(events) && in_resp_spec->content_type != NULL
|
||||
if (tfe_http_in_response(events) && in_resp_spec->content_type != NULL
|
||||
&& strcasestr(in_resp_spec->content_type, "utf-8"))
|
||||
{
|
||||
options = 1;
|
||||
@@ -1652,7 +1702,7 @@ static void http_hijack(const struct tfe_http_session * session, enum tfe_http_e
|
||||
return;
|
||||
}
|
||||
|
||||
static int format_insert_rule(int profile_id, const char* insert_position, struct insert_rule *rule)
|
||||
static int format_insert_rule(int profile_id, struct insert_rule *rule)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -1664,9 +1714,8 @@ static int format_insert_rule(int profile_id, const char* insert_position, struc
|
||||
}
|
||||
rule->script = tfe_strdup(insert_profile->profile_msg);
|
||||
rule->type = tfe_strdup(insert_profile->profile_type);
|
||||
rule->position = tfe_strdup(insert_profile->profile_position);
|
||||
|
||||
if (insert_position)
|
||||
rule->position=tfe_strdup(insert_position);
|
||||
ma_profile_table_free(insert_profile);
|
||||
insert_profile = NULL;
|
||||
return ret;
|
||||
@@ -1698,7 +1747,7 @@ static void http_insert(const struct tfe_stream * stream, const struct tfe_http_
|
||||
{
|
||||
ctx->ins_ctx = ins_ctx = ALLOC(struct insert_ctx, 1);
|
||||
ins_ctx->rule = ALLOC(struct insert_rule, 1);
|
||||
int ret=format_insert_rule(param->profile_id, param->position, ins_ctx->rule);
|
||||
int ret=format_insert_rule(param->profile_id, ins_ctx->rule);
|
||||
if (ret<0)
|
||||
{
|
||||
TFE_LOG_ERROR(g_pangu_rt->local_logger, "Failed to get policy table, profile_id = %d", param->profile_id);
|
||||
@@ -1865,7 +1914,7 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht
|
||||
{
|
||||
hit_cnt += scan_ret;
|
||||
}
|
||||
|
||||
|
||||
const char * str_url = session->req->req_spec.url;
|
||||
int str_url_length = (int) (strlen(session->req->req_spec.url));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user