mirror of
https://github.com/postgres/postgres.git
synced 2025-07-17 06:41:09 +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:
@ -279,7 +279,7 @@ DefineQueryRewrite(const char *rulename,
|
||||
/*
|
||||
* Check user has permission to apply rules to this relation.
|
||||
*/
|
||||
if (!pg_class_ownercheck(event_relid, GetUserId()))
|
||||
if (!object_ownercheck(RelationRelationId, event_relid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(event_relation->rd_rel->relkind),
|
||||
RelationGetRelationName(event_relation));
|
||||
|
||||
@ -894,7 +894,7 @@ EnableDisableRule(Relation rel, const char *rulename,
|
||||
*/
|
||||
eventRelationOid = ruleform->ev_class;
|
||||
Assert(eventRelationOid == owningRel);
|
||||
if (!pg_class_ownercheck(eventRelationOid, GetUserId()))
|
||||
if (!object_ownercheck(RelationRelationId, eventRelationOid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(get_rel_relkind(eventRelationOid)),
|
||||
get_rel_name(eventRelationOid));
|
||||
|
||||
@ -956,7 +956,7 @@ RangeVarCallbackForRenameRule(const RangeVar *rv, Oid relid, Oid oldrelid,
|
||||
rv->relname)));
|
||||
|
||||
/* you must own the table to rename one of its rules */
|
||||
if (!pg_class_ownercheck(relid, GetUserId()))
|
||||
if (!object_ownercheck(RelationRelationId, relid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(get_rel_relkind(relid)), rv->relname);
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
|
Reference in New Issue
Block a user