mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +03:00
Add USER SET parameter values for pg_db_role_setting
The USER SET flag specifies that the variable should be set on behalf of an ordinary role. That lets ordinary roles set placeholder variables, which permission requirements are not known yet. Such a value wouldn't be used if the variable finally appear to require superuser privileges. The new flags are stored in the pg_db_role_setting.setuser array. Catversion is bumped. This commit is inspired by the previous work by Steve Chavez. Discussion: https://postgr.es/m/CAPpHfdsLd6E--epnGqXENqLP6dLwuNZrPMcNYb3wJ87WR7UBOQ%40mail.gmail.com Author: Alexander Korotkov, Steve Chavez Reviewed-by: Pavel Borisov, Steve Chavez
This commit is contained in:
@@ -63,14 +63,23 @@ AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
|
||||
if (HeapTupleIsValid(tuple))
|
||||
{
|
||||
ArrayType *new = NULL;
|
||||
ArrayType *usersetArray;
|
||||
Datum datum;
|
||||
Datum usersetDatum;
|
||||
bool isnull;
|
||||
bool usersetIsnull;
|
||||
|
||||
datum = heap_getattr(tuple, Anum_pg_db_role_setting_setconfig,
|
||||
RelationGetDescr(rel), &isnull);
|
||||
usersetDatum = heap_getattr(tuple, Anum_pg_db_role_setting_setuser,
|
||||
RelationGetDescr(rel), &usersetIsnull);
|
||||
|
||||
if (!isnull)
|
||||
new = GUCArrayReset(DatumGetArrayTypeP(datum));
|
||||
{
|
||||
Assert(!usersetIsnull);
|
||||
usersetArray = DatumGetArrayTypeP(usersetDatum);
|
||||
new = GUCArrayReset(DatumGetArrayTypeP(datum), &usersetArray);
|
||||
}
|
||||
|
||||
if (new)
|
||||
{
|
||||
@@ -86,6 +95,11 @@ AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
|
||||
repl_repl[Anum_pg_db_role_setting_setconfig - 1] = true;
|
||||
repl_null[Anum_pg_db_role_setting_setconfig - 1] = false;
|
||||
|
||||
repl_val[Anum_pg_db_role_setting_setuser - 1] =
|
||||
PointerGetDatum(usersetArray);
|
||||
repl_repl[Anum_pg_db_role_setting_setuser - 1] = true;
|
||||
repl_null[Anum_pg_db_role_setting_setuser - 1] = false;
|
||||
|
||||
newtuple = heap_modify_tuple(tuple, RelationGetDescr(rel),
|
||||
repl_val, repl_null, repl_repl);
|
||||
CatalogTupleUpdate(rel, &tuple->t_self, newtuple);
|
||||
@@ -101,28 +115,39 @@ AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
|
||||
bool repl_repl[Natts_pg_db_role_setting];
|
||||
HeapTuple newtuple;
|
||||
Datum datum;
|
||||
Datum usersetDatum;
|
||||
bool isnull;
|
||||
bool usersetIsnull;
|
||||
ArrayType *a;
|
||||
ArrayType *usersetArray;
|
||||
|
||||
memset(repl_repl, false, sizeof(repl_repl));
|
||||
repl_repl[Anum_pg_db_role_setting_setconfig - 1] = true;
|
||||
repl_null[Anum_pg_db_role_setting_setconfig - 1] = false;
|
||||
repl_repl[Anum_pg_db_role_setting_setuser - 1] = true;
|
||||
repl_null[Anum_pg_db_role_setting_setuser - 1] = false;
|
||||
|
||||
/* Extract old value of setconfig */
|
||||
/* Extract old values of setconfig and setuser */
|
||||
datum = heap_getattr(tuple, Anum_pg_db_role_setting_setconfig,
|
||||
RelationGetDescr(rel), &isnull);
|
||||
a = isnull ? NULL : DatumGetArrayTypeP(datum);
|
||||
|
||||
usersetDatum = heap_getattr(tuple, Anum_pg_db_role_setting_setuser,
|
||||
RelationGetDescr(rel), &usersetIsnull);
|
||||
usersetArray = usersetIsnull ? NULL : DatumGetArrayTypeP(usersetDatum);
|
||||
|
||||
/* Update (valuestr is NULL in RESET cases) */
|
||||
if (valuestr)
|
||||
a = GUCArrayAdd(a, setstmt->name, valuestr);
|
||||
a = GUCArrayAdd(a, &usersetArray, setstmt->name, valuestr, setstmt->user_set);
|
||||
else
|
||||
a = GUCArrayDelete(a, setstmt->name);
|
||||
a = GUCArrayDelete(a, &usersetArray, setstmt->name);
|
||||
|
||||
if (a)
|
||||
{
|
||||
repl_val[Anum_pg_db_role_setting_setconfig - 1] =
|
||||
PointerGetDatum(a);
|
||||
repl_val[Anum_pg_db_role_setting_setuser - 1] =
|
||||
PointerGetDatum(usersetArray);
|
||||
|
||||
newtuple = heap_modify_tuple(tuple, RelationGetDescr(rel),
|
||||
repl_val, repl_null, repl_repl);
|
||||
@@ -137,16 +162,18 @@ AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
|
||||
HeapTuple newtuple;
|
||||
Datum values[Natts_pg_db_role_setting];
|
||||
bool nulls[Natts_pg_db_role_setting];
|
||||
ArrayType *a;
|
||||
ArrayType *a,
|
||||
*usersetArray;
|
||||
|
||||
memset(nulls, false, sizeof(nulls));
|
||||
|
||||
a = GUCArrayAdd(NULL, setstmt->name, valuestr);
|
||||
a = GUCArrayAdd(NULL, &usersetArray, setstmt->name, valuestr, setstmt->user_set);
|
||||
|
||||
values[Anum_pg_db_role_setting_setdatabase - 1] =
|
||||
ObjectIdGetDatum(databaseid);
|
||||
values[Anum_pg_db_role_setting_setrole - 1] = ObjectIdGetDatum(roleid);
|
||||
values[Anum_pg_db_role_setting_setconfig - 1] = PointerGetDatum(a);
|
||||
values[Anum_pg_db_role_setting_setuser - 1] = PointerGetDatum(usersetArray);
|
||||
newtuple = heap_form_tuple(RelationGetDescr(rel), values, nulls);
|
||||
|
||||
CatalogTupleInsert(rel, newtuple);
|
||||
@@ -240,20 +267,25 @@ ApplySetting(Snapshot snapshot, Oid databaseid, Oid roleid,
|
||||
while (HeapTupleIsValid(tup = systable_getnext(scan)))
|
||||
{
|
||||
bool isnull;
|
||||
bool usersetIsnull;
|
||||
Datum datum;
|
||||
Datum usersetDatum;
|
||||
|
||||
datum = heap_getattr(tup, Anum_pg_db_role_setting_setconfig,
|
||||
RelationGetDescr(relsetting), &isnull);
|
||||
usersetDatum = heap_getattr(tup, Anum_pg_db_role_setting_setuser,
|
||||
RelationGetDescr(relsetting), &usersetIsnull);
|
||||
if (!isnull)
|
||||
{
|
||||
ArrayType *a = DatumGetArrayTypeP(datum);
|
||||
ArrayType *usersetArray = DatumGetArrayTypeP(usersetDatum);
|
||||
|
||||
/*
|
||||
* We process all the options at SUSET level. We assume that the
|
||||
* right to insert an option into pg_db_role_setting was checked
|
||||
* when it was inserted.
|
||||
*/
|
||||
ProcessGUCArray(a, PGC_SUSET, source, GUC_ACTION_SET);
|
||||
ProcessGUCArray(a, usersetArray, PGC_SUSET, source, GUC_ACTION_SET);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user