Skip to content

Commit bf08864

Browse files
committed
Fix REASSIGN OWNED for text search objects
Trying to reassign objects owned by a user that had text search dictionaries or configurations used to fail with: ERROR: unexpected classid 3600 or ERROR: unexpected classid 3602 Fix by adding cases for those object types in a switch in pg_shdepend.c. Both REASSIGN OWNED and text search objects go back all the way to 8.1, so backpatch to all supported branches. In 9.3 the alter-owner code was made generic, so the required change in recent branches is pretty simple; however, for 9.2 and older ones we need some additional reshuffling to enable specifying objects by OID rather than name. Text search templates and parsers are not owned objects, so there's no change required for them. Per bug #9749 reported by Michal Novotný
1 parent 8b300ce commit bf08864

File tree

3 files changed

+82
-22
lines changed

3 files changed

+82
-22
lines changed

src/backend/catalog/pg_shdepend.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "catalog/pg_proc.h"
3636
#include "catalog/pg_shdepend.h"
3737
#include "catalog/pg_tablespace.h"
38+
#include "catalog/pg_ts_config.h"
39+
#include "catalog/pg_ts_dict.h"
3840
#include "catalog/pg_type.h"
3941
#include "commands/dbcommands.h"
4042
#include "commands/conversioncmds.h"
@@ -1393,6 +1395,14 @@ shdepReassignOwned(List *roleids, Oid newrole)
13931395
AlterForeignDataWrapperOwner_oid(sdepForm->objid, newrole);
13941396
break;
13951397

1398+
case TSConfigRelationId:
1399+
AlterTSConfigurationOwner_oid(sdepForm->objid, newrole);
1400+
break;
1401+
1402+
case TSDictionaryRelationId:
1403+
AlterTSDictionaryOwner_oid(sdepForm->objid, newrole);
1404+
break;
1405+
13961406
default:
13971407
elog(ERROR, "unexpected classid %u", sdepForm->classid);
13981408
break;

src/backend/commands/tsearchcmds.c

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -827,22 +827,16 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
827827
}
828828

829829
/*
830-
* ALTER TEXT SEARCH DICTIONARY OWNER
830+
* Internal routine for changing the owner of a text search dictionary
831831
*/
832-
void
833-
AlterTSDictionaryOwner(List *name, Oid newOwnerId)
832+
static void
833+
AlterTSDictionaryOwner_internal(Relation rel, Oid dictId, Oid newOwnerId)
834834
{
835835
HeapTuple tup;
836-
Relation rel;
837-
Oid dictId;
838836
Oid namespaceOid;
839837
AclResult aclresult;
840838
Form_pg_ts_dict form;
841839

842-
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
843-
844-
dictId = TSDictionaryGetDictid(name, false);
845-
846840
tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId));
847841

848842
if (!HeapTupleIsValid(tup)) /* should not happen */
@@ -860,7 +854,7 @@ AlterTSDictionaryOwner(List *name, Oid newOwnerId)
860854
/* must be owner */
861855
if (!pg_ts_dict_ownercheck(dictId, GetUserId()))
862856
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSDICTIONARY,
863-
NameListToString(name));
857+
NameStr(form->dictname));
864858

865859
/* Must be able to become new owner */
866860
check_is_member_of_role(GetUserId(), newOwnerId);
@@ -882,10 +876,41 @@ AlterTSDictionaryOwner(List *name, Oid newOwnerId)
882876
newOwnerId);
883877
}
884878

885-
heap_close(rel, NoLock);
886879
heap_freetuple(tup);
887880
}
888881

882+
/*
883+
* ALTER TEXT SEARCH DICTIONARY OWNER
884+
*/
885+
void
886+
AlterTSDictionaryOwner(List *name, Oid newOwnerId)
887+
{
888+
Relation rel;
889+
Oid dictId;
890+
891+
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
892+
dictId = TSDictionaryGetDictid(name, false);
893+
894+
AlterTSDictionaryOwner_internal(rel, dictId, newOwnerId);
895+
896+
heap_close(rel, NoLock);
897+
}
898+
899+
/*
900+
* Change text search dictionary owner, by OID
901+
*/
902+
void
903+
AlterTSDictionaryOwner_oid(Oid dictId, Oid newOwnerId)
904+
{
905+
Relation rel;
906+
907+
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
908+
909+
AlterTSDictionaryOwner_internal(rel, dictId, newOwnerId);
910+
911+
heap_close(rel, NoLock);
912+
}
913+
889914
/* ---------------------- TS Template commands -----------------------*/
890915

