diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-07-14 21:46:30 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-07-14 21:46:30 +0000 |
commit | aa1110624c08298393dfce996f7b21809d98d3fd (patch) | |
tree | b698817242cc44d7ad14cbd68cb0b96e751e4e13 /src/backend/commands/typecmds.c | |
parent | bd157821649ae203b9c8ce8daf4ec027a0003351 (diff) | |
download | postgresql-aa1110624c08298393dfce996f7b21809d98d3fd.tar.gz postgresql-aa1110624c08298393dfce996f7b21809d98d3fd.zip |
Adjust permissions checking for ALTER OWNER commands: instead of
requiring superuserness always, allow an owner to reassign ownership
to any role he is a member of, if that role would have the right to
create a similar object. These three requirements essentially state
that the would-be alterer has enough privilege to DROP the existing
object and then re-CREATE it as the new role; so we might as well
let him do it in one step. The ALTER TABLESPACE case is a bit
squirrely, but the whole concept of non-superuser tablespace owners
is pretty dubious anyway. Stephen Frost, code review by Tom Lane.
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r-- | src/backend/commands/typecmds.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 7406e15376a..0979e8aeec2 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.75 2005/07/10 21:13:58 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.76 2005/07/14 21:46:29 tgl Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -2025,6 +2025,7 @@ AlterTypeOwner(List *names, Oid newOwnerId) Relation rel; HeapTuple tup; Form_pg_type typTup; + AclResult aclresult; /* Make a TypeName so we can use standard type lookup machinery */ typename = makeNode(TypeName); @@ -2067,11 +2068,20 @@ AlterTypeOwner(List *names, Oid newOwnerId) */ if (typTup->typowner != newOwnerId) { - /* Otherwise, must be superuser to change object ownership */ - if (!superuser()) - ereport(ERROR, - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser to change owner"))); + /* Otherwise, must be owner of the existing object */ + if (!pg_type_ownercheck(HeapTupleGetOid(tup),GetUserId())) + aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE, + TypeNameToString(typename)); + + /* 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(typTup->typnamespace, newOwnerId, + ACL_CREATE); + if (aclresult != ACLCHECK_OK) + aclcheck_error(aclresult, ACL_KIND_NAMESPACE, + get_namespace_name(typTup->typnamespace)); /* * Modify the owner --- okay to scribble on typTup because it's a |