mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +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:
@ -10,7 +10,7 @@
|
||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.544 2010/03/21 00:17:59 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.545 2010/03/25 14:44:33 alvherre Exp $
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
*/
|
||||
@ -7099,7 +7099,7 @@ ParseLongOption(const char *string, char **name, char **value)
|
||||
|
||||
|
||||
/*
|
||||
* Handle options fetched from pg_database.datconfig, pg_authid.rolconfig,
|
||||
* Handle options fetched from pg_db_role_setting.setconfig,
|
||||
* pg_proc.proconfig, etc. Caller must specify proper context/source/action.
|
||||
*
|
||||
* The array parameter must be an array of TEXT (it must not be NULL).
|
||||
@ -7151,6 +7151,7 @@ ProcessGUCArray(ArrayType *array,
|
||||
free(name);
|
||||
if (value)
|
||||
free(value);
|
||||
pfree(s);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7285,6 +7286,7 @@ GUCArrayDelete(ArrayType *array, const char *name)
|
||||
&& val[strlen(name)] == '=')
|
||||
continue;
|
||||
|
||||
|
||||
/* else add it to the output array */
|
||||
if (newarray)
|
||||
{
|
||||
@ -7307,6 +7309,85 @@ GUCArrayDelete(ArrayType *array, const char *name)
|
||||
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 = TextDatumGetCString(d);
|
||||
|
||||
eqsgn = strchr(val, '=');
|
||||
*eqsgn = '\0';
|
||||
|
||||
gconf = find_option(val, false, WARNING);
|
||||
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)
|
||||
{
|
||||
newarray = array_set(newarray, 1, &index,
|
||||
d,
|
||||
false,
|
||||
-1 /* varlenarray */ ,
|
||||
-1 /* TEXT's typlen */ ,
|
||||
false /* TEXT's typbyval */ ,
|
||||
'i' /* TEXT's typalign */ );
|
||||
}
|
||||
else
|
||||
newarray = construct_array(&d, 1,
|
||||
TEXTOID,
|
||||
-1, false, 'i');
|
||||
|
||||
index++;
|
||||
pfree(val);
|
||||
}
|
||||
|
||||
return newarray;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* assign_hook and show_hook subroutines
|
||||
|
Reference in New Issue
Block a user