mirror of
https://github.com/HDFGroup/hdf5.git
synced 2026-09-25 04:09:44 +03:00
Restrict permissions for some created files (#6305)
This commit is contained in:
+7
-2
@@ -204,7 +204,8 @@ H5C__log_json_set_up(H5C_log_info_t *log_info, const char log_location[], int mp
|
||||
H5C_log_json_udata_t *json_udata = NULL;
|
||||
char *file_name = NULL;
|
||||
size_t n_chars;
|
||||
herr_t ret_value = SUCCEED; /* Return value */
|
||||
int log_file_fd = -1;
|
||||
herr_t ret_value = SUCCEED; /* Return value */
|
||||
|
||||
FUNC_ENTER_PACKAGE
|
||||
|
||||
@@ -243,8 +244,12 @@ H5C__log_json_set_up(H5C_log_info_t *log_info, const char log_location[], int mp
|
||||
snprintf(file_name, n_chars, "RANK_%d.%s", mpi_rank, log_location);
|
||||
|
||||
/* Open log file and set it to be unbuffered */
|
||||
if (NULL == (json_udata->outfile = fopen(file_name, "w")))
|
||||
if ((log_file_fd = HDopen(file_name, O_WRONLY | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_URWGROR)) < 0)
|
||||
HSYS_GOTO_ERROR(H5E_CACHE, H5E_CANTOPENFILE, FAIL, "can't create mdc log file");
|
||||
if (NULL == (json_udata->outfile = HDfdopen(log_file_fd, "w"))) {
|
||||
HDclose(log_file_fd);
|
||||
HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "can't create mdc log file");
|
||||
}
|
||||
setbuf(json_udata->outfile, NULL);
|
||||
|
||||
done:
|
||||
|
||||
+7
-2
@@ -199,7 +199,8 @@ H5C__log_trace_set_up(H5C_log_info_t *log_info, const char log_location[], int m
|
||||
H5C_log_trace_udata_t *trace_udata = NULL;
|
||||
char *file_name = NULL;
|
||||
size_t n_chars;
|
||||
herr_t ret_value = SUCCEED; /* Return value */
|
||||
int log_file_fd = -1;
|
||||
herr_t ret_value = SUCCEED; /* Return value */
|
||||
|
||||
FUNC_ENTER_PACKAGE
|
||||
|
||||
@@ -238,8 +239,12 @@ H5C__log_trace_set_up(H5C_log_info_t *log_info, const char log_location[], int m
|
||||
snprintf(file_name, n_chars, "%s.%d", log_location, mpi_rank);
|
||||
|
||||
/* Open log file and set it to be unbuffered */
|
||||
if (NULL == (trace_udata->outfile = fopen(file_name, "w")))
|
||||
if ((log_file_fd = HDopen(file_name, O_WRONLY | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_URWGROR)) < 0)
|
||||
HSYS_GOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "can't create mdc log file");
|
||||
if (NULL == (trace_udata->outfile = HDfdopen(log_file_fd, "w"))) {
|
||||
HDclose(log_file_fd);
|
||||
HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "can't create mdc log file");
|
||||
}
|
||||
setbuf(trace_udata->outfile, NULL);
|
||||
|
||||
/* Write the header */
|
||||
|
||||
+12
-2
@@ -540,8 +540,18 @@ H5FD__log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
|
||||
}
|
||||
|
||||
/* Set the log file pointer */
|
||||
if (fa->logfile)
|
||||
file->logfp = fopen(fa->logfile, "w");
|
||||
if (fa->logfile) {
|
||||
int log_file_id = -1;
|
||||
|
||||
if ((log_file_id =
|
||||
HDopen(fa->logfile, O_WRONLY | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_URWGROR)) < 0)
|
||||
HSYS_GOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open log file");
|
||||
|
||||
if (NULL == (file->logfp = HDfdopen(log_file_id, "w"))) {
|
||||
HDclose(log_file_id);
|
||||
HSYS_GOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open log file");
|
||||
}
|
||||
}
|
||||
else
|
||||
file->logfp = stderr;
|
||||
|
||||
|
||||
+9
-2
@@ -825,9 +825,16 @@ H5FD__splitter_open(const char *name, unsigned flags, hid_t splitter_fapl_id, ha
|
||||
*/
|
||||
if (!file_ptr->logfp) {
|
||||
if (file_ptr->fa.log_file_path[0] != '\0') {
|
||||
file_ptr->logfp = fopen(file_ptr->fa.log_file_path, "w");
|
||||
if (file_ptr->logfp == NULL)
|
||||
int log_file_fd = -1;
|
||||
|
||||
if ((log_file_fd = HDopen(file_ptr->fa.log_file_path, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
H5_POSIX_CREATE_MODE_URWGROR)) < 0)
|
||||
HSYS_GOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "unable to open log file");
|
||||
|
||||
if (NULL == (file_ptr->logfp = HDfdopen(log_file_fd, "w"))) {
|
||||
HDclose(log_file_fd);
|
||||
HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "unable to open log file");
|
||||
}
|
||||
} /* end if logfile path given */
|
||||
} /* end if logfile pointer/handle does not exist */
|
||||
|
||||
|
||||
@@ -2072,7 +2072,7 @@ static herr_t
|
||||
H5FD__subfiling_ioc_open_files(int64_t file_context_id, int file_acc_flags)
|
||||
{
|
||||
subfiling_context_t *sf_context = NULL;
|
||||
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||
mode_t mode = H5_POSIX_CREATE_MODE_URWGROR;
|
||||
char *filepath = NULL;
|
||||
char *subfile_dir = NULL;
|
||||
char *base = NULL;
|
||||
@@ -2210,6 +2210,7 @@ H5FD__subfiling_create_config_file(subfiling_context_t *sf_context, const char *
|
||||
FILE *config_file = NULL;
|
||||
char *config_filename = NULL;
|
||||
char *line_buf = NULL;
|
||||
int config_file_fd = -1;
|
||||
int ret = 0;
|
||||
herr_t ret_value = SUCCEED;
|
||||
|
||||
@@ -2255,7 +2256,12 @@ H5FD__subfiling_create_config_file(subfiling_context_t *sf_context, const char *
|
||||
int n_subfiles = sf_context->sf_num_subfiles;
|
||||
int num_digits;
|
||||
|
||||
if (NULL == (config_file = fopen(config_filename, "w+")))
|
||||
if ((config_file_fd =
|
||||
HDopen(config_filename, O_WRONLY | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_URWGROR)) < 0)
|
||||
HSYS_GOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, FAIL,
|
||||
"couldn't create/truncate subfiling configuration file");
|
||||
|
||||
if (NULL == (config_file = HDfdopen(config_file_fd, "w")))
|
||||
HSYS_GOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, FAIL,
|
||||
"couldn't create/truncate subfiling configuration file");
|
||||
|
||||
@@ -2301,9 +2307,12 @@ H5FD__subfiling_create_config_file(subfiling_context_t *sf_context, const char *
|
||||
}
|
||||
|
||||
done:
|
||||
if (config_file)
|
||||
if (config_file) {
|
||||
if (EOF == fclose(config_file))
|
||||
HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "couldn't close subfiling configuration file");
|
||||
}
|
||||
else if (config_file_fd >= 0 && HDclose(config_file_fd) < 0)
|
||||
HSYS_DONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "couldn't close subfiling configuration file");
|
||||
|
||||
H5MM_free(line_buf);
|
||||
H5MM_free(config_filename);
|
||||
|
||||
+6
-3
@@ -418,13 +418,16 @@
|
||||
#define H5_POSIX_MAX_IO_BYTES SSIZE_MAX
|
||||
#endif
|
||||
|
||||
/* POSIX I/O mode used as the third parameter to open/_open
|
||||
/* POSIX I/O modes used as the third parameter to open/_open
|
||||
* when creating a new file (O_CREAT is set).
|
||||
*/
|
||||
#if defined(H5_HAVE_WIN32_API)
|
||||
#define H5_POSIX_CREATE_MODE_RW (_S_IREAD | _S_IWRITE)
|
||||
#define H5_POSIX_CREATE_MODE_RW (_S_IREAD | _S_IWRITE)
|
||||
#define H5_POSIX_CREATE_MODE_URWGROR (_S_IREAD | _S_IWRITE)
|
||||
#else
|
||||
#define H5_POSIX_CREATE_MODE_RW 0666
|
||||
#define H5_POSIX_CREATE_MODE_RW 0666
|
||||
/* User R/W, Group R, Other R */
|
||||
#define H5_POSIX_CREATE_MODE_URWGROR (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
|
||||
#endif
|
||||
|
||||
/* Represents an empty asynchronous request handle.
|
||||
|
||||
Reference in New Issue
Block a user