[Libreoffice-commits] core.git: sfx2/qa sfx2/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Mar 13 08:09:18 UTC 2018


 sfx2/qa/cppunit/test_misc.cxx |   22 ++++++++++++++++++++++
 sfx2/source/doc/docfile.cxx   |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

New commits:
commit fb04780cf8523ad4e900ae8b9cecbe7a2697a12a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Mar 12 21:24:09 2018 +0100

    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 at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

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))


More information about the Libreoffice-commits mailing list