Kaydet (Commit) fb04780c authored tarafından Miklos Vajna's avatar Miklos Vajna

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/51169Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst c110b916
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include <sal/types.h> #include <sal/types.h>
#ifndef _WIN32
#include <sys/stat.h>
#endif
#include <memory> #include <memory>
#include <cppunit/TestAssert.h> #include <cppunit/TestAssert.h>
...@@ -31,6 +34,7 @@ ...@@ -31,6 +34,7 @@
#include <comphelper/propertysequence.hxx> #include <comphelper/propertysequence.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <sfx2/app.hxx> #include <sfx2/app.hxx>
#include <osl/file.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -117,11 +121,29 @@ void MiscTest::testNoThumbnail() ...@@ -117,11 +121,29 @@ void MiscTest::testNoThumbnail()
utl::TempFile aTempFile; utl::TempFile aTempFile;
uno::Sequence<beans::PropertyValue> aProperties( uno::Sequence<beans::PropertyValue> aProperties(
comphelper::InitPropertySequence({ { "NoThumbnail", uno::makeAny(true) } })); comphelper::InitPropertySequence({ { "NoThumbnail", uno::makeAny(true) } }));
osl::File::remove(aTempFile.GetURL());
xStorable->storeToURL(aTempFile.GetURL(), aProperties); xStorable->storeToURL(aTempFile.GetURL(), aProperties);
uno::Reference<packages::zip::XZipFileAccess2> xZipFile uno::Reference<packages::zip::XZipFileAccess2> xZipFile
= packages::zip::ZipFileAccess::createWithURL(m_xContext, aTempFile.GetURL()); = packages::zip::ZipFileAccess::createWithURL(m_xContext, aTempFile.GetURL());
CPPUNIT_ASSERT(!xZipFile->hasByName("Thumbnails/thumbnail.png")); 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(); xComponent->dispose();
} }
......
...@@ -165,6 +165,32 @@ bool IsLockingUsed() ...@@ -165,6 +165,32 @@ bool IsLockingUsed()
#endif #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 } // anonymous namespace
class SfxMedium_Impl class SfxMedium_Impl
...@@ -1785,8 +1811,16 @@ void SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource, ...@@ -1785,8 +1811,16 @@ void SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource,
{ {
OUString aSourceMainURL = aSource.GetMainURL(INetURLObject::DecodeMechanism::NONE); OUString aSourceMainURL = aSource.GetMainURL(INetURLObject::DecodeMechanism::NONE);
OUString aDestMainURL = aDest.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 (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; bResult = true;
}
else else
{ {
if (bOverWrite && ::utl::UCBContentHelper::IsDocument(aDestMainURL)) if (bOverWrite && ::utl::UCBContentHelper::IsDocument(aDestMainURL))
......
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