Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0c8910a

Browse files
committed
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 25fff40; 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
1 parent acad8b4 commit 0c8910a

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/backend/utils/misc/guc.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6930,15 +6930,15 @@ SetConfigOption(const char *name, const char *value,
69306930
* this cannot be distinguished from a string variable with a NULL value!),
69316931
* otherwise throw an ereport and don't return.
69326932
*
6933-
* If restrict_superuser is true, we also enforce that only superusers can
6934-
* see GUC_SUPERUSER_ONLY variables. This should only be passed as true
6935-
* in user-driven calls.
6933+
* If restrict_privileged is true, we also enforce that only superusers and
6934+
* members of the pg_read_all_settings role can see GUC_SUPERUSER_ONLY
6935+
* variables. This should only be passed as true in user-driven calls.
69366936
*
69376937
* The string is *not* allocated for modification and is really only
69386938
* valid until the next call to configuration related functions.
69396939
*/
69406940
const char *
6941-
GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
6941+
GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
69426942
{
69436943
struct config_generic *record;
69446944
static char buffer[256];
@@ -6953,7 +6953,7 @@ GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
69536953
errmsg("unrecognized configuration parameter \"%s\"",
69546954
name)));
69556955
}
6956-
if (restrict_superuser &&
6956+
if (restrict_privileged &&
69576957
(record->flags & GUC_SUPERUSER_ONLY) &&
69586958
!is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
69596959
ereport(ERROR,
@@ -8242,7 +8242,6 @@ ShowGUCConfigOption(const char *name, DestReceiver *dest)
82428242
static void
82438243
ShowAllGUCConfig(DestReceiver *dest)
82448244
{
8245-
bool am_superuser = superuser();
82468245
int i;
82478246
TupOutputState *tstate;
82488247
TupleDesc tupdesc;
@@ -8267,7 +8266,8 @@ ShowAllGUCConfig(DestReceiver *dest)
82678266
char *setting;
82688267

82698268
if ((conf->flags & GUC_NO_SHOW_ALL) ||
8270-
((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
8269+
((conf->flags & GUC_SUPERUSER_ONLY) &&
8270+
!is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
82718271
continue;
82728272

82738273
/* assign to the values array */
@@ -8593,9 +8593,10 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
85938593
/*
85948594
* If the setting came from a config file, set the source location. For
85958595
* security reasons, we don't show source file/line number for
8596-
* non-superusers.
8596+
* insufficiently-privileged users.
85978597
*/
8598-
if (conf->source == PGC_S_FILE && superuser())
8598+
if (conf->source == PGC_S_FILE &&
8599+
is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
85998600
{
86008601
values[14] = conf->sourcefile;
86018602
snprintf(buffer, sizeof(buffer), "%d", conf->sourceline);

src/include/utils/guc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ extern void DefineCustomEnumVariable(
347347
extern void EmitWarningsOnPlaceholders(const char *className);
348348

349349
extern const char *GetConfigOption(const char *name, bool missing_ok,
350-
bool restrict_superuser);
350+
bool restrict_privileged);
351351
extern const char *GetConfigOptionResetString(const char *name);
352352
extern int GetConfigOptionFlags(const char *name, bool missing_ok);
353353
extern void ProcessConfigFile(GucContext context);

0 commit comments

Comments
 (0)