Skip to content

Commit 7bae0ad

Browse files
committed
Prevent running pg_basebackup as root
Similarly to pg_upgrade, pg_ctl and initdb, a root user is able to use --version and --help, but cannot execute the actual operation to avoid the creation of files with permissions incompatible with the postmaster. This is a behavior change, so not back-patching is done. Author: Ian Barwick Discussion: https://postgr.es/m/CABvVfJVqOdD2neLkYdygdOHvbWz_5K_iWiqY+psMfA=FeAa3qQ@mail.gmail.com
1 parent 93745f1 commit 7bae0ad

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,22 @@ main(int argc, char **argv)
20772077
}
20782078
}
20792079

2080+
/*
2081+
* Don't allow pg_basebackup to be run as root, to avoid creating files in
2082+
* the data directory with ownership rights incompatible with the
2083+
* postmaster.
2084+
*/
2085+
#ifndef WIN32
2086+
if (geteuid() == 0) /* 0 is root's uid */
2087+
{
2088+
pg_log_error("cannot be run as root");
2089+
fprintf(stderr,
2090+
_("Please log in (using, e.g., \"su\") as the (unprivileged) user that will\n"
2091+
"own the server process.\n"));
2092+
exit(1);
2093+
}
2094+
#endif
2095+
20802096
atexit(cleanup_directories_atexit);
20812097

20822098
while ((c = getopt_long(argc, argv, "CD:F:r:RS:T:X:l:nNzZ:d:c:h:p:U:s:wWkvP",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy