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

Commitc31224e

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 parentcbe24a6 commitc31224e

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
@@ -357,6 +357,8 @@ static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab, LOCKMOD
357357
staticvoidATPostAlterTypeParse(OidoldId,char*cmd,
358358
List**wqueue,LOCKMODElockmode,boolrewrite);
359359
staticvoidTryReuseIndex(OidoldId,IndexStmt*stmt);
360+
staticvoidchange_owner_fix_column_acls(OidrelationOid,
361+
OidoldOwnerId,OidnewOwnerId);
360362
staticvoidchange_owner_recurse_to_sequences(OidrelationOid,
361363
OidnewOwnerId,LOCKMODElockmode);
362364
staticvoidATExecClusterOn(Relationrel,constchar*indexName,LOCKMODElockmode);
@@ -8008,6 +8010,14 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lock
80088010

80098011
heap_freetuple(newtuple);
80108012

8013+
/*
8014+
* We must similarly update any per-column ACLs to reflect the new
8015+
* owner; for neatness reasons that's split out as a subroutine.
8016+
*/
8017+
change_owner_fix_column_acls(relationOid,
8018+
tuple_class->relowner,
8019+
newOwnerId);
8020+
80118021
/*
80128022
* Update owner dependency reference, if any. A composite type has
80138023
* none, because it's tracked for the pg_type entry instead of here;
@@ -8064,6 +8074,71 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lock
80648074
relation_close(target_rel,NoLock);
80658075
}
80668076

8077+
/*
8078+
* change_owner_fix_column_acls
8079+
*
8080+
* Helper function for ATExecChangeOwner. Scan the columns of the table
8081+
* and fix any non-null column ACLs to reflect the new owner.
8082+
*/
8083+
staticvoid
8084+
change_owner_fix_column_acls(OidrelationOid,OidoldOwnerId,OidnewOwnerId)
8085+
{
8086+
RelationattRelation;
8087+
SysScanDescscan;
8088+
ScanKeyDatakey[1];
8089+
HeapTupleattributeTuple;
8090+
8091+
attRelation=heap_open(AttributeRelationId,RowExclusiveLock);
8092+
ScanKeyInit(&key[0],
8093+
Anum_pg_attribute_attrelid,
8094+
BTEqualStrategyNumber,F_OIDEQ,
8095+
ObjectIdGetDatum(relationOid));
8096+
scan=systable_beginscan(attRelation,AttributeRelidNumIndexId,
8097+
true,SnapshotNow,1,key);
8098+
while (HeapTupleIsValid(attributeTuple=systable_getnext(scan)))
8099+
{
8100+
Form_pg_attributeatt= (Form_pg_attribute)GETSTRUCT(attributeTuple);
8101+
Datumrepl_val[Natts_pg_attribute];
8102+
boolrepl_null[Natts_pg_attribute];
8103+
boolrepl_repl[Natts_pg_attribute];
8104+
Acl*newAcl;
8105+
DatumaclDatum;
8106+
boolisNull;
8107+
HeapTuplenewtuple;
8108+
8109+
/* Ignore dropped columns */
8110+
if (att->attisdropped)
8111+
continue;
8112+
8113+
aclDatum=heap_getattr(attributeTuple,
8114+
Anum_pg_attribute_attacl,
8115+
RelationGetDescr(attRelation),
8116+
&isNull);
8117+
/* Null ACLs do not require changes */
8118+
if (isNull)
8119+
continue;
8120+
8121+
memset(repl_null, false,sizeof(repl_null));
8122+
memset(repl_repl, false,sizeof(repl_repl));
8123+
8124+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
8125+
oldOwnerId,newOwnerId);
8126+
repl_repl[Anum_pg_attribute_attacl-1]= true;
8127+
repl_val[Anum_pg_attribute_attacl-1]=PointerGetDatum(newAcl);
8128+
8129+
newtuple=heap_modify_tuple(attributeTuple,
8130+
RelationGetDescr(attRelation),
8131+
repl_val,repl_null,repl_repl);
8132+
8133+
simple_heap_update(attRelation,&newtuple->t_self,newtuple);
8134+
CatalogUpdateIndexes(attRelation,newtuple);
8135+
8136+
heap_freetuple(newtuple);
8137+
}
8138+
systable_endscan(scan);
8139+
heap_close(attRelation,RowExclusiveLock);
8140+
}
8141+
80678142
/*
80688143
* change_owner_recurse_to_sequences
80698144
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp