File 00006-pg_receivewal.patch of Package postgresql10
diff -urNp a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
--- a/src/bin/pg_basebackup/pg_receivewal.c 2018-05-07 23:51:40.000000000 +0300
+++ b/src/bin/pg_basebackup/pg_receivewal.c 2018-07-06 14:48:10.133357476 +0300
@@ -91,6 +91,7 @@ usage(void)
printf(_(" -d, --dbname=CONNSTR connection string\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port number\n"));
+ printf(_(" -u, --umask set files mode according to umask (might break security!)\n"));
printf(_(" -U, --username=NAME connect as specified database user\n"));
printf(_(" -w, --no-password never prompt for password\n"));
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
@@ -461,6 +462,7 @@ main(int argc, char **argv)
{"dbname", required_argument, NULL, 'd'},
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
+ {"umask", no_argument, NULL, 'u'},
{"username", required_argument, NULL, 'U'},
{"no-loop", no_argument, NULL, 'n'},
{"no-password", no_argument, NULL, 'w'},
@@ -499,7 +501,7 @@ main(int argc, char **argv)
}
}
- while ((c = getopt_long(argc, argv, "D:d:h:p:U:s:S:nwWvZ:",
+ while ((c = getopt_long(argc, argv, "D:d:h:p:U:s:S:nuwWvZ",
long_options, &option_index)) != -1)
{
switch (c)
@@ -522,6 +524,9 @@ main(int argc, char **argv)
}
dbport = pg_strdup(optarg);
break;
+ case 'u':
+ useumask = 1;
+ break;
case 'U':
dbuser = pg_strdup(optarg);
break;
diff -urNp a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
--- a/src/bin/pg_basebackup/pg_recvlogical.c 2018-05-07 23:51:40.000000000 +0300
+++ b/src/bin/pg_basebackup/pg_recvlogical.c 2018-07-06 14:27:21.819405264 +0300
@@ -335,11 +335,14 @@ StreamLogicalLog(void)
{
struct stat statbuf;
+ mode_t mode = (useumask == 1) ?
+ (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) : (S_IRUSR | S_IWUSR);
+
if (strcmp(outfile, "-") == 0)
outfd = fileno(stdout);
else
outfd = open(outfile, O_CREAT | O_APPEND | O_WRONLY | PG_BINARY,
- S_IRUSR | S_IWUSR);
+ mode);
if (outfd == -1)
{
fprintf(stderr,
diff -urNp a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
--- a/src/bin/pg_basebackup/streamutil.c 2018-05-07 23:51:40.000000000 +0300
+++ b/src/bin/pg_basebackup/streamutil.c 2018-07-06 14:27:21.820405275 +0300
@@ -38,6 +38,7 @@ char *dbhost = NULL;
char *dbuser = NULL;
char *dbport = NULL;
char *dbname = NULL;
+int useumask = 0; /* 0=auto, -1=never, 1=always */
int dbgetpassword = 0; /* 0=auto, -1=never, 1=always */
static bool have_password = false;
static char password[100];
diff -urNp a/src/bin/pg_basebackup/streamutil.h b/src/bin/pg_basebackup/streamutil.h
--- a/src/bin/pg_basebackup/streamutil.h 2018-05-07 23:51:40.000000000 +0300
+++ b/src/bin/pg_basebackup/streamutil.h 2018-07-06 14:27:21.820405275 +0300
@@ -23,6 +23,7 @@ extern char *dbhost;
extern char *dbuser;
extern char *dbport;
extern char *dbname;
+extern int useumask;
extern int dbgetpassword;
/* Connection kept global so we can disconnect easily */
diff -urNp a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
--- a/src/bin/pg_basebackup/walmethods.c 2018-05-07 23:51:40.000000000 +0300
+++ b/src/bin/pg_basebackup/walmethods.c 2018-07-06 14:27:21.821405285 +0300
@@ -77,6 +77,8 @@ dir_open_for_write(const char *pathname,
#ifdef HAVE_LIBZ
gzFile gzfp = NULL;
#endif
+ mode_t mode = (useumask == 1) ?
+ (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) : (S_IRUSR | S_IWUSR);
snprintf(tmppath, sizeof(tmppath), "%s/%s%s%s",
dir_data->basedir, pathname,
@@ -89,7 +91,7 @@ dir_open_for_write(const char *pathname,
* does not do any system calls to fsync() to make changes permanent on
* disk.
*/
- fd = open(tmppath, O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR);
+ fd = open(tmppath, O_WRONLY | O_CREAT | PG_BINARY, mode);
if (fd < 0)
return NULL;
@@ -525,6 +527,8 @@ tar_open_for_write(const char *pathname,
{
int save_errno;
static char tmppath[MAXPGPATH];
+ mode_t mode = (useumask == 1) ?
+ (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) : (S_IRUSR | S_IWUSR);
tar_clear_error();
@@ -534,7 +538,7 @@ tar_open_for_write(const char *pathname,
* We open the tar file only when we first try to write to it.
*/
tar_data->fd = open(tar_data->tarfilename,
- O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR);
+ O_WRONLY | O_CREAT | PG_BINARY, mode);
if (tar_data->fd < 0)
return NULL;