mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
GetUserId() changes to has_privs_of_role()
The pg_stat and pg_signal-related functions have been using GetUserId() instead of has_privs_of_role() for checking if the current user should be able to see details in pg_stat_activity or signal other processes, requiring a user to do 'SET ROLE' for inheirited roles for a permissions check, unlike other permissions checks. This patch changes that behavior to, instead, act like most other permission checks and use has_privs_of_role(), removing the 'SET ROLE' need. Documentation and error messages updated accordingly. Per discussion with Alvaro, Peter, Adam (though not using Adam's patch), and Robert. Reviewed by Jeevan Chalke.
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
#include "libpq/ip.h"
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "utils/acl.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/inet.h"
|
||||
#include "utils/timestamp.h"
|
||||
@ -675,8 +676,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
else
|
||||
nulls[15] = true;
|
||||
|
||||
/* Values only available to same user or superuser */
|
||||
if (superuser() || beentry->st_userid == GetUserId())
|
||||
/* Values only available to role member */
|
||||
if (has_privs_of_role(GetUserId(), beentry->st_userid))
|
||||
{
|
||||
SockAddr zero_clientaddr;
|
||||
|
||||
@ -878,7 +879,7 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
|
||||
|
||||
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
||||
activity = "<backend information not available>";
|
||||
else if (!superuser() && beentry->st_userid != GetUserId())
|
||||
else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
|
||||
activity = "<insufficient privilege>";
|
||||
else if (*(beentry->st_activity) == '\0')
|
||||
activity = "<command string not enabled>";
|
||||
@ -899,7 +900,7 @@ pg_stat_get_backend_waiting(PG_FUNCTION_ARGS)
|
||||
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
if (!superuser() && beentry->st_userid != GetUserId())
|
||||
if (!has_privs_of_role(GetUserId(), beentry->st_userid))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
result = beentry->st_waiting;
|
||||
@ -918,7 +919,7 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
|
||||
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
if (!superuser() && beentry->st_userid != GetUserId())
|
||||
if (!has_privs_of_role(GetUserId(), beentry->st_userid))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
result = beentry->st_activity_start_timestamp;
|
||||
@ -944,7 +945,7 @@ pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
|
||||
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
if (!superuser() && beentry->st_userid != GetUserId())
|
||||
if (!has_privs_of_role(GetUserId(), beentry->st_userid))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
result = beentry->st_xact_start_timestamp;
|
||||
@ -966,7 +967,7 @@ pg_stat_get_backend_start(PG_FUNCTION_ARGS)
|
||||
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
if (!superuser() && beentry->st_userid != GetUserId())
|
||||
if (!has_privs_of_role(GetUserId(), beentry->st_userid))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
result = beentry->st_proc_start_timestamp;
|
||||
@ -990,7 +991,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
|
||||
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
if (!superuser() && beentry->st_userid != GetUserId())
|
||||
if (!has_privs_of_role(GetUserId(), beentry->st_userid))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
/* A zeroed client addr means we don't know */
|
||||
@ -1037,7 +1038,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
|
||||
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
if (!superuser() && beentry->st_userid != GetUserId())
|
||||
if (!has_privs_of_role(GetUserId(), beentry->st_userid))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
/* A zeroed client addr means we don't know */
|
||||
|
Reference in New Issue
Block a user