sal/osl/unx/file.cxx | 21 ++++++++++++++++----- sal/osl/unx/file_impl.hxx | 7 ++++++- sal/osl/unx/file_misc.cxx | 2 +- sal/osl/unx/tempfile.cxx | 11 ++++------- 4 files changed, 27 insertions(+), 14 deletions(-)
New commits: commit 533237fec4b91fb5f871e0b5028586516dd8c0be Author: Stephan Bergmann <sberg...@redhat.com> Date: Tue May 13 14:16:10 2014 +0200 Related fdo#60338: Restrictive open mode flags for tempfile w/o calling umask Change-Id: Ia83cbe4c9352eb2a2cf317dd1fc5771ddc12c993 diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index 72fda5a..e781574 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -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) @@ -1000,6 +1005,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; if ((ustrFileURL == 0) || (ustrFileURL->length == 0) || (pHandle == 0)) @@ -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 diff --git a/sal/osl/unx/file_impl.hxx b/sal/osl/unx/file_impl.hxx index db8ce4e..d1031bc 100644 --- a/sal/osl/unx/file_impl.hxx +++ b/sal/osl/unx/file_impl.hxx @@ -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 */ diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx index 7662d9f..787866e 100644 --- a/sal/osl/unx/file_misc.cxx +++ b/sal/osl/unx/file_misc.cxx @@ -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; diff --git a/sal/osl/unx/tempfile.cxx b/sal/osl/unx/tempfile.cxx index 3d643b8..bbe3c27 100644 --- a/sal/osl/unx/tempfile.cxx +++ b/sal/osl/unx/tempfile.cxx @@ -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 */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits