1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

refactor ALTER some-obj SET OWNER implementation

Remove duplicate implementation of catalog munging and miscellaneous
privilege and consistency checks.  Instead rely on already existing data
in objectaddress.c to do the work.

Author: KaiGai Kohei
Tweaked by me
Reviewed by Robert Haas
This commit is contained in:
Alvaro Herrera
2012-10-03 18:02:38 -03:00
parent 1f91c8ca1d
commit 994c36e01d
24 changed files with 270 additions and 1338 deletions

View File

@ -716,66 +716,6 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
heap_close(rel, RowExclusiveLock);
}
/*
* ALTER TEXT SEARCH DICTIONARY OWNER
*/
void
AlterTSDictionaryOwner(List *name, Oid newOwnerId)
{
HeapTuple tup;
Relation rel;
Oid dictId;
Oid namespaceOid;
AclResult aclresult;
Form_pg_ts_dict form;
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
dictId = get_ts_dict_oid(name, false);
tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId));
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "cache lookup failed for text search dictionary %u",
dictId);
form = (Form_pg_ts_dict) GETSTRUCT(tup);
namespaceOid = form->dictnamespace;
if (form->dictowner != newOwnerId)
{
/* Superusers can always do it */
if (!superuser())
{
/* must be owner */
if (!pg_ts_dict_ownercheck(dictId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSDICTIONARY,
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(namespaceOid, newOwnerId, ACL_CREATE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
get_namespace_name(namespaceOid));
}
form->dictowner = newOwnerId;
simple_heap_update(rel, &tup->t_self, tup);
CatalogUpdateIndexes(rel, tup);
/* Update owner dependency reference */
changeDependencyOnOwner(TSDictionaryRelationId, HeapTupleGetOid(tup),
newOwnerId);
}
heap_close(rel, NoLock);
heap_freetuple(tup);
}
/* ---------------------- TS Template commands -----------------------*/
/*
@ -1390,66 +1330,6 @@ RemoveTSConfigurationById(Oid cfgId)
heap_close(relMap, RowExclusiveLock);
}
/*
* ALTER TEXT SEARCH CONFIGURATION OWNER
*/
void
AlterTSConfigurationOwner(List *name, Oid newOwnerId)
{
HeapTuple tup;
Relation rel;
Oid cfgId;
AclResult aclresult;
Oid namespaceOid;
Form_pg_ts_config form;
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
cfgId = get_ts_config_oid(name, false);
tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "cache lookup failed for text search configuration %u",
cfgId);
form = (Form_pg_ts_config) GETSTRUCT(tup);
namespaceOid = form->cfgnamespace;
if (form->cfgowner != newOwnerId)
{
/* Superusers can always do it */
if (!superuser())
{
/* must be owner */
if (!pg_ts_config_ownercheck(cfgId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION,
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(namespaceOid, newOwnerId, ACL_CREATE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
get_namespace_name(namespaceOid));
}
form->cfgowner = newOwnerId;
simple_heap_update(rel, &tup->t_self, tup);
CatalogUpdateIndexes(rel, tup);
/* Update owner dependency reference */
changeDependencyOnOwner(TSConfigRelationId, HeapTupleGetOid(tup),
newOwnerId);
}
heap_close(rel, NoLock);
heap_freetuple(tup);
}
/*
* ALTER TEXT SEARCH CONFIGURATION - main entry point
*/