Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 276d2e6

Browse files
committed
Make current_logfiles use permissions assigned to files in data directory
Since its introduction in 19dc233, current_logfiles has been assigned the same permissions as a log file, which can be enforced with log_file_mode. This setup can lead to incompatibility problems with group access permissions as current_logfiles is not located in the log directory, but at the root of the data folder. Hence, if group permissions are used but log_file_mode is more restrictive, a backup with a user in the group having read access could fail even if the log directory is located outside of the data folder. Per discussion with the folks mentioned below, we have concluded that current_logfiles should not be treated as a log file as it only stores metadata related to log files, and that it should use the same permissions as all other files in the data directory. This solution has the merit to be simple and fixes all the interaction problems between group access and log_file_mode. Author: Haribabu Kommi Reviewed-by: Stephen Frost, Robert Haas, Tom Lane, Michael Paquier Discussion: https://postgr.es/m/CAJrrPGcEotF1P7AWoeQyD3Pqr-0xkQg_Herv98DjbaMj+naozw@mail.gmail.com Backpatch-through: 11, where group access has been added.
1 parent 280a408 commit 276d2e6

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/backend/postmaster/syslogger.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <sys/stat.h>
3232
#include <sys/time.h>
3333

34+
#include "common/file_perm.h"
3435
#include "lib/stringinfo.h"
3536
#include "libpq/pqsignal.h"
3637
#include "miscadmin.h"
@@ -1447,12 +1448,14 @@ set_next_rotation_time(void)
14471448
* log messages. Useful for finding the name(s) of the current log file(s)
14481449
* when there is time-based logfile rotation. Filenames are stored in a
14491450
* temporary file and which is renamed into the final destination for
1450-
* atomicity.
1451+
* atomicity. The file is opened with the same permissions as what gets
1452+
* created in the data directory and has proper buffering options.
14511453
*/
14521454
static void
14531455
update_metainfo_datafile(void)
14541456
{
14551457
FILE *fh;
1458+
mode_t oumask;
14561459

14571460
if (!(Log_destination & LOG_DESTINATION_STDERR) &&
14581461
!(Log_destination & LOG_DESTINATION_CSVLOG))
@@ -1465,7 +1468,21 @@ update_metainfo_datafile(void)
14651468
return;
14661469
}
14671470

1468-
if ((fh = logfile_open(LOG_METAINFO_DATAFILE_TMP, "w", true)) == NULL)
1471+
/* use the same permissions as the data directory for the new file */
1472+
oumask = umask(pg_mode_mask);
1473+
fh = fopen(LOG_METAINFO_DATAFILE_TMP, "w");
1474+
umask(oumask);
1475+
1476+
if (fh)
1477+
{
1478+
setvbuf(fh, NULL, PG_IOLBF, 0);
1479+
1480+
#ifdef WIN32
1481+
/* use CRLF line endings on Windows */
1482+
_setmode(_fileno(fh), _O_TEXT);
1483+
#endif
1484+
}
1485+
else
14691486
{
14701487
ereport(LOG,
14711488
(errcode_for_file_access(),

0 commit comments

Comments
 (0)