summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-05-13 14:16:10 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-05-13 14:16:10 +0200
commit533237fec4b91fb5f871e0b5028586516dd8c0be (patch)
tree4b90ef25dd33b60a3f43228a54dc177ee09168d8 /sal
parent82fa84e983fd5c8266e3b9ac820035a1d78a2ab4 (diff)
Related fdo#60338: Restrictive open mode flags for tempfile w/o calling umask
Change-Id: Ia83cbe4c9352eb2a2cf317dd1fc5771ddc12c993
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/file.cxx21
-rw-r--r--sal/osl/unx/file_impl.hxx7
-rw-r--r--sal/osl/unx/file_misc.cxx2
-rw-r--r--sal/osl/unx/tempfile.cxx11
4 files changed, 27 insertions, 14 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 72fda5a800c6..e781574cab15 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 db8ce4e9c253..d1031bc07298 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 7662d9f6bf74..787866ec48bf 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 3d643b8a01ea..bbe3c27e0d39 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 */