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

Commit7443ab2

Browse files
committed
Update per-column ACLs, not only per-table ACL, when changing table owner.
We forgot to modify column ACLs, so privileges were still shown as havingbeen granted by the old owner. This meant that neither the new owner nora superuser could revoke the now-untraceable-to-table-owner permissions.Per bug #6350 from Marc Balmer.This has been wrong since column ACLs were added, so back-patch to 8.4.
1 parent61dd2ff commit7443ab2

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ static void ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
316316
constchar*colName,TypeName*typeName);
317317
staticvoidATPostAlterTypeCleanup(List**wqueue,AlteredTableInfo*tab);
318318
staticvoidATPostAlterTypeParse(char*cmd,List**wqueue);
319+
staticvoidchange_owner_fix_column_acls(OidrelationOid,
320+
OidoldOwnerId,OidnewOwnerId);
319321
staticvoidchange_owner_recurse_to_sequences(OidrelationOid,
320322
OidnewOwnerId);
321323
staticvoidATExecClusterOn(Relationrel,constchar*indexName);
@@ -6644,6 +6646,14 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing)
66446646

66456647
heap_freetuple(newtuple);
66466648

6649+
/*
6650+
* We must similarly update any per-column ACLs to reflect the new
6651+
* owner; for neatness reasons that's split out as a subroutine.
6652+
*/
6653+
change_owner_fix_column_acls(relationOid,
6654+
tuple_class->relowner,
6655+
newOwnerId);
6656+
66476657
/*
66486658
* Update owner dependency reference, if any. A composite type has
66496659
* none, because it's tracked for the pg_type entry instead of here;
@@ -6700,6 +6710,71 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing)
67006710
relation_close(target_rel,NoLock);
67016711
}
67026712

6713+
/*
6714+
* change_owner_fix_column_acls
6715+
*
6716+
* Helper function for ATExecChangeOwner. Scan the columns of the table
6717+
* and fix any non-null column ACLs to reflect the new owner.
6718+
*/
6719+
staticvoid
6720+
change_owner_fix_column_acls(OidrelationOid,OidoldOwnerId,OidnewOwnerId)
6721+
{
6722+
RelationattRelation;
6723+
SysScanDescscan;
6724+
ScanKeyDatakey[1];
6725+
HeapTupleattributeTuple;
6726+
6727+
attRelation=heap_open(AttributeRelationId,RowExclusiveLock);
6728+
ScanKeyInit(&key[0],
6729+
Anum_pg_attribute_attrelid,
6730+
BTEqualStrategyNumber,F_OIDEQ,
6731+
ObjectIdGetDatum(relationOid));
6732+
scan=systable_beginscan(attRelation,AttributeRelidNumIndexId,
6733+
true,SnapshotNow,1,key);
6734+
while (HeapTupleIsValid(attributeTuple=systable_getnext(scan)))
6735+
{
6736+
Form_pg_attributeatt= (Form_pg_attribute)GETSTRUCT(attributeTuple);
6737+
Datumrepl_val[Natts_pg_attribute];
6738+
boolrepl_null[Natts_pg_attribute];
6739+
boolrepl_repl[Natts_pg_attribute];
6740+
Acl*newAcl;
6741+
DatumaclDatum;
6742+
boolisNull;
6743+
HeapTuplenewtuple;
6744+
6745+
/* Ignore dropped columns */
6746+
if (att->attisdropped)
6747+
continue;
6748+
6749+
aclDatum=heap_getattr(attributeTuple,
6750+
Anum_pg_attribute_attacl,
6751+
RelationGetDescr(attRelation),
6752+
&isNull);
6753+
/* Null ACLs do not require changes */
6754+
if (isNull)
6755+
continue;
6756+
6757+
memset(repl_null, false,sizeof(repl_null));
6758+
memset(repl_repl, false,sizeof(repl_repl));
6759+
6760+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
6761+
oldOwnerId,newOwnerId);
6762+
repl_repl[Anum_pg_attribute_attacl-1]= true;
6763+
repl_val[Anum_pg_attribute_attacl-1]=PointerGetDatum(newAcl);
6764+
6765+
newtuple=heap_modify_tuple(attributeTuple,
6766+
RelationGetDescr(attRelation),
6767+
repl_val,repl_null,repl_repl);
6768+
6769+
simple_heap_update(attRelation,&newtuple->t_self,newtuple);
6770+
CatalogUpdateIndexes(attRelation,newtuple);
6771+
6772+
heap_freetuple(newtuple);
6773+
}
6774+
systable_endscan(scan);
6775+
heap_close(attRelation,RowExclusiveLock);
6776+
}
6777+
67036778
/*
67046779
* change_owner_recurse_to_sequences
67056780
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp