aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/typecmds.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-11-13 08:11:17 +0100
committerPeter Eisentraut <peter@eisentraut.org>2022-11-13 08:12:37 +0100
commitafbfc02983f86c4d71825efa6befd547fe81a926 (patch)
tree0cff343b85d5c01fb022e0433d89f5d350609fd4 /src/backend/commands/typecmds.c
parentb4b7ce8061d34cea2b4915c41403b2a74d5fde0e (diff)
downloadpostgresql-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/typecmds.c')
-rw-r--r--src/backend/commands/typecmds.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index b7c3dded170..b7e0194d236 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -525,28 +525,28 @@ DefineType(ParseState *pstate, List *names, List *parameters)
* findTypeInputFunction et al, where they could be shared by AlterType.
*/
#ifdef NOT_USED
- if (inputOid && !pg_proc_ownercheck(inputOid, GetUserId()))
+ if (inputOid && !object_ownercheck(ProcedureRelationId, inputOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
NameListToString(inputName));
- if (outputOid && !pg_proc_ownercheck(outputOid, GetUserId()))
+ if (outputOid && !object_ownercheck(ProcedureRelationId, outputOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
NameListToString(outputName));
- if (receiveOid && !pg_proc_ownercheck(receiveOid, GetUserId()))
+ if (receiveOid && !object_ownercheck(ProcedureRelationId, receiveOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
NameListToString(receiveName));
- if (sendOid && !pg_proc_ownercheck(sendOid, GetUserId()))
+ if (sendOid && !object_ownercheck(ProcedureRelationId, sendOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
NameListToString(sendName));
- if (typmodinOid && !pg_proc_ownercheck(typmodinOid, GetUserId()))
+ if (typmodinOid && !object_ownercheck(ProcedureRelationId, typmodinOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
NameListToString(typmodinName));
- if (typmodoutOid && !pg_proc_ownercheck(typmodoutOid, GetUserId()))
+ if (typmodoutOid && !object_ownercheck(ProcedureRelationId, typmodoutOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
NameListToString(typmodoutName));
- if (analyzeOid && !pg_proc_ownercheck(analyzeOid, GetUserId()))
+ if (analyzeOid && !object_ownercheck(ProcedureRelationId, analyzeOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
NameListToString(analyzeName));
- if (subscriptOid && !pg_proc_ownercheck(subscriptOid, GetUserId()))
+ if (subscriptOid && !object_ownercheck(ProcedureRelationId, subscriptOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,
NameListToString(subscriptName));
#endif
@@ -1318,7 +1318,7 @@ checkEnumOwner(HeapTuple tup)
format_type_be(typTup->oid))));
/* Permission check: must own type */
- if (!pg_type_ownercheck(typTup->oid, GetUserId()))
+ if (!object_ownercheck(TypeRelationId, typTup->oid, GetUserId()))
aclcheck_error_type(ACLCHECK_NOT_OWNER, typTup->oid);
}
@@ -3430,7 +3430,7 @@ checkDomainOwner(HeapTuple tup)
format_type_be(typTup->oid))));
/* Permission check: must own type */
- if (!pg_type_ownercheck(typTup->oid, GetUserId()))
+ if (!object_ownercheck(TypeRelationId, typTup->oid, GetUserId()))
aclcheck_error_type(ACLCHECK_NOT_OWNER, typTup->oid);
}
@@ -3618,7 +3618,7 @@ RenameType(RenameStmt *stmt)
typTup = (Form_pg_type) GETSTRUCT(tup);
/* check permissions on type */
- if (!pg_type_ownercheck(typeOid, GetUserId()))
+ if (!object_ownercheck(TypeRelationId, typeOid, GetUserId()))
aclcheck_error_type(ACLCHECK_NOT_OWNER, typeOid);
/* ALTER DOMAIN used on a non-domain? */
@@ -3741,7 +3741,7 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
if (!superuser())
{
/* Otherwise, must be owner of the existing object */
- if (!pg_type_ownercheck(typTup->oid, GetUserId()))
+ if (!object_ownercheck(TypeRelationId, typTup->oid, GetUserId()))
aclcheck_error_type(ACLCHECK_NOT_OWNER, typTup->oid);
/* Must be able to become new owner */
@@ -3916,7 +3916,7 @@ AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved)
Oid elemOid;
/* check permissions on type */
- if (!pg_type_ownercheck(typeOid, GetUserId()))
+ if (!object_ownercheck(TypeRelationId, typeOid, GetUserId()))
aclcheck_error_type(ACLCHECK_NOT_OWNER, typeOid);
/* don't allow direct alteration of array types */
@@ -4277,7 +4277,7 @@ AlterType(AlterTypeStmt *stmt)
}
else
{
- if (!pg_type_ownercheck(typeOid, GetUserId()))
+ if (!object_ownercheck(TypeRelationId, typeOid, GetUserId()))
aclcheck_error_type(ACLCHECK_NOT_OWNER, typeOid);
}