From 599bab590a02a6b836414519fc90747d9f488f57 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 7 Apr 2020 13:29:59 +0900 Subject: [PATCH] Create temporary pg.auto.conf file with the same permissions as the original Commit 0574279 set the file permissions to 0600 rather than the user's umask, but if initdb was executed with -g/--allow-group-access, the file is maintained with 0640, so we'll just maintain the existing permssions. --- configfile.c | 10 ++++++++-- dbutils.c | 1 - doc/appendix-release-notes.xml | 7 +++++++ repmgr-action-standby.c | 1 - 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/configfile.c b/configfile.c index 3acf6587..cfcfa95b 100644 --- a/configfile.c +++ b/configfile.c @@ -1821,6 +1821,7 @@ modify_auto_conf(const char *data_dir, KeyValueList *items) FILE *fp; mode_t um; + struct stat auto_conf_st; KeyValueList config = {NULL, NULL}; KeyValueListCell *cell = NULL; @@ -1877,8 +1878,13 @@ modify_auto_conf(const char *data_dir, KeyValueList *items) cell->key, cell->value); } - /* Set umask to 0600 */ - um = umask((~(S_IRUSR | S_IWUSR)) & (S_IRWXG | S_IRWXO)); + stat(auto_conf.data, &auto_conf_st); + + /* + * Set umask so the temporary file is created in the same mode as the original + * postgresql.auto.conf file. + */ + um = umask(~(auto_conf_st.st_mode)); fp = fopen(auto_conf_tmp.data, "w"); umask(um); diff --git a/dbutils.c b/dbutils.c index 7b455e86..dba4b46a 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1165,7 +1165,6 @@ _get_pg_setting(PGconn *conn, const char *setting, char *str_output, bool *bool_ /* * Note we assume the caller is sure this is a boolean parameter */ - printf("YYY %s\n", PQgetvalue(res, i, 1)); if (strncmp(PQgetvalue(res, i, 1), "on", MAXLEN) == 0) *bool_output = true; else diff --git a/doc/appendix-release-notes.xml b/doc/appendix-release-notes.xml index 5a955b37..cd38e999 100644 --- a/doc/appendix-release-notes.xml +++ b/doc/appendix-release-notes.xml @@ -136,6 +136,13 @@ + + + Ensure postgresql.auto.conf is created with + correct permissions (PostgreSQL 12 and later). + + + diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index e6c45ff9..e3027303 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -6221,7 +6221,6 @@ check_upstream_config(PGconn *conn, int server_version_num, t_node_info *upstrea } } - printf("XXX %i\n", PQserverVersion(conn)); if (data_checksums == false && wal_log_hints == false) { /*