Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitrijs Goloscapovs <dmitrijs.goloscapovs@zabbix.com>2021-08-30 04:50:43 +0300
committerDmitrijs Goloscapovs <dmitrijs.goloscapovs@zabbix.com>2021-08-30 04:50:43 +0300
commit6341a366e3191f9fa9b973ba90923f415a6208af (patch)
tree1c801626492dcca288f23d011e6197a459c39c65
parent016ee8e15420e368759518cc4f396bea61cacae0 (diff)
........S. [ZBXNEXT-6787] refactored
-rw-r--r--include/service_protocol.h5
-rw-r--r--src/libs/zbxservice/service_protocol.c21
-rw-r--r--src/zabbix_server/escalator/escalator.c27
-rw-r--r--src/zabbix_server/service/service_manager.c6
4 files changed, 21 insertions, 38 deletions
diff --git a/include/service_protocol.h b/include/service_protocol.h
index 41f2a89a94e..4e3220d0868 100644
--- a/include/service_protocol.h
+++ b/include/service_protocol.h
@@ -45,8 +45,7 @@ void zbx_service_serialize_parent_service(unsigned char **data, size_t *data_all
zbx_uint64_t serviceid, zbx_vector_tags_t *tags);
void zbx_service_deserialize_parent_services(const unsigned char *data, zbx_uint32_t size,
zbx_vector_ptr_t *parent_services);
-void zbx_service_serialize_parentids(unsigned char **data, zbx_uint32_t *data_alloc, zbx_uint32_t *data_offset,
- const zbx_vector_uint64_t *ids);
-void zbx_service_deserialize_parentids(const unsigned char *data, zbx_uint32_t size, zbx_vector_uint64_t *ids);
+zbx_uint32_t zbx_service_serialize_parentids(unsigned char **data, const zbx_vector_uint64_t *ids);
+void zbx_service_deserialize_parentids(const unsigned char *data, zbx_vector_uint64_t *ids);
#endif
diff --git a/src/libs/zbxservice/service_protocol.c b/src/libs/zbxservice/service_protocol.c
index fc3e6fb52d9..91a9f52c0e7 100644
--- a/src/libs/zbxservice/service_protocol.c
+++ b/src/libs/zbxservice/service_protocol.c
@@ -312,8 +312,7 @@ void zbx_service_deserialize_rootcause(const unsigned char *data, zbx_uint32_t s
}
}
-void zbx_service_serialize_parentids(unsigned char **data, zbx_uint32_t *data_alloc, zbx_uint32_t *data_offset,
- const zbx_vector_uint64_t *ids)
+zbx_uint32_t zbx_service_serialize_parentids(unsigned char **data, const zbx_vector_uint64_t *ids)
{
zbx_uint32_t data_len = 0;
int i;
@@ -324,27 +323,17 @@ void zbx_service_serialize_parentids(unsigned char **data, zbx_uint32_t *data_al
for (i = 0; i < ids->values_num; i++)
zbx_serialize_prepare_value(data_len, ids->values[i]);
- if (NULL != *data)
- {
- if (*data_alloc - *data_offset < data_len)
- {
- *data_alloc = *data_offset + data_len;
- *data = (unsigned char *)zbx_realloc(*data, *data_alloc);
- }
- }
- else
- *data = (unsigned char *)zbx_malloc(NULL, (*data_alloc = data_len));
-
- ptr = *data + *data_offset;
- *data_offset += data_len;
+ ptr = *data = (unsigned char *)zbx_malloc(NULL, data_len);
ptr += zbx_serialize_value(ptr, ids->values_num);
for (i = 0; i < ids->values_num; i++)
ptr += zbx_serialize_value(ptr, ids->values[i]);
+
+ return data_len;
}
-void zbx_service_deserialize_parentids(const unsigned char *data, zbx_uint32_t size, zbx_vector_uint64_t *ids)
+void zbx_service_deserialize_parentids(const unsigned char *data, zbx_vector_uint64_t *ids)
{
int values_num, i;
diff --git a/src/zabbix_server/escalator/escalator.c b/src/zabbix_server/escalator/escalator.c
index 31f2892894a..e1eceb848eb 100644
--- a/src/zabbix_server/escalator/escalator.c
+++ b/src/zabbix_server/escalator/escalator.c
@@ -436,19 +436,16 @@ static int check_db_parent_rule_tag_match(zbx_vector_uint64_t *parent_ids,
tag_esc = DBdyn_escape_string(tag->tag);
if (i > 0)
- zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " or");
+ zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, " or ");
- if (NULL == tag->value)
- {
- zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "(tag='%s')", tag_esc);
- }
- else
+ zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "tag='%s'", tag_esc);
+
+ if (NULL != tag->value)
{
char *value_esc;
value_esc = DBdyn_escape_string(tag->value);
- zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "(tag='%s' and value='%s')", tag_esc,
- value_esc);
+ zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " and value='%s'", value_esc);
zbx_free(value_esc);
}
@@ -482,8 +479,11 @@ static int check_service_tags_rule_match(const zbx_vector_tags_t *service_tags,
if (0 == strcmp(service_tag->tag, role_tag->tag))
{
- if (NULL != role_tag->value || 0 == strcmp(service_tag->value, role_tag->value))
+ if (NULL != role_tag->value || 0 == strcmp(service_tag->value,
+ ZBX_NULL2EMPTY_STR(role_tag->value)))
+ {
return PERM_READ;
+ }
}
}
}
@@ -496,7 +496,6 @@ static void zbx_db_cache_service_role(zbx_service_role_t *role)
DB_RESULT result;
DB_ROW row;
unsigned char services_read = 1, services_write = 0;
- int ret = FAIL;
result = DBselect("select name,roleid,value_int,value_str,value_serviceid,type from role_rule where roleid="
ZBX_FS_UI64 " and name like 'services.%%' order by name", role->roleid);
@@ -509,8 +508,6 @@ static void zbx_db_cache_service_role(zbx_service_role_t *role)
name = row[0] + ZBX_CONST_STRLEN(ZBX_SERVICES_RULE_PREFIX);
type = atoi(row[5]);
- ret = SUCCEED;
-
if (ZBX_ROLE_RULE_TYPE_INT == type) /* services.read or services.write */
{
char *value_int = row[2];
@@ -576,8 +573,6 @@ static void zbx_db_cache_service_role(zbx_service_role_t *role)
}
DBfree_result(result);
-
- return ret;
}
/******************************************************************************
@@ -621,7 +616,7 @@ static int get_service_permission(zbx_uint64_t userid, char **user_timezone, con
if (SUCCEED == zbx_vector_uint64_bsearch(&role->serviceids, service->serviceid, ZBX_DEFAULT_UINT64_COMPARE_FUNC))
return PERM_READ;
- // check if service tags does not match tag rules
+ // check if service tags do not match tag rules
if (PERM_DENY < (perm = check_service_tags_rule_match(&service->service_tags, &role->tags)))
return perm;
@@ -634,7 +629,7 @@ static int get_service_permission(zbx_uint64_t userid, char **user_timezone, con
zbx_ipc_message_init(&response);
zbx_service_send(ZBX_IPC_SERVICE_SERVICE_PARENT_LIST, data, data_offset, &response);
zbx_vector_uint64_create(&parent_ids);
- zbx_service_deserialize_parentids(response.data, response.size, &parent_ids);
+ zbx_service_deserialize_parentids(response.data, &parent_ids);
zbx_ipc_message_clean(&response);
// check if the returned vector doesn't intersect rule serviceids vector
diff --git a/src/zabbix_server/service/service_manager.c b/src/zabbix_server/service/service_manager.c
index 467f670e3b6..3ff53c6a772 100644
--- a/src/zabbix_server/service/service_manager.c
+++ b/src/zabbix_server/service/service_manager.c
@@ -2358,7 +2358,7 @@ static void process_parentlist(const zbx_ipc_message_t *message, zbx_service_man
zbx_ipc_client_t *client)
{
unsigned char *data = NULL;
- zbx_uint32_t data_alloc = 0, data_offset = 0;
+ zbx_uint32_t data_len = 0;
zbx_uint64_t child_serviceid = 0;
zbx_service_t *service, service_local;
zbx_vector_uint64_t parentids;
@@ -2376,10 +2376,10 @@ static void process_parentlist(const zbx_ipc_message_t *message, zbx_service_man
zbx_vector_uint64_sort(&parentids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
zbx_vector_uint64_uniq(&parentids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
- zbx_service_serialize_parentids(&data, &data_alloc, &data_offset, &parentids);
+ data_len = zbx_service_serialize_parentids(&data, &parentids);
}
- zbx_ipc_client_send(client, ZBX_IPC_SERVICE_SERVICE_PARENT_LIST, data, data_offset);
+ zbx_ipc_client_send(client, ZBX_IPC_SERVICE_SERVICE_PARENT_LIST, data, data_len);
zbx_vector_uint64_destroy(&parentids);
zbx_free(data);