diff options
author | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2021-10-13 16:33:03 +0300 |
---|---|---|
committer | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2021-10-13 16:36:29 +0300 |
commit | 51a325e869119896f9d921e27d9a187678d92e17 (patch) | |
tree | 08db8df409cb6743f1d906bf73b4cf6645b0ba6d /src/libs/zbxaudit/audit.c | |
parent | 26cf2029b2c2b5e702cd6336f89e935a39a3cfd1 (diff) |
........S. [ZBX-20077] fixed possible collision of audit entities for server in json
Diffstat (limited to 'src/libs/zbxaudit/audit.c')
-rw-r--r-- | src/libs/zbxaudit/audit.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/src/libs/zbxaudit/audit.c b/src/libs/zbxaudit/audit.c index 403209149a8..fce157eb787 100644 --- a/src/libs/zbxaudit/audit.c +++ b/src/libs/zbxaudit/audit.c @@ -36,12 +36,14 @@ zbx_hashset_t *zbx_get_audit_hashset(void) return &zbx_audit; } -zbx_audit_entry_t *zbx_audit_entry_init(zbx_uint64_t id, const char *name, int audit_action, int resource_type) +zbx_audit_entry_t *zbx_audit_entry_init(zbx_uint64_t id, const int id_table, const char *name, int audit_action, + int resource_type) { zbx_audit_entry_t *audit_entry; audit_entry = (zbx_audit_entry_t*)zbx_malloc(NULL, sizeof(zbx_audit_entry_t)); audit_entry->id = id; + audit_entry->id_table = id_table; audit_entry->name = zbx_strdup(NULL, name); audit_entry->audit_action = audit_action; audit_entry->resource_type = resource_type; @@ -216,10 +218,13 @@ out: static unsigned zbx_audit_hash_func(const void *data) { - const zbx_audit_entry_t * const *audit_entry = (const zbx_audit_entry_t * const *)data; + zbx_hash_t hash; + const zbx_audit_entry_t * const *audit_entry = (const zbx_audit_entry_t * const *)data; - return ZBX_DEFAULT_UINT64_HASH_ALGO(&((*audit_entry)->id), sizeof((*audit_entry)->id), - ZBX_DEFAULT_HASH_SEED); + hash = ZBX_DEFAULT_UINT64_HASH_ALGO(&((*audit_entry)->id), sizeof((*audit_entry)->id), ZBX_DEFAULT_HASH_SEED); + + return ZBX_DEFAULT_UINT64_HASH_ALGO(&((*audit_entry)->id_table), sizeof((*audit_entry)->id_table), + hash); } static int zbx_audit_compare_func(const void *d1, const void *d2) @@ -228,6 +233,7 @@ static int zbx_audit_compare_func(const void *d1, const void *d2) const zbx_audit_entry_t * const *audit_entry_2 = (const zbx_audit_entry_t * const *)d2; ZBX_RETURN_IF_NOT_EQUAL((*audit_entry_1)->id, (*audit_entry_2)->id); + ZBX_RETURN_IF_NOT_EQUAL((*audit_entry_1)->id_table, (*audit_entry_2)->id_table); return 0; } @@ -350,8 +356,8 @@ static int audit_field_default(const char *table_name, const char *field_name, c return FAIL; } -void zbx_audit_update_json_append_string(const zbx_uint64_t id, const char *audit_op, const char *key, - const char *value, const char *table, const char *field) +void zbx_audit_update_json_append_string(const zbx_uint64_t id, const int id_table, const char *audit_op, + const char *key, const char *value, const char *table, const char *field) { zbx_audit_entry_t local_audit_entry, **found_audit_entry; zbx_audit_entry_t *local_audit_entry_x = &local_audit_entry; @@ -360,7 +366,7 @@ void zbx_audit_update_json_append_string(const zbx_uint64_t id, const char *audi return; local_audit_entry.id = id; - + local_audit_entry.id_table = id_table; found_audit_entry = (zbx_audit_entry_t**)zbx_hashset_search(&zbx_audit, &(local_audit_entry_x)); if (NULL == found_audit_entry) @@ -372,8 +378,8 @@ void zbx_audit_update_json_append_string(const zbx_uint64_t id, const char *audi append_str_json(&((*found_audit_entry)->details_json), audit_op, key, value); } -void zbx_audit_update_json_append_string_secret(const zbx_uint64_t id, const char *audit_op, const char *key, - const char *value, const char *table, const char *field) +void zbx_audit_update_json_append_string_secret(const zbx_uint64_t id, const int id_table, const char *audit_op, + const char *key, const char *value, const char *table, const char *field) { zbx_audit_entry_t local_audit_entry, **found_audit_entry; zbx_audit_entry_t *local_audit_entry_x = &local_audit_entry; @@ -382,7 +388,7 @@ void zbx_audit_update_json_append_string_secret(const zbx_uint64_t id, const cha return; local_audit_entry.id = id; - + local_audit_entry.id_table = id_table; found_audit_entry = (zbx_audit_entry_t**)zbx_hashset_search(&zbx_audit, &(local_audit_entry_x)); if (NULL == found_audit_entry) @@ -394,8 +400,8 @@ void zbx_audit_update_json_append_string_secret(const zbx_uint64_t id, const cha append_str_json(&((*found_audit_entry)->details_json), audit_op, key, ZBX_MACRO_SECRET_MASK); } -void zbx_audit_update_json_append_uint64(const zbx_uint64_t id, const char *audit_op, const char *key, - uint64_t value, const char *table, const char *field) +void zbx_audit_update_json_append_uint64(const zbx_uint64_t id, const int id_table, const char *audit_op, + const char *key, uint64_t value, const char *table, const char *field) { char buffer[MAX_ID_LEN]; zbx_audit_entry_t local_audit_entry, **found_audit_entry; @@ -406,7 +412,7 @@ void zbx_audit_update_json_append_uint64(const zbx_uint64_t id, const char *audi return; local_audit_entry.id = id; - + local_audit_entry.id_table = id_table; found_audit_entry = (zbx_audit_entry_t**)zbx_hashset_search(&zbx_audit, &(local_audit_entry_x)); if (NULL == found_audit_entry) @@ -423,7 +429,7 @@ void zbx_audit_update_json_append_uint64(const zbx_uint64_t id, const char *audi zbx_audit_entry_t *local_audit_entry_x = &local_audit_entry; \ \ local_audit_entry.id = id; \ - \ + local_audit_entry.id_table = id_table; \ found_audit_entry = (zbx_audit_entry_t**)zbx_hashset_search(&zbx_audit, \ &(local_audit_entry_x)); \ if (NULL == found_audit_entry) \ @@ -432,14 +438,15 @@ void zbx_audit_update_json_append_uint64(const zbx_uint64_t id, const char *audi exit(EXIT_FAILURE); \ } \ -void zbx_audit_update_json_append_no_value(const zbx_uint64_t id, const char *audit_op, const char *key) +void zbx_audit_update_json_append_no_value(const zbx_uint64_t id, const int id_table, const char *audit_op, + const char *key) { PREPARE_UPDATE_JSON_APPEND_OP(); append_json_no_value(&((*found_audit_entry)->details_json), audit_op, key); } -void zbx_audit_update_json_append_int(const zbx_uint64_t id, const char *audit_op, const char *key, int value, - const char *table, const char *field) +void zbx_audit_update_json_append_int(const zbx_uint64_t id, const int id_table, const char *audit_op, + const char *key, int value, const char *table, const char *field) { char buffer[MAX_ID_LEN]; @@ -456,8 +463,8 @@ void zbx_audit_update_json_append_int(const zbx_uint64_t id, const char *audit_o } } -void zbx_audit_update_json_append_double(const zbx_uint64_t id, const char *audit_op, const char *key, double value, - const char *table, const char *field) +void zbx_audit_update_json_append_double(const zbx_uint64_t id, const int id_table, const char *audit_op, + const char *key, double value, const char *table, const char *field) { char buffer[MAX_ID_LEN]; @@ -474,35 +481,35 @@ void zbx_audit_update_json_append_double(const zbx_uint64_t id, const char *audi } } -void zbx_audit_update_json_update_string(const zbx_uint64_t id, const char *key, const char *value_old, - const char *value_new) +void zbx_audit_update_json_update_string(const zbx_uint64_t id, const int id_table, const char *key, + const char *value_old, const char *value_new) { PREPARE_UPDATE_JSON_APPEND_OP(); update_str_json(&((*found_audit_entry)->details_json), key, value_old, value_new); } -void zbx_audit_update_json_update_uint64(const zbx_uint64_t id, const char *key, uint64_t value_old, - uint64_t value_new) +void zbx_audit_update_json_update_uint64(const zbx_uint64_t id, const int id_table, const char *key, + uint64_t value_old, uint64_t value_new) { PREPARE_UPDATE_JSON_APPEND_OP(); update_uint64_json(&((*found_audit_entry)->details_json), key, value_old, value_new); } -void zbx_audit_update_json_update_int(const zbx_uint64_t id, const char *key, int value_old, +void zbx_audit_update_json_update_int(const zbx_uint64_t id, const int id_table, const char *key, int value_old, int value_new) { PREPARE_UPDATE_JSON_APPEND_OP(); update_int_json(&((*found_audit_entry)->details_json), key, value_old, value_new); } -void zbx_audit_update_json_update_double(const zbx_uint64_t id, const char *key, double value_old, - double value_new) +void zbx_audit_update_json_update_double(const zbx_uint64_t id, const int id_table, const char *key, + double value_old, double value_new) { PREPARE_UPDATE_JSON_APPEND_OP(); update_double_json(&((*found_audit_entry)->details_json), key, value_old, value_new); } -void zbx_audit_update_json_delete(const zbx_uint64_t id, const char *audit_op, const char *key) +void zbx_audit_update_json_delete(const zbx_uint64_t id, const int id_table, const char *audit_op, const char *key) { PREPARE_UPDATE_JSON_APPEND_OP(); delete_json(&((*found_audit_entry)->details_json), audit_op, key); |