Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I've somehow investigated the problem with password protected Word documents. It was marked as Hard Hack. I have to admit, that I don't know any further and someone else with more background on form protection has to look into this.

I've attached "fix.patch" which only shows where the difference between both file formats begins. "0001-debug.patch" is my debug information.


Here's some of the mail correspondence with mst:

--- snip ---

I compared the behavior of odt and doc files. The difference is at:
http://opengrok.libreoffice.org/xref/core/sw/source/core/crsr/pam.cxx#724

IDocumentSettingAccess::PROTECT_FORM is always 0 for odt files. And 1 for doc files. This seems strange, I expected that odt files have this flag too. So odt has no (proper?) form protection as I understand this. I added two files to the bug, which demonstrate, that odt has no form protection (I could click the button and the checkbox).

This code block in pam.cxx had a comment in history:
"TODO: Form Protection when Enhanced Fields are enabled"

What are "Enhanced Fields"? Are this forms?


Nevertheless if I comment that block out (see patch) the problem is fixed. The doc file can be unlocked, edited and saved properly. But I don't know what the deeper consequences are ;)

--- snap ---

--- snip ---

On 18.04.2013 13:05, Michael Stahl wrote:
>> IDocumentSettingAccess::PROTECT_FORM is always 0 for odt files. And 1
>> for doc files. This seems strange, I expected that odt files have this
>> flag too. So odt has no (proper?) form protection as I understand this.
>> I added two files to the bug, which demonstrate, that odt has no form
>> protection (I could click the button and the checkbox).
>
> apparently this is available at SwXDocumentSettings as "ProtectForm"
> property and should also be stored into/loaded from ODF files (in a
> generic way).  but the only way for it to be enabled is apparently
> loading an WW8 file.  i assume if you load a WW8 file with it enabled,
> store it as ODF and load again it should be on?

Yes you are right, if I store the ww8 file as odf and load it again the form protection mode is on.

>> This code block in pam.cxx had a comment in history:
>> "TODO: Form Protection when Enhanced Fields are enabled"
>>
>> What are "Enhanced Fields"? Are this forms?
>
> "ordinary" fields in Writer contain just an unformatted string of text,
> and are represented by a single dummy character in the paragraph text.
>
> the "enhanced" ones however are implemented totally differently, with a
> special kind of bookmark and dummy 0x04 or so characters in the text to
> mark the start/end positions.  the content of an enhanced field is
> arbitrary paragraph content with arbitrary formatting.
>
>> Nevertheless if I comment that block out (see patch) the problem is
>> fixed. The doc file can be unlocked, edited and saved properly. But I
>> don't know what the deeper consequences are ;)
>
> i don't think that is such a good idea.  perhaps there should be some
> way to enable this setting for newly created documents, but i don't know
> how it is possible to create the enhanced fields from the UI... has that
> ever been implemented?   can we just load them from WW8 and ODF
> (extended) files?

I've got some closer to the problem.

https://bugs.freedesktop.org/attachment.cgi?id=48023
( password: 1111 )

->bProtectForm:0
-> can be edited and saved in the first iteration

after closing and reloading this is not possible to edit anymore. the error described in the bug report pops up.
->bProtectForm:1



https://bugs.freedesktop.org/show_bug.cgi?id=43229

seems to be already saved by libreoffice, because the error pops up by default.

-> loads with
->bProtectForm:1


Where is the problem? It's at: sw/source/filter/ww8/wrtww8.cxx WriteDop()

rDop.lKeyProtDoc is set to a value so the form protection mode get's enabled while saving this file. If you load this file again it will now have the form protection mode enabled. This additional check for lKeyProtDoc came in with 2559ef0f64b7a9a593d60edfcc8107f3a13ee5e1 in 2010.

This fProtEnabled will bes PROTECT_FORM to true at sw/source/filter/ww8/ww8par.cxx ImportDop().

If this is really the root of the problem all ww8 documents with enabled protection which were opened/edited and saved since then will have this form protection flag enabled and are not editable...

--- snap ---


Hopefully this will get fixed sometime :)


Thomas


diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 182521d..3c3537ff 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -721,9 +721,9 @@ bool SwPaM::HasReadonlySel( bool bFormView, bool bAnnotationMode ) const
             bool bAtStartA = pA != NULL && pA->GetMarkStart() == *GetPoint();
             bool bAtStartB = pB != NULL && pB->GetMarkStart() == *GetMark();
             bRet = ( pA != pB ) || bAtStartA || bAtStartB;
-            bool bProtectForm = pDoc->get( IDocumentSettingAccess::PROTECT_FORM );
-            if ( bProtectForm )
-                bRet |= ( pA == NULL || pB == NULL );
+            //bool bProtectForm = pDoc->get( IDocumentSettingAccess::PROTECT_FORM );
+            //if ( bProtectForm )
+            //    bRet |= ( pA == NULL || pB == NULL );
         }
     }
     else

From 78c83d30b8b0116c72adffa73f215cdb6cd682f9 Mon Sep 17 00:00:00 2001
From: Thomas Arnhold <thomas@arnhold.org>
Date: Sun, 2 Jun 2013 21:17:49 +0200
Subject: [PATCH] debug

Change-Id: Iaafc73ed23eefa9893785d6eb4fad4e164e7c6c8
---
 TODO.txt                                 | 27 +++++++++++++++++++++++++++
 sw/source/core/crsr/crbm.cxx             |  1 +
 sw/source/core/crsr/pam.cxx              |  5 +++++
 sw/source/core/doc/doc.cxx               |  3 +++
 sw/source/core/docnode/section.cxx       |  2 ++
 sw/source/core/layout/trvlfrm.cxx        |  1 +
 sw/source/filter/ww8/wrtw8sty.cxx        |  5 ++++-
 sw/source/filter/ww8/wrtww8.cxx          |  9 +++++++++
 sw/source/filter/ww8/wrtww8.hxx          |  5 ++++-
 sw/source/filter/ww8/ww8par.cxx          |  5 ++++-
 sw/source/ui/uno/SwXDocumentSettings.cxx |  2 ++
 11 files changed, 62 insertions(+), 3 deletions(-)
 create mode 100644 TODO.txt

diff --git a/TODO.txt b/TODO.txt
new file mode 100644
index 0000000..b148f40
--- /dev/null
+++ b/TODO.txt
@@ -0,0 +1,27 @@
+https://bugs.freedesktop.org/attachment.cgi?id=48023
+( password: 1111 )
+
+->bProtectForm:0
+-> can be edited and saved in the first iteration
+
+after closing and reloading this is not possible to edit anymore. the error described in the bug 
report pops up.
+->bProtectForm:1
+
+problem at sw/source/filter/ww8/wrtww8.cxx
+
+
+
+https://bugs.freedesktop.org/show_bug.cgi?id=43229
+
+seems to be already saved by libreoffice, because the error pops up by default.
+
+-> loads with
+->bProtectForm:1
+
+
+
+
+
+export form protected doc to odt -> form protection is present and not undoable!
+
+* moreover the edit file button is pressed down
diff --git a/sw/source/core/crsr/crbm.cxx b/sw/source/core/crsr/crbm.cxx
index b61575f..225a18d 100644
--- a/sw/source/core/crsr/crbm.cxx
+++ b/sw/source/core/crsr/crbm.cxx
@@ -209,6 +209,7 @@ bool SwCrsrShell::GoPrevBookmark()
 
 bool SwCrsrShell::IsFormProtected()
 {
+    SAL_WARN("me", "SwCrsrShell::IsFormProtected PROTECT_FORM:" << 
getIDocumentSettingAccess()->get(IDocumentSettingAccess::PROTECT_FORM));
     return getIDocumentSettingAccess()->get(IDocumentSettingAccess::PROTECT_FORM);
 }
 
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 182521d..cb3ef47 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -722,8 +722,13 @@ bool SwPaM::HasReadonlySel( bool bFormView, bool bAnnotationMode ) const
             bool bAtStartB = pB != NULL && pB->GetMarkStart() == *GetMark();
             bRet = ( pA != pB ) || bAtStartA || bAtStartB;
             bool bProtectForm = pDoc->get( IDocumentSettingAccess::PROTECT_FORM );
+            // here's the difference between both formats
+            // bProtectForm in only true for xls format
+            SAL_WARN("me", "bProtectForm:" << bProtectForm);
             if ( bProtectForm )
+            {
                 bRet |= ( pA == NULL || pB == NULL );
+            }
         }
     }
     else
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index db23e35..21a1667 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -306,7 +306,10 @@ void SwDoc::set(/*[in]*/ DocumentSettingId id, /*[in]*/ bool value)
             break;
 
         case PROTECT_FORM:
+            {
+            SAL_WARN("me", "SwDoc::set() PROTECT_FORM:" << value);
             mbProtectForm = value;
+            }
             break;
 
         case TABS_RELATIVE_TO_INDENT:
diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx
index 54c3e58..cbdae13 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -342,6 +342,8 @@ bool SwSection::IsProtect() const
 {
     SwSectionFmt *const pFmt( GetFmt() );
     OSL_ENSURE(pFmt, "SwSection::IsProtect: no format?");
+SAL_WARN("section", "IsCntntProtected():" << pFmt->GetProtect().IsCntntProtected());
+SAL_WARN("section", "IsProtectFlag():" << IsProtectFlag());
     return (pFmt)
         ?   pFmt->GetProtect().IsCntntProtected()
         :   IsProtectFlag();
diff --git a/sw/source/core/layout/trvlfrm.cxx b/sw/source/core/layout/trvlfrm.cxx
index 0d9fd9c..12b7903 100644
--- a/sw/source/core/layout/trvlfrm.cxx
+++ b/sw/source/core/layout/trvlfrm.cxx
@@ -1728,6 +1728,7 @@ sal_Bool SwFrm::IsProtected() const
     {
         const SwDoc *pDoc=((SwCntntFrm*)this)->GetNode()->GetDoc();
         bool isFormProtected=pDoc->get(IDocumentSettingAccess::PROTECT_FORM );
+        //SAL_WARN("me", "SwFrm::IsProtected PROTECT_FORM:" << isFormProtected);
         if (isFormProtected)
         {
             return sal_False; // TODO a hack for now, well deal with it laster, I we return true 
here we have a "double" locking
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 6d52d6b..9677c10 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -1218,8 +1218,10 @@ void WW8_WrPlcSepx::OutHeaderFooter( WW8Export& rWrt, bool bHeader,
 
 void MSWordSections::NeedsDocumentProtected(const WW8_SepInfo &rInfo)
 {
-    if (rInfo.IsProtected())
+    if (rInfo.IsProtected()) {
+        SAL_WARN("wrtme", "mbDocumentIsProtected=true");
         mbDocumentIsProtected = true;
+    }
 }
 
 bool WW8_SepInfo::IsProtected() const
@@ -1236,6 +1238,7 @@ bool WW8_SepInfo::IsProtected() const
             bRet = true;
         }
     }
+    SAL_WARN("wrtme", "IsProtected():" << bRet);
     return bRet;
 }
 
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 08bf24b..55eaf17 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -267,13 +267,22 @@ static void WriteDop( WW8Export& rWrt )
         rDop.lKeyProtDoc = pDocShell->GetModifyPasswordHash();
     }
 
+    // doc has a protection key, so fProtEnabled gets true
+    // saving will add form protection to the document
+    // loading this file again now has form protection enabled
+    SAL_WARN("me2", "rDop.lKeyProtDoc:" << rDop.lKeyProtDoc);
     if ((rWrt.pSepx && rWrt.pSepx->DocumentIsProtected()) ||
         rDop.lKeyProtDoc != 0)
     {
+        // when saving a document with bProtectForm:0
+        // this here get's entered and so the form protection get's enabled!
+        // after a reload it's PROTECT_FORM:1
+        SAL_WARN("me2", "fProtEnabled = 1");
         rDop.fProtEnabled =  1;
     }
     else
     {
+        SAL_WARN("me2", "fProtEnabled = 0");
         rDop.fProtEnabled = 0;
     }
 
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index c48e101..0d6cd7d 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -203,7 +203,10 @@ public:
     /// Number of columns of the provided WW8_SepInfo.
     sal_uInt16 NumberOfColumns( const SwDoc &rDoc, const WW8_SepInfo& rInfo ) const;
 
-    bool DocumentIsProtected() const { return mbDocumentIsProtected; }
+    bool DocumentIsProtected() const {
+        SAL_WARN("wrtme", "DocumentIsProtected():" << mbDocumentIsProtected);
+        return mbDocumentIsProtected;
+    }
 
     /// The most recent WW8_SepInfo.
     const WW8_SepInfo* CurrentSectionInfo();
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 598385a..e23bf8e 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -1610,8 +1610,10 @@ void SwWW8ImplReader::ImportDop()
     mpDocShell->SetModifyPasswordHash(pWDop->lKeyProtDoc);
 
     const SvtFilterOptions& rOpt = SvtFilterOptions::Get();
-    if (rOpt.IsUseEnhancedFields())
+    if (rOpt.IsUseEnhancedFields()) {
+        SAL_WARN("me", "set3 PROTECT_FORM:" << pWDop->fProtEnabled);
         rDoc.set(IDocumentSettingAccess::PROTECT_FORM, pWDop->fProtEnabled );
+    }
 }
 
 void SwWW8ImplReader::ImportDopTypography(const WW8DopTypography &rTypo)
@@ -3987,6 +3989,7 @@ void wwSectionManager::InsertSegments()
         {
             // here we have the special case that the whole document is protected, with the 
execption of this section.
             // I want to address this when I do the section rework, so for the moment we disable 
the overall protection then...
+            SAL_WARN("me", "set4 PROTECT_FORM:false");
             mrReader.rDoc.set(IDocumentSettingAccess::PROTECT_FORM, false );
         }
 
diff --git a/sw/source/ui/uno/SwXDocumentSettings.cxx b/sw/source/ui/uno/SwXDocumentSettings.cxx
index 080f3b7..83288a9 100644
--- a/sw/source/ui/uno/SwXDocumentSettings.cxx
+++ b/sw/source/ui/uno/SwXDocumentSettings.cxx
@@ -687,6 +687,7 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
         case HANDLE_PROTECT_FORM:
         {
             sal_Bool bTmp = *(sal_Bool*)rValue.getValue();
+            SAL_WARN("me", "set PROTECT_FORM:" << (bTmp ? 1 : 0));
             mpDoc->set(IDocumentSettingAccess::PROTECT_FORM, bTmp);
         }
         break;
@@ -1110,6 +1111,7 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & 
rInf
         case HANDLE_PROTECT_FORM:
         {
             sal_Bool bTmp = mpDoc->get(IDocumentSettingAccess::PROTECT_FORM);
+            SAL_WARN("me", "set2 PROTECT_FORM:" << (bTmp ? 1 : 0));
             rValue.setValue( &bTmp, ::getBooleanCppuType() );
         }
         break;
-- 
1.8.3


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.