8000 Fix REASSIGN OWNED for text search objects · patchsoft/postgres@4b76778 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b76778

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 bae0b5c commit 4b76778

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
@@ -31,6 +31,8 @@
3131
#include "catalog/pg_proc.h"
3232
#include "catalog/pg_shdepend.h"
3333
#include "catalog/pg_tablespace.h"
34+
#include "catalog/pg_ts_config.h"
35+
#include "catalog/pg_ts_dict.h"
3436
#include "catalog/pg_type.h"
3537
#include "commands/conversioncmds.h"
3638
#include "commands/defrem.h"
@@ -1381,6 +1383,14 @@ shdepReassignOwned(List *roleids, Oid newrole)
13811383
AlterOpFamilyOwner_oid(sdepForm->objid, newrole);
13821384
break;
13831385

1386+
case TSConfigRelationId:
1387+
AlterTSConfigurationOwner_oid(sdepForm->objid, newrole);
1388+
break;
1389+
1390+
case TSDictionaryRelationId:
1391+
AlterTSDictionaryOwner_oid(sdepForm->objid, newrole);
1392+
break;
1393+
13841394
default:
13851395
elog(ERROR, "unexpected classid %d", sdepForm->classid);
13861396
break;

src/backend/commands/tsearchcmds.c

Lines changed: 70 additions & 22 deletions
< AC01 /tr>
Original file line numberDiff line numberDiff line change
@@ -843,22 +843,16 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
843843
}
844844

845845
/*
846-
* ALTER TEXT SEARCH DICTIONARY OWNER
846+
* Internal routine for changing the owner of a text search dictionary
847847
*/
848-
void
849-
AlterTSDictionaryOwner(List *name, Oid newOwnerId)
848+
static void
849+
AlterTSDictionaryOwner_internal(Relation rel, Oid dictId, Oid newOwnerId)
850850
{
851851
HeapTuple tup;
852-
Relation rel;
853-
Oid dictId;
854852
Oid namespaceOid;
855853
AclResult aclresult;
856854
Form_pg_ts_dict form;
857855

858-
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
859-
860-
dictId = TSDictionaryGetDictid(name, false);
861-
862856
tup = SearchSysCacheCopy(TSDICTOID,
863857
ObjectIdGetDatum(dictId),
864858
0, 0, 0);
@@ -878,7 +872,7 @@ AlterTSDictionaryOwner(List *name, Oid newOwnerId)
878872
/* must be owner */
879873
if (!pg_ts_dict_ownercheck(dictId, GetUserId()))
880874
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSDICTIONARY,
881-
NameListToString(name));
875+
NameStr(form->dictname));
882876

883877
/* Must be able to become new owner */
884878
check_is_member_of_role(GetUserId(), newOwnerId);
@@ -900,10 +894,41 @@ AlterTSDictionaryOwner(List *name, Oid newOwnerId)
900894
newOwnerId);
901895
}
902896

903-
heap_close(rel, NoLock);
904897
heap_freetuple(tup);
905898
}
906899

900+
/*
901+
* ALTER TEXT SEARCH DICTIONARY OWNER
902+
*/
903+
void
904+
AlterTSDictionaryOwner(List *name, Oid newOwnerId)
905+
{
906+
Relation rel;
907+
Oid dictId;
908+
909+
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
910+
dictId = TSDictionaryGetDictid(name, false);
911+
912+
AlterTSDictionaryOwner_internal(rel, dictId, newOwnerId);
913+
914+
heap_close(rel, NoLock);
915+
}
916+
917+
/*
918+
* Change text search dictionary owner, by OID
919+
*/
920+
void
921+
AlterTSDictionaryOwner_oid(Oid dictId, Oid newOwnerId)
922+
{
923+
Relation rel;
924+
925+
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
926+
927+
AlterTSDictionaryOwner_internal(rel, dictId, newOwnerId);
928+
929+
heap_close(rel, NoLock);
930+
}
931+
907932
/* ---------------------- TS Template commands -----------------------*/
908933

