summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorTünde Tóth <toth.tunde@nisz.hu>2021-08-31 12:08:39 +0200
committerLászló Németh <nemeth@numbertext.org>2021-09-01 11:29:08 +0200
commitc082158018148be01476d5bc82c1cd71ea6541df (patch)
treef4cb11058151559e6da2b0211109f0d3454fe134 /sc/source
parent521d91bce3a88dfaf529216f19e133dea7bb5af4 (diff)
tdf#118938 XLSX import/export: fix permission for editing
The password for editing wasn't asked, also wasn't exported in XLSX documents. Now it's exported in Calc using the following steps, also verified before editing: - In File->Save As, choose Excel 2007–365 (.xlsx) format; - enable checkbox "Save with password" and click Save; - in the dialog "Set password", click on "Options" and enable checkbox "Open file read-only", and enter a password for editing (i.e. skip the password for opening). Note: Excel 2016 doesn't ask password for editing, but Office 365 does. Passwords created in Excel haven't been supported, yet. Also passwords with diacritics aren't interoperable. Note: saving the file under a different path is still allowed both in Calc and Excel without asking the password for editing. Change-Id: Ic00d7c5a785e04d270a182a4087ea922d7d92979 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121371 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/filter/excel/excdoc.cxx11
-rw-r--r--sc/source/filter/oox/workbooksettings.cxx11
-rw-r--r--sc/source/ui/unoobj/confuno.cxx13
3 files changed, 25 insertions, 10 deletions
diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx
index ebc5a69f937a..1f43caaf73f9 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -806,7 +806,11 @@ void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
- rStrm.exportDocumentProperties(xDocProps, pDocShell->IsSecurityOptOpenReadOnly());
+ sal_uInt32 nWriteProtHash = pDocShell->GetModifyPasswordHash();
+ OUString sUserName = GetUserName();
+ bool bHasPassword = nWriteProtHash && !sUserName.isEmpty();
+ rStrm.exportDocumentProperties(xDocProps,
+ pDocShell->IsSecurityOptOpenReadOnly() && !bHasPassword);
rStrm.exportCustomFragments();
sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream();
@@ -821,6 +825,11 @@ void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
// OOXTODO: XML_rupBuild
);
+ if (bHasPassword)
+ rWorkbook->singleElement(XML_fileSharing,
+ XML_userName, sUserName,
+ XML_reservationPassword, OString::number(nWriteProtHash, 16).getStr());
+
if( !maTableList.IsEmpty() )
{
InitializeSave();
diff --git a/sc/source/filter/oox/workbooksettings.cxx b/sc/source/filter/oox/workbooksettings.cxx
index 19967601cd30..a7ab887bf967 100644
--- a/sc/source/filter/oox/workbooksettings.cxx
+++ b/sc/source/filter/oox/workbooksettings.cxx
@@ -210,15 +210,8 @@ void WorkbookSettings::finalizeImport()
if (maFileSharing.mbRecommendReadOnly || !maFileSharing.maHashValue.isEmpty())
aSettingsProp.setProperty( PROP_LoadReadonly, true );
- /* TODO: setting ModifyPasswordHash was commented out with commit
- * 1a842832cd174d5ccfd832fdb94c93ae42e8eacc of which the filter
- * fragment parts meanwhile contain PASSWORDTOMODIFY again, also for
- * calc_OOXML.xcu, but setting the property doesn't raise a dialog. If
- * it worked, a Sequence<PropertyValue> should be used for
- * algorithmName,hashValue,... see also
- * SfxObjectShell::SetModifyPasswordInfo() */
-// if( maFileSharing.mnPasswordHash != 0 )
-// aSettingsProp.setProperty( PROP_ModifyPasswordHash, static_cast< sal_Int32 >( maFileSharing.mnPasswordHash ) );
+ if( maFileSharing.mnPasswordHash != 0 )
+ aSettingsProp.setProperty( PROP_ModifyPasswordHash, static_cast< sal_Int32 >( maFileSharing.mnPasswordHash ) );
}
catch( Exception& )
{
diff --git a/sc/source/ui/unoobj/confuno.cxx b/sc/source/ui/unoobj/confuno.cxx
index d7ead11acdd4..f148b9abed8f 100644
--- a/sc/source/ui/unoobj/confuno.cxx
+++ b/sc/source/ui/unoobj/confuno.cxx
@@ -83,6 +83,7 @@ static const SfxItemPropertyMapEntry* lcl_GetConfigPropertyMap()
{u"" SC_UNO_LOADREADONLY, 0, cppu::UnoType<bool>::get(), 0, 0},
{u"" SC_UNO_SHAREDOC, 0, cppu::UnoType<bool>::get(), 0, 0},
{u"" SC_UNO_MODIFYPASSWORDINFO, 0, cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), 0, 0},
+ {u"" SC_UNO_MODIFYPASSWORDHASH, 0, cppu::UnoType<sal_Int32>::get(), 0, 0},
{u"" SC_UNO_EMBED_FONTS, 0, cppu::UnoType<bool>::get(), 0, 0},
{u"" SC_UNO_EMBED_ONLY_USED_FONTS, 0, cppu::UnoType<bool>::get(), 0, 0},
{u"" SC_UNO_EMBED_FONT_SCRIPT_LATIN, 0, cppu::UnoType<bool>::get(), 0, 0},
@@ -337,6 +338,16 @@ void SAL_CALL ScDocumentConfiguration::setPropertyValue(
throw beans::PropertyVetoException(
"The hash is not allowed to be changed now!" );
}
+ else if (aPropertyName == SC_UNO_MODIFYPASSWORDHASH)
+ {
+ sal_Int32 nHash;
+ if (!(aValue >>= nHash))
+ throw lang::IllegalArgumentException("Value of type sal_Int32 expected!",
+ uno::Reference<uno::XInterface>(), 2);
+
+ if (!pDocShell->SetModifyPasswordHash(nHash))
+ throw beans::PropertyVetoException("The hash is not allowed to be changed now!");
+ }
else if (aPropertyName == SC_UNO_EMBED_FONTS)
{
bool bVal = aValue.has<bool>() && aValue.get<bool>();
@@ -537,6 +548,8 @@ uno::Any SAL_CALL ScDocumentConfiguration::getPropertyValue( const OUString& aPr
}
else if ( aPropertyName == SC_UNO_MODIFYPASSWORDINFO )
aRet <<= pDocShell->GetModifyPasswordInfo();
+ else if (aPropertyName == SC_UNO_MODIFYPASSWORDHASH)
+ aRet <<= pDocShell->GetModifyPasswordHash();
else if (aPropertyName == SC_UNO_EMBED_FONTS)
aRet <<= rDoc.IsEmbedFonts();
else if (aPropertyName == SC_UNO_EMBED_ONLY_USED_FONTS)