mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Teach SHOW ALL to honor pg_read_all_settings membership
Also, fix the pg_settings view to display source filename and line number when invoked by a pg_read_all_settings member. This addition by me (Álvaro). Also, fix wording of the comment in GetConfigOption regarding the restriction it implements, renaming the parameter for extra clarity. Noted by Michaël. These were all oversight in commit 25fff40798fc; backpatch to pg10, where that commit first appeared. Author: Laurenz Albe Reviewed-by: Michaël Paquier, Álvaro Herrera Discussion: https://postgr.es/m/1519917758.6586.8.camel@cybertec.at
This commit is contained in:
parent
acad8b409a
commit
0c8910a0ca
@ -6930,15 +6930,15 @@ SetConfigOption(const char *name, const char *value,
|
|||||||
* this cannot be distinguished from a string variable with a NULL value!),
|
* this cannot be distinguished from a string variable with a NULL value!),
|
||||||
* otherwise throw an ereport and don't return.
|
* otherwise throw an ereport and don't return.
|
||||||
*
|
*
|
||||||
* If restrict_superuser is true, we also enforce that only superusers can
|
* If restrict_privileged is true, we also enforce that only superusers and
|
||||||
* see GUC_SUPERUSER_ONLY variables. This should only be passed as true
|
* members of the pg_read_all_settings role can see GUC_SUPERUSER_ONLY
|
||||||
* in user-driven calls.
|
* variables. This should only be passed as true in user-driven calls.
|
||||||
*
|
*
|
||||||
* The string is *not* allocated for modification and is really only
|
* The string is *not* allocated for modification and is really only
|
||||||
* valid until the next call to configuration related functions.
|
* valid until the next call to configuration related functions.
|
||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
|
GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
|
||||||
{
|
{
|
||||||
struct config_generic *record;
|
struct config_generic *record;
|
||||||
static char buffer[256];
|
static char buffer[256];
|
||||||
@ -6953,7 +6953,7 @@ GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
|
|||||||
errmsg("unrecognized configuration parameter \"%s\"",
|
errmsg("unrecognized configuration parameter \"%s\"",
|
||||||
name)));
|
name)));
|
||||||
}
|
}
|
||||||
if (restrict_superuser &&
|
if (restrict_privileged &&
|
||||||
(record->flags & GUC_SUPERUSER_ONLY) &&
|
(record->flags & GUC_SUPERUSER_ONLY) &&
|
||||||
!is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
|
!is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
@ -8242,7 +8242,6 @@ ShowGUCConfigOption(const char *name, DestReceiver *dest)
|
|||||||
static void
|
static void
|
||||||
ShowAllGUCConfig(DestReceiver *dest)
|
ShowAllGUCConfig(DestReceiver *dest)
|
||||||
{
|
{
|
||||||
bool am_superuser = superuser();
|
|
||||||
int i;
|
int i;
|
||||||
TupOutputState *tstate;
|
TupOutputState *tstate;
|
||||||
TupleDesc tupdesc;
|
TupleDesc tupdesc;
|
||||||
@ -8267,7 +8266,8 @@ ShowAllGUCConfig(DestReceiver *dest)
|
|||||||
char *setting;
|
char *setting;
|
||||||
|
|
||||||
if ((conf->flags & GUC_NO_SHOW_ALL) ||
|
if ((conf->flags & GUC_NO_SHOW_ALL) ||
|
||||||
((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
|
((conf->flags & GUC_SUPERUSER_ONLY) &&
|
||||||
|
!is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* assign to the values array */
|
/* assign to the values array */
|
||||||
@ -8593,9 +8593,10 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
|
|||||||
/*
|
/*
|
||||||
* If the setting came from a config file, set the source location. For
|
* If the setting came from a config file, set the source location. For
|
||||||
* security reasons, we don't show source file/line number for
|
* security reasons, we don't show source file/line number for
|
||||||
* non-superusers.
|
* insufficiently-privileged users.
|
||||||
*/
|
*/
|
||||||
if (conf->source == PGC_S_FILE && superuser())
|
if (conf->source == PGC_S_FILE &&
|
||||||
|
is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
|
||||||
{
|
{
|
||||||
values[14] = conf->sourcefile;
|
values[14] = conf->sourcefile;
|
||||||
snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
|
snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);
|
||||||
|
@ -347,7 +347,7 @@ extern void DefineCustomEnumVariable(
|
|||||||
extern void EmitWarningsOnPlaceholders(const char *className);
|
extern void EmitWarningsOnPlaceholders(const char *className);
|
||||||
|
|
||||||
extern const char *GetConfigOption(const char *name, bool missing_ok,
|
extern const char *GetConfigOption(const char *name, bool missing_ok,
|
||||||
bool restrict_superuser);
|
bool restrict_privileged);
|
||||||
extern const char *GetConfigOptionResetString(const char *name);
|
extern const char *GetConfigOptionResetString(const char *name);
|
||||||
extern int GetConfigOptionFlags(const char *name, bool missing_ok);
|
extern int GetConfigOptionFlags(const char *name, bool missing_ok);
|
||||||
extern void ProcessConfigFile(GucContext context);
|
extern void ProcessConfigFile(GucContext context);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user