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

Commit 8a06c36

Browse files
committed
Fix process startup in pg_rewind.
Don't allow pg_rewind to run as root on Unix platforms, as any new or replaced files in the data directory would become owned by root. On Windows, it can run under a user that has Administrator rights, but a restricted token needs to be used. This is the same we do e.g. in pg_resetxlog. Also, add missing set_pglocale_pgservice() call, to fix localization. Michael Paquier and Fujii Masao
1 parent 1cdf4d0 commit 8a06c36

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/bin/pg_rewind/nls.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# src/bin/pg_rewind/nls.mk
22
CATALOG_NAME = pg_rewind
33
AVAIL_LANGUAGES =
4-
GETTEXT_FILES = copy_fetch.c datapagemap.c fetch.c filemap.c libpq_fetch.c logging.c parsexlog.c pg_rewind.c timeline.c ../../common/fe_memutils.c ../../../src/backend/access/transam/xlogreader.c
4+
GETTEXT_FILES = copy_fetch.c datapagemap.c fetch.c filemap.c libpq_fetch.c logging.c parsexlog.c pg_rewind.c timeline.c ../../common/fe_memutils.c ../../common/restricted_token.c ../../../src/backend/access/transam/xlogreader.c
55

66
GETTEXT_TRIGGERS = pg_log pg_fatal report_invalid_record:2
77
GETTEXT_FLAGS = pg_log:2:c-format \

src/bin/pg_rewind/pg_rewind.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "access/xlog_internal.h"
2525
#include "catalog/catversion.h"
2626
#include "catalog/pg_control.h"
27+
#include "common/restricted_token.h"
2728
#include "getopt_long.h"
2829
#include "storage/bufpage.h"
2930

@@ -102,6 +103,7 @@ main(int argc, char **argv)
102103
TimeLineID endtli;
103104
ControlFileData ControlFile_new;
104105

106+
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_rewind"));
105107
progname = get_progname(argv[0]);
106108

107109
/* Process command-line arguments */
@@ -174,6 +176,21 @@ main(int argc, char **argv)
174176
exit(1);
175177
}
176178

179+
/*
180+
* Don't allow pg_rewind to be run as root, to avoid overwriting the
181+
* ownership of files in the data directory. We need only check for root
182+
* -- any other user won't have sufficient permissions to modify files in
183+
* the data directory.
184+
*/
185+
#ifndef WIN32
186+
if (geteuid() == 0)
187+
pg_fatal("cannot be executed by \"root\"\n"
188+
"You must run %s as the PostgreSQL superuser.\n",
189+
progname);
190+
#endif
191+
192+
get_restricted_token(progname);
193+
177194
/* Connect to remote server */
178195
if (connstr_source)
179196
libpqConnect(connstr_source);

0 commit comments

Comments
 (0)