Skip to content

Commit a25c207

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 6695e95 commit a25c207

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
@@ -6696,15 +6696,15 @@ SetConfigOption(const char *name, const char *value,
66966696
* this cannot be distinguished from a string variable with a NULL value!),
66976697
* otherwise throw an ereport and don't return.
66986698
*
6699-
* If restrict_superuser is true, we also enforce that only superusers can
6700-
* see GUC_SUPERUSER_ONLY variables. This should only be passed as true
6701-
* in user-driven calls.
6699+
* If restrict_privileged is true, we also enforce that only superusers and
6700+
* members of the pg_read_all_settings role can see GUC_SUPERUSER_ONLY
6701+
* variables. This should only be passed as true in user-driven calls.
67026702
*
67036703
* The string is *not* allocated for modification and is really only
67046704
* valid until the next call to configuration related functions.
67056705
*/
67066706
const char *
6707-
GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
6707+
GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
67086708
{
67096709
struct config_generic *record;
67106710
static char buffer[256];
@@ -6719,7 +6719,7 @@ GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
67196719
errmsg("unrecognized configuration parameter \"%s\"",
67206720
name)));
67216721
}
6722-
if (restrict_superuser &&
6722+
if (restrict_privileged &&
67236723
(record->flags & GUC_SUPERUSER_ONLY) &&
67246724
!is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
67256725
ereport(ERROR,
@@ -8000,7 +8000,6 @@ ShowGUCConfigOption(const char *name, DestReceiver *dest)
80008000
static void
80018001
ShowAllGUCConfig(DestReceiver *dest)
80028002
{
8003-
bool am_superuser = superuser();
80048003
int i;
80058004
TupOutputState *tstate;
80068005
TupleDesc tupdesc;
@@ -8025,7 +8024,8 @@ ShowAllGUCConfig(DestReceiver *dest)
80258024
char *setting;
80268025

80278026
if ((conf->flags & GUC_NO_SHOW_ALL) ||
8028-
((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
8027+
((conf->flags & GUC_SUPERUSER_ONLY) &&
8028+
!is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS)))
80298029
continue;
80308030

80318031
/* assign to the values array */
@@ -8348,9 +8348,10 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
83488348
/*
83498349
* If the setting came from a config file, set the source location. For
83508350
* security reasons, we don't show source file/line number for
8351-
* non-superusers.
8351+
* insufficiently-privileged users.
83528352
*/
8353-
if (conf->source == PGC_S_FILE && superuser())
8353+
if (conf->source == PGC_S_FILE &&
8354+
is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_SETTINGS))
83548355
{
83558356
values[14] = conf->sourcefile;
83568357
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
@@ -346,7 +346,7 @@ extern void DefineCustomEnumVariable(
346346
extern void EmitWarningsOnPlaceholders(const char *className);
347347

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

0 commit comments

Comments
 (0)