summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/dbcommands.c29
-rw-r--r--src/backend/commands/user.c28
-rw-r--r--src/backend/utils/misc/guc.c84
-rw-r--r--src/include/utils/guc.h3
4 files changed, 135 insertions, 9 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 1e870b975e5..d766f333b89 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.124.2.2 2005/03/12 21:12:18 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.124.2.3 2010/03/25 14:46:04 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -721,9 +721,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 13e80283ff2..ea9659015f6 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.128 2003/10/02 06:36:37 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.128.2.1 2010/03/25 14:46:04 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -972,8 +972,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
{
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6d83b4722e2..f77e20b1bf9 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.164.2.8 2010/02/25 23:45:28 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.164.2.9 2010/03/25 14:46:06 alvherre Exp $
*
*--------------------------------------------------------------------
*/
@@ -4102,6 +4102,7 @@ ProcessGUCArray(ArrayType *array, GucSource source)
free(name);
if (value)
free(value);
+ pfree(s);
}
}
@@ -4237,6 +4238,86 @@ GUCArrayDelete(ArrayType *array, const char *name)
&& val[strlen(name)] == '=')
continue;
+
+ /* else add it to the output array */
+ if (newarray)
+ {
+ isnull = false;
+ newarray = array_set(newarray, 1, &index,
+ d,
+ -1 /* varlenarray */ ,
+ -1 /* TEXT's typlen */ ,
+ false /* TEXT's typbyval */ ,
+ 'i' /* TEXT's typalign */ ,
+ &isnull);
+ }
+ else
+ newarray = construct_array(&d, 1,
+ TEXTOID,
+ -1, false, 'i');
+
+ index++;
+ }
+
+ return newarray;
+}
+
+/*
+ * Given a GUC array, delete all settings from it that our permission
+ * level allows: if superuser, delete them all; if regular user, only
+ * those that are PGC_USERSET
+ */
+ArrayType *
+GUCArrayReset(ArrayType *array)
+{
+ ArrayType *newarray;
+ int i;
+ int index;
+
+ /* if array is currently null, nothing to do */
+ if (!array)
+ return NULL;
+
+ /* if we're superuser, we can delete everything */
+ if (superuser())
+ return NULL;
+
+ newarray = NULL;
+ index = 1;
+
+ for (i = 1; i <= ARR_DIMS(array)[0]; i++)
+ {
+ Datum d;
+ char *val;
+ char *eqsgn;
+ bool isnull;
+ struct config_generic *gconf;
+
+ d = array_ref(array, 1, &i,
+ -1 /* varlenarray */ ,
+ -1 /* TEXT's typlen */ ,
+ false /* TEXT's typbyval */ ,
+ 'i' /* TEXT's typalign */ ,
+ &isnull);
+
+ if (isnull)
+ continue;
+ val = DatumGetCString(DirectFunctionCall1(textout, d));
+
+ eqsgn = strchr(val, '=');
+ *eqsgn = '\0';
+
+ gconf = find_option(val);
+ if (!gconf)
+ continue;
+
+ /* note: superuser-ness was already checked above */
+ /* skip entry if OK to delete */
+ if (gconf->context == PGC_USERSET)
+ continue;
+
+ /* XXX do we need to worry about database owner? */
+
/* else add it to the output array */
if (newarray)
{
@@ -4255,6 +4336,7 @@ GUCArrayDelete(ArrayType *array, const char *name)
-1, false, 'i');
index++;
+ pfree(val);
}
return newarray;
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index 75288ac43c2..a12f8ec8bfa 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -7,7 +7,7 @@
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
- * $Id: guc.h,v 1.41 2003/09/01 04:15:51 momjian Exp $
+ * $Id: guc.h,v 1.41.2.1 2010/03/25 14:46:06 alvherre Exp $
*--------------------------------------------------------------------
*/
#ifndef GUC_H
@@ -144,6 +144,7 @@ extern char *flatten_set_variable_args(const char *name, List *args);
extern void ProcessGUCArray(ArrayType *array, GucSource source);
extern ArrayType *GUCArrayAdd(ArrayType *array, const char *name, const char *value);
extern ArrayType *GUCArrayDelete(ArrayType *array, const char *name);
+extern ArrayType *GUCArrayReset(ArrayType *array);
#ifdef EXEC_BACKEND
void write_nondefault_variables(GucContext context);