oox/source/ppt/presentationfragmenthandler.cxx |   76 +++++++++++++++++++++++++
 sd/qa/uitest/impress_tests/data/tdf144943.pptx |binary
 sd/qa/uitest/impress_tests/tdf144943.py        |   29 +++++++++
 sd/source/ui/unoidl/UnoDocumentSettings.cxx    |    2 
 4 files changed, 107 insertions(+)

New commits:
commit 5697e09b3e726a38b58ce31ac0c3a97e7871c74a
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Wed Oct 6 10:19:05 2021 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed Oct 13 14:45:30 2021 +0200

    tdf#144943 PPTX import: fix permission for editing
    
    The passwords for editing in PPTX documents
    created with PowerPoint weren't asked and verified.
    
    Change-Id: I62eb4fd68aac6422c1221a639f4815459ab556c9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123130
    Tested-by: Jenkins
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/oox/source/ppt/presentationfragmenthandler.cxx 
b/oox/source/ppt/presentationfragmenthandler.cxx
index 9aabd45d18af..95eb5fdb53c0 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -37,6 +37,7 @@
 #include <com/sun/star/task/XStatusIndicator.hpp>
 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
 #include <com/sun/star/container/XIndexContainer.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
 #include <com/sun/star/container/XNameContainer.hpp>
 
@@ -598,6 +599,81 @@ void PresentationFragmentHandler::finalizeImport()
         return new CustomShowListContext( *this, maCustomShowList );
     case PPT_TOKEN( defaultTextStyle ):
         return new TextListStyleContext( *this, *mpTextListStyle );
+    case PPT_TOKEN( modifyVerifier ):
+        OUString sAlgorithmClass = rAttribs.getString(XML_cryptAlgorithmClass, 
OUString());
+        OUString sAlgorithmType = rAttribs.getString(XML_cryptAlgorithmType, 
OUString());
+        sal_Int32 nAlgorithmSid = rAttribs.getInteger(XML_cryptAlgorithmSid, 
0);
+        sal_Int32 nSpinCount = rAttribs.getInteger(XML_spinCount, 0);
+        OUString sSalt = rAttribs.getString(XML_saltData, OUString());
+        OUString sHash = rAttribs.getString(XML_hashData, OUString());
+        if (sAlgorithmClass == "hash" && sAlgorithmType == "typeAny" && 
nAlgorithmSid != 0
+            && !sSalt.isEmpty() && !sHash.isEmpty())
+        {
+            OUString sAlgorithmName;
+            switch (nAlgorithmSid)
+            {
+                case 1:
+                    sAlgorithmName = "MD2";
+                    break;
+                case 2:
+                    sAlgorithmName = "MD4";
+                    break;
+                case 3:
+                    sAlgorithmName = "MD5";
+                    break;
+                case 4:
+                    sAlgorithmName = "SHA-1";
+                    break;
+                case 5:
+                    sAlgorithmName = "MAC";
+                    break;
+                case 6:
+                    sAlgorithmName = "RIPEMD";
+                    break;
+                case 7:
+                    sAlgorithmName = "RIPEMD-160";
+                    break;
+                case 9:
+                    sAlgorithmName = "HMAC";
+                    break;
+                case 12:
+                    sAlgorithmName = "SHA-256";
+                    break;
+                case 13:
+                    sAlgorithmName = "SHA-384";
+                    break;
+                case 14:
+                    sAlgorithmName = "SHA-512";
+                    break;
+                default:; // 8, 10, 11, any other value: Undefined.
+            }
+
+            if (!sAlgorithmName.isEmpty())
+            {
+                uno::Sequence<beans::PropertyValue> aResult;
+                aResult.realloc(4);
+                aResult[0].Name = "algorithm-name";
+                aResult[0].Value <<= sAlgorithmName;
+                aResult[1].Name = "salt";
+                aResult[1].Value <<= sSalt;
+                aResult[2].Name = "iteration-count";
+                aResult[2].Value <<= nSpinCount;
+                aResult[3].Name = "hash";
+                aResult[3].Value <<= sHash;
+                try
+                {
+                    uno::Reference<beans::XPropertySet> xDocSettings(
+                        getFilter().getModelFactory()->createInstance(
+                            "com.sun.star.document.Settings"),
+                        uno::UNO_QUERY);
+                    xDocSettings->setPropertyValue("ModifyPasswordInfo", 
uno::makeAny(aResult));
+                }
+                catch (const uno::Exception&)
+                {
+                }
+            }
+        }
+        return this;
     }
     return this;
 }
diff --git a/sd/qa/uitest/impress_tests/data/tdf144943.pptx 
b/sd/qa/uitest/impress_tests/data/tdf144943.pptx
new file mode 100644
index 000000000000..e03788fbadb1
Binary files /dev/null and b/sd/qa/uitest/impress_tests/data/tdf144943.pptx 
differ
diff --git a/sd/qa/uitest/impress_tests/tdf144943.py 
b/sd/qa/uitest/impress_tests/tdf144943.py
new file mode 100644
index 000000000000..7c63dfab8637
--- /dev/null
+++ b/sd/qa/uitest/impress_tests/tdf144943.py
@@ -0,0 +1,29 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_url_for_data_file
+from libreoffice.uno.propertyvalue import mkPropertyValues
+
+#Bug 144943 - FILEOPEN PPTX Read-only passwords on PPTX files are not working
+
+class tdf144943(UITestCase):
+
+    def test_tdf144943(self):
+        with self.ui_test.load_file(get_url_for_data_file("tdf144943.pptx")):
+            document = self.ui_test.get_component()
+
+            # Without the fix in place, this test would have failed with
+            # AssertionError: False is not true
+            self.assertTrue(document.isReadonly())
+
+            with self.ui_test.execute_dialog_through_command(".uno:EditDoc") 
as xDialog:
+                xPassword = xDialog.getChild("newpassEntry")
+                xPassword.executeAction("TYPE", mkPropertyValues({"TEXT": 
"password"}))
+
+            self.assertFalse(document.isReadonly())
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sd/source/ui/unoidl/UnoDocumentSettings.cxx 
b/sd/source/ui/unoidl/UnoDocumentSettings.cxx
index 24ac8f626dbe..5d13db6c4ecd 100644
--- a/sd/source/ui/unoidl/UnoDocumentSettings.cxx
+++ b/sd/source/ui/unoidl/UnoDocumentSettings.cxx
@@ -951,6 +951,8 @@ DocumentSettings::_setPropertyValues(const 
PropertyMapEntry** ppEntries,
                 if ( !pDocSh->SetModifyPasswordInfo( aInfo ) )
                     throw beans::PropertyVetoException(
                         "The hash is not allowed to be changed now!" );
+                else
+                    bOk = true;
 
             }
             break;

Reply via email to