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

Commit 75e39c4

Browse files
author
Neil Conway
committed
Prevent pg_resetxlog from being run as root. If this is allowed, some
root-owned files will be written to the data directory, leaving it in an unusable state.
1 parent 374abf9 commit 75e39c4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/bin/pg_resetxlog/pg_resetxlog.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
26-
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.25 2004/11/17 21:37:47 tgl Exp $
26+
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.26 2004/12/14 01:59:41 neilc Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -176,6 +176,25 @@ main(int argc, char *argv[])
176176
exit(1);
177177
}
178178

179+
/*
180+
* Don't allow pg_resetxlog to be run as root, to avoid
181+
* overwriting the ownership of files in the data directory. We
182+
* need only check for root -- any other user won't have
183+
* sufficient permissions to modify files in the data directory.
184+
*/
185+
#ifndef WIN32
186+
#ifndef __BEOS__ /* no root check on BeOS */
187+
if (geteuid() == 0)
188+
{
189+
fprintf(stderr, _("%s: cannot be executed by \"root\"\n"),
190+
progname);
191+
fprintf(stderr, _("You must run %s as the PostgreSQL superuser.\n"),
192+
progname);
193+
exit(1);
194+
}
195+
#endif
196+
#endif
197+
179198
DataDir = argv[optind];
180199
snprintf(XLogDir, MAXPGPATH, "%s/pg_xlog", DataDir);
181200
snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);

0 commit comments

Comments
 (0)