mirror of
https://github.com/postgres/postgres.git
synced 2025-05-05 09:19:17 +03:00
ALTER AGGREGATE OWNER seems to have been missed by the last couple of
patches that dealt with object ownership. It wasn't updating pg_shdepend nor adjusting the aggregate's ACL. In 8.2 and up, fix this permanently by making it use AlterFunctionOwner_oid. In 8.1, the function code wasn't factored that way, so just copy and paste.
This commit is contained in:
parent
742627a27e
commit
af55dc839b
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.41 2006/10/04 00:29:50 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.41.2.1 2008/06/08 21:09:59 tgl Exp $
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* The "DefineFoo" routines take the parse tree and pick out the
|
* The "DefineFoo" routines take the parse tree and pick out the
|
||||||
@ -319,58 +319,10 @@ void
|
|||||||
AlterAggregateOwner(List *name, List *args, Oid newOwnerId)
|
AlterAggregateOwner(List *name, List *args, Oid newOwnerId)
|
||||||
{
|
{
|
||||||
Oid procOid;
|
Oid procOid;
|
||||||
HeapTuple tup;
|
|
||||||
Form_pg_proc procForm;
|
|
||||||
Relation rel;
|
|
||||||
AclResult aclresult;
|
|
||||||
|
|
||||||
rel = heap_open(ProcedureRelationId, RowExclusiveLock);
|
|
||||||
|
|
||||||
/* Look up function and make sure it's an aggregate */
|
/* Look up function and make sure it's an aggregate */
|
||||||
procOid = LookupAggNameTypeNames(name, args, false);
|
procOid = LookupAggNameTypeNames(name, args, false);
|
||||||
|
|
||||||
tup = SearchSysCacheCopy(PROCOID,
|
/* The rest is just like a function */
|
||||||
ObjectIdGetDatum(procOid),
|
AlterFunctionOwner_oid(procOid, newOwnerId);
|
||||||
0, 0, 0);
|
|
||||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
|
||||||
elog(ERROR, "cache lookup failed for function %u", procOid);
|
|
||||||
procForm = (Form_pg_proc) GETSTRUCT(tup);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the new owner is the same as the existing owner, consider the
|
|
||||||
* command to have succeeded. This is for dump restoration purposes.
|
|
||||||
*/
|
|
||||||
if (procForm->proowner != newOwnerId)
|
|
||||||
{
|
|
||||||
/* Superusers can always do it */
|
|
||||||
if (!superuser())
|
|
||||||
{
|
|
||||||
/* Otherwise, must be owner of the existing object */
|
|
||||||
if (!pg_proc_ownercheck(procOid, GetUserId()))
|
|
||||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC,
|
|
||||||
NameListToString(name));
|
|
||||||
|
|
||||||
/* Must be able to become new owner */
|
|
||||||
check_is_member_of_role(GetUserId(), newOwnerId);
|
|
||||||
|
|
||||||
/* New owner must have CREATE privilege on namespace */
|
|
||||||
aclresult = pg_namespace_aclcheck(procForm->pronamespace,
|
|
||||||
newOwnerId,
|
|
||||||
ACL_CREATE);
|
|
||||||
if (aclresult != ACLCHECK_OK)
|
|
||||||
aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
|
|
||||||
get_namespace_name(procForm->pronamespace));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Modify the owner --- okay to scribble on tup because it's a copy
|
|
||||||
*/
|
|
||||||
procForm->proowner = newOwnerId;
|
|
||||||
|
|
||||||
simple_heap_update(rel, &tup->t_self, tup);
|
|
||||||
CatalogUpdateIndexes(rel, tup);
|
|
||||||
}
|
|
||||||
|
|
||||||
heap_close(rel, NoLock);
|
|
||||||
heap_freetuple(tup);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user