[Libreoffice-commits] core.git: Branch 'distro/cib/libreoffice-6-1' - dbaccess/source
Samuel Mehrbrodt (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jun 26 14:54:20 UTC 2020
dbaccess/source/core/dataaccess/ModelImpl.cxx | 93 +++++++++++++++++++
dbaccess/source/core/dataaccess/databasedocument.cxx | 90 ------------------
dbaccess/source/core/inc/ModelImpl.hxx | 2
3 files changed, 95 insertions(+), 90 deletions(-)
New commits:
commit 322e0825d1c6382a8affa53283abc6c1298752c5
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Mon Apr 20 16:10:03 2020 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Jun 26 16:53:40 2020 +0200
Fix macro signature getting lost when inserting data into table
Change-Id: Iec514bfc0edd4f10a09809c68b8501667d978e52
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92573
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
(cherry picked from commit 919bd3e78cce84a3338208e81d7056d8379d1bd5)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93189
(cherry picked from commit 77f02e09a9ef9f4c53dfcec481aa0f35c763beb0)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97123
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx
index ef4525cc3877..6c88be36560d 100644
--- a/dbaccess/source/core/dataaccess/ModelImpl.cxx
+++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx
@@ -58,11 +58,13 @@
#include <tools/debug.hxx>
#include <sfx2/docfile.hxx>
#include <tools/diagnose_ex.h>
+#include <osl/file.hxx>
#include <osl/diagnose.h>
#include <sal/log.hxx>
#include <vcl/errcode.hxx>
#include <tools/urlobj.hxx>
#include <unotools/sharedunocomponent.hxx>
+#include <unotools/tempfile.hxx>
#include <algorithm>
@@ -856,6 +858,23 @@ bool ODatabaseModelImpl::commitEmbeddedStorage( bool _bPreventRootCommits )
bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage )
{
+ bool bTryToPreserveScriptSignature = false;
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ OUString m_sTmpFileUrl = aTempFile.GetURL();
+ SignatureState aSignatureState = getScriptingSignatureState();
+ if (aSignatureState == SignatureState::OK
+ || aSignatureState == SignatureState::NOTVALIDATED
+ || aSignatureState == SignatureState::INVALID)
+ {
+ bTryToPreserveScriptSignature = true;
+ // We need to first save the file (which removes the macro signature), then add the macro signature again.
+ // For that, we need a temporary copy of the original file.
+ osl::File::RC rc = osl::File::copy(getDocFileLocation(), m_sTmpFileUrl);
+ if (rc != osl::FileBase::E_None)
+ throw uno::RuntimeException("Could not create temp file");
+ }
+
bool bSuccess = false;
try
{
@@ -865,6 +884,80 @@ bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference<
{
DBG_UNHANDLED_EXCEPTION("dbaccess");
}
+
+ // Preserve script signature if the script has not changed
+ if (bTryToPreserveScriptSignature)
+ {
+ // Need to close this storage, otherwise we can't open it for signing below
+ // (Windows needs exclusive file access)
+ //uno::Reference < lang::XComponent > xComp = xCurrentStorage;
+ //xComp->dispose();
+ OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(_rxStorage));
+ uno::Reference<security::XDocumentDigitalSignatures> xDDSigns;
+ try
+ {
+ xDDSigns = security::DocumentDigitalSignatures::createWithVersion(
+ comphelper::getProcessComponentContext(), aODFVersion);
+
+ const OUString aScriptSignName
+ = xDDSigns->getScriptingContentSignatureDefaultStreamName();
+
+ if (!aScriptSignName.isEmpty())
+ {
+ Reference<XStorage> xReadOrig
+ = comphelper::OStorageHelper::GetStorageOfFormatFromURL(
+ ZIP_STORAGE_FORMAT_STRING, m_sTmpFileUrl, ElementModes::READ);
+ if (!xReadOrig.is())
+ throw uno::RuntimeException("Could not read " + m_sTmpFileUrl);
+ uno::Reference<embed::XStorage> xMetaInf
+ = xReadOrig->openStorageElement("META-INF", embed::ElementModes::READ);
+
+ OUString aURL = getDocFileLocation();
+ Reference<XStorage> xTarget
+ = comphelper::OStorageHelper::GetStorageOfFormatFromURL(
+ ZIP_STORAGE_FORMAT_STRING, aURL, ElementModes::READWRITE);
+ if (!xTarget.is())
+ throw uno::RuntimeException("Could not read " + aURL);
+ uno::Reference<embed::XStorage> xTargetMetaInf
+ = xTarget->openStorageElement("META-INF", embed::ElementModes::READWRITE);
+
+ if (xMetaInf.is() && xTargetMetaInf.is())
+ {
+ xMetaInf->copyElementTo(aScriptSignName, xTargetMetaInf, aScriptSignName);
+
+ uno::Reference<embed::XTransactedObject> xTransact(xTargetMetaInf,
+ uno::UNO_QUERY);
+ if (xTransact.is())
+ xTransact->commit();
+
+ xTargetMetaInf->dispose();
+
+ // now check the copied signature
+ uno::Sequence<security::DocumentSignatureInformation> aInfos
+ = xDDSigns->verifyScriptingContentSignatures(
+ xTarget, uno::Reference<io::XInputStream>());
+ SignatureState nState = DocumentSignatures::getSignatureState(aInfos);
+ if (nState == SignatureState::OK || nState == SignatureState::NOTVALIDATED
+ || nState == SignatureState::PARTIAL_OK)
+ {
+ // commit the ZipStorage from target medium
+ xTransact.set(xTarget, uno::UNO_QUERY);
+ if (xTransact.is())
+ xTransact->commit();
+ }
+ else
+ {
+ SAL_WARN("dbaccess", "An invalid signature was copied!");
+ }
+ }
+ }
+ }
+ catch (uno::Exception&)
+ {
+ SAL_WARN("dbaccess", "Could not preserve script signature!");
+ }
+ }
+
return bSuccess;
}
diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx
index f76104e93aa9..c75356a61dc3 100644
--- a/dbaccess/source/core/dataaccess/databasedocument.cxx
+++ b/dbaccess/source/core/dataaccess/databasedocument.cxx
@@ -1029,22 +1029,6 @@ void ODatabaseDocument::impl_storeAs_throw( const OUString& _rURL, const ::comph
_rGuard.reset();
}
- bool bTryToPreserveScriptSignature = false;
- utl::TempFile aTempFile;
- aTempFile.EnableKillingFile();
- OUString aTmpFileURL = aTempFile.GetURL();
- if (m_pImpl->getScriptingSignatureState() == SignatureState::OK
- || m_pImpl->getScriptingSignatureState() == SignatureState::NOTVALIDATED
- || m_pImpl->getScriptingSignatureState() == SignatureState::INVALID)
- {
- bTryToPreserveScriptSignature = true;
- // We need to first save the file (which removes the macro signature), then add the macro signature again.
- // For that, we need a temporary copy of the original file.
- osl::File::RC rc = osl::File::copy(m_pImpl->getDocFileLocation(), aTmpFileURL);
- if (rc != osl::FileBase::E_None)
- throw uno::RuntimeException("Could not create temp file");
- }
-
Reference< XStorage > xNewRootStorage;
// will be non-NULL if our storage changed
@@ -1094,81 +1078,9 @@ void ODatabaseDocument::impl_storeAs_throw( const OUString& _rURL, const ::comph
// store to current storage
Reference< XStorage > xCurrentStorage( m_pImpl->getOrCreateRootStorage(), UNO_SET_THROW );
- OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(xCurrentStorage));
Sequence< PropertyValue > aMediaDescriptor( lcl_appendFileNameToDescriptor( _rArguments, _rURL ) );
impl_storeToStorage_throw( xCurrentStorage, aMediaDescriptor, _rGuard );
- // Preserve script signature if the script has not changed
- if (bTryToPreserveScriptSignature)
- {
- // Need to close this storage, otherwise we can't open it for signing below
- // (Windows needs exclusive file access)
- uno::Reference < lang::XComponent > xComp = xCurrentStorage;
- xComp->dispose();
- uno::Reference<security::XDocumentDigitalSignatures> xDDSigns;
- try
- {
- xDDSigns = security::DocumentDigitalSignatures::createWithVersion(
- comphelper::getProcessComponentContext(), aODFVersion);
-
- const OUString aScriptSignName
- = xDDSigns->getScriptingContentSignatureDefaultStreamName();
-
- if (!aScriptSignName.isEmpty())
- {
- Reference<XStorage> xReadOrig
- = comphelper::OStorageHelper::GetStorageOfFormatFromURL(
- ZIP_STORAGE_FORMAT_STRING, aTmpFileURL, ElementModes::READ);
- if (!xReadOrig.is())
- throw uno::RuntimeException("Could not read " + aTmpFileURL);
- uno::Reference<embed::XStorage> xMetaInf
- = xReadOrig->openStorageElement("META-INF", embed::ElementModes::READ);
-
- Reference<XStorage> xTarget
- = comphelper::OStorageHelper::GetStorageOfFormatFromURL(
- ZIP_STORAGE_FORMAT_STRING, _rURL, ElementModes::READWRITE);
- if (!xTarget.is())
- throw uno::RuntimeException("Could not read " + _rURL);
- uno::Reference<embed::XStorage> xTargetMetaInf
- = xTarget->openStorageElement("META-INF", embed::ElementModes::READWRITE);
-
- if (xMetaInf.is() && xTargetMetaInf.is())
- {
- xMetaInf->copyElementTo(aScriptSignName, xTargetMetaInf, aScriptSignName);
-
- uno::Reference<embed::XTransactedObject> xTransact(xTargetMetaInf,
- uno::UNO_QUERY);
- if (xTransact.is())
- xTransact->commit();
-
- xTargetMetaInf->dispose();
-
- // now check the copied signature
- uno::Sequence<security::DocumentSignatureInformation> aInfos
- = xDDSigns->verifyScriptingContentSignatures(
- xTarget, uno::Reference<io::XInputStream>());
- SignatureState nState = DocumentSignatures::getSignatureState(aInfos);
- if (nState == SignatureState::OK || nState == SignatureState::NOTVALIDATED
- || nState == SignatureState::PARTIAL_OK)
- {
- // commit the ZipStorage from target medium
- xTransact.set(xTarget, uno::UNO_QUERY);
- if (xTransact.is())
- xTransact->commit();
- }
- else
- {
- SAL_WARN("dbaccess", "An invalid signature was copied!");
- }
- }
- }
- }
- catch (uno::Exception&)
- {
- SAL_WARN("dbaccess", "Preserving macro signature failed!");
- }
- }
-
// success - tell our impl
m_pImpl->setDocFileLocation( _rURL );
m_pImpl->setResource( _rURL, aMediaDescriptor );
@@ -1309,7 +1221,7 @@ void ODatabaseDocument::impl_storeToStorage_throw( const Reference< XStorage >&
lcl_triggerStatusIndicator_throw( aWriteArgs, _rDocGuard, false );
// commit target storage
- OSL_VERIFY( tools::stor::commitStorageIfWriteable( _rxTargetStorage ) );
+ m_pImpl->commitStorageIfWriteable_ignoreErrors(_rxTargetStorage);
}
catch( const IOException& ) { throw; }
catch( const RuntimeException& ) { throw; }
diff --git a/dbaccess/source/core/inc/ModelImpl.hxx b/dbaccess/source/core/inc/ModelImpl.hxx
index 1a375b0b1e19..dff7dafb74e6 100644
--- a/dbaccess/source/core/inc/ModelImpl.hxx
+++ b/dbaccess/source/core/inc/ModelImpl.hxx
@@ -300,7 +300,7 @@ public:
void commitRootStorage();
/// commits a given storage if it's not readonly, ignoring (but asserting) all errors
- static bool commitStorageIfWriteable_ignoreErrors(
+ bool commitStorageIfWriteable_ignoreErrors(
const css::uno::Reference< css::embed::XStorage >& _rxStorage
);
More information about the Libreoffice-commits
mailing list