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

Commit2bfe015

Browse files
committed
Fix "unexpected relkind" error when denying permissions on toast tables.
get_relkind_objtype, and hence get_object_type, failed when applied to atoast table. This is not a good thing, because it prevents reporting ofperfectly legitimate permissions errors. (At present, these functionsare in fact *only* used to determine the ObjectType argument foracl_error() calls.) It seems best to have them fall back to returningOBJECT_TABLE in every case where they can't determine an object typefor a pg_class entry, so do that.In passing, make some edits to alter.c to make it more obvious thatthose calls of get_object_type() are used only for error reporting.This might save a few cycles in the non-error code path, too.Back-patch to v11 where this issue originated.John Hsu, Michael Paquier, Tom LaneDiscussion:https://postgr.es/m/C652D3DF-2B0C-4128-9420-FB5379F6B1E4@amazon.com
1 parent3574c0a commit2bfe015

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

‎src/backend/catalog/objectaddress.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,13 @@ get_object_attnum_acl(Oid class_id)
25642564
returnprop->attnum_acl;
25652565
}
25662566

2567+
/*
2568+
* get_object_type
2569+
*
2570+
* Return the object type associated with a given object. This routine
2571+
* is primarily used to determine the object type to mention in ACL check
2572+
* error messages, so it's desirable for it to avoid failing.
2573+
*/
25672574
ObjectType
25682575
get_object_type(Oidclass_id,Oidobject_id)
25692576
{
@@ -5274,6 +5281,16 @@ strlist_to_textarray(List *list)
52745281
returnarr;
52755282
}
52765283

5284+
/*
5285+
* get_relkind_objtype
5286+
*
5287+
* Return the object type for the relkind given by the caller.
5288+
*
5289+
* If an unexpected relkind is passed, we say OBJECT_TABLE rather than
5290+
* failing. That's because this is mostly used for generating error messages
5291+
* for failed ACL checks on relations, and we'd rather produce a generic
5292+
* message saying "table" than fail entirely.
5293+
*/
52775294
ObjectType
52785295
get_relkind_objtype(charrelkind)
52795296
{
@@ -5293,13 +5310,10 @@ get_relkind_objtype(char relkind)
52935310
returnOBJECT_MATVIEW;
52945311
caseRELKIND_FOREIGN_TABLE:
52955312
returnOBJECT_FOREIGN_TABLE;
5296-
5297-
/*
5298-
* other relkinds are not supported here because they don't map to
5299-
* OBJECT_* values
5300-
*/
5313+
caseRELKIND_TOASTVALUE:
5314+
returnOBJECT_TABLE;
53015315
default:
5302-
elog(ERROR,"unexpected relkind: %d",relkind);
5303-
return0;
5316+
/* Per above, don't raise an error */
5317+
returnOBJECT_TABLE;
53045318
}
53055319
}

‎src/backend/commands/alter.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
171171
AttrNumberAnum_name=get_object_attnum_name(classId);
172172
AttrNumberAnum_namespace=get_object_attnum_namespace(classId);
173173
AttrNumberAnum_owner=get_object_attnum_owner(classId);
174-
ObjectTypeobjtype=get_object_type(classId,objectId);
175174
HeapTupleoldtup;
176175
HeapTuplenewtup;
177176
Datumdatum;
@@ -223,7 +222,8 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
223222
ownerId=DatumGetObjectId(datum);
224223

225224
if (!has_privs_of_role(GetUserId(),DatumGetObjectId(ownerId)))
226-
aclcheck_error(ACLCHECK_NOT_OWNER,objtype,old_name);
225+
aclcheck_error(ACLCHECK_NOT_OWNER,get_object_type(classId,objectId),
226+
old_name);
227227

228228
/* User must have CREATE privilege on the namespace */
229229
if (OidIsValid(namespaceId))
@@ -663,7 +663,6 @@ AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
663663
AttrNumberAnum_name=get_object_attnum_name(classId);
664664
AttrNumberAnum_namespace=get_object_attnum_namespace(classId);
665665
AttrNumberAnum_owner=get_object_attnum_owner(classId);
666-
ObjectTypeobjtype=get_object_type(classId,objid);
667666
OidoldNspOid;
668667
Datumname,
669668
namespace;
@@ -719,7 +718,7 @@ AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
719718
ownerId=DatumGetObjectId(owner);
720719

721720
if (!has_privs_of_role(GetUserId(),ownerId))
722-
aclcheck_error(ACLCHECK_NOT_OWNER,objtype,
721+
aclcheck_error(ACLCHECK_NOT_OWNER,get_object_type(classId,objid),
723722
NameStr(*(DatumGetName(name))));
724723

725724
/* User must have CREATE privilege on new namespace */
@@ -942,8 +941,6 @@ AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
942941
/* Superusers can bypass permission checks */
943942
if (!superuser())
944943
{
945-
ObjectTypeobjtype=get_object_type(classId,objectId);
946-
947944
/* must be owner */
948945
if (!has_privs_of_role(GetUserId(),old_ownerId))
949946
{
@@ -963,7 +960,8 @@ AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
963960
HeapTupleGetOid(oldtup));
964961
objname=namebuf;
965962
}
966-
aclcheck_error(ACLCHECK_NOT_OWNER,objtype,objname);
963+
aclcheck_error(ACLCHECK_NOT_OWNER,get_object_type(classId,objectId),
964+
objname);
967965
}
968966
/* Must be able to become new owner */
969967
check_is_member_of_role(GetUserId(),new_ownerId);

‎src/test/regress/expected/create_index.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,8 +3134,17 @@ CREATE ROLE regress_reindexuser NOLOGIN;
31343134
SET SESSION ROLE regress_reindexuser;
31353135
REINDEX SCHEMA schema_to_reindex;
31363136
ERROR: must be owner of schema schema_to_reindex
3137+
-- Permission failures with toast tables and indexes (pg_proc's toast here)
3138+
RESET ROLE;
3139+
GRANT USAGE ON SCHEMA pg_toast TO regress_reindexuser;
3140+
SET SESSION ROLE regress_reindexuser;
3141+
REINDEX TABLE pg_toast.pg_toast_1255;
3142+
ERROR: must be owner of table pg_toast_1255
3143+
REINDEX INDEX pg_toast.pg_toast_1255_index;
3144+
ERROR: must be owner of index pg_toast_1255_index
31373145
-- Clean up
31383146
RESET ROLE;
3147+
REVOKE USAGE ON SCHEMA pg_toast FROM regress_reindexuser;
31393148
DROP ROLE regress_reindexuser;
31403149
\set VERBOSITY terse \\ -- suppress cascade details
31413150
DROP SCHEMA schema_to_reindex CASCADE;

‎src/test/regress/sql/create_index.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,16 @@ END;
11261126
CREATE ROLE regress_reindexuser NOLOGIN;
11271127
SET SESSION ROLE regress_reindexuser;
11281128
REINDEX SCHEMA schema_to_reindex;
1129+
-- Permission failures with toast tables and indexes (pg_proc's toast here)
1130+
RESET ROLE;
1131+
GRANT USAGEON SCHEMA pg_toast TO regress_reindexuser;
1132+
SET SESSION ROLE regress_reindexuser;
1133+
REINDEX TABLEpg_toast.pg_toast_1255;
1134+
REINDEX INDEXpg_toast.pg_toast_1255_index;
11291135

11301136
-- Clean up
11311137
RESET ROLE;
1138+
REVOKE USAGEON SCHEMA pg_toastFROM regress_reindexuser;
11321139
DROP ROLE regress_reindexuser;
11331140
\set VERBOSITY terse \\-- suppress cascade details
11341141
DROPSCHEMA schema_to_reindex CASCADE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp