Create debug log file with more sane file permissions
Previously the file permissions for the debug log file were not explicitly set. Instead it was implicitly relying on a secure umask, which in most cases would result in a file that is world-readable. This is a violation of good practices, since not every user should have access to sensitive information that might be contained in the debug log file. Explicitly set sane default file permissions in case the file is newly created. Unfortunately the fopen(3) function does not provide such a facility, so the approach needs to be changed in the following way: 1) The file descriptor needs to be created manually using the open(3) function with the correct flags and the desired mode set. 2) fdopen(3) can then be used on the file descriptor to associate a file stream with it. Note: This modification will not change the file permissions of any already existing debug log files, and only applies to newly created ones. Signed-off-by: Karol Babioch <karol@babioch.de>
This commit is contained in:
parent
1d914d01d8
commit
1737eb3982
1 changed files with 17 additions and 1 deletions
|
@ -58,6 +58,10 @@ static int wpa_to_android_level(int level)
|
||||||
#ifndef CONFIG_NO_STDOUT_DEBUG
|
#ifndef CONFIG_NO_STDOUT_DEBUG
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_FILE
|
#ifdef CONFIG_DEBUG_FILE
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
static FILE *out_file = NULL;
|
static FILE *out_file = NULL;
|
||||||
#endif /* CONFIG_DEBUG_FILE */
|
#endif /* CONFIG_DEBUG_FILE */
|
||||||
|
|
||||||
|
@ -539,6 +543,8 @@ int wpa_debug_reopen_file(void)
|
||||||
int wpa_debug_open_file(const char *path)
|
int wpa_debug_open_file(const char *path)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_DEBUG_FILE
|
#ifdef CONFIG_DEBUG_FILE
|
||||||
|
int out_fd;
|
||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -548,10 +554,20 @@ int wpa_debug_open_file(const char *path)
|
||||||
last_path = os_strdup(path);
|
last_path = os_strdup(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
out_file = fopen(path, "a");
|
out_fd = open(path, O_CREAT | O_APPEND | O_WRONLY,
|
||||||
|
S_IRUSR | S_IWUSR | S_IRGRP);
|
||||||
|
if (out_fd < 0) {
|
||||||
|
wpa_printf(MSG_ERROR,
|
||||||
|
"%s: Failed to open output file descriptor, using standard output",
|
||||||
|
__func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
out_file = fdopen(out_fd, "a");
|
||||||
if (out_file == NULL) {
|
if (out_file == NULL) {
|
||||||
wpa_printf(MSG_ERROR, "wpa_debug_open_file: Failed to open "
|
wpa_printf(MSG_ERROR, "wpa_debug_open_file: Failed to open "
|
||||||
"output file, using standard output");
|
"output file, using standard output");
|
||||||
|
close(out_fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
|
Loading…
Reference in a new issue