Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 59367fd

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 ACL list should be changed from the old owner to the new owner. This patch fixes types, foreign data wrappers, and foreign servers to change their ACL list properly; they already changed owners properly. BACKWARD INCOMPATIBILITY? Report by Alexey Bashtanov
1 parent b181a91 commit 59367fd

File tree

3 files changed

+161
-64
lines changed

3 files changed

+161
-64
lines changed

src/backend/commands/foreigncmds.c

+54-2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ static void
225225
AlterForeignDataWrapperOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
226226
{
227227
Form_pg_foreign_data_wrapper form;
228+
Datum repl_val[Natts_pg_foreign_data_wrapper];
229+
bool repl_null[Natts_pg_foreign_data_wrapper];
230+
bool repl_repl[Natts_pg_foreign_data_wrapper];
231+
Acl *newAcl;
232+
Datum aclDatum;
233+
bool isNull;
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(Relation rel, HeapTuple tup, Oid newOwnerId)
328354
{
329355
Form_pg_foreign_server form;
356+
Datum repl_val[Natts_pg_foreign_server];
357+
bool repl_null[Natts_pg_foreign_server];
358+
bool repl_repl[Natts_pg_foreign_server];
359+
Acl *newAcl;
360+
Datum aclDatum;
361+
bool isNull;
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

+55-10
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+
Datum repl_val[Natts_pg_type];
3380+
bool repl_null[Natts_pg_type];
3381+
bool repl_repl[Natts_pg_type];
3382+
Acl *newAcl;
3383+
Datum aclDatum;
3384+
bool isNull;
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
Relation rel;
34253447
HeapTuple tup;
34263448
Form_pg_type typTup;
3449+
Datum repl_val[Natts_pg_type];
3450+
bool repl_null[Natts_pg_type];
3451+
bool repl_repl[Natts_pg_type];
3452+
Acl *newAcl;
3453+
Datum aclDatum;
3454+
bool isNull;
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)