maat_options set logger -> set log_path

This commit is contained in:
liuwentan
2023-03-16 15:16:42 +08:00
parent 6afb0a0194
commit 8312b69fda
8 changed files with 160 additions and 134 deletions

View File

@@ -99,6 +99,7 @@ int maat_options_set_gc_timeout_ms(struct maat_options *opts, int interval_ms);
int maat_options_set_instance_name(struct maat_options *opts, const char *instance_name); int maat_options_set_instance_name(struct maat_options *opts, const char *instance_name);
int maat_options_set_deferred_load_on(struct maat_options *opts); int maat_options_set_deferred_load_on(struct maat_options *opts);
int maat_options_set_foreign_cont_dir(struct maat_options *opts, const char *dir); int maat_options_set_foreign_cont_dir(struct maat_options *opts, const char *dir);
int maat_options_set_logger_path(struct maat_options *opts, const char *log_path);
int maat_options_set_iris(struct maat_options *opts, const char *full_directory, int maat_options_set_iris(struct maat_options *opts, const char *full_directory,
const char *increment_directory); const char *increment_directory);
@@ -106,8 +107,6 @@ int maat_options_set_json_file(struct maat_options *opts, const char *json_filen
int maat_options_set_redis(struct maat_options *opts, const char *redis_ip, int maat_options_set_redis(struct maat_options *opts, const char *redis_ip,
uint16_t redis_port, int redis_db); uint16_t redis_port, int redis_db);
int maat_options_set_logger(struct maat_options *opts, void *logger);
/* maat_instance API */ /* maat_instance API */
struct maat *maat_new(struct maat_options *opts, const char *table_info_path); struct maat *maat_new(struct maat_options *opts, const char *table_info_path);
void maat_free(struct maat *instance); void maat_free(struct maat *instance);

View File

@@ -323,7 +323,10 @@ struct adapter_hs *adapter_hs_initialize(enum hs_scan_mode scan_mode,
} }
compile_data->ids[pattern_index] = pattern_index; compile_data->ids[pattern_index] = pattern_index;
if (pattern_type == HS_PATTERN_TYPE_STR) {
compile_data->flags[pattern_index] = HS_FLAG_SOM_LEFTMOST; compile_data->flags[pattern_index] = HS_FLAG_SOM_LEFTMOST;
}
if (exprs[i].patterns[j].case_sensitive == HS_CASE_INSESITIVE) { if (exprs[i].patterns[j].case_sensitive == HS_CASE_INSESITIVE) {
compile_data->flags[pattern_index] |= HS_FLAG_CASELESS; compile_data->flags[pattern_index] |= HS_FLAG_CASELESS;
} }

View File

@@ -17,6 +17,7 @@ extern "C"
#endif #endif
#include <stddef.h> #include <stddef.h>
#include <limits.h>
#include "log/log.h" #include "log/log.h"
#include "maat_rule.h" #include "maat_rule.h"
@@ -24,6 +25,7 @@ extern "C"
struct maat_options { struct maat_options {
char instance_name[NAME_MAX]; char instance_name[NAME_MAX];
char foreign_cont_dir[NAME_MAX]; char foreign_cont_dir[NAME_MAX];
char log_path[PATH_MAX];
size_t nr_worker_threads; size_t nr_worker_threads;
char *accept_tags; char *accept_tags;
int rule_effect_interval_ms; int rule_effect_interval_ms;
@@ -31,7 +33,6 @@ struct maat_options {
int gc_timeout_ms; int gc_timeout_ms;
int deferred_load_on; int deferred_load_on;
int log_level; int log_level;
struct log_handle *logger;
enum data_source input_mode; enum data_source input_mode;
union { union {
struct source_iris_ctx iris_ctx; struct source_iris_ctx iris_ctx;

View File

@@ -241,9 +241,13 @@ int maat_options_set_redis(struct maat_options *opts, const char *redis_ip,
return 0; return 0;
} }
int maat_options_set_logger(struct maat_options *opts, void *logger) int maat_options_set_logger_path(struct maat_options *opts, const char *log_path)
{ {
opts->logger = (struct log_handle *)logger; if (NULL == opts || NULL == log_path || strlen(log_path) >= PATH_MAX) {
return -1;
}
memcpy(opts->log_path, log_path, strlen(log_path));
return 0; return 0;
} }
@@ -330,8 +334,8 @@ struct maat *maat_new(struct maat_options *opts, const char *table_info_path)
int garbage_gc_timeout_s = 0; int garbage_gc_timeout_s = 0;
struct maat *maat_instance = ALLOC(struct maat, 1); struct maat *maat_instance = ALLOC(struct maat, 1);
if (opts->logger != NULL) { if (strlen(opts->log_path) != 0) {
maat_instance->logger = opts->logger; maat_instance->logger = log_handle_create(opts->log_path, opts->log_level);
} else { } else {
char log_path[1024] = {0}; char log_path[1024] = {0};
if (strlen(maat_instance->instance_name) > 0) { if (strlen(maat_instance->instance_name) > 0) {

View File

@@ -205,6 +205,8 @@ void ex_container_free(void *schema, void *data)
if (NULL == data) { if (NULL == data) {
return; return;
} }
struct ex_container *ex_container = (struct ex_container *)data;
//TODO: //TODO:
if (NULL == schema) { if (NULL == schema) {
@@ -214,7 +216,7 @@ void ex_container_free(void *schema, void *data)
long argl = container_schema->ex_schema->argl; long argl = container_schema->ex_schema->argl;
void *argp = container_schema->ex_schema->argp; void *argp = container_schema->ex_schema->argp;
struct ex_container *ex_container = (struct ex_container *)data;
if (ex_container->ex_data != NULL if (ex_container->ex_data != NULL
&& container_schema->ex_schema->free_func != NULL) { && container_schema->ex_schema->free_func != NULL) {
container_schema->ex_schema->free_func(container_schema->table_id, container_schema->ex_schema->free_func(container_schema->table_id,

View File

@@ -19,7 +19,6 @@ const char *table_info_path = "./table_info.conf";
const char *json_path="./maat_json.json"; const char *json_path="./maat_json.json";
const char *json_filename = "maat_json.json"; const char *json_filename = "maat_json.json";
struct log_handle *g_logger = NULL;
size_t g_thread_num = 4; size_t g_thread_num = 4;
extern int system_cmd_rmdir(const char *dir); extern int system_cmd_rmdir(const char *dir);
@@ -276,24 +275,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -301,13 +298,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *MaatFlagScan::_shared_maat_instance; struct maat *MaatFlagScan::_shared_maat_instance;
struct log_handle *MaatFlagScan::logger;
TEST_F(MaatFlagScan, basic) { TEST_F(MaatFlagScan, basic) {
const char *flag_table_name = "FLAG_CONFIG"; const char *flag_table_name = "FLAG_CONFIG";
@@ -507,24 +506,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -532,13 +529,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *MaatStringScan::_shared_maat_instance; struct maat *MaatStringScan::_shared_maat_instance;
struct log_handle *MaatStringScan::logger;
TEST_F(MaatStringScan, Expr8) { TEST_F(MaatStringScan, Expr8) {
const char *table_name = "KEYWORDS_TABLE"; const char *table_name = "KEYWORDS_TABLE";
@@ -638,11 +637,11 @@ TEST_F(MaatStringScan, ExprAndExprPlus) {
long long results[ARRAY_SIZE] = {0}; long long results[ARRAY_SIZE] = {0};
size_t n_hit_result = 0; size_t n_hit_result = 0;
struct maat_state *state = NULL; struct maat_state *state = NULL;
struct maat *maat_instance = MaatStringScan::_shared_maat_instance;
const char *expr_table_name = "HTTP_URL_LITERAL"; const char *expr_table_name = "HTTP_URL_LITERAL";
const char *expr_plus_table_name = "HTTP_SIGNATURE"; const char *expr_plus_table_name = "HTTP_SIGNATURE";
const char *region_name = "I love China"; const char *region_name = "I love China";
const char *scan_data = "today is Monday and yesterday is Tuesday"; const char *scan_data = "today is Monday and yesterday is Tuesday";
struct maat *maat_instance = MaatStringScan::_shared_maat_instance;
int expr_table_id = maat_get_table_id(maat_instance, expr_table_name); int expr_table_id = maat_get_table_id(maat_instance, expr_table_name);
int expr_plus_table_id = maat_get_table_id(maat_instance, expr_plus_table_name); int expr_plus_table_id = maat_get_table_id(maat_instance, expr_plus_table_name);
@@ -668,13 +667,14 @@ TEST_F(MaatStringScan, StreamInput) {
long long results[ARRAY_SIZE] = {0}; long long results[ARRAY_SIZE] = {0};
size_t n_hit_result = 0; size_t n_hit_result = 0;
struct maat_state *state = NULL; struct maat_state *state = NULL;
struct maat *maat_instance = MaatStringScan::_shared_maat_instance;
const char *scan_data = "http://www.cyberessays.com/search_results.php?action=search&query=yulingjing,abckkk,1234567"; const char *scan_data = "http://www.cyberessays.com/search_results.php?action=search&query=yulingjing,abckkk,1234567";
const char *table_name = "HTTP_URL_STREAM"; const char *table_name = "HTTP_URL_REGEX";
int table_id = maat_get_table_id(g_maat_instance, table_name); int table_id = maat_get_table_id(maat_instance, table_name);
ASSERT_GT(table_id, 0); ASSERT_GT(table_id, 0);
struct maat_stream *sp = maat_scan_stream_open(g_maat_instance, table_id, 0); struct maat_stream *sp = maat_scan_stream_open(maat_instance, table_id, 0);
ASSERT_FALSE(sp==NULL); ASSERT_FALSE(sp==NULL);
int ret = maat_scan_stream(&sp, "www.cyberessays.com", strlen("www.cyberessays.com"), int ret = maat_scan_stream(&sp, "www.cyberessays.com", strlen("www.cyberessays.com"),
@@ -889,24 +889,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -914,13 +912,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *MaatIPScan::_shared_maat_instance; struct maat *MaatIPScan::_shared_maat_instance;
struct log_handle *MaatIPScan::logger;
TEST_F(MaatIPScan, IPv4) { TEST_F(MaatIPScan, IPv4) {
const char *table_name = "IP_PLUS_CONFIG"; const char *table_name = "IP_PLUS_CONFIG";
@@ -1046,24 +1046,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -1071,13 +1069,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *MaatIntervalScan::_shared_maat_instance; struct maat *MaatIntervalScan::_shared_maat_instance;
struct log_handle *MaatIntervalScan::logger;
TEST_F(MaatIntervalScan, Pure) { TEST_F(MaatIntervalScan, Pure) {
long long results[ARRAY_SIZE] = {0}; long long results[ARRAY_SIZE] = {0};
@@ -1133,24 +1133,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -1158,13 +1156,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *NOTLogic::_shared_maat_instance; struct maat *NOTLogic::_shared_maat_instance;
struct log_handle *NOTLogic::logger;
TEST_F(NOTLogic, OneRegion) { TEST_F(NOTLogic, OneRegion) {
const char *string_should_hit = "This string ONLY contains must-contained-string-of-rule-143."; const char *string_should_hit = "This string ONLY contains must-contained-string-of-rule-143.";
@@ -1403,25 +1403,23 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_deferred_load_on(opts); maat_options_set_deferred_load_on(opts);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -1429,13 +1427,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *PluginTable::_shared_maat_instance; struct maat *PluginTable::_shared_maat_instance;
struct log_handle *PluginTable::logger;
TEST_F(PluginTable, Callback) { TEST_F(PluginTable, Callback) {
const char *table_name = "QD_ENTRY_INFO"; const char *table_name = "QD_ENTRY_INFO";
@@ -1560,24 +1560,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -1585,13 +1583,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *IPPluginTable::_shared_maat_instance; struct maat *IPPluginTable::_shared_maat_instance;
struct log_handle *IPPluginTable::logger;
struct ip_plugin_ud { struct ip_plugin_ud {
long long rule_id; long long rule_id;
@@ -1701,24 +1701,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -1726,13 +1724,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *FQDNPluginTable::_shared_maat_instance; struct maat *FQDNPluginTable::_shared_maat_instance;
struct log_handle *FQDNPluginTable::logger;
#define FQDN_PLUGIN_EX_DATA #define FQDN_PLUGIN_EX_DATA
struct fqdn_plugin_ud struct fqdn_plugin_ud
@@ -1867,24 +1867,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -1892,13 +1890,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *BoolPluginTable::_shared_maat_instance; struct maat *BoolPluginTable::_shared_maat_instance;
struct log_handle *BoolPluginTable::logger;
TEST_F(BoolPluginTable, EX_DATA) { TEST_F(BoolPluginTable, EX_DATA) {
int ex_data_counter = 0, i = 0; int ex_data_counter = 0, i = 0;
@@ -1957,24 +1957,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -1982,13 +1980,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *VirtualTable::_shared_maat_instance; struct maat *VirtualTable::_shared_maat_instance;
struct log_handle *VirtualTable::logger;
TEST_F(VirtualTable, basic) { TEST_F(VirtualTable, basic) {
long long results[ARRAY_SIZE] = {0}; long long results[ARRAY_SIZE] = {0};
@@ -2016,24 +2016,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -2041,13 +2039,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *CompileTable::_shared_maat_instance; struct maat *CompileTable::_shared_maat_instance;
struct log_handle *CompileTable::logger;
struct rule_ex_param { struct rule_ex_param {
int ref_cnt; int ref_cnt;
@@ -2192,24 +2192,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -2217,13 +2215,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *Policy::_shared_maat_instance; struct maat *Policy::_shared_maat_instance;
struct log_handle *Policy::logger;
void accept_tags_entry_cb(int table_id, const char *table_line, void *u_para) void accept_tags_entry_cb(int table_id, const char *table_line, void *u_para)
{ {
@@ -2399,24 +2399,22 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0); logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL); int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, g_logger);
if (ret < 0) { if (ret < 0) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__);
} }
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
maat_options_set_accept_tags(opts, accept_tags); maat_options_set_accept_tags(opts, accept_tags);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
if (NULL == _shared_maat_instance) { if (NULL == _shared_maat_instance) {
log_error(g_logger, MODULE_FRAMEWORK_GTEST, log_error(logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.", "[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
} }
@@ -2424,13 +2422,15 @@ protected:
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL; log_handle_destroy(logger);
} }
static struct log_handle *logger;
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;
}; };
struct maat *TableInfo::_shared_maat_instance; struct maat *TableInfo::_shared_maat_instance;
struct log_handle *TableInfo::logger;
TEST_F(TableInfo, Conjunction) { TEST_F(TableInfo, Conjunction) {
long long results[ARRAY_SIZE] = {0}; long long results[ARRAY_SIZE] = {0};
@@ -2464,33 +2464,23 @@ protected:
int redis_port = 6379; int redis_port = 6379;
int redis_db = 0; int redis_db = 0;
g_logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL);
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_framework_gtest.log");
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
if (NULL == _shared_maat_instance) { assert(_shared_maat_instance != NULL);
log_error(g_logger, MODULE_FRAMEWORK_GTEST,
"[%s:%d] create maat instance in MaatFlagScan failed.",
__FUNCTION__, __LINE__);
}
maat_cmd_flushDB(_shared_maat_instance); maat_cmd_flushDB(_shared_maat_instance);
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = log_handle_create("./maat_framework_gtest.log", 0);
assert(g_logger != NULL);
maat_options_set_deferred_load_on(opts); maat_options_set_deferred_load_on(opts);
maat_options_set_logger(opts, g_logger);
_shared_maat_instance = maat_new(opts, table_info_path); _shared_maat_instance = maat_new(opts, table_info_path);
maat_options_free(opts); maat_options_free(opts);
} }
static void TearDownTestCase() { static void TearDownTestCase() {
maat_free(_shared_maat_instance); maat_free(_shared_maat_instance);
g_logger = NULL;
} }
static struct maat *_shared_maat_instance; static struct maat *_shared_maat_instance;

View File

@@ -33,6 +33,7 @@ TEST(json_mode, maat_scan_string) {
char json_path[PATH_MAX] = {0}; char json_path[PATH_MAX] = {0};
snprintf(json_path, sizeof(json_path), "./%s", json_filename); snprintf(json_path, sizeof(json_path), "./%s", json_filename);
maat_options_set_json_file(opts, json_path); maat_options_set_json_file(opts, json_path);
maat_options_set_logger_path(opts, "./maat_input_mode_gtest.log");
struct maat *maat_instance = maat_new(opts, table_info_path); struct maat *maat_instance = maat_new(opts, table_info_path);
EXPECT_TRUE(maat_instance != NULL); EXPECT_TRUE(maat_instance != NULL);
@@ -60,7 +61,7 @@ TEST(json_mode, maat_scan_string) {
maat_state_free(&state); maat_state_free(&state);
maat_free(maat_instance); maat_free(maat_instance);
} }
#if 0
TEST(iris_mode, maat_scan_string) { TEST(iris_mode, maat_scan_string) {
char tmp_iris_path[512] = {0}; char tmp_iris_path[512] = {0};
char json_iris_path[512] = {0}; char json_iris_path[512] = {0};
@@ -86,6 +87,7 @@ TEST(iris_mode, maat_scan_string) {
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_iris(opts, tmp_iris_full_idx_path, tmp_iris_inc_idx_path); maat_options_set_iris(opts, tmp_iris_full_idx_path, tmp_iris_inc_idx_path);
maat_options_set_logger_path(opts, "./maat_input_mode_gtest.log");
struct maat *maat_instance = maat_new(opts, table_info_path); struct maat *maat_instance = maat_new(opts, table_info_path);
EXPECT_TRUE(maat_instance != NULL); EXPECT_TRUE(maat_instance != NULL);
@@ -211,7 +213,7 @@ TEST(redis_mode, maat_scan_string) {
struct maat_options *opts = maat_options_new(); struct maat_options *opts = maat_options_new();
maat_options_set_redis(opts, redis_ip, redis_port, redis_db); maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
maat_options_set_logger(opts, g_logger); maat_options_set_logger_path(opts, "./maat_input_mode_gtest.log");
struct maat *maat_instance = maat_new(opts, table_info_path); struct maat *maat_instance = maat_new(opts, table_info_path);
const char *table_name = "KEYWORDS_TABLE"; const char *table_name = "KEYWORDS_TABLE";
@@ -230,7 +232,7 @@ TEST(redis_mode, maat_scan_string) {
maat_state_free(&state); maat_state_free(&state);
maat_free(maat_instance); maat_free(maat_instance);
} }
#endif
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
int ret=0; int ret=0;

View File

@@ -283,6 +283,31 @@
} }
] ]
}, },
{
"compile_id": 125,
"service": 1,
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"user_region": "anything",
"is_valid": "yes",
"groups": [
{
"regions": [
{
"table_name": "HTTP_URL_REGEX",
"table_type": "expr",
"table_content": {
"keywords": "action=search\\&query=(.*)",
"expr_type": "regex",
"match_method": "sub",
"format": "uncase plain"
}
}
]
}
]
},
{ {
"compile_id": 126, "compile_id": 126,
"service": 1, "service": 1,