aboutsummaryrefslogtreecommitdiff
path: root/src/backend/main/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/main/main.c')
-rw-r--r--src/backend/main/main.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index 2421ccbdf7b..4d6a07e0af7 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -59,6 +59,8 @@ static char *get_current_username(const char *progname);
int
main(int argc, char *argv[])
{
+ bool do_check_root = true;
+
progname = get_progname(argv[0]);
/*
@@ -153,7 +155,8 @@ main(int argc, char *argv[])
unsetenv("LC_ALL");
/*
- * Catch standard options before doing much else
+ * Catch standard options before doing much else, in particular before we
+ * insist on not being root.
*/
if (argc > 1)
{
@@ -167,12 +170,29 @@ main(int argc, char *argv[])
puts("postgres (PostgreSQL) " PG_VERSION);
exit(0);
}
+
+ /*
+ * In addition to the above, we allow "--describe-config" and "-C var"
+ * to be called by root. This is reasonably safe since these are
+ * read-only activities. The -C case is important because pg_ctl may
+ * try to invoke it while still holding administrator privileges on
+ * Windows. Note that while -C can normally be in any argv position,
+ * if you wanna bypass the root check you gotta put it first. This
+ * reduces the risk that we might misinterpret some other mode's -C
+ * switch as being the postmaster/postgres one.
+ */
+ if (strcmp(argv[1], "--describe-config") == 0)
+ do_check_root = false;
+ else if (argc > 2 && strcmp(argv[1], "-C") == 0)
+ do_check_root = false;
}
/*
- * Make sure we are not running as root.
+ * Make sure we are not running as root, unless it's safe for the selected
+ * option.
*/
- check_root(progname);
+ if (do_check_root)
+ check_root(progname);
/*
* Dispatch to one of various subprograms depending on first argument.