1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-09 13:09:39 +03:00

Prevent ALTER USER f RESET ALL from removing the settings that were put there

by a superuser -- "ALTER USER f RESET setting" already disallows removing such a
setting.

Apply the same treatment to ALTER DATABASE d RESET ALL when run by a database
owner that's not superuser.
This commit is contained in:
Alvaro Herrera
2010-03-25 14:45:06 +00:00
parent e1eb7c8119
commit e429448f33
4 changed files with 134 additions and 10 deletions

View File

@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.204.2.4 2008/10/09 10:34:22 heikki Exp $
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.204.2.5 2010/03/25 14:45:06 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -982,9 +982,30 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
if (stmt->setstmt->kind == VAR_RESET_ALL)
{
/* RESET ALL, so just set datconfig to null */
repl_null[Anum_pg_database_datconfig - 1] = 'n';
repl_val[Anum_pg_database_datconfig - 1] = (Datum) 0;
ArrayType *new = NULL;
Datum datum;
bool isnull;
/*
* in RESET ALL, request GUC to reset the settings array; if none
* left, we can set datconfig to null; otherwise use the returned
* array
*/
datum = heap_getattr(tuple, Anum_pg_database_datconfig,
RelationGetDescr(rel), &isnull);
if (!isnull)
new = GUCArrayReset(DatumGetArrayTypeP(datum));
if (new)
{
repl_val[Anum_pg_database_datconfig - 1] = PointerGetDatum(new);
repl_repl[Anum_pg_database_datconfig - 1] = 'r';
repl_null[Anum_pg_database_datconfig - 1] = ' ';
}
else
{
repl_null[Anum_pg_database_datconfig - 1] = 'n';
repl_val[Anum_pg_database_datconfig - 1] = (Datum) 0;
}
}
else
{

View File

@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.178 2008/01/01 19:45:49 momjian Exp $
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.178.2.1 2010/03/25 14:45:06 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -758,9 +758,30 @@ AlterRoleSet(AlterRoleSetStmt *stmt)
if (stmt->setstmt->kind == VAR_RESET_ALL)
{
/* RESET ALL, so just set rolconfig to null */
repl_null[Anum_pg_authid_rolconfig - 1] = 'n';
repl_val[Anum_pg_authid_rolconfig - 1] = (Datum) 0;
ArrayType *new = NULL;
Datum datum;
bool isnull;
/*
* in RESET ALL, request GUC to reset the settings array; if none
* left, we can set rolconfig to null; otherwise use the returned
* array
*/
datum = SysCacheGetAttr(AUTHNAME, oldtuple,
Anum_pg_authid_rolconfig, &isnull);
if (!isnull)
new = GUCArrayReset(DatumGetArrayTypeP(datum));
if (new)
{
repl_val[Anum_pg_authid_rolconfig - 1] = PointerGetDatum(new);
repl_repl[Anum_pg_authid_rolconfig - 1] = 'r';
repl_null[Anum_pg_authid_rolconfig - 1] = ' ';
}
else
{
repl_null[Anum_pg_authid_rolconfig - 1] = 'n';
repl_val[Anum_pg_authid_rolconfig - 1] = (Datum) 0;
}
}
else
{