From ca02ecade092730cb520e93e2b157be17fd753dc Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Mon, 27 May 2019 18:22:25 +0300 Subject: [PATCH] limit tablespace permissions kludge to only PG11 --- src/dir.c | 62 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/dir.c b/src/dir.c index 7d84856b..426d1696 100644 --- a/src/dir.c +++ b/src/dir.c @@ -939,6 +939,7 @@ opt_externaldir_map(ConfigOption *opt, const char *arg) * Enforce permissions from backup_content.control. The only * problem now is with PGDATA itself. * TODO: we must preserve PGDATA permissions somewhere. Is it actually a problem? + * Shouldn`t starting postgres force correct permissions on PGDATA? * * TODO: symlink handling. If user located symlink in PG_TBLSPC_DIR, it will * be restored as directory. @@ -949,35 +950,9 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba { int i; parray *links = NULL; - mode_t pg_tablespace_mode = 0; + mode_t pg_tablespace_mode = DIR_PERMISSION; char to_path[MAXPGPATH]; - /* Ugly: get PG_TBLSPC_DIR pemission mask. - * We will use it to set permissions for tablespace directories. - */ - for (i = 0; i < parray_num(dest_files); i++) - { - pgFile *file = (pgFile *) parray_get(dest_files, i); - - if (!S_ISDIR(file->mode)) - continue; - - /* skip external directory content */ - if (file->external_dir_num != 0) - continue; - - /* look for 'pg_tblspc' directory */ - if (strcmp(file->rel_path, PG_TBLSPC_DIR) == 0) - { - pg_tablespace_mode = file->mode; - break; - } - } - - /* sanity */ - if (!pg_tablespace_mode) - pg_tablespace_mode = DIR_PERMISSION; - /* get tablespace map */ if (extract_tablespaces) { @@ -987,6 +962,39 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba parray_qsort(links, pgFileCompareName); } + /* + * We have no idea about tablespace permission + * For PG < 11 we can just force default permissions. + */ +#if PG_VERSION_NUM >= 110000 + if (links) + { + /* For PG>=11 we use temp kludge: trust permissions on 'pg_tblspc' + * and force them on every tablespace. + * TODO: remove kludge and ask data_directory_mode + * at the start of backup. + */ + for (i = 0; i < parray_num(dest_files); i++) + { + pgFile *file = (pgFile *) parray_get(dest_files, i); + + if (!S_ISDIR(file->mode)) + continue; + + /* skip external directory content */ + if (file->external_dir_num != 0) + continue; + + /* look for 'pg_tblspc' directory */ + if (strcmp(file->rel_path, PG_TBLSPC_DIR) == 0) + { + pg_tablespace_mode = file->mode; + break; + } + } + } +#endif + /* * We iterate over dest_files and for every directory with parent 'pg_tblspc' * we must lookup this directory name in tablespace map.