Source
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
const char *zbx_permission_string(int perm)
{
switch (perm)
{
case PERM_DENY:
return "dn";
case PERM_READ:
return "r";
case PERM_READ_WRITE:
return "rw";
default:
return "unknown";
}
}
int zbx_get_user_info(zbx_uint64_t userid, zbx_uint64_t *roleid, char **user_timezone)
{
int user_type = -1;
zbx_db_result_t result;
zbx_db_row_t row;
char *user_tz = NULL;
result = zbx_db_select("select r.type,u.roleid,u.timezone from users u,role r where u.roleid=r.roleid and"
" userid=" ZBX_FS_UI64, userid);
if (NULL != (row = zbx_db_fetch(result)) && FAIL == zbx_db_is_null(row[0]))
{
user_type = atoi(row[0]);
ZBX_STR2UINT64(*roleid, row[1]);
user_tz = row[2];
}
if (NULL != user_timezone)
*user_timezone = (NULL != user_tz ? zbx_strdup(NULL, user_tz) : NULL);
zbx_db_free_result(result);
return user_type;
}
/******************************************************************************
* *
* Purpose: Return user permissions for access to the host *
* *
* Parameters: *
* *
* Return value: PERM_DENY - if host or user not found, *
* or permission otherwise *
* *
******************************************************************************/
int zbx_get_hostgroups_permission(zbx_uint64_t userid, zbx_vector_uint64_t *hostgroupids)
{
int perm = PERM_DENY;
char *sql = NULL;
size_t sql_alloc = 0, sql_offset = 0;
zbx_db_result_t result;
zbx_db_row_t row;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
if (0 == hostgroupids->values_num)
goto out;
zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
"select min(r.permission)"
" from rights r"
" join users_groups ug on ug.usrgrpid=r.groupid"