From 994c36e01d19dece2b0c76fb781e1d08a6e1c814 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Wed, 3 Oct 2012 18:02:38 -0300 Subject: 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 --- src/backend/commands/tsearchcmds.c | 120 ------------------------------------- 1 file changed, 120 deletions(-) (limited to 'src/backend/commands/tsearchcmds.c') diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c index 8d2b4c09c93..e545e95a49e 100644 --- a/src/backend/commands/tsearchcmds.c +++ b/src/backend/commands/tsearchcmds.c @@ -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 */ -- cgit v1.2.3