891916
/*
@@ -1612,22 +1637,16 @@ RemoveTSConfigurationById(Oid cfgId)
16121637
}
16131638

16141639
/*
1615-
* ALTER TEXT SEARCH CONFIGURATION OWNER
1640+
* Internal routine for changing the owner of a text search configuration
16161641
*/
1617-
void
1618-
AlterTSConfigurationOwner(List *name, Oid newOwnerId)
1642+
static void
1643+
AlterTSConfigurationOwner_internal(Relation rel, Oid cfgId, Oid newOwnerId)
16191644
{
16201645
HeapTuple tup;
1621-
Relation rel;
1622-
Oid cfgId;
16231646
AclResult aclresult;
16241647
Oid namespaceOid;
16251648
Form_pg_ts_config form;
16261649

1627-
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
1628-
1629-
cfgId = TSConfigGetCfgid(name, false);
1630-
16311650
tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
16321651

16331652
if (!HeapTupleIsValid(tup)) /* should not happen */
@@ -1645,7 +1664,7 @@ AlterTSConfigurationOwner(List *name, Oid newOwnerId)
16451664
/* must be owner */
16461665
if (!pg_ts_config_ownercheck(cfgId, GetUserId()))
16471666
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION,
1648-
NameListToString(name));
1667+
NameStr(form->cfgname));
16491668

16501669
/* Must be able to become new owner */
16511670
check_is_member_of_role(GetUserId(), newOwnerId);
@@ -1667,10 +1686,39 @@ AlterTSConfigurationOwner(List *name, Oid newOwnerId)
16671686
newOwnerId);
16681687
}
16691688

1670-
heap_close(rel, NoLock);
16711689
heap_freetuple(tup);
16721690
}
16731691

1692+
/*
1693+
* ALTER TEXT SEARCH CONFIGURATION OWNER
1694+
*/
1695+
void
1696+
AlterTSConfigurationOwner(List *name, Oid newOwnerId)
1697+
{
1698+
Relation rel;
1699+
Oid cfgId;
1700+
1701+
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
1702+
cfgId = TSConfigGetCfgid(name, false);
1703+
1704+
AlterTSConfigurationOwner_internal(rel, cfgId, newOwnerId);
1705+
1706+
heap_close(rel, NoLock);
1707+
}
1708+
1709+
void
1710+
AlterTSConfigurationOwner_oid(Oid cfgId, Oid newOwnerId)
1711+
{
1712+
Relation rel;
1713+
1714+
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
1715+
1716+
AlterTSConfigurationOwner_internal(rel, cfgId, newOwnerId);
1717+
1718+
heap_close(rel, NoLock);
1719+
}
1720+
1721+
16741722
/*
16751723
* ALTER TEXT SEARCH CONFIGURATION - main entry point
16761724
*/

src/include/commands/defrem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ extern void RemoveTSDictionaries(DropStmt *drop);
112112
extern void RemoveTSDictionaryById(Oid dictId);
113113
extern void AlterTSDictionary(AlterTSDictionaryStmt *stmt);
114114
extern void AlterTSDictionaryOwner(List *name, Oid newOwnerId);
115+
extern void AlterTSDictionaryOwner_oid(Oid dictId, Oid newOwnerId);
115116

116117
extern void DefineTSTemplate(List *names, List *parameters);
117118
extern void RenameTSTemplate(List *oldname, const char *newname);
@@ -124,6 +125,7 @@ extern void RemoveTSConfigurations(DropStmt *stmt);
124125
extern void RemoveTSConfigurationById(Oid cfgId);
125126
extern void AlterTSConfiguration(AlterTSConfigurationStmt *stmt);
126127
extern void AlterTSConfigurationOwner(List *name, Oid newOwnerId);
128+
extern void AlterTSConfigurationOwner_oid(Oid cfgId, Oid newOwnerId);
127129

128130
extern text *serialize_deflist(List *deflist);
129131
extern List *deserialize_deflist(Datum txt);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy