mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
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
This commit is contained in:
@@ -1394,7 +1394,7 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
|
||||
pubform = (Form_pg_publication) GETSTRUCT(tup);
|
||||
|
||||
/* must be owner */
|
||||
if (!pg_publication_ownercheck(pubform->oid, GetUserId()))
|
||||
if (!object_ownercheck(PublicationRelationId, pubform->oid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_PUBLICATION,
|
||||
stmt->pubname);
|
||||
|
||||
@@ -1764,7 +1764,7 @@ PublicationAddTables(Oid pubid, List *rels, bool if_not_exists,
|
||||
ObjectAddress obj;
|
||||
|
||||
/* Must be owner of the table or superuser. */
|
||||
if (!pg_class_ownercheck(RelationGetRelid(rel), GetUserId()))
|
||||
if (!object_ownercheck(RelationRelationId, RelationGetRelid(rel), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(rel->rd_rel->relkind),
|
||||
RelationGetRelationName(rel));
|
||||
|
||||
@@ -1905,7 +1905,7 @@ AlterPublicationOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
|
||||
AclResult aclresult;
|
||||
|
||||
/* Must be owner */
|
||||
if (!pg_publication_ownercheck(form->oid, GetUserId()))
|
||||
if (!object_ownercheck(PublicationRelationId, form->oid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_PUBLICATION,
|
||||
NameStr(form->pubname));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user