909934
/*
@@ -1644,22 +1669,16 @@ RemoveTSConfigurationById(Oid cfgId)
16441669
}
16451670

16461671
/*
1647-
* ALTER TEXT SEARCH CONFIGURATION OWNER
1672+
* Internal routine for changing the owner of a text search configuration
16481673
*/
1649-
void
1650-
AlterTSConfigurationOwner(List *name, Oid newOwnerId)
1674+
static void
1675+
AlterTSConfigurationOwner_internal(Relation rel, Oid cfgId, Oid newOwnerId)
16511676
{
16521677
HeapTuple tup;
1653-
Relation rel;
1654-
Oid cfgId;
16551678
AclResult aclresult;
16561679
Oid namespaceOid;
16571680
Form_pg_ts_config form;
16581681

1659-
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
1660-
1661-
cfgId = TSConfigGetCfgid(name, false);
1662-
16631682
tup = SearchSysCacheCopy(TSCONFIGOID,
16641683
ObjectIdGetDatum(cfgId),
16651684
0, 0, 0);
@@ -1679,7 +1698,7 @@ AlterTSConfigurationOwner(List *name, Oid newOwnerId)
16791698
/* must be owner */
16801699
if (!pg_ts_config_ownercheck(cfgId, GetUserId()))
16811700
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION,
1682-
NameListToString(name));
1701+
NameStr(form->cfgname));
16831702

16841703
/* Must be able to become new owner */
16851704
check_is_member_of_role(GetUserId(), newOwnerId);
@@ -1701,10 +1720,39 @@ AlterTSConfigurationOwner(List *name, Oid newOwnerId)
17011720
newOwnerId);
17021721
}
17031722

1704-
heap_close(rel, NoLock);
17051723
heap_freetuple(tup);
17061724
}
17071725

1726+
/*
1727+
* ALTER TEXT SEARCH CONFIGURATION OWNER
1728+
*/
1729+
void
1730+
AlterTSConfigurationOwner(List *name, Oid newOwnerId)
1731+
{
1732+
Relation rel;
1733+
Oid cfgId;
1734+
1735+
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
1736+
cfgId = TSConfigGetCfgid(name, false);
1737+
1738+
AlterTSConfigurationOwner_internal(rel, cfgId, newOwnerId);
1739+
1740+
heap_close(rel, NoLock);
1741+
}
1742+
1743+
void
1744+
AlterTSConfigurationOwner_oid(Oid cfgId, Oid newOwnerId)
1745+
{
1746+
Relation rel;
1747+
1748+
rel = heap_open(TSConfigRelationId, RowExclusiveLock);
1749+
1750+
AlterTSConfigurationOwner_internal(rel, cfgId, newOwnerId);
1751+
1752+
heap_close(rel, NoLock);
1753+
}
1754+
1755+
17081756
/*
17091757
* ALTER TEXT SEARCH CONFIGURATION - main entry point
17101758
*/

src/include/commands/defrem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ extern void RemoveTSDictionaries(DropStmt *drop);
104104
extern void RemoveTSDictionaryById(Oid dictId);
105105
extern void AlterTSDictionary(AlterTSDictionaryStmt *stmt);
106106
extern void AlterTSDictionaryOwner(List *name, Oid newOwnerId);
107+
extern void AlterTSDictionaryOwner_oid(Oid dictId, Oid newOwnerId);
107108

108109
extern void DefineTSTemplate(List *names, List *parameters);
109110
extern void RenameTSTemplate(List *oldname, const char *newname);
@@ -116,6 +117,7 @@ extern void RemoveTSConfigurations(DropStmt *stmt);
116117
extern void RemoveTSConfigurationById(Oid cfgId);
117118
extern void AlterTSConfiguration(AlterTSConfigurationStmt *stmt);
118119
extern void AlterTSConfigurationOwner(List *name, Oid newOwnerId);
120+
extern void AlterTSConfigurationOwner_oid(Oid cfgId, Oid newOwnerId);
119121

120122
extern text *serialize_deflist(List *deflist);
121123
extern List *deserialize_deflist(Datum txt);

0 commit comments

Comments
 (0)
0