diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ac23531 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +BUILD_DIR = $(CURDIR)/build +LOCAL_DIR = $(CURDIR) +DEBUG_FLAGS = -DCMAKE_BUILD_TYPE=Debug +REL_FLAGS = -DCMAKE_BUILD_TYPE=RelWithDebInfo + +ifneq ($(INSTALL_PREFIX),) +DEBUG_FLAGS += -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX) +REL_FLAGS += -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX) +endif + +all: _make_build_dir _compile_rel + +PHONY: all _make_build_dir _compile_debug _compile_rel _install \ + build_release build_debug install + +_make_build_dir: + mkdir -p $(BUILD_DIR) + +_compile_debug: + cd $(BUILD_DIR) && cmake $(LOCAL_DIR) $(DEBUG_FLAGS) && make + +_compile_rel: + cd $(BUILD_DIR) && cmake $(LOCAL_DIR) $(REL_FLAGS) && make + +_install: + cd $(BUILD_DIR) && make install +_package: + cd $(BUILD_DIR) && make package +_clean: + rm -rf $(BUILD_DIR) + +# Release Version, No Debug Symbol and Optimized with -O2 +release: _make_build_dir _compile_rel +# Debug Version, Optimized with -O0 +debug: _make_build_dir _compile_debug +# Install +install: _install +# Package +package: _package +# Clean +clean: _clean diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2266c93..9099334 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,8 +8,6 @@ set(MAAT_FRAME_VERSION ${MAAT_FRAME_MAJOR_VERSION}.${MAAT_FRAME_MINOR_VERSION}.$ message(STATUS "Maat Frame, Version: ${MAAT_FRAME_VERSION}") -set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall) - add_definitions(-fPIC) set(MAAT_SRC entry/cJSON.c entry/config_monitor.cpp entry/dynamic_array.cpp entry/gram_index_engine.c entry/interval_index.c entry/json2iris.cpp entry/Maat_api.cpp entry/Maat_command.cpp entry/Maat_rule.cpp entry/Maat_stat.cpp entry/map_str2int.cpp entry/rbtree.c entry/stream_fuzzy_hash.c entry/UniversalBoolMatch.cpp) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../inc/) @@ -34,3 +32,5 @@ target_include_directories(maat_frame_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} target_include_directories(maat_frame_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc_internal/hiredis) target_link_libraries(maat_frame_shared MESA_handle_logger MESA_htable pcre rulescan pthread m pcre MESA_field_stat2 crypto hiredis_vip) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/inc/ DESTINATION /opt/MESA/include/MESA/ FILES_MATCHING PATTERN "*.h") +install(TARGETS maat_frame_shared DESTINATION /opt/MESA/lib/) diff --git a/src/entry/Maat_rule.cpp b/src/entry/Maat_rule.cpp index 41be4df..b0a0f82 100644 --- a/src/entry/Maat_rule.cpp +++ b/src/entry/Maat_rule.cpp @@ -748,7 +748,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char* FILE*fp=NULL; char line[MAX_TABLE_LINE_SIZE]; int i=0,ret=0,table_cnt=0; - char table_type_str[16],not_care[1024], user_region_encoding[32]; + char table_type_str[16],not_care[1024], tmp_str[32]; MESA_htable_handle string2int_map=map_create(); struct _Maat_table_info_t*p=NULL; struct _Maat_table_info_t*conj_table=NULL; @@ -833,17 +833,17 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char* case TABLE_TYPE_PLUGIN: p->cb_info=(struct _plugin_table_info*)calloc(sizeof(struct _plugin_table_info),1); p->cb_info->cache_lines=dynamic_array_create(1024,1024); - ret=sscanf(not_care,"%d\t%d",&(p->valid_flag_column), &p->rule_tag_column); + ret=sscanf(not_care,"%d\t%d\t%[0-9,]",&(p->valid_flag_column), &p->rule_tag_column, tmp_str); if(ret==0||ret==EOF) { p->valid_flag_column=-1; } break; case TABLE_TYPE_COMPILE: - ret=sscanf(not_care,"%[a-z0-9]",user_region_encoding); + ret=sscanf(not_care,"%[a-z0-9]",tmp_str); if(ret>0) { - ret=map_str2int(string2int_map,str_tolower(user_region_encoding),(int*)&(p->user_region_encoding)); + ret=map_str2int(string2int_map,str_tolower(tmp_str),(int*)&(p->user_region_encoding)); } if(ret!=1) { @@ -3085,7 +3085,7 @@ void update_plugin_table(struct _Maat_table_info_t* table,const char* table_line char* copy=NULL; char *token=NULL,*sub_token=NULL,*saveptr; - if(table->rule_tag_column!=0&&n_tags>0) + if(table->rule_tag_column>0&&n_tags>0) { copy=_maat_strdup(table_line); for (token = copy, i=0; irule_tag_column ; token= NULL, i++) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d2a8e69..e1a6223 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,4 +11,6 @@ file(COPY conf DESTINATION ./) file(COPY rule DESTINATION ./) file(COPY testdata DESTINATION ./) file(COPY testdata_uni2ascii DESTINATION ./) -add_test(NAME MaatframeFunctionTest COMMAND test_maatframe) \ No newline at end of file + +include(GoogleTest) +gtest_discover_tests(test_maatframe)