mirror of
https://github.com/postgres/postgres.git
synced 2025-06-04 12:42:24 +03:00
Check that aggregate creator has the right to execute the transition
functions of the aggregate, at both aggregate creation and execution times.
This commit is contained in:
parent
64e3271ebc
commit
1263d7b8d1
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.56 2002/09/18 21:35:20 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.56.2.1 2005/01/27 23:43:34 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -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"
|
||||||
|
|
||||||
|
|
||||||
@ -46,6 +49,7 @@ AggregateCreate(const char *aggName,
|
|||||||
char nulls[Natts_pg_aggregate];
|
char nulls[Natts_pg_aggregate];
|
||||||
Datum values[Natts_pg_aggregate];
|
Datum values[Natts_pg_aggregate];
|
||||||
Form_pg_proc proc;
|
Form_pg_proc proc;
|
||||||
|
AclResult aclresult;
|
||||||
Oid transfn;
|
Oid transfn;
|
||||||
Oid finalfn = InvalidOid; /* can be omitted */
|
Oid finalfn = InvalidOid; /* can be omitted */
|
||||||
Oid finaltype;
|
Oid finaltype;
|
||||||
@ -100,6 +104,11 @@ AggregateCreate(const char *aggName,
|
|||||||
}
|
}
|
||||||
ReleaseSysCache(tup);
|
ReleaseSysCache(tup);
|
||||||
|
|
||||||
|
/* Check aggregate creator has permission to call the function */
|
||||||
|
aclresult = pg_proc_aclcheck(transfn, GetUserId(), ACL_EXECUTE);
|
||||||
|
if (aclresult != ACLCHECK_OK)
|
||||||
|
aclcheck_error(aclresult, get_func_name(transfn));
|
||||||
|
|
||||||
/* handle finalfn, if supplied */
|
/* handle finalfn, if supplied */
|
||||||
if (aggfinalfnName)
|
if (aggfinalfnName)
|
||||||
{
|
{
|
||||||
@ -116,6 +125,11 @@ AggregateCreate(const char *aggName,
|
|||||||
proc = (Form_pg_proc) GETSTRUCT(tup);
|
proc = (Form_pg_proc) GETSTRUCT(tup);
|
||||||
finaltype = proc->prorettype;
|
finaltype = proc->prorettype;
|
||||||
ReleaseSysCache(tup);
|
ReleaseSysCache(tup);
|
||||||
|
|
||||||
|
/* Check aggregate creator has permission to call the function */
|
||||||
|
aclresult = pg_proc_aclcheck(finalfn, GetUserId(), ACL_EXECUTE);
|
||||||
|
if (aclresult != ACLCHECK_OK)
|
||||||
|
aclcheck_error(aclresult, get_func_name(finalfn));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.90 2002/11/01 19:33:09 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.90.2.1 2005/01/27 23:43:45 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -56,6 +56,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"
|
||||||
@ -903,6 +904,33 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
|
|||||||
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, 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, get_func_name(finalfn_oid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmgr_info(transfn_oid, &peraggstate->transfn);
|
fmgr_info(transfn_oid, &peraggstate->transfn);
|
||||||
if (OidIsValid(finalfn_oid))
|
if (OidIsValid(finalfn_oid))
|
||||||
fmgr_info(finalfn_oid, &peraggstate->finalfn);
|
fmgr_info(finalfn_oid, &peraggstate->finalfn);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user