Commit 5ae5e3bf authored by Tom Lane's avatar Tom Lane

Check that aggregate creator has the right to execute the transition

functions of the aggregate, at both aggregate creation and execution times.
parent f76730e3
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.69 2004/12/31 21:59:38 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.70 2005/01/27 23:42:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,10 +22,13 @@ ...@@ -22,10 +22,13 @@
#include "catalog/pg_aggregate.h" #include "catalog/pg_aggregate.h"
#include "catalog/pg_language.h" #include "catalog/pg_language.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "miscadmin.h"
#include "optimizer/cost.h" #include "optimizer/cost.h"
#include "parser/parse_coerce.h" #include "parser/parse_coerce.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
#include "utils/acl.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -262,6 +265,7 @@ lookup_agg_function(List *fnName, ...@@ -262,6 +265,7 @@ lookup_agg_function(List *fnName,
bool retset; bool retset;
Oid *true_oid_array; Oid *true_oid_array;
FuncDetailCode fdresult; FuncDetailCode fdresult;
AclResult aclresult;
/* /*
* func_get_detail looks up the function in the catalogs, does * func_get_detail looks up the function in the catalogs, does
...@@ -326,5 +330,10 @@ lookup_agg_function(List *fnName, ...@@ -326,5 +330,10 @@ lookup_agg_function(List *fnName,
errmsg("function %s requires run-time type coercion", errmsg("function %s requires run-time type coercion",
func_signature_string(fnName, nargs, true_oid_array)))); func_signature_string(fnName, nargs, true_oid_array))));
/* Check aggregate creator has permission to call the function */
aclresult = pg_proc_aclcheck(fnOid, GetUserId(), ACL_EXECUTE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_PROC, get_func_name(fnOid));
return fnOid; return fnOid;
} }
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.126 2004/12/31 21:59:45 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.127 2005/01/27 23:42:18 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "access/heapam.h" #include "access/heapam.h"
#include "catalog/pg_aggregate.h" #include "catalog/pg_aggregate.h"
#include "catalog/pg_operator.h" #include "catalog/pg_operator.h"
#include "catalog/pg_proc.h"
#include "executor/executor.h" #include "executor/executor.h"
#include "executor/nodeAgg.h" #include "executor/nodeAgg.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -1260,6 +1261,35 @@ ExecInitAgg(Agg *node, EState *estate) ...@@ -1260,6 +1261,35 @@ ExecInitAgg(Agg *node, EState *estate)
peraggstate->transfn_oid = transfn_oid = aggform->aggtransfn; peraggstate->transfn_oid = transfn_oid = aggform->aggtransfn;
peraggstate->finalfn_oid = finalfn_oid = aggform->aggfinalfn; peraggstate->finalfn_oid = finalfn_oid = aggform->aggfinalfn;
/* Check that aggregate owner has permission to call component fns */
{
HeapTuple procTuple;
AclId aggOwner;
procTuple = SearchSysCache(PROCOID,
ObjectIdGetDatum(aggref->aggfnoid),
0, 0, 0);
if (!HeapTupleIsValid(procTuple))
elog(ERROR, "cache lookup failed for function %u",
aggref->aggfnoid);
aggOwner = ((Form_pg_proc) GETSTRUCT(procTuple))->proowner;
ReleaseSysCache(procTuple);
aclresult = pg_proc_aclcheck(transfn_oid, aggOwner,
ACL_EXECUTE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_PROC,
get_func_name(transfn_oid));
if (OidIsValid(finalfn_oid))
{
aclresult = pg_proc_aclcheck(finalfn_oid, aggOwner,
ACL_EXECUTE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_PROC,
get_func_name(finalfn_oid));
}
}
/* resolve actual type of transition state, if polymorphic */ /* resolve actual type of transition state, if polymorphic */
aggtranstype = aggform->aggtranstype; aggtranstype = aggform->aggtranstype;
if (aggtranstype == ANYARRAYOID || aggtranstype == ANYELEMENTOID) if (aggtranstype == ANYARRAYOID || aggtranstype == ANYELEMENTOID)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment