File 00008-receivexlog-umask.patch of Package postgresql96-libs.7822

diff -urNp a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c
--- a/src/bin/pg_basebackup/pg_receivexlog.c	2017-08-29 00:21:42.000000000 +0300
+++ b/src/bin/pg_basebackup/pg_receivexlog.c	2017-10-30 11:16:55.033824965 +0300
@@ -80,6 +80,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 breaks 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"));
@@ -369,6 +370,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'},
@@ -406,7 +408,7 @@ main(int argc, char **argv)
 		}
 	}
 
-	while ((c = getopt_long(argc, argv, "D:d:h:p:U:s:S:nwWv",
+	while ((c = getopt_long(argc, argv, "D:d:h:p:U:s:S:nuwWv",
 							long_options, &option_index)) != -1)
 	{
 		switch (c)
@@ -429,6 +431,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	2017-08-29 00:21:42.000000000 +0300
+++ b/src/bin/pg_basebackup/pg_recvlogical.c	2017-10-30 11:16:55.034824975 +0300
@@ -328,11 +328,13 @@ 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/receivelog.c b/src/bin/pg_basebackup/receivelog.c
--- a/src/bin/pg_basebackup/receivelog.c	2017-08-29 00:21:42.000000000 +0300
+++ b/src/bin/pg_basebackup/receivelog.c	2017-10-30 11:18:39.985906493 +0300
@@ -63,7 +63,8 @@ mark_file_as_archived(const char *basedi
 	snprintf(tmppath, sizeof(tmppath), "%s/archive_status/%s.done",
 			 basedir, fname);
 
-	fd = open(tmppath, O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR);
+	mode_t mode = useumask == 1 ? S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH : S_IRUSR | S_IWUSR;
+	fd = open(tmppath, O_WRONLY | O_CREAT | PG_BINARY, mode);
 	if (fd < 0)
 	{
 		fprintf(stderr, _("%s: could not create archive status file \"%s\": %s\n"),
@@ -107,7 +108,8 @@ open_walfile(StreamCtl *stream, XLogRecP
 
 	snprintf(fn, sizeof(fn), "%s/%s%s", stream->basedir, current_walfile_name,
 			 stream->partial_suffix ? stream->partial_suffix : "");
-	f = open(fn, O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR);
+	mode_t mode = useumask == 1 ? S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH : S_IRUSR | S_IWUSR;
+	f = open(fn, O_WRONLY | O_CREAT | PG_BINARY, mode);
 	if (f == -1)
 	{
 		fprintf(stderr,
@@ -316,7 +318,8 @@ writeTimeLineHistoryFile(StreamCtl *stre
 
 	unlink(tmppath);
 
-	fd = open(tmppath, O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR);
+	mode_t mode = useumask == 1 ? S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH : S_IRUSR | S_IWUSR;
+	fd = open(tmppath, O_WRONLY | O_CREAT | PG_BINARY, mode);
 	if (fd < 0)
 	{
 		fprintf(stderr, _("%s: could not create timeline history file \"%s\": %s\n"),
diff -urNp a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
--- a/src/bin/pg_basebackup/streamutil.c	2017-08-29 00:21:42.000000000 +0300
+++ b/src/bin/pg_basebackup/streamutil.c	2017-10-30 11:16:55.034824975 +0300
@@ -40,6 +40,7 @@ char	   *dbuser = NULL;
 char	   *dbport = NULL;
 char	   *replication_slot = NULL;
 char	   *dbname = NULL;
+int			useumask = 0;	/* 0=auto, -1=never, 1=always */
 int			dbgetpassword = 0;	/* 0=auto, -1=never, 1=always */
 static char *dbpassword = NULL;
 PGconn	   *conn = NULL;
diff -urNp a/src/bin/pg_basebackup/streamutil.h b/src/bin/pg_basebackup/streamutil.h
--- a/src/bin/pg_basebackup/streamutil.h	2017-08-29 00:21:42.000000000 +0300
+++ b/src/bin/pg_basebackup/streamutil.h	2017-10-30 11:16:55.034824975 +0300
@@ -22,6 +22,7 @@ extern char *dbhost;
 extern char *dbuser;
 extern char *dbport;
 extern char *dbname;
+extern int	useumask;
 extern int	dbgetpassword;
 extern char *replication_slot;