Kaydet (Commit) 533237fe authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Related fdo#60338: Restrictive open mode flags for tempfile w/o calling umask

Change-Id: Ia83cbe4c9352eb2a2cf317dd1fc5771ddc12c993
üst 82fa84e9
......@@ -821,7 +821,8 @@ openMemoryAsFile( void *address, size_t size, oslFileHandle *pHandle, const char
#endif
oslFileError
openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags )
openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags,
mode_t mode)
{
oslFileError eRet;
......@@ -852,18 +853,22 @@ openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags
#endif
/* set mode and flags */
int mode = S_IRUSR | S_IRGRP | S_IROTH;
int defmode = S_IRUSR | S_IRGRP | S_IROTH;
int flags = O_RDONLY;
if (uFlags & osl_File_OpenFlag_Write)
{
mode |= S_IWUSR | S_IWGRP | S_IWOTH;
defmode |= S_IWUSR | S_IWGRP | S_IWOTH;
flags = OPEN_WRITE_FLAGS;
}
if (uFlags & osl_File_OpenFlag_Create)
{
mode |= S_IWUSR | S_IWGRP | S_IWOTH;
defmode |= S_IWUSR | S_IWGRP | S_IWOTH;
flags = OPEN_CREATE_FLAGS;
}
if (mode == mode_t(-1))
{
mode = defmode;
}
/* Check for flags passed in from SvFileStream::Open() */
if (uFlags & osl_File_OpenFlag_Trunc)
......@@ -999,6 +1004,12 @@ openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags
oslFileError
SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags )
{
return openFile(ustrFileURL, pHandle, uFlags, mode_t(-1));
}
oslFileError
SAL_CALL openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags, mode_t mode )
{
oslFileError eRet;
......@@ -1016,7 +1027,7 @@ SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uIn
return oslTranslateFileError (OSL_FET_ERROR, errno);
#endif /* MACOSX */
return openFilePath (buffer, pHandle, uFlags);
return openFilePath (buffer, pHandle, uFlags, mode);
}
oslFileError
......
......@@ -22,6 +22,7 @@
#include "osl/file.h"
#include <stddef.h>
#include <sys/types.h>
struct DirectoryItem_Impl
{
......@@ -43,10 +44,14 @@ struct DirectoryItem_Impl
oslFileType getFileType() const;
};
oslFileError openFile(
rtl_uString * pustrFileURL, oslFileHandle * pHandle, sal_uInt32 uFlags,
mode_t mode);
oslFileError openFilePath(
const char *cpFilePath,
oslFileHandle* pHandle,
sal_uInt32 uFlags );
sal_uInt32 uFlags, mode_t mode );
#endif /* INCLUDED_FILE_IMPL_HXX */
......
......@@ -917,7 +917,7 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD
if (openFilePath(pszSourceFileName,
&SourceFileFH,
osl_File_OpenFlag_Read|osl_File_OpenFlag_NoLock|osl_File_OpenFlag_NoExcl) != osl_File_E_None)
osl_File_OpenFlag_Read|osl_File_OpenFlag_NoLock|osl_File_OpenFlag_NoExcl, mode_t(-1)) != osl_File_E_None)
{
// Let's hope errno is still set relevantly after openFilePath...
nRet=errno;
......
......@@ -30,6 +30,7 @@
#include <sal/macros.h>
#include "file_url.h"
#include "file_impl.hxx"
oslFileError SAL_CALL osl_getTempDirURL( rtl_uString** pustrTempDir )
{
......@@ -233,17 +234,13 @@ static oslFileError osl_create_temp_file_impl_(
if (osl_File_E_None == osl_error)
{
/* RW permission for the user only! */
mode_t old_mode = umask(077);
osl_error = osl_openFile(
osl_error = openFile(
tmp_file_url,
file_handle,
osl_File_OpenFlag_Read |
osl_File_OpenFlag_Write |
osl_File_OpenFlag_Create);
umask(old_mode);
osl_File_OpenFlag_Create,
S_IRUSR | S_IWUSR);
}
/* in case of error osl_File_E_EXIST we simply try again else we give up */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment