Kaydet (Commit) 5246fa26 authored tarafından Michael Stahl's avatar Michael Stahl

fdo#68983: basic: if the library is not loaded fully, copy source storage

Also fixes fdo#42899 and fdo#67685 in a different way; the previous fix
for fdo#42899 caused the problem with password-protected libraries for
which the password is not known: only the binary representation of the
BAISC module was stored, not the source code; by simply copying from the
source storage the problem can be avoided.

It would be possible to ask for the password when storing, but that
would not work when non-interactive (called via API).

An alternative fix would be to pass in the
SfxObjectShell::IsSetModifyEnabled() flag and actually reset the BASIC
library's modify flag correctly, but that requires adding a
parameter to XStorageBasedLibraryContainer::storeLibrariesToStorage().

(regression from af34774d )

Change-Id: I4701401f35171139fc2fe8d225d13d4e533091a0
üst 5ca4b9d5
...@@ -582,7 +582,9 @@ private: ...@@ -582,7 +582,9 @@ private:
bool mbReadOnlyLink; bool mbReadOnlyLink;
bool mbPreload; bool mbPreload;
protected:
bool mbPasswordProtected; bool mbPasswordProtected;
private:
bool mbPasswordVerified; bool mbPasswordVerified;
bool mbDoc50Password; bool mbDoc50Password;
OUString maPassword; OUString maPassword;
...@@ -702,6 +704,8 @@ public: ...@@ -702,6 +704,8 @@ public:
} }
protected: protected:
virtual bool isLoadedStorable();
virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const = 0; virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const = 0;
}; };
......
...@@ -154,6 +154,7 @@ class SfxScriptLibrary : public SfxLibrary, public SfxScriptLibrary_BASE ...@@ -154,6 +154,7 @@ class SfxScriptLibrary : public SfxLibrary, public SfxScriptLibrary_BASE
const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ) SAL_OVERRIDE; const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ) SAL_OVERRIDE;
virtual void storeResourcesToStorage( const ::com::sun::star::uno::Reference virtual void storeResourcesToStorage( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage >& xStorage ) SAL_OVERRIDE; < ::com::sun::star::embed::XStorage >& xStorage ) SAL_OVERRIDE;
virtual bool isLoadedStorable() SAL_OVERRIDE;
public: public:
SfxScriptLibrary SfxScriptLibrary
......
...@@ -1909,8 +1909,6 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto ...@@ -1909,8 +1909,6 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
if( pImplLib->implIsModified() || bComplete ) if( pImplLib->implIsModified() || bComplete )
{ {
// For the moment don't copy storage (as an optimisation )
// but instead always write to storage from memory.
// Testing pImplLib->implIsModified() is not reliable, // Testing pImplLib->implIsModified() is not reliable,
// IMHO the value of pImplLib->implIsModified() should // IMHO the value of pImplLib->implIsModified() should
// reflect whether the library ( in-memory ) model // reflect whether the library ( in-memory ) model
...@@ -1921,9 +1919,14 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto ...@@ -1921,9 +1919,14 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
// temp storage when saving ( and later sets the root storage of the // temp storage when saving ( and later sets the root storage of the
// library container ) and similar madness in dbaccess means some surgery // library container ) and similar madness in dbaccess means some surgery
// is required to make it possible to successfully use this optimisation // is required to make it possible to successfully use this optimisation
#if 0 // It would be possible to do the implSetModified() call below only
// conditionally, but that would require an additional boolean to be
// passed in via the XStorageBasedDocument::storeLibrariesToStorage()...
// fdo#68983: If there's a password and the password is not known, only
// copying the storage works!
// Can we simply copy the storage? // Can we simply copy the storage?
if( !mbOldInfoFormat && !pImplLib->implIsModified() && !mbOasis2OOoFormat && xSourceLibrariesStor.is() ) if (!mbOldInfoFormat && !pImplLib->isLoadedStorable() &&
!mbOasis2OOoFormat && xSourceLibrariesStor.is())
{ {
try try
{ {
...@@ -1936,7 +1939,6 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto ...@@ -1936,7 +1939,6 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
} }
} }
else else
#endif
{ {
uno::Reference< embed::XStorage > xLibraryStor; uno::Reference< embed::XStorage > xLibraryStor;
if( bStorage ) if( bStorage )
...@@ -3037,6 +3039,11 @@ SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType, ...@@ -3037,6 +3039,11 @@ SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
{ {
} }
bool SfxLibrary::isLoadedStorable()
{
return mbLoaded && (!mbPasswordProtected || mbPasswordVerified);
}
void SfxLibrary::implSetModified( bool _bIsModified ) void SfxLibrary::implSetModified( bool _bIsModified )
{ {
if ( mbIsModified == _bIsModified ) if ( mbIsModified == _bIsModified )
......
...@@ -1259,6 +1259,12 @@ SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable, ...@@ -1259,6 +1259,12 @@ SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable,
{ {
} }
bool SfxScriptLibrary::isLoadedStorable()
{
// note: mbLoadedSource can only be true for password-protected lib!
return SfxLibrary::isLoadedStorable() && (!mbPasswordProtected || mbLoadedSource);
}
// Provide modify state including resources // Provide modify state including resources
bool SfxScriptLibrary::isModified( void ) bool SfxScriptLibrary::isModified( void )
{ {
......
...@@ -66,35 +66,39 @@ $(eval $(call gb_CppunitTest_use_api,sw_macros_test,\ ...@@ -66,35 +66,39 @@ $(eval $(call gb_CppunitTest_use_api,sw_macros_test,\
$(eval $(call gb_CppunitTest_use_ure,sw_macros_test)) $(eval $(call gb_CppunitTest_use_ure,sw_macros_test))
$(eval $(call gb_CppunitTest_use_components,sw_macros_test,\ $(eval $(call gb_CppunitTest_use_components,sw_macros_test,\
basic/util/sb \ basic/util/sb \
comphelper/util/comphelp \ embeddedobj/util/embobj \
configmgr/source/configmgr \ comphelper/util/comphelp \
dbaccess/util/dba \ configmgr/source/configmgr \
filter/source/config/cache/filterconfig1 \ dbaccess/util/dba \
forms/util/frm \ filter/source/config/cache/filterconfig1 \
framework/util/fwk \ filter/source/storagefilterdetect/storagefd \
i18npool/util/i18npool \ forms/util/frm \
oox/util/oox \ framework/util/fwk \
package/source/xstor/xstor \ i18npool/util/i18npool \
package/util/package2 \ oox/util/oox \
sax/source/expatwrap/expwrap \ package/source/xstor/xstor \
sw/util/sw \ package/util/package2 \
sw/util/swd \ sax/source/expatwrap/expwrap \
sw/util/msword \ scripting/source/basprov/basprov \
sw/util/vbaswobj \ scripting/util/scriptframe \
scripting/source/basprov/basprov \ sfx2/util/sfx \
scripting/util/scriptframe \ sot/util/sot \
sfx2/util/sfx \ svl/source/fsstor/fsstorage \
sot/util/sot \ svtools/util/svt \
svl/source/fsstor/fsstorage \ sw/util/msword \
svtools/util/svt \ sw/util/sw \
toolkit/util/tk \ sw/util/swd \
ucb/source/core/ucb1 \ sw/util/vbaswobj \
ucb/source/ucp/file/ucpfile1 \ toolkit/util/tk \
ucb/source/ucp/tdoc/ucptdoc1 \ ucb/source/core/ucb1 \
unotools/util/utl \ ucb/source/ucp/file/ucpfile1 \
unoxml/source/rdf/unordf \ ucb/source/ucp/tdoc/ucptdoc1 \
unoxml/source/service/unoxml \ unotools/util/utl \
unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \
xmloff/util/xo \
xmlsecurity/util/xsec_xmlsec \
)) ))
$(eval $(call gb_CppunitTest_use_configuration,sw_macros_test)) $(eval $(call gb_CppunitTest_use_configuration,sw_macros_test))
......
...@@ -20,7 +20,11 @@ ...@@ -20,7 +20,11 @@
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp> #include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/document/MacroExecMode.hpp> #include <com/sun/star/document/MacroExecMode.hpp>
#include <com/sun/star/document/XEmbeddedScripts.hpp>
#include <com/sun/star/script/XLibraryContainer.hpp>
#include <com/sun/star/script/XLibraryContainerPassword.hpp>
#include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/drawing/XShapes.hpp>
#include <com/sun/star/drawing/XShape.hpp> #include <com/sun/star/drawing/XShape.hpp>
...@@ -35,6 +39,7 @@ ...@@ -35,6 +39,7 @@
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <basic/sbxdef.hxx> #include <basic/sbxdef.hxx>
#include <unotools/tempfile.hxx>
#include <doc.hxx> #include <doc.hxx>
#include "docsh.hxx" #include "docsh.hxx"
...@@ -63,6 +68,7 @@ public: ...@@ -63,6 +68,7 @@ public:
void testVba(); void testVba();
#endif #endif
void testFdo55289(); void testFdo55289();
void testFdo68983();
CPPUNIT_TEST_SUITE(SwMacrosTest); CPPUNIT_TEST_SUITE(SwMacrosTest);
#if !defined(MACOSX) && !defined(WNT) #if !defined(MACOSX) && !defined(WNT)
//enable this test if you want to play with star basic macros in unit tests //enable this test if you want to play with star basic macros in unit tests
...@@ -71,6 +77,7 @@ public: ...@@ -71,6 +77,7 @@ public:
CPPUNIT_TEST(testVba); CPPUNIT_TEST(testVba);
#endif #endif
CPPUNIT_TEST(testFdo55289); CPPUNIT_TEST(testFdo55289);
CPPUNIT_TEST(testFdo68983);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
...@@ -190,6 +197,47 @@ void SwMacrosTest::testFdo55289() ...@@ -190,6 +197,47 @@ void SwMacrosTest::testFdo55289()
xShapeContent->attach(xEnd); xShapeContent->attach(xEnd);
} }
void SwMacrosTest::testFdo68983()
{
const OUString aFileNameBase("StarBasic.");
OUString aFileName;
createFileURL("fdo68983.", "odt", aFileName);
Reference< com::sun::star::lang::XComponent > xComponent =
loadFromDesktop(aFileName, "com.sun.star.text.TextDocument");
CPPUNIT_ASSERT_MESSAGE("Failed to load StarBasic.ods", xComponent.is());
Reference< frame::XStorable > xDocStorable(xComponent, UNO_QUERY_THROW);
CPPUNIT_ASSERT(xDocStorable.is());
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
Sequence<beans::PropertyValue> desc(1);
desc[0].Name = "FilterName";
desc[0].Value <<= OUString("writer8");
xDocStorable->storeAsURL(aTempFile.GetURL(), desc);
Reference<util::XCloseable>(xComponent, UNO_QUERY_THROW)->close(false);
// re-load
xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument");
// check that password-protected library survived store and re-load
Reference<document::XEmbeddedScripts> xDocScr(xComponent, UNO_QUERY_THROW);
Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected("Library1"));
CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("Library1", "foo"));
xBasLib->loadLibrary("Library1");
CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("Library1"));
// close
Reference<util::XCloseable> xDocCloseable(xComponent, UNO_QUERY_THROW);
xDocCloseable->close(false);
}
SwMacrosTest::SwMacrosTest() SwMacrosTest::SwMacrosTest()
: m_aBaseString("/sw/qa/core/data") : m_aBaseString("/sw/qa/core/data")
{ {
......
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