Skip to content

Commit afbfc02

Browse files
committedNov 13, 2022
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 <[email protected]> Reviewed-by: Antonin Houska <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/[email protected]
1 parent b4b7ce8 commit afbfc02

37 files changed

+183
-806
lines changed
 

‎contrib/pg_surgery/heap_surgery.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ heap_force_common(FunctionCallInfo fcinfo, HeapTupleForceOption heap_force_opt)
118118
errmsg("only heap AM is supported")));
119119

120120
/* Must be owner of the table or superuser. */
121-
if (!pg_class_ownercheck(RelationGetRelid(rel), GetUserId()))
121+
if (!object_ownercheck(RelationRelationId, RelationGetRelid(rel), GetUserId()))
122122
aclcheck_error(ACLCHECK_NOT_OWNER,
123123
get_relkind_objtype(rel->rd_rel->relkind),
124124
RelationGetRelationName(rel));

‎src/backend/access/brin/brin.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ brin_summarize_range(PG_FUNCTION_ARGS)
10691069
RelationGetRelationName(indexRel))));
10701070

10711071
/* User must own the index (comparable to privileges needed for VACUUM) */
1072-
if (heapRel != NULL && !pg_class_ownercheck(indexoid, save_userid))
1072+
if (heapRel != NULL && !object_ownercheck(RelationRelationId, indexoid, save_userid))
10731073
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_INDEX,
10741074
RelationGetRelationName(indexRel));
10751075

@@ -1152,7 +1152,7 @@ brin_desummarize_range(PG_FUNCTION_ARGS)
11521152
RelationGetRelationName(indexRel))));
11531153

11541154
/* User must own the index (comparable to privileges needed for VACUUM) */
1155-
if (!pg_class_ownercheck(indexoid, GetUserId()))
1155+
if (!object_ownercheck(RelationRelationId, indexoid, GetUserId()))
11561156
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_INDEX,
11571157
RelationGetRelationName(indexRel));
11581158

‎src/backend/access/gin/ginfast.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ gin_clean_pending_list(PG_FUNCTION_ARGS)
10541054
errmsg("cannot access temporary indexes of other sessions")));
10551055

10561056
/* User must own the index (comparable to privileges needed for VACUUM) */
1057-
if (!pg_class_ownercheck(indexoid, GetUserId()))
1057+
if (!object_ownercheck(RelationRelationId, indexoid, GetUserId()))
10581058
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_INDEX,
10591059
RelationGetRelationName(indexRel));
10601060

0 commit comments

Comments
 (0)
Please sign in to comment.