From 621ae259fa967f4e4c9f1ed91738ff679cec961a Mon Sep 17 00:00:00 2001 From: zhengchao Date: Mon, 26 Dec 2016 17:20:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entry/Maat_rule.cpp | 33 ++++++++++++++++--- test/maat_test.cpp | 18 +++++++--- test/rule/full/COMPILE.local | 13 ++++++++ test/rule/full/CONTENT_SIZE.local | 3 ++ test/rule/full/FILE_DIGEST.local | 2 ++ test/rule/full/GROUP.local | 16 +++++++++ test/rule/full/HTTP_HOST.local | 2 ++ test/rule/full/HTTP_REGION.local | 2 ++ test/rule/full/HTTP_URL.local | 6 ++++ test/rule/full/IP_CONFIG.local | 3 ++ test/rule/full/KEYWORDS_TABLE.local | 4 +++ test/rule/full/QD_ENTRY_INFO.local | 4 +++ test/rule/full/TEST_PLUGIN_TABLE.local | 4 +++ test/rule/full/TEST_PLUGIN_TABLE_NO1.local | 4 +++ test/rule/full/TEST_PLUGIN_TABLE_NO2.local | 1 + .../full/index/full_config_index.0000000001 | 11 +++++++ test/rule/inc/COMPILE.local | 13 ++++++++ test/rule/inc/CONTENT_SIZE.local | 3 ++ test/rule/inc/FILE_DIGEST.local | 2 ++ test/rule/inc/GROUP.local | 16 +++++++++ test/rule/inc/HTTP_HOST.local | 2 ++ test/rule/inc/HTTP_REGION.local | 2 ++ test/rule/inc/HTTP_URL.local | 6 ++++ test/rule/inc/IP_CONFIG.local | 3 ++ test/rule/inc/KEYWORDS_TABLE.local | 3 ++ test/rule/inc/QD_ENTRY_INFO.local | 4 +++ test/rule/inc/TEST_PLUGIN_TABLE.local | 4 +++ test/rule/inc/TEST_PLUGIN_TABLE_NO1.local | 4 +++ test/rule/inc/TEST_PLUGIN_TABLE_NO2.local | 1 + .../inc/index/full_config_index.0000000002 | 10 ++++++ 30 files changed, 191 insertions(+), 8 deletions(-) create mode 100644 test/rule/full/COMPILE.local create mode 100644 test/rule/full/CONTENT_SIZE.local create mode 100644 test/rule/full/FILE_DIGEST.local create mode 100644 test/rule/full/GROUP.local create mode 100644 test/rule/full/HTTP_HOST.local create mode 100644 test/rule/full/HTTP_REGION.local create mode 100644 test/rule/full/HTTP_URL.local create mode 100644 test/rule/full/IP_CONFIG.local create mode 100644 test/rule/full/KEYWORDS_TABLE.local create mode 100644 test/rule/full/QD_ENTRY_INFO.local create mode 100644 test/rule/full/TEST_PLUGIN_TABLE.local create mode 100644 test/rule/full/TEST_PLUGIN_TABLE_NO1.local create mode 100644 test/rule/full/TEST_PLUGIN_TABLE_NO2.local create mode 100644 test/rule/full/index/full_config_index.0000000001 create mode 100644 test/rule/inc/COMPILE.local create mode 100644 test/rule/inc/CONTENT_SIZE.local create mode 100644 test/rule/inc/FILE_DIGEST.local create mode 100644 test/rule/inc/GROUP.local create mode 100644 test/rule/inc/HTTP_HOST.local create mode 100644 test/rule/inc/HTTP_REGION.local create mode 100644 test/rule/inc/HTTP_URL.local create mode 100644 test/rule/inc/IP_CONFIG.local create mode 100644 test/rule/inc/KEYWORDS_TABLE.local create mode 100644 test/rule/inc/QD_ENTRY_INFO.local create mode 100644 test/rule/inc/TEST_PLUGIN_TABLE.local create mode 100644 test/rule/inc/TEST_PLUGIN_TABLE_NO1.local create mode 100644 test/rule/inc/TEST_PLUGIN_TABLE_NO2.local create mode 100644 test/rule/inc/index/full_config_index.0000000002 diff --git a/src/entry/Maat_rule.cpp b/src/entry/Maat_rule.cpp index 3fea60c..b901c43 100644 --- a/src/entry/Maat_rule.cpp +++ b/src/entry/Maat_rule.cpp @@ -60,6 +60,32 @@ int hex2bin(char *hex,int hex_len,char *binary,int size) binary[resultlen]='\0'; return resultlen; } +int is_valid_expr_type(enum MAAT_EXPR_TYPE expr_type) +{ + switch(expr_type) + { + case EXPR_TYPE_STRING: + case EXPR_TYPE_AND: + case EXPR_TYPE_REGEX: + case EXPR_TYPE_OFFSET: + return 1; + default: + return 0; + } +} +int is_valid_match_method(enum MAAT_MATCH_METHOD match_method) +{ + switch(match_method) + { + case MATCH_METHOD_SUB: + case MATCH_METHOD_RIGHT: + case MATCH_METHOD_LEFT: + case MATCH_METHOD_FULL: + return 1; + default: + return 0; + } +} iconv_t maat_iconv_open(struct _Maat_scanner_t* scanner,enum MAAT_CHARSET to,enum MAAT_CHARSET from) { const char *from_s=CHARSET_STRING[from]; @@ -1959,7 +1985,6 @@ void compatible_group_udpate(struct _Maat_table_info_t* table,int region_id,int update_group_rule(table, virtual_group_line,scanner,logger); return; } - void update_expr_rule(struct _Maat_table_info_t* table,const char* table_line,struct _Maat_scanner_t *scanner,void* logger,int group_mode_on) { struct db_str_rule_t* maat_str_rule=(struct db_str_rule_t*)malloc(sizeof(struct db_str_rule_t)); @@ -2029,7 +2054,7 @@ void update_expr_rule(struct _Maat_table_info_t* table,const char* table_line,st table->udpate_err_cnt++; goto error_out; } - if(maat_str_rule->match_methodmatch_method>MATCH_METHOD_FULL) + if(!is_valid_match_method(maat_str_rule->match_method)) { MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module , "abandon config %d:update error,invalid match method=%d in expr table %s:%s" @@ -2039,7 +2064,7 @@ void update_expr_rule(struct _Maat_table_info_t* table,const char* table_line,st table->udpate_err_cnt++; goto error_out; } - if(maat_str_rule->expr_typematch_method>EXPR_TYPE_OFFSET) + if(!is_valid_expr_type(maat_str_rule->expr_type)) { MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module , "abandon config %d:update error,invalid expr type=%d in expr table %s:%s" @@ -2682,7 +2707,7 @@ void maat_start_cb(unsigned int new_version,int update_type,void*u_para) continue; } p_table->cfg_num=0; - p_table->expr_rule_cn=0; + p_table->expr_rule_cnt=0; p_table->regex_rule_cnt=0; if(p_table->table_type==TABLE_TYPE_PLUGIN) { diff --git a/test/maat_test.cpp b/test/maat_test.cpp index 96ae1f7..d8a28b4 100644 --- a/test/maat_test.cpp +++ b/test/maat_test.cpp @@ -462,16 +462,26 @@ int main(int argc,char* argv[]) int g_iThreadNum=4; const char* table_info_path="./table_info.conf"; const char* json_path="./maat_json.json"; -// const char* ful_cfg_dir="./maat_json.json_iris_tmp/index"; -// const char* inc_cfg_dir="./rules/inc/index"; + const char* ful_cfg_dir="./rule/full/index"; + const char* inc_cfg_dir="./rule/inc/index"; const char* log_file="./test.log"; const char* stat_file="./scan_staus.log"; int scan_detail=0; scan_status_t mid=NULL; + int wait_second=4; void *logger=MESA_create_runtime_log_handle(log_file,0); feather=Maat_feather(g_iThreadNum, table_info_path, logger); - Maat_set_feather_opt(feather, MAAT_OPT_JSON_FILE_PATH, json_path, strlen(json_path)+1); + if(argc>1&&0==strcmp(argv[1],"update")) + { + Maat_set_feather_opt(feather, MAAT_OPT_FULL_CFG_DIR, ful_cfg_dir, strlen(ful_cfg_dir)+1); + Maat_set_feather_opt(feather, MAAT_OPT_INC_CFG_DIR, inc_cfg_dir, strlen(inc_cfg_dir)+1); + wait_second=14; + } + else + { + Maat_set_feather_opt(feather, MAAT_OPT_JSON_FILE_PATH, json_path, strlen(json_path)+1); + } Maat_set_feather_opt(feather, MAAT_OPT_STAT_FILE_PATH, stat_file, strlen(stat_file)+1); Maat_set_feather_opt(feather, MAAT_OPT_STAT_ON, NULL, 0); Maat_set_feather_opt(feather, MAAT_OPT_PERF_ON, NULL, 0); @@ -519,7 +529,7 @@ int main(int argc,char* argv[]) test_table_conjunction(feather, "HTTP_URL", "HTTP_HOST", &mid); Maat_clean_status(&mid); - sleep(4); + sleep(wait_second); Maat_burn_feather(feather); diff --git a/test/rule/full/COMPILE.local b/test/rule/full/COMPILE.local new file mode 100644 index 0000000..44b431d --- /dev/null +++ b/test/rule/full/COMPILE.local @@ -0,0 +1,13 @@ +0000000012 +123 1 1 1 1 0 anything 1 +124 1 1 1 1 0 anything 1 +125 1 1 1 1 0 anything 1 +126 1 1 1 1 0 anything 1 +127 1 1 1 1 0 anything 1 +128 1 1 1 1 0 anything 1 +129 1 1 1 1 0 utf8_中文 1 +130 1 1 1 1 0 utf8_维语 1 +131 1 1 1 1 0 utf8_维语2 1 +132 1 1 1 1 0 string\bunescape 1 +133 1 1 1 1 0 table_conjunction_test_part1 1 +134 1 1 1 1 0 table_conjunction_test_part2 1 diff --git a/test/rule/full/CONTENT_SIZE.local b/test/rule/full/CONTENT_SIZE.local new file mode 100644 index 0000000..e1bc0a6 --- /dev/null +++ b/test/rule/full/CONTENT_SIZE.local @@ -0,0 +1,3 @@ +0000000002 +3 2 100 500 1 +6 5 2014 2016 1 diff --git a/test/rule/full/FILE_DIGEST.local b/test/rule/full/FILE_DIGEST.local new file mode 100644 index 0000000..86b0eec --- /dev/null +++ b/test/rule/full/FILE_DIGEST.local @@ -0,0 +1,2 @@ +0000000001 +7 6 1160164 12288:UChtbFS6pypdTy4m2[0:1160163] 3 1 diff --git a/test/rule/full/GROUP.local b/test/rule/full/GROUP.local new file mode 100644 index 0000000..92ca5c6 --- /dev/null +++ b/test/rule/full/GROUP.local @@ -0,0 +1,16 @@ +0000000015 +0 123 1 +1 123 1 +0 124 1 +2 124 1 +3 125 1 +4 126 1 +5 126 1 +6 127 1 +7 128 1 +8 129 1 +9 130 1 +10 131 1 +11 132 1 +12 133 1 +13 134 1 diff --git a/test/rule/full/HTTP_HOST.local b/test/rule/full/HTTP_HOST.local new file mode 100644 index 0000000..096daac --- /dev/null +++ b/test/rule/full/HTTP_HOST.local @@ -0,0 +1,2 @@ +0000000001 +13 12 www.3300av.com 0 0 0 1 diff --git a/test/rule/full/HTTP_REGION.local b/test/rule/full/HTTP_REGION.local new file mode 100644 index 0000000..bdb46b7 --- /dev/null +++ b/test/rule/full/HTTP_REGION.local @@ -0,0 +1,2 @@ +0000000001 +8 7 URL abckkk&123 1 0 0 1 diff --git a/test/rule/full/HTTP_URL.local b/test/rule/full/HTTP_URL.local new file mode 100644 index 0000000..2261a7a --- /dev/null +++ b/test/rule/full/HTTP_URL.local @@ -0,0 +1,6 @@ +0000000005 +2 1 abckkk&123 1 0 0 1 +4 3 action=search\&query=(.*) 2 0 0 1 +5 4 should_not_hit_any_rule 0 0 0 1 +9 8 C#中国 0 0 0 1 +14 13 novel&27122.txt 1 0 0 1 diff --git a/test/rule/full/IP_CONFIG.local b/test/rule/full/IP_CONFIG.local new file mode 100644 index 0000000..ad27ad1 --- /dev/null +++ b/test/rule/full/IP_CONFIG.local @@ -0,0 +1,3 @@ +0000000002 +0 0 4 10.0.6.201 255.255.0.0 0 65535 0.0.0.0 255.255.255.255 0 65535 6 0 1 +1 0 6 2001:da8:205:1::101 ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000 0 65535 0::0 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 0 65535 6 0 1 diff --git a/test/rule/full/KEYWORDS_TABLE.local b/test/rule/full/KEYWORDS_TABLE.local new file mode 100644 index 0000000..af8f1f0 --- /dev/null +++ b/test/rule/full/KEYWORDS_TABLE.local @@ -0,0 +1,4 @@ +0000000003 +10 9 2010&يىلىدىكى 1 0 0 1 +11 10 سىياسىي 1 0 0 1 +12 11 Take\bme\bHome&Batman\ 1 0 0 1 diff --git a/test/rule/full/QD_ENTRY_INFO.local b/test/rule/full/QD_ENTRY_INFO.local new file mode 100644 index 0000000..cb1bd15 --- /dev/null +++ b/test/rule/full/QD_ENTRY_INFO.local @@ -0,0 +1,4 @@ +0000000003 +1 192.168.0.1 101 +2 192.168.0.2 101 +3 192.168.1.1 102 diff --git a/test/rule/full/TEST_PLUGIN_TABLE.local b/test/rule/full/TEST_PLUGIN_TABLE.local new file mode 100644 index 0000000..763d635 --- /dev/null +++ b/test/rule/full/TEST_PLUGIN_TABLE.local @@ -0,0 +1,4 @@ +0000000003 +1 3388 99 1 +2 3355 66 1 +3 cccc 11 1 diff --git a/test/rule/full/TEST_PLUGIN_TABLE_NO1.local b/test/rule/full/TEST_PLUGIN_TABLE_NO1.local new file mode 100644 index 0000000..b278b17 --- /dev/null +++ b/test/rule/full/TEST_PLUGIN_TABLE_NO1.local @@ -0,0 +1,4 @@ +0000000003 +1 plugname1 1 +2 plugname2 1 +3 plugname3 1 diff --git a/test/rule/full/TEST_PLUGIN_TABLE_NO2.local b/test/rule/full/TEST_PLUGIN_TABLE_NO2.local new file mode 100644 index 0000000..62580c9 --- /dev/null +++ b/test/rule/full/TEST_PLUGIN_TABLE_NO2.local @@ -0,0 +1 @@ +0000000000 diff --git a/test/rule/full/index/full_config_index.0000000001 b/test/rule/full/index/full_config_index.0000000001 new file mode 100644 index 0000000..59f5edf --- /dev/null +++ b/test/rule/full/index/full_config_index.0000000001 @@ -0,0 +1,11 @@ +COMPILE 12 ./rule/full/COMPILE.local +GROUP 15 ./rule/full/GROUP.local +TEST_PLUGIN_TABLE 3 ./rule/full/TEST_PLUGIN_TABLE.local +HTTP_REGION 1 ./rule/full/HTTP_REGION.local +IP_CONFIG 2 ./rule/full/IP_CONFIG.local +CONTENT_SIZE 2 ./rule/full/CONTENT_SIZE.local +HTTP_URL 5 ./rule/full/HTTP_URL.local +HTTP_HOST 1 ./rule/full/HTTP_HOST.local +QD_ENTRY_INFO 3 ./rule/full/QD_ENTRY_INFO.local +FILE_DIGEST 1 ./rule/full/FILE_DIGEST.local +KEYWORDS_TABLE 3 ./rule/full/KEYWORDS_TABLE.local diff --git a/test/rule/inc/COMPILE.local b/test/rule/inc/COMPILE.local new file mode 100644 index 0000000..44b431d --- /dev/null +++ b/test/rule/inc/COMPILE.local @@ -0,0 +1,13 @@ +0000000012 +123 1 1 1 1 0 anything 1 +124 1 1 1 1 0 anything 1 +125 1 1 1 1 0 anything 1 +126 1 1 1 1 0 anything 1 +127 1 1 1 1 0 anything 1 +128 1 1 1 1 0 anything 1 +129 1 1 1 1 0 utf8_中文 1 +130 1 1 1 1 0 utf8_维语 1 +131 1 1 1 1 0 utf8_维语2 1 +132 1 1 1 1 0 string\bunescape 1 +133 1 1 1 1 0 table_conjunction_test_part1 1 +134 1 1 1 1 0 table_conjunction_test_part2 1 diff --git a/test/rule/inc/CONTENT_SIZE.local b/test/rule/inc/CONTENT_SIZE.local new file mode 100644 index 0000000..e1bc0a6 --- /dev/null +++ b/test/rule/inc/CONTENT_SIZE.local @@ -0,0 +1,3 @@ +0000000002 +3 2 100 500 1 +6 5 2014 2016 1 diff --git a/test/rule/inc/FILE_DIGEST.local b/test/rule/inc/FILE_DIGEST.local new file mode 100644 index 0000000..86b0eec --- /dev/null +++ b/test/rule/inc/FILE_DIGEST.local @@ -0,0 +1,2 @@ +0000000001 +7 6 1160164 12288:UChtbFS6pypdTy4m2[0:1160163] 3 1 diff --git a/test/rule/inc/GROUP.local b/test/rule/inc/GROUP.local new file mode 100644 index 0000000..92ca5c6 --- /dev/null +++ b/test/rule/inc/GROUP.local @@ -0,0 +1,16 @@ +0000000015 +0 123 1 +1 123 1 +0 124 1 +2 124 1 +3 125 1 +4 126 1 +5 126 1 +6 127 1 +7 128 1 +8 129 1 +9 130 1 +10 131 1 +11 132 1 +12 133 1 +13 134 1 diff --git a/test/rule/inc/HTTP_HOST.local b/test/rule/inc/HTTP_HOST.local new file mode 100644 index 0000000..096daac --- /dev/null +++ b/test/rule/inc/HTTP_HOST.local @@ -0,0 +1,2 @@ +0000000001 +13 12 www.3300av.com 0 0 0 1 diff --git a/test/rule/inc/HTTP_REGION.local b/test/rule/inc/HTTP_REGION.local new file mode 100644 index 0000000..bdb46b7 --- /dev/null +++ b/test/rule/inc/HTTP_REGION.local @@ -0,0 +1,2 @@ +0000000001 +8 7 URL abckkk&123 1 0 0 1 diff --git a/test/rule/inc/HTTP_URL.local b/test/rule/inc/HTTP_URL.local new file mode 100644 index 0000000..2261a7a --- /dev/null +++ b/test/rule/inc/HTTP_URL.local @@ -0,0 +1,6 @@ +0000000005 +2 1 abckkk&123 1 0 0 1 +4 3 action=search\&query=(.*) 2 0 0 1 +5 4 should_not_hit_any_rule 0 0 0 1 +9 8 C#中国 0 0 0 1 +14 13 novel&27122.txt 1 0 0 1 diff --git a/test/rule/inc/IP_CONFIG.local b/test/rule/inc/IP_CONFIG.local new file mode 100644 index 0000000..ad27ad1 --- /dev/null +++ b/test/rule/inc/IP_CONFIG.local @@ -0,0 +1,3 @@ +0000000002 +0 0 4 10.0.6.201 255.255.0.0 0 65535 0.0.0.0 255.255.255.255 0 65535 6 0 1 +1 0 6 2001:da8:205:1::101 ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000 0 65535 0::0 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 0 65535 6 0 1 diff --git a/test/rule/inc/KEYWORDS_TABLE.local b/test/rule/inc/KEYWORDS_TABLE.local new file mode 100644 index 0000000..d685f4d --- /dev/null +++ b/test/rule/inc/KEYWORDS_TABLE.local @@ -0,0 +1,3 @@ +0000000003 +10 9 2010&يىلىدىكى 1 0 0 1 +11 10 سىياسىي 1 0 0 1 diff --git a/test/rule/inc/QD_ENTRY_INFO.local b/test/rule/inc/QD_ENTRY_INFO.local new file mode 100644 index 0000000..cb1bd15 --- /dev/null +++ b/test/rule/inc/QD_ENTRY_INFO.local @@ -0,0 +1,4 @@ +0000000003 +1 192.168.0.1 101 +2 192.168.0.2 101 +3 192.168.1.1 102 diff --git a/test/rule/inc/TEST_PLUGIN_TABLE.local b/test/rule/inc/TEST_PLUGIN_TABLE.local new file mode 100644 index 0000000..763d635 --- /dev/null +++ b/test/rule/inc/TEST_PLUGIN_TABLE.local @@ -0,0 +1,4 @@ +0000000003 +1 3388 99 1 +2 3355 66 1 +3 cccc 11 1 diff --git a/test/rule/inc/TEST_PLUGIN_TABLE_NO1.local b/test/rule/inc/TEST_PLUGIN_TABLE_NO1.local new file mode 100644 index 0000000..b278b17 --- /dev/null +++ b/test/rule/inc/TEST_PLUGIN_TABLE_NO1.local @@ -0,0 +1,4 @@ +0000000003 +1 plugname1 1 +2 plugname2 1 +3 plugname3 1 diff --git a/test/rule/inc/TEST_PLUGIN_TABLE_NO2.local b/test/rule/inc/TEST_PLUGIN_TABLE_NO2.local new file mode 100644 index 0000000..62580c9 --- /dev/null +++ b/test/rule/inc/TEST_PLUGIN_TABLE_NO2.local @@ -0,0 +1 @@ +0000000000 diff --git a/test/rule/inc/index/full_config_index.0000000002 b/test/rule/inc/index/full_config_index.0000000002 new file mode 100644 index 0000000..a67d6a1 --- /dev/null +++ b/test/rule/inc/index/full_config_index.0000000002 @@ -0,0 +1,10 @@ +COMPILE 12 ./rule/inc/COMPILE.local +GROUP 15 ./rule/inc/GROUP.local +HTTP_REGION 1 ./rule/inc/HTTP_REGION.local +IP_CONFIG 2 ./rule/inc/IP_CONFIG.local +CONTENT_SIZE 2 ./rule/inc/CONTENT_SIZE.local +HTTP_URL 5 ./rule/inc/HTTP_URL.local +HTTP_HOST 1 ./rule/inc/HTTP_HOST.local +QD_ENTRY_INFO 3 ./rule/inc/QD_ENTRY_INFO.local +FILE_DIGEST 1 ./rule/inc/FILE_DIGEST.local +KEYWORDS_TABLE 2 ./rule/inc/KEYWORDS_TABLE.local