summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-03-12 21:24:09 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-03-13 09:08:55 +0100
commitfb04780cf8523ad4e900ae8b9cecbe7a2697a12a (patch)
treec46195825a825f032b646129d18d03e8a73989e6 /sfx2
parentc110b916b2662be2ddf7966fc102cc75ad72b5a6 (diff)
tdf#116117 sfx2 store: don't inherit temp file permissions when renaming
This has to be handled explicitly, otherwise the tempfile permissions (which intentionally don't respect umask()) would be preserved on rename(). Change-Id: I0a2681dbf06986e73f6e12d294e35e87b93b4f8a Reviewed-on: https://gerrit.libreoffice.org/51169 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/qa/cppunit/test_misc.cxx22
-rw-r--r--sfx2/source/doc/docfile.cxx34
2 files changed, 56 insertions, 0 deletions
diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx
index 5f36b438f089..a1ecc01a7c61 100644
--- a/sfx2/qa/cppunit/test_misc.cxx
+++ b/sfx2/qa/cppunit/test_misc.cxx
@@ -9,6 +9,9 @@
#include <sal/types.h>
+#ifndef _WIN32
+#include <sys/stat.h>
+#endif
#include <memory>
#include <cppunit/TestAssert.h>
@@ -31,6 +34,7 @@
#include <comphelper/propertysequence.hxx>
#include <comphelper/processfactory.hxx>
#include <sfx2/app.hxx>
+#include <osl/file.hxx>
using namespace ::com::sun::star;
@@ -117,11 +121,29 @@ void MiscTest::testNoThumbnail()
utl::TempFile aTempFile;
uno::Sequence<beans::PropertyValue> aProperties(
comphelper::InitPropertySequence({ { "NoThumbnail", uno::makeAny(true) } }));
+ osl::File::remove(aTempFile.GetURL());
xStorable->storeToURL(aTempFile.GetURL(), aProperties);
uno::Reference<packages::zip::XZipFileAccess2> xZipFile
= packages::zip::ZipFileAccess::createWithURL(m_xContext, aTempFile.GetURL());
CPPUNIT_ASSERT(!xZipFile->hasByName("Thumbnails/thumbnail.png"));
+#ifndef _WIN32
+ // Check permissions of the URL after store.
+ mode_t nMask = umask(022);
+ osl::DirectoryItem aItem;
+ CPPUNIT_ASSERT_EQUAL(osl::DirectoryItem::E_None,
+ osl::DirectoryItem::get(aTempFile.GetURL(), aItem));
+
+ osl::FileStatus aStatus(osl_FileStatus_Mask_Attributes);
+ CPPUNIT_ASSERT_EQUAL(osl::DirectoryItem::E_None, aItem.getFileStatus(aStatus));
+
+ // This failed, osl_File_Attribute_GrpRead was not set even if umask
+ // requested so.
+ CPPUNIT_ASSERT(aStatus.getAttributes() & osl_File_Attribute_GrpRead);
+ CPPUNIT_ASSERT(aStatus.getAttributes() & osl_File_Attribute_OthRead);
+ umask(nMask);
+#endif
+
xComponent->dispose();
}
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 9635f872b210..916acba81659 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -165,6 +165,32 @@ bool IsLockingUsed()
#endif
+/// Gets default attributes of a file:// URL.
+sal_uInt64 GetDefaultFileAttributes(const OUString& rURL)
+{
+ sal_uInt64 nRet = 0;
+
+ if (!comphelper::isFileUrl(rURL))
+ return nRet;
+
+ osl::File aFile(rURL);
+ if (aFile.open(osl_File_OpenFlag_Create) != osl::File::E_None)
+ return nRet;
+
+ aFile.close();
+
+ osl::DirectoryItem aItem;
+ if (osl::DirectoryItem::get(rURL, aItem) != osl::DirectoryItem::E_None)
+ return nRet;
+
+ osl::FileStatus aStatus(osl_FileStatus_Mask_Attributes);
+ if (aItem.getFileStatus(aStatus) != osl::DirectoryItem::E_None)
+ return nRet;
+
+ nRet = aStatus.getAttributes();
+ return nRet;
+}
+
} // anonymous namespace
class SfxMedium_Impl
@@ -1785,8 +1811,16 @@ void SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource,
{
OUString aSourceMainURL = aSource.GetMainURL(INetURLObject::DecodeMechanism::NONE);
OUString aDestMainURL = aDest.GetMainURL(INetURLObject::DecodeMechanism::NONE);
+
+ sal_uInt64 nAttributes = GetDefaultFileAttributes(aDestMainURL);
if (comphelper::isFileUrl(aDestMainURL) && osl::File::move(aSourceMainURL, aDestMainURL) == osl::FileBase::E_None)
+ {
+ if (nAttributes)
+ // Adjust attributes, source might be created with
+ // the osl_File_OpenFlag_Private flag.
+ osl::File::setAttributes(aDestMainURL, nAttributes);
bResult = true;
+ }
else
{
if (bOverWrite && ::utl::UCBContentHelper::IsDocument(aDestMainURL))