mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Improve reporting of permission errors for array types
Because permissions are assigned to element types, not array types, complaining about permission denied on an array type would be misleading to users. So adjust the reporting to refer to the element type instead. In order not to duplicate the required logic in two dozen places, refactor the permission denied reporting for types a bit. pointed out by Yeb Havinga during the review of the type privilege feature
This commit is contained in:
@@ -154,8 +154,7 @@ compute_return_type(TypeName *returnType, Oid languageOid,
|
||||
|
||||
aclresult = pg_type_aclcheck(rettype, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(rettype));
|
||||
aclcheck_error_type(aclresult, rettype);
|
||||
|
||||
*prorettype_p = rettype;
|
||||
*returnsSet_p = returnType->setof;
|
||||
@@ -247,8 +246,7 @@ examine_parameter_list(List *parameters, Oid languageOid,
|
||||
|
||||
aclresult = pg_type_aclcheck(toid, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(toid));
|
||||
aclcheck_error_type(aclresult, toid);
|
||||
|
||||
if (t->setof)
|
||||
ereport(ERROR,
|
||||
@@ -1510,13 +1508,11 @@ CreateCast(CreateCastStmt *stmt)
|
||||
|
||||
aclresult = pg_type_aclcheck(sourcetypeid, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(sourcetypeid));
|
||||
aclcheck_error_type(aclresult, sourcetypeid);
|
||||
|
||||
aclresult = pg_type_aclcheck(targettypeid, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(targettypeid));
|
||||
aclcheck_error_type(aclresult, targettypeid);
|
||||
|
||||
/* Domains are allowed for historical reasons, but we warn */
|
||||
if (sourcetyptype == TYPTYPE_DOMAIN)
|
||||
|
||||
@@ -414,8 +414,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
/* XXX this is unnecessary given the superuser check above */
|
||||
/* Check we have ownership of the datatype */
|
||||
if (!pg_type_ownercheck(typeoid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
|
||||
format_type_be(typeoid));
|
||||
aclcheck_error_type(ACLCHECK_NOT_OWNER, typeoid);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -565,8 +564,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
/* XXX this is unnecessary given the superuser check above */
|
||||
/* Check we have ownership of the datatype */
|
||||
if (!pg_type_ownercheck(storageoid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
|
||||
format_type_be(storageoid));
|
||||
aclcheck_error_type(ACLCHECK_NOT_OWNER, storageoid);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -181,16 +181,14 @@ DefineOperator(List *names, List *parameters)
|
||||
{
|
||||
aclresult = pg_type_aclcheck(typeId1, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(typeId1));
|
||||
aclcheck_error_type(aclresult, typeId1);
|
||||
}
|
||||
|
||||
if (typeName2)
|
||||
{
|
||||
aclresult = pg_type_aclcheck(typeId2, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(typeId2));
|
||||
aclcheck_error_type(aclresult, typeId2);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -227,8 +225,7 @@ DefineOperator(List *names, List *parameters)
|
||||
rettype = get_func_rettype(functionOid);
|
||||
aclresult = pg_type_aclcheck(rettype, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(rettype));
|
||||
aclcheck_error_type(aclresult, rettype);
|
||||
|
||||
/*
|
||||
* Look up restriction estimator if specified
|
||||
|
||||
@@ -526,8 +526,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
|
||||
|
||||
aclresult = pg_type_aclcheck(ofTypeId, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(ofTypeId));
|
||||
aclcheck_error_type(aclresult, ofTypeId);
|
||||
}
|
||||
else
|
||||
ofTypeId = InvalidOid;
|
||||
@@ -4500,8 +4499,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
|
||||
|
||||
aclresult = pg_type_aclcheck(typeOid, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(typeOid));
|
||||
aclcheck_error_type(aclresult, typeOid);
|
||||
|
||||
collOid = GetColumnDefCollation(NULL, colDef, typeOid);
|
||||
|
||||
@@ -7248,8 +7246,7 @@ ATPrepAlterColumnType(List **wqueue,
|
||||
|
||||
aclresult = pg_type_aclcheck(targettype, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(targettype));
|
||||
aclcheck_error_type(aclresult, targettype);
|
||||
|
||||
/* And the collation */
|
||||
targetcollid = GetColumnDefCollation(NULL, def, targettype);
|
||||
|
||||
@@ -758,8 +758,7 @@ DefineDomain(CreateDomainStmt *stmt)
|
||||
|
||||
aclresult = pg_type_aclcheck(basetypeoid, GetUserId(), ACL_USAGE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_TYPE,
|
||||
format_type_be(basetypeoid));
|
||||
aclcheck_error_type(aclresult, basetypeoid);
|
||||
|
||||
/*
|
||||
* Identify the collation if any
|
||||
@@ -1208,8 +1207,7 @@ checkEnumOwner(HeapTuple tup)
|
||||
|
||||
/* Permission check: must own type */
|
||||
if (!pg_type_ownercheck(HeapTupleGetOid(tup), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
|
||||
format_type_be(HeapTupleGetOid(tup)));
|
||||
aclcheck_error_type(ACLCHECK_NOT_OWNER, HeapTupleGetOid(tup));
|
||||
}
|
||||
|
||||
|
||||
@@ -2809,8 +2807,7 @@ checkDomainOwner(HeapTuple tup)
|
||||
|
||||
/* Permission check: must own type */
|
||||
if (!pg_type_ownercheck(HeapTupleGetOid(tup), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
|
||||
format_type_be(HeapTupleGetOid(tup)));
|
||||
aclcheck_error_type(ACLCHECK_NOT_OWNER, HeapTupleGetOid(tup));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3116,8 +3113,7 @@ RenameType(RenameStmt *stmt)
|
||||
|
||||
/* check permissions on type */
|
||||
if (!pg_type_ownercheck(typeOid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
|
||||
format_type_be(typeOid));
|
||||
aclcheck_error_type(ACLCHECK_NOT_OWNER, typeOid);
|
||||
|
||||
/* ALTER DOMAIN used on a non-domain? */
|
||||
if (stmt->renameType == OBJECT_DOMAIN && typTup->typtype != TYPTYPE_DOMAIN)
|
||||
@@ -3238,8 +3234,7 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
|
||||
{
|
||||
/* Otherwise, must be owner of the existing object */
|
||||
if (!pg_type_ownercheck(HeapTupleGetOid(tup), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
|
||||
format_type_be(HeapTupleGetOid(tup)));
|
||||
aclcheck_error_type(ACLCHECK_NOT_OWNER, HeapTupleGetOid(tup));
|
||||
|
||||
/* Must be able to become new owner */
|
||||
check_is_member_of_role(GetUserId(), newOwnerId);
|
||||
@@ -3367,8 +3362,7 @@ AlterTypeNamespace_oid(Oid typeOid, Oid nspOid)
|
||||
|
||||
/* check permissions on type */
|
||||
if (!pg_type_ownercheck(typeOid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE,
|
||||
format_type_be(typeOid));
|
||||
aclcheck_error_type(ACLCHECK_NOT_OWNER, typeOid);
|
||||
|
||||
/* don't allow direct alteration of array types */
|
||||
elemOid = get_element_type(typeOid);
|
||||
|
||||
Reference in New Issue
Block a user