diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-04-04 22:03:35 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-04-04 22:03:35 -0400 |
commit | b203c57bb778d90bb8728be19e78825134d5820f (patch) | |
tree | 3a795d8b5d4899f7ce217467f51dd4c70cc5c1be /src/bin/pg_ctl/pg_ctl.c | |
parent | 2209c0f8618bbed257975055e017efab139e3fa3 (diff) | |
download | postgresql-b203c57bb778d90bb8728be19e78825134d5820f.tar.gz postgresql-b203c57bb778d90bb8728be19e78825134d5820f.zip |
Allow "-C variable" and "--describe-config" even to root users.
There's no really compelling reason to refuse to do these read-only,
non-server-starting options as root, and there's at least one good
reason to allow -C: pg_ctl uses -C to find out the true data directory
location when pointed at a config-only directory. On Windows, this is
done before dropping administrator privileges, which means that pg_ctl
fails for administrators if and only if a config-only layout is used.
Since the root-privilege check is done so early in startup, it's a bit
awkward to check for these switches. Make the somewhat arbitrary
decision that we'll only skip the root check if -C is the first switch.
This is not just to make the code a bit simpler: it also guarantees that
we can't misinterpret a --boot mode switch. (While AuxiliaryProcessMain
doesn't currently recognize any such switch, it might have one in the
future.) This is no particular problem for pg_ctl, and since the whole
behavior is undocumented anyhow, it's not a documentation issue either.
(--describe-config only works as the first switch anyway, so this is
no restriction for that case either.)
Back-patch to 9.2 where pg_ctl first began to use -C.
MauMau, heavily edited by me
Diffstat (limited to 'src/bin/pg_ctl/pg_ctl.c')
-rw-r--r-- | src/bin/pg_ctl/pg_ctl.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 1f921819c23..fc87e7d76ed 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -2034,9 +2034,11 @@ adjust_data_dir(void) else my_exec_path = pg_strdup(exec_path); - snprintf(cmd, MAXPGPATH, SYSTEMQUOTE "\"%s\" %s%s -C data_directory" SYSTEMQUOTE, - my_exec_path, pgdata_opt ? pgdata_opt : "", post_opts ? - post_opts : ""); + /* it's important for -C to be the first option, see main.c */ + snprintf(cmd, MAXPGPATH, SYSTEMQUOTE "\"%s\" -C data_directory %s%s" SYSTEMQUOTE, + my_exec_path, + pgdata_opt ? pgdata_opt : "", + post_opts ? post_opts : ""); fd = popen(cmd, "r"); if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL) |