mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
Refactor dir/file permissions
Consolidate directory and file create permissions for tools which work with the PG data directory by adding a new module (common/file_perm.c) that contains variables (pg_file_create_mode, pg_dir_create_mode) and constants to initialize them (0600 for files and 0700 for directories). Convert mkdir() calls in the backend to MakePGDirectory() if the original call used default permissions (always the case for regular PG directories). Add tests to make sure permissions in PGDATA are set correctly by the tools which modify the PG data directory. Authors: David Steele <david@pgmasters.net>, Adam Brightwell <adam.brightwell@crunchydata.com> Reviewed-By: Michael Paquier, with discussion amongst many others. Discussion: https://postgr.es/m/ad346fe6-b23e-59f1-ecb7-0e08390ad629%40pgmasters.net
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "postgres_fe.h"
|
||||
|
||||
#include "access/visibilitymap.h"
|
||||
#include "common/file_perm.h"
|
||||
#include "pg_upgrade.h"
|
||||
#include "storage/bufpage.h"
|
||||
#include "storage/checksum.h"
|
||||
@@ -44,7 +45,7 @@ copyFile(const char *src, const char *dst,
|
||||
schemaName, relName, src, strerror(errno));
|
||||
|
||||
if ((dest_fd = open(dst, O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
|
||||
S_IRUSR | S_IWUSR)) < 0)
|
||||
pg_file_create_mode)) < 0)
|
||||
pg_fatal("error while copying relation \"%s.%s\": could not create file \"%s\": %s\n",
|
||||
schemaName, relName, dst, strerror(errno));
|
||||
|
||||
@@ -151,7 +152,7 @@ rewriteVisibilityMap(const char *fromfile, const char *tofile,
|
||||
schemaName, relName, fromfile, strerror(errno));
|
||||
|
||||
if ((dst_fd = open(tofile, O_RDWR | O_CREAT | O_EXCL | PG_BINARY,
|
||||
S_IRUSR | S_IWUSR)) < 0)
|
||||
pg_file_create_mode)) < 0)
|
||||
pg_fatal("error while copying relation \"%s.%s\": could not create file \"%s\": %s\n",
|
||||
schemaName, relName, tofile, strerror(errno));
|
||||
|
||||
|
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "pg_upgrade.h"
|
||||
#include "catalog/pg_class.h"
|
||||
#include "common/file_perm.h"
|
||||
#include "common/restricted_token.h"
|
||||
#include "fe_utils/string_utils.h"
|
||||
|
||||
@@ -79,7 +80,7 @@ main(int argc, char **argv)
|
||||
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_upgrade"));
|
||||
|
||||
/* Ensure that all files created by pg_upgrade are non-world-readable */
|
||||
umask(S_IRWXG | S_IRWXO);
|
||||
umask(PG_MODE_MASK_OWNER);
|
||||
|
||||
parseCommandLine(argc, argv);
|
||||
|
||||
|
@@ -230,6 +230,17 @@ standard_initdb 'initdb'
|
||||
|
||||
pg_upgrade $PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir" -p "$PGPORT" -P "$PGPORT"
|
||||
|
||||
# make sure all directories and files have correct permissions
|
||||
if [ $(find ${PGDATA} -type f ! -perm 600 | wc -l) -ne 0 ]; then
|
||||
echo "files in PGDATA with permission != 600";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ $(find ${PGDATA} -type d ! -perm 700 | wc -l) -ne 0 ]; then
|
||||
echo "directories in PGDATA with permission != 700";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
pg_ctl start -l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w
|
||||
|
||||
case $testhost in
|
||||
|
Reference in New Issue
Block a user