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

Commit2c8ae64

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.Report by Alexey BashtanovThis is a backpatch of commit59367fd (for bug #9923) by BruceMomjian to branches 9.1 - 9.4; it wasn't backpatched originally out ofconcerns that it would create a backwards compatibility problem, but perdiscussion related to bug #13666 that turns out to have been misguided.(Therefore, the entry in the 9.5 release notes should be removed.)Note that 9.1 didn't have privileges on types (which were introduced bycommit7292055), so this commit only changes foreign-data relatedobjects in that branch.Discussion:http://www.postgresql.org/message-id/20151216224004.GL2618@alvherre.pgsqlhttp://www.postgresql.org/message-id/10227.1450373793@sss.pgh.pa.us
1 parentf02137d commit2c8ae64

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
@@ -213,6 +213,12 @@ static void
213213
AlterForeignDataWrapperOwner_internal(Relationrel,HeapTupletup,OidnewOwnerId)
214214
{
215215
Form_pg_foreign_data_wrapperform;
216+
Datumrepl_val[Natts_pg_foreign_data_wrapper];
217+
boolrepl_null[Natts_pg_foreign_data_wrapper];
218+
boolrepl_repl[Natts_pg_foreign_data_wrapper];
219+
Acl*newAcl;
220+
DatumaclDatum;
221+
boolisNull;
216222

217223
form= (Form_pg_foreign_data_wrapper)GETSTRUCT(tup);
218224

@@ -234,7 +240,27 @@ AlterForeignDataWrapperOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerI
234240

235241
if (form->fdwowner!=newOwnerId)
236242
{
237-
form->fdwowner=newOwnerId;
243+
memset(repl_null, false,sizeof(repl_null));
244+
memset(repl_repl, false,sizeof(repl_repl));
245+
246+
repl_repl[Anum_pg_foreign_data_wrapper_fdwowner-1]= true;
247+
repl_val[Anum_pg_foreign_data_wrapper_fdwowner-1]=ObjectIdGetDatum(newOwnerId);
248+
249+
aclDatum=heap_getattr(tup,
250+
Anum_pg_foreign_data_wrapper_fdwacl,
251+
RelationGetDescr(rel),
252+
&isNull);
253+
/* Null ACLs do not require changes */
254+
if (!isNull)
255+
{
256+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
257+
form->fdwowner,newOwnerId);
258+
repl_repl[Anum_pg_foreign_data_wrapper_fdwacl-1]= true;
259+
repl_val[Anum_pg_foreign_data_wrapper_fdwacl-1]=PointerGetDatum(newAcl);
260+
}
261+
262+
tup=heap_modify_tuple(tup,RelationGetDescr(rel),repl_val,repl_null,
263+
repl_repl);
238264

239265
simple_heap_update(rel,&tup->t_self,tup);
240266
CatalogUpdateIndexes(rel,tup);
@@ -315,6 +341,12 @@ static void
315341
AlterForeignServerOwner_internal(Relationrel,HeapTupletup,OidnewOwnerId)
316342
{
317343
Form_pg_foreign_serverform;
344+
Datumrepl_val[Natts_pg_foreign_server];
345+
boolrepl_null[Natts_pg_foreign_server];
346+
boolrepl_repl[Natts_pg_foreign_server];
347+
Acl*newAcl;
348+
DatumaclDatum;
349+
boolisNull;
318350

319351
form= (Form_pg_foreign_server)GETSTRUCT(tup);
320352

@@ -346,7 +378,27 @@ AlterForeignServerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
346378
}
347379
}
348380

349-
form->srvowner=newOwnerId;
381+
memset(repl_null, false,sizeof(repl_null));
382+
memset(repl_repl, false,sizeof(repl_repl));
383+
384+
repl_repl[Anum_pg_foreign_server_srvowner-1]= true;
385+
repl_val[Anum_pg_foreign_server_srvowner-1]=ObjectIdGetDatum(newOwnerId);
386+
387+
aclDatum=heap_getattr(tup,
388+
Anum_pg_foreign_server_srvacl,
389+
RelationGetDescr(rel),
390+
&isNull);
391+
/* Null ACLs do not require changes */
392+
if (!isNull)
393+
{
394+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
395+
form->srvowner,newOwnerId);
396+
repl_repl[Anum_pg_foreign_server_srvacl-1]= true;
397+
repl_val[Anum_pg_foreign_server_srvacl-1]=PointerGetDatum(newAcl);
398+
}
399+
400+
tup=heap_modify_tuple(tup,RelationGetDescr(rel),repl_val,repl_null,
401+
repl_repl);
350402

351403
simple_heap_update(rel,&tup->t_self,tup);
352404
CatalogUpdateIndexes(rel,tup);

‎src/backend/commands/typecmds.c

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,12 +3324,34 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
33243324
ATExecChangeOwner(typTup->typrelid,newOwnerId, true,AccessExclusiveLock);
33253325
else
33263326
{
3327-
/*
3328-
* We can just apply the modification directly.
3329-
*
3330-
* okay to scribble on typTup because it's a copy
3331-
*/
3332-
typTup->typowner=newOwnerId;
3327+
Datumrepl_val[Natts_pg_type];
3328+
boolrepl_null[Natts_pg_type];
3329+
boolrepl_repl[Natts_pg_type];
3330+
Acl*newAcl;
3331+
DatumaclDatum;
3332+
boolisNull;
3333+
3334+
memset(repl_null, false,sizeof(repl_null));
3335+
memset(repl_repl, false,sizeof(repl_repl));
3336+
3337+
repl_repl[Anum_pg_type_typowner-1]= true;
3338+
repl_val[Anum_pg_type_typowner-1]=ObjectIdGetDatum(newOwnerId);
3339+
3340+
aclDatum=heap_getattr(tup,
3341+
Anum_pg_type_typacl,
3342+
RelationGetDescr(rel),
3343+
&isNull);
3344+
/* Null ACLs do not require changes */
3345+
if (!isNull)
3346+
{
3347+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
3348+
typTup->typowner,newOwnerId);
3349+
repl_repl[Anum_pg_type_typacl-1]= true;
3350+
repl_val[Anum_pg_type_typacl-1]=PointerGetDatum(newAcl);
3351+
}
3352+
3353+
tup=heap_modify_tuple(tup,RelationGetDescr(rel),repl_val,repl_null,
3354+
repl_repl);
33333355

33343356
simple_heap_update(rel,&tup->t_self,tup);
33353357

@@ -3372,6 +3394,12 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
33723394
Relationrel;
33733395
HeapTupletup;
33743396
Form_pg_typetypTup;
3397+
Datumrepl_val[Natts_pg_type];
3398+
boolrepl_null[Natts_pg_type];
3399+
boolrepl_repl[Natts_pg_type];
3400+
Acl*newAcl;
3401+
DatumaclDatum;
3402+
boolisNull;
33753403

33763404
rel=heap_open(TypeRelationId,RowExclusiveLock);
33773405

@@ -3380,10 +3408,27 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
33803408
elog(ERROR,"cache lookup failed for type %u",typeOid);
33813409
typTup= (Form_pg_type)GETSTRUCT(tup);
33823410

3383-
/*
3384-
* Modify the owner --- okay to scribble on typTup because it's a copy
3385-
*/
3386-
typTup->typowner=newOwnerId;
3411+
memset(repl_null, false,sizeof(repl_null));
3412+
memset(repl_repl, false,sizeof(repl_repl));
3413+
3414+
repl_repl[Anum_pg_type_typowner-1]= true;
3415+
repl_val[Anum_pg_type_typowner-1]=ObjectIdGetDatum(newOwnerId);
3416+
3417+
aclDatum=heap_getattr(tup,
3418+
Anum_pg_type_typacl,
3419+
RelationGetDescr(rel),
3420+
&isNull);
3421+
/* Null ACLs do not require changes */
3422+
if (!isNull)
3423+
{
3424+
newAcl=aclnewowner(DatumGetAclP(aclDatum),
3425+
typTup->typowner,newOwnerId);
3426+
repl_repl[Anum_pg_type_typacl-1]= true;
3427+
repl_val[Anum_pg_type_typacl-1]=PointerGetDatum(newAcl);
3428+
}
3429+
3430+
tup=heap_modify_tuple(tup,RelationGetDescr(rel),repl_val,repl_null,
3431+
repl_repl);
33873432

33883433
simple_heap_update(rel,&tup->t_self,tup);
33893434

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp