8000 adjust ACL owners for REASSIGN and ALTER OWNER TO · home201448/postgres@62e6eba · GitHub
[go: up one dir, main page]

Skip to content

Commit 62e6eba

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. Report by Alexey Bashtanov This is a backpatch of commit 59367fd (for bug #9923) by Bruce Momjian to branches 9.1 - 9.4; it wasn't backpatched originally out of concerns that it would create a backwards compatibility problem, but per discussion 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 by commit 7292055), so this commit only changes foreign-data related objects in that branch. Discussion: http://www.postgresql.org/message-id/20151216224004.GL2618@alvherre.pgsql http://www.postgresql.org/message-id/10227.1450373793@sss.pgh.pa.us
1 parent 4271ed3 commit 62e6eba

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(Relation rel, HeapTuple tup, Oid newOwnerId)
214214
{
215215
Form_pg_foreign_data_wrapper form;
216+
Datum repl_val[Natts_pg_foreign_data_wrapper];
217+
bool repl_null[Natts_pg_foreign_data_wrapper];
218+
bool repl_repl[Natts_pg_foreign_data_wrapper];
219+
Acl *newAcl;
220+
Datum aclDatum;
221+
bool isNull;
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);
8000
240266
CatalogUpdateIndexes(rel, tup);
@@ -315,6 +341,12 @@ static void
315341
AlterForeignServerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
316342
{
317343
Form_pg_foreign_server form;
344+
Datum repl_val[Natts_pg_foreign_server];
345+
bool repl_null[Natts_pg_foreign_server];
346+
bool repl_repl[Natts_pg_foreign_server];
347+
Acl *newAcl;
348+
Datum aclDatum;
349+
bool isNull;
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
@@ -3316,12 +3316,34 @@ AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
33163316
ATExecChangeOwner(typTup->typrelid, newOwnerId, true, AccessExclusiveLock);
33173317
else
33183318
{
3319-
/*
3320-
* We can just apply the modification directly.
3321-
*
3322-
* okay to scribble on typTup because it's a copy
3323-
*/
3324-
typTup->typowner = newOwnerId;
3319+
Datum repl_val[Natts_pg_type];
3320+
bool repl_null[Natts_pg_type];
3321+
bool repl_repl[Natts_pg_type];
3322+
Acl *newAcl;
3323+
Datum aclDatum;
3324+
bool isNull;
3325+
3326+
memset(repl_null, false, sizeof(repl_null));
3327+
memset(repl_repl, false, sizeof(repl_repl));
3328+
3329+
repl_repl[Anum_pg_type_typowner - 1] = true;
3330+
repl_val[Anum_pg_type_typowner - 1] = ObjectIdGetDatum(newOwnerId);
3331+
3332+
aclDatum = heap_getattr(tup,
3333+
Anum_pg_type_typacl,
3334+
RelationGetDescr(rel),
3335+
&isNull);
3336+
/* Null ACLs do not require changes */
3337+
if (!isNull)
3338+
{
3339+
newAcl = aclnewowner(DatumGetAclP(aclDatum),
3340+
typTup->typowner, newOwnerId);
3341+
repl_repl[Anum_pg_type_typacl - 1] = true;
3342+
repl_val[Anum_pg_type_typacl - 1] = PointerGetDatum(newAcl);
3343+
}
3344+
3345+
tup = heap_modify_tuple(tup, RelationGetDescr(rel), repl_val, repl_null,
3346+
repl_repl);
33253347

33263348
simple_heap_update(rel, &tup->t_self, tup);
33273349

@@ -3364,6 +3386,12 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
33643386
Relation rel;
33653387
HeapTuple tup;
33663388
Form_pg_type typTup;
3389+
Datum repl_val[Natts_pg_type];
3390+
bool repl_null[Natts_pg_type];
3391+
bool repl_repl[Natts_pg_type];
3392+
Acl *newAcl;
3393+
Datum aclDatum;
3394+
bool isNull;
33673395

33683396
rel = heap_open(TypeRelationId, RowExclusiveLock);
33693397

@@ -3372,10 +3400,27 @@ AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId,
33723400
elog(ERROR, "cache lookup failed for type %u", typeOid);
33733401
typTup = (Form_pg_type) GETSTRUCT(tup);
33743402

3375-
/*
3376-
* Modify the owner --- okay to scribble on typTup because it's a copy
3377-
*/
3378-
typTup->typowner = newOwnerId;
3403+
memset(repl_null, false, sizeof(repl_null));
3404+
memset(repl_repl, false, sizeof(repl_repl));
3405+
3406+
repl_repl[Anum_pg_type_typowner - 1] = true;
3407+
repl_val[Anum_pg_type_typowner - 1] = ObjectIdGetDatum(newOwnerId);
3408+
3409+
aclDatum = heap_getattr(tup,
3410+
Anum_pg_type_typacl,
3411+
RelationGetDescr(rel),
3412+
&isNull);
3413+
/* Null ACLs do not require changes */
3414+
if (!isNull)
3415+
{
3416+
newAcl = aclnewowner(DatumGetAclP(aclDatum),
3417+
typTup->typowner, newOwnerId);
3418+
repl_repl[Anum_pg_type_typacl - 1] = true;
3419+
repl_val[Anum_pg_type_typacl - 1] = PointerGetDatum(newAcl);
3420+
}
3421+
3422+
tup = heap_modify_tuple(tup, RelationGetDescr(rel), repl_val, repl_null,
3423+
repl_repl);
33793424

33803425
simple_heap_update(rel, &tup->t_self, tup);
33813426

0 commit comments

Comments
 (0)
0