mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Fix MAINTAIN privileges for toast tables and partitions.
Commit 60684dd8
left loose ends when it came to maintaining toast
tables or partitions.
For toast tables, simply skip the privilege check if the toast table
is an indirect target of the maintenance command, because the main
table privileges have already been checked.
For partitions, allow the maintenance command if the user has the
MAINTAIN privilege on the partition or any parent.
Also make CLUSTER emit "skipping" messages when the user doesn't have
privileges, similar to VACUUM.
Author: Nathan Bossart
Reported-by: Pavel Luzanov
Reviewed-by: Pavel Luzanov, Ted Yu
Discussion: https://postgr.es/m/20230113231339.GA2422750@nathanxps13
This commit is contained in:
@ -16886,12 +16886,38 @@ RangeVarCallbackMaintainsTable(const RangeVar *relation,
|
||||
errmsg("\"%s\" is not a table or materialized view", relation->relname)));
|
||||
|
||||
/* Check permissions */
|
||||
if (!object_ownercheck(RelationRelationId, relId, GetUserId()) &&
|
||||
pg_class_aclcheck(relId, GetUserId(), ACL_MAINTAIN) != ACLCHECK_OK)
|
||||
if (pg_class_aclcheck(relId, GetUserId(), ACL_MAINTAIN) != ACLCHECK_OK &&
|
||||
!has_partition_ancestor_privs(relId, GetUserId(), ACL_MAINTAIN))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_TABLE,
|
||||
relation->relname);
|
||||
}
|
||||
|
||||
/*
|
||||
* If relid is a partition, returns whether userid has any of the privileges
|
||||
* specified in acl on any of its ancestors. Otherwise, returns false.
|
||||
*/
|
||||
bool
|
||||
has_partition_ancestor_privs(Oid relid, Oid userid, AclMode acl)
|
||||
{
|
||||
List *ancestors;
|
||||
ListCell *lc;
|
||||
|
||||
if (!get_rel_relispartition(relid))
|
||||
return false;
|
||||
|
||||
ancestors = get_partition_ancestors(relid);
|
||||
foreach(lc, ancestors)
|
||||
{
|
||||
Oid ancestor = lfirst_oid(lc);
|
||||
|
||||
if (OidIsValid(ancestor) &&
|
||||
pg_class_aclcheck(ancestor, userid, acl) == ACLCHECK_OK)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback to RangeVarGetRelidExtended() for TRUNCATE processing.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user