diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-11-13 08:11:17 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-11-13 08:12:37 +0100 |
commit | afbfc02983f86c4d71825efa6befd547fe81a926 (patch) | |
tree | 0cff343b85d5c01fb022e0433d89f5d350609fd4 /src/backend/commands/cluster.c | |
parent | b4b7ce8061d34cea2b4915c41403b2a74d5fde0e (diff) | |
download | postgresql-afbfc02983f86c4d71825efa6befd547fe81a926.tar.gz postgresql-afbfc02983f86c4d71825efa6befd547fe81a926.zip |
Refactor ownercheck functions
Instead of dozens of mostly-duplicate pg_foo_ownercheck() functions,
write one common function object_ownercheck() that can handle almost
all of them. We already have all the information we need, such as
which system catalog corresponds to which catalog table and which
column is the owner column.
Reviewed-by: Corey Huinker <corey.huinker@gmail.com>
Reviewed-by: Antonin Houska <ah@cybertec.at>
Discussion: https://www.postgresql.org/message-id/flat/95c30f96-4060-2f48-98b5-a4392d3b6066@enterprisedb.com
Diffstat (limited to 'src/backend/commands/cluster.c')
-rw-r--r-- | src/backend/commands/cluster.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 1976a373efa..3b78a2f100d 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -34,6 +34,7 @@ #include "catalog/objectaccess.h" #include "catalog/partition.h" #include "catalog/pg_am.h" +#include "catalog/pg_database.h" #include "catalog/pg_inherits.h" #include "catalog/toasting.h" #include "commands/cluster.h" @@ -364,7 +365,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params) if (recheck) { /* Check that the user still owns the relation */ - if (!pg_class_ownercheck(tableOid, save_userid)) + if (!object_ownercheck(RelationRelationId, tableOid, save_userid)) { relation_close(OldHeap, AccessExclusiveLock); goto out; @@ -1641,7 +1642,7 @@ get_tables_to_cluster(MemoryContext cluster_context) index = (Form_pg_index) GETSTRUCT(indexTuple); - if (!pg_class_ownercheck(index->indrelid, GetUserId())) + if (!object_ownercheck(RelationRelationId, index->indrelid, GetUserId())) continue; /* Use a permanent memory context for the result list */ @@ -1690,8 +1691,8 @@ get_tables_to_cluster_partitioned(MemoryContext cluster_context, Oid indexOid) continue; /* Silently skip partitions which the user has no access to. */ - if (!pg_class_ownercheck(relid, GetUserId()) && - (!pg_database_ownercheck(MyDatabaseId, GetUserId()) || + if (!object_ownercheck(RelationRelationId, relid, GetUserId()) && + (!object_ownercheck(DatabaseRelationId, MyDatabaseId, GetUserId()) || IsSharedRelation(relid))) continue; |