summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2010-03-25 14:45:51 +0000
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2010-03-25 14:45:51 +0000
commitd07f5947058eae0433c0a08e84711b3d32a84f4d (patch)
treee3d147a06950b53da6422f0bfa652088efb11b63 /src/backend/commands
parent75d4be8ddd259124d3009e3f38185137dcd35943 (diff)
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.
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/dbcommands.c29
-rw-r--r--src/backend/commands/user.c28
2 files changed, 50 insertions, 7 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 70329ce3974..fdb2ed2fcbd 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.148.4.3 2005/06/25 22:47:49 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.148.4.4 2010/03/25 14:45:51 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -812,9 +812,30 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
if (strcmp(stmt->variable, "all") == 0 && valuestr == NULL)
{
- /* RESET ALL */
- 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
{
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index c69956d41c9..9ffb2fbf456 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.147.4.1 2005/10/26 13:43:28 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.147.4.2 2010/03/25 14:45:51 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1022,8 +1022,30 @@ AlterUserSet(AlterUserSetStmt *stmt)
repl_repl[Anum_pg_shadow_useconfig - 1] = 'r';
if (strcmp(stmt->variable, "all") == 0 && valuestr == NULL)
{
- /* RESET ALL */
- repl_null[Anum_pg_shadow_useconfig - 1] = 'n';
+ ArrayType *new = NULL;
+ Datum datum;
+ bool isnull;
+
+ /*
+ * in RESET ALL, request GUC to reset the settings array; if none
+ * left, we can set useconfig to null; otherwise use the returned
+ * array
+ */
+ datum = SysCacheGetAttr(SHADOWNAME, oldtuple,
+ Anum_pg_shadow_useconfig, &isnull);
+ if (!isnull)
+ new = GUCArrayReset(DatumGetArrayTypeP(datum));
+ if (new)
+ {
+ repl_val[Anum_pg_shadow_useconfig - 1] = PointerGetDatum(new);
+ repl_repl[Anum_pg_shadow_useconfig - 1] = 'r';
+ repl_null[Anum_pg_shadow_useconfig - 1] = ' ';
+ }
+ else
+ {
+ repl_null[Anum_pg_shadow_useconfig - 1] = 'n';
+ repl_val[Anum_pg_shadow_useconfig - 1] = (Datum) 0;
+ }
}
else
{