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

Commit59367fd

Browse files
committed
adjust ACL owners for REASSIGN and ALTER OWNER TO
When REASSIGN and ALTER OWNER TO are used, both the object owner and ACLlist should be changed from the old owner to the new owner. This patchfixes types, foreign data wrappers, and foreign servers to change theirACL list properly; they already changed owners properly.BACKWARD INCOMPATIBILITY?Report by Alexey Bashtanov
1 parentb181a91 commit59367fd

File tree

3 files changed

+161
-64
lines changed

3 files changed

+161
-64
lines changed

‎src/backend/commands/foreigncmds.c

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ static void
225225
AlterForeignDataWrapperOwner_internal(Relationrel,HeapTupletup,OidnewOwnerId)
226226
{
227227
Form_pg_foreign_data_wrapperform;
228+
Datumrepl_val[Natts_pg_foreign_data_wrapper];
229+
boolrepl_null[Natts_pg_foreign_data_wrapper];
230+
boolrepl_repl[Natts_pg_foreign_data_wrapper];
231+
Acl*newAcl;
232+
DatumaclDatum;
233+
boolisNull;
228234

229235
form= (Form_pg_foreign_data_wrapper)GETSTRUCT(tup);
230236

@@ -246,7 +252,27 @@ AlterForeignDataWrapperOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerI
246252

247253
if (form->fdwowner!=newOwnerId)
248254
{
249-
form->fdwowner=newOwnerId;
255+
memset(repl_null, false,sizeof(repl_null));
256+
memset(repl_repl, false,sizeof(repl_repl));
257+
258+
repl_repl[Anum_pg_foreign_data_wrapper_fdwowner-1]= true;
259+
repl_val[Anum_pg_foreign_data_wrapper_fdwowner-1]=ObjectIdGetDatum(newOwnerId);
260+
261+
aclDatum=heap_getattr(tup,
262+
Anum_pg_foreign_data_wrapper_fdwacl,
263+
RelationGetDescr(rel),
264+
&isNull);
265+
/* Null ACLs do not require changes */
266+
if (!isNull)
267+
{
268+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
269+
form->fdwowner,newOwnerId);
270+
repl_repl[Anum_pg_foreign_data_wrapper_fdwacl-1]= true;
271+
repl_val[Anum_pg_foreign_data_wrapper_fdwacl-1]=PointerGetDatum(newAcl);
272+
}
273+
274+
tup=heap_modify_tuple(tup,RelationGetDescr(rel),repl_val,repl_null,
275+
repl_repl);
250276

251277
simple_heap_update(rel,&tup->t_self,tup);
252278
CatalogUpdateIndexes(rel,tup);
@@ -327,6 +353,12 @@ static void
327353
AlterForeignServerOwner_internal(Relationrel,HeapTupletup,OidnewOwnerId)
328354
{
329355
Form_pg_foreign_serverform;
356+
Datumrepl_val[Natts_pg_foreign_server];
357+
boolrepl_null[Natts_pg_foreign_server];
358+
boolrepl_repl[Natts_pg_foreign_server];
359+
Acl*newAcl;
360+
DatumaclDatum;
361+
boolisNull;
330362

331363
form= (Form_pg_foreign_server)GETSTRUCT(tup);
332364

@@ -358,7 +390,27 @@ AlterForeignServerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
358390
}
359391
}
360392

361-
form->srvowner=newOwnerId;
393+
memset(repl_null, false,sizeof(repl_null));
394+
memset(repl_repl, false,sizeof(repl_repl));
395+
396+
repl_repl[Anum_pg_foreign_server_srvowner-1]= true;
397+
repl_val[Anum_pg_foreign_server_srvowner-1]=ObjectIdGetDatum(newOwnerId);
398+
399+
aclDatum=heap_getattr(tup,
400+
Anum_pg_foreign_server_srvacl,
401+
RelationGetDescr(rel),
402+
&isNull);
403+
/* Null ACLs do not require changes */
404+
if (!isNull)
405+
{
406+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
407+
form->srvowner,newOwnerId);
408+
repl_repl[Anum_pg_foreign_server_srvacl-1]= true;
409+
repl_val[Anum_pg_foreign_server_srvacl-1]=PointerGetDatum(newAcl);
410+
}
411+
412+
tup=heap_modify_tuple(tup,RelationGetDescr(rel),repl_val,repl_null,
413+
repl_repl);
362414

363415
simple_heap_update(rel,&tup->t_self,tup);
364416
CatalogUpdateIndexes(rel,tup);

‎src/backend/commands/typecmds.c

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,12 +3376,34 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
33763376
ATExecChangeOwner(typTup->typrelid,newOwnerId, true,AccessExclusiveLock);
33773377
else
33783378
{
3379-
/*
3380-
* We can just apply the modification directly.
3381-
*
3382-
* okay to scribble on typTup because it's a copy
3383-
*/
3384-
typTup->typowner=newOwnerId;
3379+
Datumrepl_val[Natts_pg_type];
3380+
boolrepl_null[Natts_pg_type];
3381+
boolrepl_repl[Natts_pg_type];
3382+
Acl*newAcl;
3383+
DatumaclDatum;
3384+
boolisNull;
3385+
3386+
memset(repl_null, false,sizeof(repl_null));
3387+
memset(repl_repl, false,sizeof(repl_repl));
3388+
3389+
repl_repl[Anum_pg_type_typowner-1]= true;
3390+
repl_val[Anum_pg_type_typowner-1]=ObjectIdGetDatum(newOwnerId);
3391+
3392+
aclDatum=heap_getattr(tup,
3393+
Anum_pg_type_typacl,
3394+
RelationGetDescr(rel),
3395+
&isNull);
3396+
/* Null ACLs do not require changes */
3397+
if (!isNull)
3398+
{
3399+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
3400+
typTup->typowner,newOwnerId);
3401+
repl_repl[Anum_pg_type_typacl-1]= true;
3402+
repl_val[Anum_pg_type_typacl-1]=PointerGetDatum(newAcl);
3403+
}
3404+
3405+
tup=heap_modify_tuple(tup,RelationGetDescr(rel),repl_val,repl_null,
3406+
repl_repl);
33853407

33863408
simple_heap_update(rel,&tup->t_self,tup);
33873409

@@ -3424,6 +3446,12 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
34243446
Relationrel;
34253447
HeapTupletup;
34263448
Form_pg_typetypTup;
3449+
Datumrepl_val[Natts_pg_type];
3450+
boolrepl_null[Natts_pg_type];
3451+
boolrepl_repl[Natts_pg_type];
3452+
Acl*newAcl;
3453+
DatumaclDatum;
3454+
boolisNull;
34273455

34283456
rel=heap_open(TypeRelationId,RowExclusiveLock);
34293457

@@ -3432,10 +3460,27 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
34323460
elog(ERROR,"cache lookup failed for type %u",typeOid);
34333461
typTup= (Form_pg_type)GETSTRUCT(tup);
34343462

3435-
/*
3436-
* Modify the owner --- okay to scribble on typTup because it's a copy
3437-
*/
3438-
typTup->typowner=newOwnerId;
3463+
memset(repl_null, false,sizeof(repl_null));
3464+
memset(repl_repl, false,sizeof(repl_repl));
3465+
3466+
repl_repl[Anum_pg_type_typowner-1]= true;
3467+
repl_val[Anum_pg_type_typowner-1]=ObjectIdGetDatum(newOwnerId);
3468+
3469+
aclDatum=heap_getattr(tup,
3470+
Anum_pg_type_typacl,
3471+
RelationGetDescr(rel),
3472+
&isNull);
3473+
/* Null ACLs do not require changes */
3474+
if (!isNull)
3475+
{
3476+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
3477+
typTup->typowner,newOwnerId);
3478+
repl_repl[Anum_pg_type_typacl-1]= true;
3479+
repl_val[Anum_pg_type_typacl-1]=PointerGetDatum(newAcl);
3480+
}
3481+
3482+
tup=heap_modify_tuple(tup,RelationGetDescr(rel),repl_val,repl_null,
3483+
repl_repl);
34393484

34403485
simple_heap_update(rel,&tup->t_self,tup);
34413486

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp