mirror of
https://github.com/postgres/postgres.git
synced 2025-07-12 21:01:52 +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:
@ -421,7 +421,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
#ifdef NOT_USED
|
||||
/* XXX this is unnecessary given the superuser check above */
|
||||
/* Check we have ownership of the datatype */
|
||||
if (!pg_type_ownercheck(typeoid, GetUserId()))
|
||||
if (!object_ownercheck(TypeRelationId, typeoid, GetUserId()))
|
||||
aclcheck_error_type(ACLCHECK_NOT_OWNER, typeoid);
|
||||
#endif
|
||||
|
||||
@ -513,11 +513,11 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
#ifdef NOT_USED
|
||||
/* XXX this is unnecessary given the superuser check above */
|
||||
/* Caller must own operator and its underlying function */
|
||||
if (!pg_oper_ownercheck(operOid, GetUserId()))
|
||||
if (!object_ownercheck(OperatorRelationId, operOid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_OPERATOR,
|
||||
get_opname(operOid));
|
||||
funcOid = get_opcode(operOid);
|
||||
if (!pg_proc_ownercheck(funcOid, GetUserId()))
|
||||
if (!object_ownercheck(ProcedureRelationId, funcOid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
|
||||
get_func_name(funcOid));
|
||||
#endif
|
||||
@ -542,7 +542,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
#ifdef NOT_USED
|
||||
/* XXX this is unnecessary given the superuser check above */
|
||||
/* Caller must own function */
|
||||
if (!pg_proc_ownercheck(funcOid, GetUserId()))
|
||||
if (!object_ownercheck(ProcedureRelationId, funcOid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
|
||||
get_func_name(funcOid));
|
||||
#endif
|
||||
@ -570,7 +570,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
#ifdef NOT_USED
|
||||
/* XXX this is unnecessary given the superuser check above */
|
||||
/* Check we have ownership of the datatype */
|
||||
if (!pg_type_ownercheck(storageoid, GetUserId()))
|
||||
if (!object_ownercheck(TypeRelationId, storageoid, GetUserId()))
|
||||
aclcheck_error_type(ACLCHECK_NOT_OWNER, storageoid);
|
||||
#endif
|
||||
break;
|
||||
@ -930,11 +930,11 @@ AlterOpFamilyAdd(AlterOpFamilyStmt *stmt, Oid amoid, Oid opfamilyoid,
|
||||
#ifdef NOT_USED
|
||||
/* XXX this is unnecessary given the superuser check above */
|
||||
/* Caller must own operator and its underlying function */
|
||||
if (!pg_oper_ownercheck(operOid, GetUserId()))
|
||||
if (!object_ownercheck(OperatorRelationId, operOid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_OPERATOR,
|
||||
get_opname(operOid));
|
||||
funcOid = get_opcode(operOid);
|
||||
if (!pg_proc_ownercheck(funcOid, GetUserId()))
|
||||
if (!object_ownercheck(ProcedureRelationId, funcOid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
|
||||
get_func_name(funcOid));
|
||||
#endif
|
||||
@ -964,7 +964,7 @@ AlterOpFamilyAdd(AlterOpFamilyStmt *stmt, Oid amoid, Oid opfamilyoid,
|
||||
#ifdef NOT_USED
|
||||
/* XXX this is unnecessary given the superuser check above */
|
||||
/* Caller must own function */
|
||||
if (!pg_proc_ownercheck(funcOid, GetUserId()))
|
||||
if (!object_ownercheck(ProcedureRelationId, funcOid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
|
||||
get_func_name(funcOid));
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user