Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf73bed3

Browse files
committed
Repair a longstanding bug in CLUSTER and the rewriting variants of ALTER
TABLE: if the command is executed by someone other than the table owner (eg,a superuser) and the table has a toast table, the toast table's pg_type rowends up with the wrong typowner, ie, the command issuer not the table owner.This is quite harmless for most purposes, since no interesting permissionschecks consult the pg_type row. However, it could lead to unexpected failuresif one later tries to drop the role that issued the command (in 8.1 or 8.2),or strange warnings from pg_dump afterwards (in 8.3 and up, which will allowthe DROP ROLE because we don't create a "redundant" owner dependency for tablerowtypes). Problem identified by Cott Lang.Back-patch to 8.1. The problem is actually far older --- the CLUSTER variantcan be demonstrated in 7.0 --- but it's mostly cosmetic before 8.1 because wedidn't track ownership dependencies before 8.1. Also, fixing it before 8.1would require changing the call signature of heap_create_with_catalog(), whichseems to carry a nontrivial risk of breaking add-on modules.
1 parent7de7876 commitf73bed3

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

‎src/backend/catalog/heap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.350 2009/01/22 20:16:01 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.351 2009/02/24 01:38:09 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -79,6 +79,7 @@ static Oid AddNewRelationType(const char *typeName,
7979
OidtypeNamespace,
8080
Oidnew_rel_oid,
8181
charnew_rel_kind,
82+
Oidownerid,
8283
Oidnew_array_type);
8384
staticvoidRelationRemoveInheritance(Oidrelid);
8485
staticvoidStoreRelCheck(Relationrel,char*ccname,Node*expr,
@@ -784,6 +785,7 @@ AddNewRelationType(const char *typeName,
784785
OidtypeNamespace,
785786
Oidnew_rel_oid,
786787
charnew_rel_kind,
788+
Oidownerid,
787789
Oidnew_array_type)
788790
{
789791
return
@@ -792,6 +794,7 @@ AddNewRelationType(const char *typeName,
792794
typeNamespace,/* type namespace */
793795
new_rel_oid,/* relation oid */
794796
new_rel_kind,/* relation kind */
797+
ownerid,/* owner's ID */
795798
-1,/* internal size (varlena) */
796799
TYPTYPE_COMPOSITE,/* type-type (composite) */
797800
TYPCATEGORY_COMPOSITE,/* type-category (ditto) */
@@ -955,6 +958,7 @@ heap_create_with_catalog(const char *relname,
955958
relnamespace,
956959
relid,
957960
relkind,
961+
ownerid,
958962
new_array_oid);
959963

960964
/*
@@ -971,6 +975,7 @@ heap_create_with_catalog(const char *relname,
971975
relnamespace,/* Same namespace as parent */
972976
InvalidOid,/* Not composite, no relationOid */
973977
0,/* relkind, also N/A here */
978+
ownerid,/* owner's ID */
974979
-1,/* Internal size (varlena) */
975980
TYPTYPE_BASE,/* Not composite - typelem is */
976981
TYPCATEGORY_ARRAY,/* type-category (array) */

‎src/backend/catalog/pg_type.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.124 2009/01/22 20:16:01 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.125 2009/02/24 01:38:09 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -47,7 +47,7 @@
4747
* ----------------------------------------------------------------
4848
*/
4949
Oid
50-
TypeShellMake(constchar*typeName,OidtypeNamespace)
50+
TypeShellMake(constchar*typeName,OidtypeNamespace,OidownerId)
5151
{
5252
Relationpg_type_desc;
5353
TupleDesctupDesc;
@@ -87,7 +87,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace)
8787
namestrcpy(&name,typeName);
8888
values[i++]=NameGetDatum(&name);/* typname */
8989
values[i++]=ObjectIdGetDatum(typeNamespace);/* typnamespace */
90-
values[i++]=ObjectIdGetDatum(GetUserId());/* typowner */
90+
values[i++]=ObjectIdGetDatum(ownerId);/* typowner */
9191
values[i++]=Int16GetDatum(sizeof(int4));/* typlen */
9292
values[i++]=BoolGetDatum(true);/* typbyval */
9393
values[i++]=CharGetDatum(TYPTYPE_PSEUDO);/* typtype */
@@ -134,7 +134,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace)
134134
typoid,
135135
InvalidOid,
136136
0,
137-
GetUserId(),
137+
ownerId,
138138
F_SHELL_IN,
139139
F_SHELL_OUT,
140140
InvalidOid,
@@ -173,6 +173,7 @@ TypeCreate(Oid newTypeOid,
173173
OidtypeNamespace,
174174
OidrelationOid,/* only for relation rowtypes */
175175
charrelationKind,/* ditto */
176+
OidownerId,
176177
int16internalSize,
177178
chartypeType,
178179
chartypeCategory,
@@ -310,7 +311,7 @@ TypeCreate(Oid newTypeOid,
310311
namestrcpy(&name,typeName);
311312
values[i++]=NameGetDatum(&name);/* typname */
312313
values[i++]=ObjectIdGetDatum(typeNamespace);/* typnamespace */
313-
values[i++]=ObjectIdGetDatum(GetUserId());/* typowner */
314+
values[i++]=ObjectIdGetDatum(ownerId);/* typowner */
314315
values[i++]=Int16GetDatum(internalSize);/* typlen */
315316
values[i++]=BoolGetDatum(passedByValue);/* typbyval */
316317
values[i++]=CharGetDatum(typeType);/* typtype */
@@ -380,7 +381,7 @@ TypeCreate(Oid newTypeOid,
380381
/*
381382
* shell type must have been created by same owner
382383
*/
383-
if (((Form_pg_type)GETSTRUCT(tup))->typowner!=GetUserId())
384+
if (((Form_pg_type)GETSTRUCT(tup))->typowner!=ownerId)
384385
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_TYPE,typeName);
385386

386387
/* trouble if caller wanted to force the OID */
@@ -426,7 +427,7 @@ TypeCreate(Oid newTypeOid,
426427
typeObjectId,
427428
relationOid,
428429
relationKind,
429-
GetUserId(),
430+
ownerId,
430431
inputProcedure,
431432
outputProcedure,
432433
receiveProcedure,

‎src/backend/commands/functioncmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.107 2009/01/06 02:01:27 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.108 2009/02/2401:38:09 tgl Exp $
1414
*
1515
* DESCRIPTION
1616
* These routines take the parse tree and pick out the
@@ -144,7 +144,7 @@ compute_return_type(TypeName *returnType, Oid languageOid,
144144
if (aclresult!=ACLCHECK_OK)
145145
aclcheck_error(aclresult,ACL_KIND_NAMESPACE,
146146
get_namespace_name(namespaceId));
147-
rettype=TypeShellMake(typname,namespaceId);
147+
rettype=TypeShellMake(typname,namespaceId,GetUserId());
148148
Assert(OidIsValid(rettype));
149149
}
150150

‎src/backend/commands/typecmds.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.131 2009/02/02 19:31:39 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.132 2009/02/24 01:38:09 tgl Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -199,7 +199,7 @@ DefineType(List *names, List *parameters)
199199
*/
200200
if (!OidIsValid(typoid))
201201
{
202-
typoid=TypeShellMake(typeName,typeNamespace);
202+
typoid=TypeShellMake(typeName,typeNamespace,GetUserId());
203203
/* Make new shell type visible for modification below */
204204
CommandCounterIncrement();
205205

@@ -536,6 +536,7 @@ DefineType(List *names, List *parameters)
536536
typeNamespace,/* namespace */
537537
InvalidOid,/* relation oid (n/a here) */
538538
0,/* relation kind (ditto) */
539+
GetUserId(),/* owner's ID */
539540
internalLength,/* internal size */
540541
TYPTYPE_BASE,/* type-type (base type) */
541542
category,/* type-category */
@@ -574,6 +575,7 @@ DefineType(List *names, List *parameters)
574575
typeNamespace,/* namespace */
575576
InvalidOid,/* relation oid (n/a here) */
576577
0,/* relation kind (ditto) */
578+
GetUserId(),/* owner's ID */
577579
-1,/* internal size (always varlena) */
578580
TYPTYPE_BASE,/* type-type (base type) */
579581
TYPCATEGORY_ARRAY,/* type-category (array) */
@@ -1018,6 +1020,7 @@ DefineDomain(CreateDomainStmt *stmt)
10181020
domainNamespace,/* namespace */
10191021
InvalidOid,/* relation oid (n/a here) */
10201022
0,/* relation kind (ditto) */
1023+
GetUserId(),/* owner's ID */
10211024
internalLength,/* internal size */
10221025
TYPTYPE_DOMAIN,/* type-type (domain type) */
10231026
category,/* type-category */
@@ -1131,6 +1134,7 @@ DefineEnum(CreateEnumStmt *stmt)
11311134
enumNamespace,/* namespace */
11321135
InvalidOid,/* relation oid (n/a here) */
11331136
0,/* relation kind (ditto) */
1137+
GetUserId(),/* owner's ID */
11341138
sizeof(Oid),/* internal size */
11351139
TYPTYPE_ENUM,/* type-type (enum type) */
11361140
TYPCATEGORY_ENUM,/* type-category (enum type) */
@@ -1169,6 +1173,7 @@ DefineEnum(CreateEnumStmt *stmt)
11691173
enumNamespace,/* namespace */
11701174
InvalidOid,/* relation oid (n/a here) */
11711175
0,/* relation kind (ditto) */
1176+
GetUserId(),/* owner's ID */
11721177
-1,/* internal size (always varlena) */
11731178
TYPTYPE_BASE,/* type-type (base type) */
11741179
TYPCATEGORY_ARRAY,/* type-category (array) */

‎src/include/catalog/pg_type_fn.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_type_fn.h,v 1.3 2009/01/01 17:23:58 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_type_fn.h,v 1.4 2009/02/24 01:38:10 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -17,13 +17,16 @@
1717
#include"nodes/nodes.h"
1818

1919

20-
externOidTypeShellMake(constchar*typeName,OidtypeNamespace);
20+
externOidTypeShellMake(constchar*typeName,
21+
OidtypeNamespace,
22+
OidownerId);
2123

2224
externOidTypeCreate(OidnewTypeOid,
2325
constchar*typeName,
2426
OidtypeNamespace,
2527
OidrelationOid,
2628
charrelationKind,
29+
OidownerId,
2730
int16internalSize,
2831
chartypeType,
2932
chartypeCategory,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp