diff options
| author | Alvaro Herrera | 2005-11-21 12:49:33 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2005-11-21 12:49:33 +0000 |
| commit | cec3b0a9e63fd94b05dac894cca8bfa51358afec (patch) | |
| tree | 464377c39a1b3f42b4d2ab82a261e9a603fa1220 /src/backend/commands/conversioncmds.c | |
| parent | c52795d18a698d25b9cd7cd1ca9318a42b08fdb9 (diff) | |
Implement DROP OWNED and REASSIGN OWNED. These new commands facilitate the
process of dropping roles by dropping objects owned by them and privileges
granted to them, or giving the owned objects to someone else, through the
use of the data stored in the new pg_shdepend catalog.
Some refactoring of the GRANT/REVOKE code was needed, as well as ALTER OWNER
code. Further cleanup of code duplication in the GRANT code seems necessary.
Implemented by me after an idea from Tom Lane, who also provided various kind
of implementation advice.
Regression tests pass. Some tests for the new functionality are also added,
as well as rudimentary documentation.
Diffstat (limited to 'src/backend/commands/conversioncmds.c')
| -rw-r--r-- | src/backend/commands/conversioncmds.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c index 97abc9fc774..42bb0853a10 100644 --- a/src/backend/commands/conversioncmds.c +++ b/src/backend/commands/conversioncmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.24 2005/11/19 17:39:44 adunstan Exp $ + * $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.25 2005/11/21 12:49:30 alvherre Exp $ * *------------------------------------------------------------------------- */ @@ -30,6 +30,8 @@ #include "utils/lsyscache.h" #include "utils/syscache.h" +static void AlterConversionOwner_internal(Relation rel, Oid conversionOid, + Oid newOwnerId); /* * CREATE CONVERSION @@ -185,16 +187,13 @@ RenameConversion(List *name, const char *newname) } /* - * Change conversion owner + * Change conversion owner, by name */ void AlterConversionOwner(List *name, Oid newOwnerId) { Oid conversionOid; - HeapTuple tup; Relation rel; - Form_pg_conversion convForm; - AclResult aclresult; rel = heap_open(ConversionRelationId, RowExclusiveLock); @@ -205,6 +204,40 @@ AlterConversionOwner(List *name, Oid newOwnerId) errmsg("conversion \"%s\" does not exist", NameListToString(name)))); + AlterConversionOwner_internal(rel, conversionOid, newOwnerId); + + heap_close(rel, NoLock); +} + +/* + * Change conversion owner, by oid + */ +void +AlterConversionOwner_oid(Oid conversionOid, Oid newOwnerId) +{ + Relation rel; + + rel = heap_open(ConversionRelationId, RowExclusiveLock); + + AlterConversionOwner_internal(rel, conversionOid, newOwnerId); + + heap_close(rel, NoLock); +} + +/* + * AlterConversionOwner_internal + * + * Internal routine for changing the owner. rel must be pg_conversion, already + * open and suitably locked; it will not be closed. + */ +static void +AlterConversionOwner_internal(Relation rel, Oid conversionOid, Oid newOwnerId) +{ + Form_pg_conversion convForm; + HeapTuple tup; + + Assert(RelationGetRelid(rel) == ConversionRelationId); + tup = SearchSysCacheCopy(CONOID, ObjectIdGetDatum(conversionOid), 0, 0, 0); @@ -219,13 +252,15 @@ AlterConversionOwner(List *name, Oid newOwnerId) */ if (convForm->conowner != newOwnerId) { + AclResult aclresult; + /* Superusers can always do it */ if (!superuser()) { /* Otherwise, must be owner of the existing object */ if (!pg_conversion_ownercheck(HeapTupleGetOid(tup), GetUserId())) aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CONVERSION, - NameListToString(name)); + NameStr(convForm->conname)); /* Must be able to become new owner */ check_is_member_of_role(GetUserId(), newOwnerId); @@ -253,6 +288,5 @@ AlterConversionOwner(List *name, Oid newOwnerId) newOwnerId); } - heap_close(rel, NoLock); heap_freetuple(tup); } |
